Beispiel #1
0
int gbr_remote_delta(const char *name, git_branch_t type, struct gbr_dump_context *ctx)
{
	char tbuf[32];
	struct gbr_sha sha;
	int err;

	ctx->local_name = name;
	ctx->uptodate_remotes = 0;
	err = git_revparse_single(&ctx->local_obj, ctx->repo, name);
	if (err == 0) {
		printf("%s %s %s",
		       gbr_ctime_object(tbuf, sizeof(tbuf), ctx->local_obj),
		       name,
		       gbr_sha(&sha, git_object_id(ctx->local_obj), ctx->abbrev));
		gbr_for_each_remote(ctx->repo, dump_matching_branch, ctx);
		git_object_free(ctx->local_obj);
	} else {
		printf("%s ERROR [%d] %s", name, err, giterr_last()->message);
	}

	printf("\n");

	if (ctx->prune && ctx->uptodate_remotes > 0) {
		do_prune(ctx->repo, name);
	}

	return err;
}
Beispiel #2
0
void test_refs_read__nested_symbolic(void)
{
   // lookup a nested symbolic reference
	git_reference *reference, *resolved_ref;
	git_object *object;
	git_oid id;

	cl_git_pass(git_reference_lookup(&reference, g_repo, head_tracker_sym_ref_name));
	cl_assert(git_reference_type(reference) & GIT_REF_SYMBOLIC);
	cl_assert(git_reference_is_packed(reference) == 0);
	cl_assert_equal_s(reference->name, head_tracker_sym_ref_name);

	cl_git_pass(git_reference_resolve(&resolved_ref, reference));
	cl_assert(git_reference_type(resolved_ref) == GIT_REF_OID);

	cl_git_pass(git_object_lookup(&object, g_repo, git_reference_target(resolved_ref), GIT_OBJ_ANY));
	cl_assert(object != NULL);
	cl_assert(git_object_type(object) == GIT_OBJ_COMMIT);

	git_oid_fromstr(&id, current_master_tip);
	cl_assert(git_oid_cmp(&id, git_object_id(object)) == 0);

	git_object_free(object);

	git_reference_free(reference);
	git_reference_free(resolved_ref);
}
Beispiel #3
0
int git_branch_create(
		git_reference **ref_out,
		git_repository *repository,
		const char *branch_name,
		const git_object *target,
		int force)
{
	git_object *commit = NULL;
	git_reference *branch = NULL;
	git_buf canonical_branch_name = GIT_BUF_INIT;
	int error = -1;

	assert(branch_name && target && ref_out);
	assert(git_object_owner(target) == repository);

	if (git_object_peel(&commit, (git_object *)target, GIT_OBJ_COMMIT) < 0)
		return create_error_invalid("The given target does not resolve to a commit");

	if (git_buf_joinpath(&canonical_branch_name, GIT_REFS_HEADS_DIR, branch_name) < 0)
		goto cleanup;

	error = git_reference_create_oid(&branch, repository,
		git_buf_cstr(&canonical_branch_name), git_object_id(commit), force);

	if (!error)
		*ref_out = branch;

cleanup:
	git_object_free(commit);
	git_buf_free(&canonical_branch_name);
	return error;
}
Beispiel #4
0
static int write_tag_annotation(
    git_oid *oid,
    git_repository *repo,
    const char *tag_name,
    const git_object *target,
    const git_signature *tagger,
    const char *message)
{
    git_buf tag = GIT_BUF_INIT;
    git_odb *odb;

    git_oid__writebuf(&tag, "object ", git_object_id(target));
    git_buf_printf(&tag, "type %s\n", git_object_type2string(git_object_type(target)));
    git_buf_printf(&tag, "tag %s\n", tag_name);
    git_signature__writebuf(&tag, "tagger ", tagger);
    git_buf_putc(&tag, '\n');

    if (git_buf_puts(&tag, message) < 0)
        goto on_error;

    if (git_repository_odb__weakptr(&odb, repo) < 0)
        goto on_error;

    if (git_odb_write(oid, odb, tag.ptr, tag.size, GIT_OBJ_TAG) < 0)
        goto on_error;

    git_buf_free(&tag);
    return 0;

on_error:
    git_buf_free(&tag);
    giterr_set(GITERR_OBJECT, "Failed to create tag annotation.");
    return -1;
}
Beispiel #5
0
int git_commit_nth_gen_ancestor(
	git_commit **ancestor,
	const git_commit *commit,
	unsigned int n)
{
	git_commit *current, *parent;
	int error;

	assert(ancestor && commit);

	current = (git_commit *)commit;

	if (n == 0)
		return git_commit_lookup(
			ancestor,
			commit->object.repo,
			git_object_id((const git_object *)commit));

	while (n--) {
		error = git_commit_parent(&parent, (git_commit *)current, 0);

		if (current != commit)
			git_commit_free(current);

		if (error < 0)
			return error;

		current = parent;
	}

	*ancestor = parent;
	return 0;
}
Beispiel #6
0
void test_repo_head__setting_head_updates_reflog(void)
{
	git_object *tag;
	git_signature *sig;
	git_annotated_commit *annotated;

	cl_git_pass(git_signature_now(&sig, "me", "*****@*****.**"));

	cl_git_pass(git_repository_set_head(repo, "refs/heads/haacked"));
	cl_git_pass(git_repository_set_head(repo, "refs/heads/unborn"));
	cl_git_pass(git_revparse_single(&tag, repo, "tags/test"));
	cl_git_pass(git_repository_set_head_detached(repo, git_object_id(tag)));
	cl_git_pass(git_repository_set_head(repo, "refs/heads/haacked"));

	test_reflog(repo, 2, NULL, "refs/heads/haacked", "*****@*****.**", "checkout: moving from master to haacked");
	test_reflog(repo, 1, NULL, "tags/test^{commit}", "*****@*****.**", "checkout: moving from unborn to e90810b8df3e80c413d903f631643c716887138d");
	test_reflog(repo, 0, "tags/test^{commit}", "refs/heads/haacked", "*****@*****.**", "checkout: moving from e90810b8df3e80c413d903f631643c716887138d to haacked");

	cl_git_pass(git_annotated_commit_from_revspec(&annotated, repo, "haacked~0"));
	cl_git_pass(git_repository_set_head_detached_from_annotated(repo, annotated));

	test_reflog(repo, 0, NULL, "refs/heads/haacked", "*****@*****.**", "checkout: moving from haacked to haacked~0");

	git_annotated_commit_free(annotated);
	git_object_free(tag);
	git_signature_free(sig);
}
Beispiel #7
0
void test_reset_mixed__reflog_is_correct(void)
{
	git_buf buf = GIT_BUF_INIT;
	const char *exp_msg = "commit: Updating test data so we can test inter-hunk-context";

	reflog_check(repo, "HEAD", 9, "*****@*****.**", exp_msg);
	reflog_check(repo, "refs/heads/master", 9, "*****@*****.**", exp_msg);

	/* Branch not moving, no reflog entry */
	cl_git_pass(git_revparse_single(&target, repo, "HEAD^{commit}"));
	cl_git_pass(git_reset(repo, target, GIT_RESET_MIXED, NULL));
	reflog_check(repo, "HEAD", 9, "*****@*****.**", exp_msg);
	reflog_check(repo, "refs/heads/master", 9, "*****@*****.**", exp_msg);

	git_object_free(target);
	target = NULL;

	/* Moved branch, expect default message */
	cl_git_pass(git_revparse_single(&target, repo, "HEAD~^{commit}"));
	git_buf_clear(&buf);
	cl_git_pass(git_buf_printf(&buf, "reset: moving to %s", git_oid_tostr_s(git_object_id(target))));
	cl_git_pass(git_reset(repo, target, GIT_RESET_MIXED, NULL));
	reflog_check(repo, "HEAD", 10, NULL, git_buf_cstr(&buf));
	reflog_check(repo, "refs/heads/master", 10, NULL, git_buf_cstr(&buf));

	git_buf_free(&buf);
}
Beispiel #8
0
int git_annotated_commit_from_revspec(
	git_annotated_commit **out,
	git_repository *repo,
	const char *revspec)
{
	git_object *obj, *commit;
	int error;

	assert(out && repo && revspec);

	if ((error = git_revparse_single(&obj, repo, revspec)) < 0)
		return error;

	if ((error = git_object_peel(&commit, obj, GIT_OBJ_COMMIT))) {
		git_object_free(obj);
		return error;
	}

	error = annotated_commit_init(out, repo, git_object_id(commit), revspec, NULL);

	git_object_free(obj);
	git_object_free(commit);

	return error;
}
Beispiel #9
0
void test_refs_branches_create__can_force_create_over_an_existing_branch(void)
{
	retrieve_known_commit(&target, repo);

	cl_git_pass(git_branch_create(&branch_target_oid, repo, "br2", target, 1));
	cl_git_pass(git_oid_cmp(&branch_target_oid, git_object_id(target)));
}
Beispiel #10
0
void test_refs_branches_create__can_create_a_local_branch(void)
{
	retrieve_known_commit(&target, repo);

	cl_git_pass(git_branch_create(&branch_target_oid, repo, NEW_BRANCH_NAME, target, 0));
	cl_git_pass(git_oid_cmp(&branch_target_oid, git_object_id(target)));
}
Beispiel #11
0
static void retrieve_target_from_oid(git_commit **out, git_repository *repo, const char *sha)
{
	git_object *obj;

	cl_git_pass(git_revparse_single(&obj, repo, sha));
	cl_git_pass(git_commit_lookup(out, repo, git_object_id(obj)));
	git_object_free(obj);
}
Beispiel #12
0
int git_reset(
	git_repository *repo,
	const git_object *target,
	git_reset_t reset_type,
	const git_checkout_options *checkout_opts)
{
	return reset(repo, target, git_oid_tostr_s(git_object_id(target)), reset_type, checkout_opts);
}
Beispiel #13
0
PyObject *
Object_richcompare(PyObject *o1, PyObject *o2, int op)
{
    PyObject *res;
    Object *obj1;
    Object *obj2;

    if (!PyObject_TypeCheck(o2, &ObjectType)) {
        Py_INCREF(Py_NotImplemented);
        return Py_NotImplemented;
    }

    switch (op) {
        case Py_NE:
            obj1 = (Object *) o1;
            obj2 = (Object *) o2;
            if (git_oid_equal(git_object_id(obj1->obj), git_object_id(obj2->obj))) {
                res = Py_False;
            } else {
                res = Py_True;
            }
            break;
        case Py_EQ:
            obj1 = (Object *) o1;
            obj2 = (Object *) o2;
            if (git_oid_equal(git_object_id(obj1->obj), git_object_id(obj2->obj))) {
                res = Py_True;
            } else {
                res = Py_False;
            }
            break;
        case Py_LT:
        case Py_LE:
        case Py_GT:
        case Py_GE:
            Py_INCREF(Py_NotImplemented);
            return Py_NotImplemented;
        default:
            PyErr_Format(PyExc_RuntimeError, "Unexpected '%d' op", op);
            return NULL;
    }

    Py_INCREF(res);
    return res;
}
Beispiel #14
0
Py_hash_t
Object_hash(Object *object)
{
    const git_oid *oid = git_object_id(object->obj);
    PyObject *py_oid = git_oid_to_py_str(oid);
    Py_hash_t ret = PyObject_Hash(py_oid);
    Py_DECREF(py_oid);
    return ret;
}
Beispiel #15
0
void test_stash_drop__dropping_the_top_stash_updates_the_stash_reference(void)
{
	git_object *next_top_stash;
	git_oid oid;

	push_three_states();

	retrieve_top_stash_id(&oid);

	cl_git_pass(git_revparse_single(&next_top_stash, repo, "stash@{1}"));
	cl_assert_equal_i(false, git_oid_cmp(&oid, git_object_id(next_top_stash)) == 0);

	cl_git_pass(git_stash_drop(repo, 0));

	retrieve_top_stash_id(&oid);

	cl_git_pass(git_oid_cmp(&oid, git_object_id(next_top_stash)));
}
Beispiel #16
0
int git_branch_create(
		git_oid *oid_out,
		git_repository *repo,
		const char *branch_name,
		const git_object *target,
		int force)
{
	git_otype target_type = GIT_OBJ_BAD;
	git_object *commit = NULL;
	git_reference *branch = NULL;
	git_buf canonical_branch_name = GIT_BUF_INIT;
	int error = -1;

	assert(repo && branch_name && target && oid_out);

	if (git_object_owner(target) != repo)
		return create_error_invalid("The given target does not belong to this repository");

	target_type = git_object_type(target);

	switch (target_type)
	{
	case GIT_OBJ_TAG:
		if (git_tag_peel(&commit, (git_tag *)target) < 0)
			goto cleanup;

		if (git_object_type(commit) != GIT_OBJ_COMMIT) {
			create_error_invalid("The given target does not resolve to a commit");
			goto cleanup;
		}
		break;

	case GIT_OBJ_COMMIT:
		commit = (git_object *)target;
		break;

	default:
		return create_error_invalid("Only git_tag and git_commit objects are valid targets.");
	}

	if (git_buf_joinpath(&canonical_branch_name, GIT_REFS_HEADS_DIR, branch_name) < 0)
		goto cleanup;

	if (git_reference_create_oid(&branch, repo, git_buf_cstr(&canonical_branch_name), git_object_id(commit), force) < 0)
		goto cleanup;

	git_oid_cpy(oid_out, git_reference_oid(branch));
	error = 0;

cleanup:
	if (target_type == GIT_OBJ_TAG)
		git_object_free(commit);

	git_reference_free(branch);
	git_buf_free(&canonical_branch_name);
	return error;
}
Beispiel #17
0
void retrieve_top_stash_id(git_oid *out)
{
	git_object *top_stash;

	cl_git_pass(git_revparse_single(&top_stash, repo, "stash@{0}"));
	cl_git_pass(git_reference_name_to_id(out, repo, GIT_REFS_STASH_FILE));

	cl_assert_equal_i(true, git_oid_cmp(out, git_object_id(top_stash)) == 0);
}
int CRepositoryBrowser::ReadTreeRecursive(git_repository &repo, git_tree * tree, CShadowFilesTree * treeroot)
{
	size_t count = git_tree_entrycount(tree);

	for (int i = 0; i < count; ++i)
	{
		const git_tree_entry *entry = git_tree_entry_byindex(tree, i);
		if (entry == NULL)
			continue;
		int mode = git_tree_entry_filemode(entry);

		CString base = CUnicodeUtils::GetUnicode(git_tree_entry_name(entry), CP_UTF8);

		git_object *object = NULL;
		git_tree_entry_to_object(&object, &repo, entry);
		if (object == NULL)
			continue;

		const git_oid *oid = git_object_id(object);
		CShadowFilesTree * pNextTree = &treeroot->m_ShadowTree[base];
		pNextTree->m_sName = base;
		pNextTree->m_pParent = treeroot;
		pNextTree->m_hash = CGitHash((char *)oid->id);

		if (mode & S_IFDIR)
		{
			pNextTree->m_bFolder = true;

			TVINSERTSTRUCT tvinsert = {0};
			tvinsert.hParent = treeroot->m_hTree;
			tvinsert.hInsertAfter = TVI_SORT;
			tvinsert.itemex.mask = TVIF_DI_SETITEM | TVIF_PARAM | TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_STATE;
			tvinsert.itemex.pszText = base.GetBuffer(base.GetLength());
			tvinsert.itemex.lParam = (LPARAM)pNextTree;
			tvinsert.itemex.iImage = m_nIconFolder;
			tvinsert.itemex.iSelectedImage = m_nOpenIconFolder;
			pNextTree->m_hTree = m_RepoTree.InsertItem(&tvinsert);
			base.ReleaseBuffer();

			ReadTreeRecursive(repo, (git_tree*)object, pNextTree);
		}
		else
		{
			git_blob * blob;
			git_blob_lookup(&blob, &repo, oid);
			if (blob == NULL)
				continue;

			pNextTree->m_iSize = git_blob_rawsize(blob);
			git_blob_free(blob);
		}

		git_object_free(object);
	}

	return 0;
}
Beispiel #19
0
static int parse_revision(struct parse_state *ps, const char *revstr)
{
	git_revspec rs;
	char str[GIT_OID_HEXSZ + 1];

	if (!ps->repo) {
		if (!ps->repodir)
			ps->repodir = ".";
		check(git_repository_open_ext(&ps->repo, ps->repodir, 0, NULL),
			"Could not open repository from", ps->repodir);
	}

	check(git_revparse(&rs, ps->repo, revstr), "Could not parse", revstr);

	if ((rs.flags & GIT_REVPARSE_SINGLE) != 0) {
		git_oid_tostr(str, sizeof(str), git_object_id(rs.from));
		printf("%s\n", str);
		git_object_free(rs.from);
	}
	else if ((rs.flags & GIT_REVPARSE_RANGE) != 0) {
		git_oid_tostr(str, sizeof(str), git_object_id(rs.to));
		printf("%s\n", str);
		git_object_free(rs.to);

		if ((rs.flags & GIT_REVPARSE_MERGE_BASE) != 0) {
			git_oid base;
			check(git_merge_base(&base, ps->repo,
				git_object_id(rs.from), git_object_id(rs.to)),
				"Could not find merge base", revstr);

			git_oid_tostr(str, sizeof(str), &base);
			printf("%s\n", str);
		}

		git_oid_tostr(str, sizeof(str), git_object_id(rs.from));
		printf("^%s\n", str);
		git_object_free(rs.from);
	}
	else {
		check(0, "Invalid results from git_revparse", revstr);
	}

	return 0;
}
Beispiel #20
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;
}
Beispiel #21
0
PyObject *
Object_oid__get__(Object *self)
{
    const git_oid *oid;

    oid = git_object_id(self->obj);
    assert(oid);

    return git_oid_to_python(oid->id);
}
Beispiel #22
0
PyObject *
Object_hex__get__(Object *self)
{
    const git_oid *oid;

    oid = git_object_id(self->obj);
    assert(oid);

    return git_oid_to_py_str(oid);
}
Beispiel #23
0
void test_repo_head__set_head_detached_Fails_when_the_object_isnt_a_commitish(void)
{
	git_object *blob;

	cl_git_pass(git_revparse_single(&blob, repo, "point_to_blob"));

	cl_git_fail(git_repository_set_head_detached(repo, git_object_id(blob)));

	git_object_free(blob);
}
Beispiel #24
0
void test_checkout_typechange__checkout_typechanges_safe(void)
{
    int i;
    git_object *obj;
    git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;

    for (i = 0; g_typechange_oids[i] != NULL; ++i) {
        cl_git_pass(git_revparse_single(&obj, g_repo, g_typechange_oids[i]));

        opts.checkout_strategy = GIT_CHECKOUT_FORCE;

        /* There are bugs in some submodule->tree changes that prevent
         * SAFE from passing here, even though the following should work:
         */
        /* !i ? GIT_CHECKOUT_FORCE : GIT_CHECKOUT_SAFE; */

        cl_git_pass(git_checkout_tree(g_repo, obj, &opts));

        cl_git_pass(
            git_repository_set_head_detached(g_repo, git_object_id(obj)));

        assert_workdir_matches_tree(g_repo, git_object_id(obj), NULL, true);

        git_object_free(obj);

        if (!g_typechange_empty[i]) {
            cl_assert(git_path_isdir("typechanges"));
            cl_assert(git_path_exists("typechanges/a"));
            cl_assert(git_path_exists("typechanges/b"));
            cl_assert(git_path_exists("typechanges/c"));
            cl_assert(git_path_exists("typechanges/d"));
            cl_assert(git_path_exists("typechanges/e"));
        } else {
            cl_assert(git_path_isdir("typechanges"));
            cl_assert(!git_path_exists("typechanges/a"));
            cl_assert(!git_path_exists("typechanges/b"));
            cl_assert(!git_path_exists("typechanges/c"));
            cl_assert(!git_path_exists("typechanges/d"));
            cl_assert(!git_path_exists("typechanges/e"));
        }
    }
}
Beispiel #25
0
/**
 * ggit_object_get_id:
 * @object: a #GgitObject.
 *
 * Gets the #GgitOId of @object.
 *
 * Returns: (transfer full): the #GgitOId of the object.
 */
GgitOId *
ggit_object_get_id (GgitObject *object)
{
	const git_oid *oid;

	g_return_val_if_fail (GGIT_IS_OBJECT (object), NULL);

	oid = git_object_id (object->priv->obj);

	return _ggit_oid_new ((git_oid *)oid);
}
Beispiel #26
0
/* Helpers */
static void test_object(const char *spec, const char *expected_oid)
{
	char objstr[64] = {0};

	cl_git_pass(git_revparse_single(&g_obj, g_repo, spec));
	git_oid_fmt(objstr, git_object_id(g_obj));
	cl_assert_equal_s(objstr, expected_oid);

	git_object_free(g_obj);
	g_obj = NULL;
}
Beispiel #27
0
/*
 *  call-seq:
 *    obj.remove_note(data = {}) -> boolean
 *
 *  Removes a +note+ from +object+, with the given +data+
 *  arguments, passed as a +Hash+:
 *
 *  - +:committer+ (optional): a hash with the signature for the committer,
 *    defaults to the signature from the configuration
 *  - +:author+ (optional): a hash with the signature for the author,
 *    defaults to the signature from the configuration
 *  - +:ref+: (optional): canonical name of the reference to use, defaults to "refs/notes/commits"
 *
 *  When the note is successfully removed +true+ will be
 *  returned as a +Boolean+.
 *
 *    author = {:email=>"*****@*****.**", :time=>Time.now, :name=>"Vicent Mart\303\255"}
 *
 *    obj.remove_note(
 *      :author    => author,
 *      :committer => author,
 *      :ref       => 'refs/notes/builds'
 *    )
 */
static VALUE rb_git_note_remove(int argc, VALUE *argv, VALUE self)
{
	int error = 0;
	const char *notes_ref = NULL;
	git_repository *repo = NULL;
	git_signature *author, *committer;
	git_object *target = NULL;
	VALUE rb_data;
	VALUE rb_ref = Qnil;
	VALUE rb_author = Qnil;
	VALUE rb_committer = Qnil;
	VALUE owner;

	Data_Get_Struct(self, git_object, target);

	owner = rugged_owner(self);
	Data_Get_Struct(owner, git_repository, repo);

	rb_scan_args(argc, argv, "01", &rb_data);

	if (!NIL_P(rb_data)) {
		Check_Type(rb_data, T_HASH);

		rb_ref = rb_hash_aref(rb_data, CSTR2SYM("ref"));
		if (!NIL_P(rb_ref)) {
			Check_Type(rb_ref, T_STRING);
			notes_ref = StringValueCStr(rb_ref);
		}

		rb_committer = rb_hash_aref(rb_data, CSTR2SYM("committer"));
		rb_author = rb_hash_aref(rb_data, CSTR2SYM("author"));
	}

	committer = rugged_signature_get(rb_committer, repo);
	author = rugged_signature_get(rb_author, repo);

	error = git_note_remove(
			repo,
			notes_ref,
			author,
			committer,
			git_object_id(target));

	git_signature_free(author);
	git_signature_free(committer);

	if (error == GIT_ENOTFOUND)
		return Qfalse;

	rugged_exception_check(error);

	return Qtrue;
}
Beispiel #28
0
static int push_spec(git_repository *repo, git_revwalk *walk, const char *spec, int hide)
{
	int error;
	git_object *obj;

	if ((error = git_revparse_single(&obj, repo, spec)) < 0)
		return error;

	error = push_commit(walk, git_object_id(obj), hide);
	git_object_free(obj);
	return error;
}
Beispiel #29
0
int git_object_peel(
	git_object **peeled,
	const git_object *object,
	git_otype target_type)
{
	git_object *source, *deref = NULL;
	int error;

	if (target_type != GIT_OBJ_TAG && 
		target_type != GIT_OBJ_COMMIT && 
		target_type != GIT_OBJ_TREE && 
		target_type != GIT_OBJ_BLOB && 
		target_type != GIT_OBJ_ANY)
			return GIT_EINVALIDSPEC;

	assert(object && peeled);

	if (git_object_type(object) == target_type)
		return git_object__dup(peeled, (git_object *)object);

	source = (git_object *)object;

	while (!(error = dereference_object(&deref, source))) {

		if (source != object)
			git_object_free(source);

		if (git_object_type(deref) == target_type) {
			*peeled = deref;
			return 0;
		}

		if (target_type == GIT_OBJ_ANY &&
			git_object_type(deref) != git_object_type(object))
		{
			*peeled = deref;
			return 0;
		}

		source = deref;
		deref = NULL;
	}

	if (source != object)
		git_object_free(source);

	git_object_free(deref);

	if (error)
		error = peel_error(error, git_object_id(object), target_type);

	return error;
}
Beispiel #30
0
static int push_commit(git_revwalk *walk, const git_oid *oid, int uninteresting, int from_glob)
{
	git_oid commit_id;
	int error;
	git_object *obj, *oobj;
	git_commit_list_node *commit;
	git_commit_list *list;

	if ((error = git_object_lookup(&oobj, walk->repo, oid, GIT_OBJ_ANY)) < 0)
		return error;

	error = git_object_peel(&obj, oobj, GIT_OBJ_COMMIT);
	git_object_free(oobj);

	if (error == GIT_ENOTFOUND || error == GIT_EINVALIDSPEC || error == GIT_EPEEL) {
		/* If this comes from e.g. push_glob("tags"), ignore this */
		if (from_glob)
			return 0;

		giterr_set(GITERR_INVALID, "Object is not a committish");
		return -1;
	}
	if (error < 0)
		return error;

	git_oid_cpy(&commit_id, git_object_id(obj));
	git_object_free(obj);

	commit = git_revwalk__commit_lookup(walk, &commit_id);
	if (commit == NULL)
		return -1; /* error already reported by failed lookup */

	/* A previous hide already told us we don't want this commit  */
	if (commit->uninteresting)
		return 0;

	if (uninteresting)
		walk->did_hide = 1;
	else
		walk->did_push = 1;

	commit->uninteresting = uninteresting;
	list = walk->user_input;
	if (git_commit_list_insert(commit, &list) == NULL) {
		giterr_set_oom();
		return -1;
	}

	walk->user_input = list;

	return 0;
}