Esempio n. 1
0
PyObject *
Object_short_id__get__(Object *self)
{
    git_buf short_id = { NULL, 0, 0 };
    PyObject *py_short_id;

    int err = git_object_short_id(&short_id, self->obj);

    if (err != GIT_OK)
        return Error_set(err);

    py_short_id = to_unicode_n(short_id.ptr, short_id.size, NULL, "strict");
    git_buf_dispose(&short_id);
    return py_short_id;
}
Esempio n. 2
0
void test_object_shortid__select(void)
{
	git_oid full;
	git_object *obj;
	git_buf shorty = {0};

	git_oid_fromstr(&full, "ce013625030ba8dba906f756967f9e9ca394464a");
	cl_git_pass(git_object_lookup(&obj, _repo, &full, GIT_OBJ_ANY));
	cl_git_pass(git_object_short_id(&shorty, obj));
	cl_assert_equal_i(7, shorty.size);
	cl_assert_equal_s("ce01362", shorty.ptr);
	git_object_free(obj);

	git_oid_fromstr(&full, "038d718da6a1ebbc6a7780a96ed75a70cc2ad6e2");
	cl_git_pass(git_object_lookup(&obj, _repo, &full, GIT_OBJ_ANY));
	cl_git_pass(git_object_short_id(&shorty, obj));
	cl_assert_equal_i(7, shorty.size);
	cl_assert_equal_s("038d718", shorty.ptr);
	git_object_free(obj);

	git_oid_fromstr(&full, "dea509d097ce692e167dfc6a48a7a280cc5e877e");
	cl_git_pass(git_object_lookup(&obj, _repo, &full, GIT_OBJ_ANY));
	cl_git_pass(git_object_short_id(&shorty, obj));
	cl_assert_equal_i(9, shorty.size);
	cl_assert_equal_s("dea509d09", shorty.ptr);
	git_object_free(obj);

	git_oid_fromstr(&full, "dea509d0b3cb8ee0650f6ca210bc83f4678851ba");
	cl_git_pass(git_object_lookup(&obj, _repo, &full, GIT_OBJ_ANY));
	cl_git_pass(git_object_short_id(&shorty, obj));
	cl_assert_equal_i(9, shorty.size);
	cl_assert_equal_s("dea509d0b", shorty.ptr);
	git_object_free(obj);

	git_buf_free(&shorty);
}
Esempio n. 3
0
MasterlistInfo Masterlist::GetInfo(const boost::filesystem::path& path, bool shortID) {
    // Compare HEAD and working copy, and get revision info.
  GitHelper git;
  MasterlistInfo info;
  git.SetErrorMessage((boost::format(translate("An error occurred while trying to read the local masterlist's version. If this error happens again, try deleting the \".git\" folder in %1%.")) % path.parent_path().string()).str());

  if (!fs::exists(path)) {
    BOOST_LOG_TRIVIAL(info) << "Unknown masterlist revision: No masterlist present.";
    throw FileAccessError(translate("N/A: No masterlist present"));
  } else if (!git.IsRepository(path.parent_path())) {
    BOOST_LOG_TRIVIAL(info) << "Unknown masterlist revision: Git repository missing.";
    throw GitStateError(translate("Unknown: Git repository missing"));
  }

  BOOST_LOG_TRIVIAL(debug) << "Existing repository found, attempting to open it.";
  git.Call(git_repository_open(&git.GetData().repo, path.parent_path().string().c_str()));

  //Need to get the HEAD object, because the individual file has a different SHA.
  BOOST_LOG_TRIVIAL(info) << "Getting the Git object for the tree at HEAD.";
  git.Call(git_revparse_single(&git.GetData().object, git.GetData().repo, "HEAD"));

  BOOST_LOG_TRIVIAL(trace) << "Generating hex string for Git object ID.";
  if (shortID) {
    git.Call(git_object_short_id(&git.GetData().buffer, git.GetData().object));
    info.revision_id = git.GetData().buffer.ptr;
  } else {
    char c_rev[GIT_OID_HEXSZ + 1];
    info.revision_id = git_oid_tostr(c_rev, GIT_OID_HEXSZ + 1, git_object_id(git.GetData().object));
  }

  BOOST_LOG_TRIVIAL(trace) << "Getting date for Git object.";
  const git_oid * oid = git_object_id(git.GetData().object);
  git.Call(git_commit_lookup(&git.GetData().commit, git.GetData().repo, oid));
  git_time_t time = git_commit_time(git.GetData().commit);
  boost::locale::date_time dateTime(time);
  std::stringstream out;
  out << boost::locale::as::ftime("%Y-%m-%d") << dateTime;
  info.revision_date = out.str();

  BOOST_LOG_TRIVIAL(trace) << "Diffing masterlist HEAD and working copy.";
  info.is_modified = GitHelper::IsFileDifferent(path.parent_path(), path.filename().string());

  return info;
}
Esempio n. 4
0
static void action_delete_tag(tag_state *state)
{
	tag_options *opts = state->opts;
	git_object *obj;
	git_buf abbrev_oid = {0};

	check(!opts->tag_name, "Name required");

	check_lg2(git_revparse_single(&obj, state->repo, opts->tag_name),
			"Failed to lookup rev", opts->tag_name);

	check_lg2(git_object_short_id(&abbrev_oid, obj),
			"Unable to get abbreviated OID", opts->tag_name);

	check_lg2(git_tag_delete(state->repo, opts->tag_name),
			"Unable to delete tag", opts->tag_name);

	printf("Deleted tag '%s' (was %s)\n", opts->tag_name, abbrev_oid.ptr);

	git_buf_free(&abbrev_oid);
	git_object_free(obj);
}