Esempio n. 1
0
PyObject *
Commit_tree__get__(Commit *commit)
{
    git_tree *tree;
    Tree *py_tree;
    int err;

    err = git_commit_tree(&tree, commit->commit);
    if (err == GIT_ENOTFOUND) {
        char tree_id[GIT_OID_HEXSZ + 1] = { 0 };
        git_oid_fmt(tree_id, git_commit_tree_id(commit->commit));
        return PyErr_Format(GitError, "Unable to read tree %s", tree_id);
    }

    if (err < 0)
        return Error_set(err);

    py_tree = PyObject_New(Tree, &TreeType);
    if (py_tree) {
        Py_INCREF(commit->repo);
        py_tree->repo = commit->repo;
        py_tree->tree = (git_tree*)tree;
    }
    return (PyObject*)py_tree;
}
Esempio n. 2
0
void test_rebase_merge__commit(void)
{
	git_rebase *rebase;
	git_reference *branch_ref, *upstream_ref;
	git_annotated_commit *branch_head, *upstream_head;
	git_rebase_operation *rebase_operation;
	git_oid commit_id, tree_id, parent_id;
	git_signature *author;
	git_commit *commit;
	git_reflog *reflog;
	const git_reflog_entry *reflog_entry;

	cl_git_pass(git_reference_lookup(&branch_ref, repo, "refs/heads/beef"));
	cl_git_pass(git_reference_lookup(&upstream_ref, repo, "refs/heads/master"));

	cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref));
	cl_git_pass(git_annotated_commit_from_ref(&upstream_head, repo, upstream_ref));

	cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, NULL));

	cl_git_pass(git_rebase_next(&rebase_operation, rebase));
	cl_git_pass(git_rebase_commit(&commit_id, rebase, NULL, signature,
		NULL, NULL));

	cl_git_pass(git_commit_lookup(&commit, repo, &commit_id));

	git_oid_fromstr(&parent_id, "efad0b11c47cb2f0220cbd6f5b0f93bb99064b00");
	cl_assert_equal_i(1, git_commit_parentcount(commit));
	cl_assert_equal_oid(&parent_id, git_commit_parent_id(commit, 0));

	git_oid_fromstr(&tree_id, "4461379789c777d2a6c1f2ee0e9d6c86731b9992");
	cl_assert_equal_oid(&tree_id, git_commit_tree_id(commit));

	cl_assert_equal_s(NULL, git_commit_message_encoding(commit));
	cl_assert_equal_s("Modification 1 to beef\n", git_commit_message(commit));

	cl_git_pass(git_signature_new(&author,
		"Edward Thomson", "*****@*****.**", 1405621769, 0-(4*60)));
	cl_assert(git_signature__equal(author, git_commit_author(commit)));

	cl_assert(git_signature__equal(signature, git_commit_committer(commit)));

	/* Make sure the reflogs are updated appropriately */
	cl_git_pass(git_reflog_read(&reflog, repo, "HEAD"));
	cl_assert(reflog_entry = git_reflog_entry_byindex(reflog, 0));
	cl_assert_equal_oid(&parent_id, git_reflog_entry_id_old(reflog_entry));
	cl_assert_equal_oid(&commit_id, git_reflog_entry_id_new(reflog_entry));
	cl_assert_equal_s("rebase: Modification 1 to beef", git_reflog_entry_message(reflog_entry));

	git_reflog_free(reflog);
	git_signature_free(author);
	git_commit_free(commit);
	git_annotated_commit_free(branch_head);
	git_annotated_commit_free(upstream_head);
	git_reference_free(branch_ref);
	git_reference_free(upstream_ref);
	git_rebase_free(rebase);
}
Esempio n. 3
0
File: merge.c Progetto: mikeando/agb
//TODO: Add error handling.
static int commit_oid_to_tree(git_tree ** tree, git_repository * repo, git_oid * oid ) {
	if(!repo) return 1;
	git_commit * commit;
	git_commit_lookup(&commit, repo, oid);
	const git_oid * tree_oid = git_commit_tree_id(commit);
	git_tree_lookup(tree, repo, tree_oid);
	git_commit_free(commit);
	return 0;
}
Esempio n. 4
0
/*
 *  call-seq:
 *    commit.tree_id -> oid
 *
 *  Return the tree oid pointed at by this +commit+. The tree is
 *  returned as a String object.
 *
 *    commit.tree_id #=> "f148106ca58764adc93ad4e2d6b1d168422b9796"
 */
static VALUE rb_git_commit_tree_id_GET(VALUE self)
{
	git_commit *commit;
	const git_oid *tree_id;

	Data_Get_Struct(self, git_commit, commit);

	tree_id = git_commit_tree_id(commit);

	return rugged_create_oid(tree_id);
}
Esempio n. 5
0
ERL_NIF_TERM
geef_commit_tree_id(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
{
	const git_oid *id;
	geef_object *obj;
	ErlNifBinary bin;

	if (!enif_get_resource(env, argv[0], geef_object_type, (void **) &obj))
		return enif_make_badarg(env);

	id = git_commit_tree_id((git_commit *) obj->obj);

	if (geef_oid_bin(&bin, id) < 0)
		return geef_oom(env);

	return enif_make_binary(env, &bin);
}
Esempio n. 6
0
void test_rebase_inmemory__with_directories(void)
{
	git_rebase *rebase;
	git_reference *branch_ref, *upstream_ref;
	git_annotated_commit *branch_head, *upstream_head;
	git_rebase_operation *rebase_operation;
	git_oid commit_id, tree_id;
	git_commit *commit;
	git_rebase_options opts = GIT_REBASE_OPTIONS_INIT;

	opts.inmemory = true;

	git_oid_fromstr(&tree_id, "a4d6d9c3d57308fd8e320cf2525bae8f1adafa57");

	cl_git_pass(git_reference_lookup(&branch_ref, repo, "refs/heads/deep_gravy"));
	cl_git_pass(git_reference_lookup(&upstream_ref, repo, "refs/heads/veal"));

	cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref));
	cl_git_pass(git_annotated_commit_from_ref(&upstream_head, repo, upstream_ref));

	cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, &opts));

	cl_git_pass(git_rebase_next(&rebase_operation, rebase));
	cl_git_pass(git_rebase_commit(&commit_id, rebase, NULL, signature,
		NULL, NULL));

	cl_git_pass(git_rebase_next(&rebase_operation, rebase));
	cl_git_pass(git_rebase_commit(&commit_id, rebase, NULL, signature,
		NULL, NULL));

	cl_git_fail_with(GIT_ITEROVER, git_rebase_next(&rebase_operation, rebase));

	cl_git_pass(git_commit_lookup(&commit, repo, &commit_id));
	cl_assert_equal_oid(&tree_id, git_commit_tree_id(commit));

	git_commit_free(commit);
	git_annotated_commit_free(branch_head);
	git_annotated_commit_free(upstream_head);
	git_reference_free(branch_ref);
	git_reference_free(upstream_ref);
	git_rebase_free(rebase);
}
Esempio n. 7
0
/**
 * Commits and tags have a few interesting fields in their header.
 */
static void show_commit(const git_commit *commit)
{
	unsigned int i, max_i;
	char oidstr[GIT_OID_HEXSZ + 1];

	git_oid_tostr(oidstr, sizeof(oidstr), git_commit_tree_id(commit));
	printf("tree %s\n", oidstr);

	max_i = (unsigned int)git_commit_parentcount(commit);
	for (i = 0; i < max_i; ++i) {
		git_oid_tostr(oidstr, sizeof(oidstr), git_commit_parent_id(commit, i));
		printf("parent %s\n", oidstr);
	}

	print_signature("author", git_commit_author(commit));
	print_signature("committer", git_commit_committer(commit));

	if (git_commit_message(commit))
		printf("\n%s\n", git_commit_message(commit));
}
Esempio n. 8
0
/**
 * Reads the tree object out of a commit object, or returns an empty tree
 * if the commit id is zero.
 */
static int sync_get_tree(git_oid *out,
                         git_repository *repo,
                         const git_oid *commit_id)
{
    int e = 0;
    git_treebuilder *tb = NULL;
    git_commit *commit = NULL;

    if (git_oid_iszero(commit_id))
    {
        git_check(git_treebuilder_new(&tb, repo, NULL));
        git_check(git_treebuilder_write(out, tb));
    }
    else
    {
        git_check(git_commit_lookup(&commit, repo, commit_id));
        git_oid_cpy(out, git_commit_tree_id(commit));
    }

exit:
    if (tb)             git_treebuilder_free(tb);
    if (commit)         git_commit_free(commit);
    return e;
}
Esempio n. 9
0
Rcpp::Reference Commit::tree_id()
{
    const git_oid *result = git_commit_tree_id(commit.get());
    return OID::create(result);
}
Esempio n. 10
0
/**
 * Prints selected details about the given commit.
 *
 * @param wcommit
 * @param fmt
 */
void print_commit(git_commit *wcommit, const char *fmt)
{
	char c;
	int percent = 0;

	const char *cmsg;
	int nl;
	const git_signature *cauth;
	char oid_str[80];
	char t[40];
	time_t tt;
	struct tm tm;
	const git_oid *woid;
	const git_oid *toid;

	woid = git_commit_id(wcommit);
	toid = git_commit_tree_id(wcommit);
	cmsg  = git_commit_message(wcommit);
	cauth = git_commit_author(wcommit);
	tt = cauth->when.time + cauth->when.offset*60;
	tm = *gmtime(&tt);
	tm.tm_gmtoff = cauth->when.offset*60;
	strftime(t,sizeof(t),"%a %d %b %Y %T %z",&tm);

	while ((c = *fmt++))
	{
		if (!percent)
		{
			if (c == '%')
			{
				percent = 1;
				continue;
			}
		} else
		{
			switch (c)
			{
				case	'a':
						printf("%s <%s>",cauth->name,cauth->email);
						break;
				case	'd':
						printf("%s",t);
						break;
				case	'm':
						{
							nl = 1;
							while ((c = *cmsg++))
							{
								if (nl)
								{
									printf("    ");
									nl = 0;
								}
								putc(c,stdout);
								if (c == '\n') nl = 1;
							}
						}
						break;
				case	'p':
						{
							int i;
							int num_parents = git_commit_parentcount(wcommit);
							struct optarg prefix;
							struct optarg suffix;

							memset(&prefix,0,sizeof(prefix));
							memset(&suffix,0,sizeof(suffix));

							fmt = sgit_find_optional_arg(&prefix, fmt);
							fmt = sgit_find_optional_arg(&suffix, fmt);

							for (i=0;i<num_parents;i++)
							{
								git_commit *pcommit;

								if (git_commit_parent(&pcommit,wcommit,i) == GIT_OK)
								{
									int j;
									for (j=0;j<prefix.len;j++)
										printf("%c",prefix.start[j]);
									printf("%s",git_oid_tostr(oid_str,sizeof(oid_str),git_commit_id(pcommit)));
									for (j=0;j<suffix.len;j++)
										printf("%c",suffix.start[j]);

								}
							}
						}
						break;
				case	'C':
						printf("%s",git_oid_tostr(oid_str,sizeof(oid_str),woid));
						break;
				case	'T':
						printf("%s",git_oid_tostr(oid_str,sizeof(oid_str),toid));
						break;
			}
			percent  = 0;
			continue;
		}
		printf("%c",c);
	}
}
Esempio n. 11
0
PyObject *
Commit_tree_id__get__(Commit *commit)
{
    return git_oid_to_python(git_commit_tree_id(commit->commit));
}