Пример #1
0
static int diff_print_oid_range(
	git_buf *out, const git_diff_delta *delta, int oid_strlen)
{
	char start_oid[GIT_OID_HEXSZ+1], end_oid[GIT_OID_HEXSZ+1];

	git_oid_tostr(start_oid, oid_strlen, &delta->old_file.id);
	git_oid_tostr(end_oid, oid_strlen, &delta->new_file.id);

	/* TODO: Match git diff more closely */
	if (delta->old_file.mode == delta->new_file.mode) {
		git_buf_printf(out, "index %s..%s %o\n",
			start_oid, end_oid, delta->old_file.mode);
	} else {
		if (delta->old_file.mode == 0) {
			git_buf_printf(out, "new file mode %o\n", delta->new_file.mode);
		} else if (delta->new_file.mode == 0) {
			git_buf_printf(out, "deleted file mode %o\n", delta->old_file.mode);
		} else {
			git_buf_printf(out, "old mode %o\n", delta->old_file.mode);
			git_buf_printf(out, "new mode %o\n", delta->new_file.mode);
		}
		git_buf_printf(out, "index %s..%s\n", start_oid, end_oid);
	}

	return git_buf_oom(out) ? -1 : 0;
}
Пример #2
0
/** Helper to print a commit object. */
static void print_commit(git_commit *commit)
{
	char buf[GIT_OID_HEXSZ + 1];
	int i, count;
	const git_signature *sig;
	const char *scan, *eol;

	git_oid_tostr(buf, sizeof(buf), git_commit_id(commit));
	printf("commit %s\n", buf);

	if ((count = (int)git_commit_parentcount(commit)) > 1) {
		printf("Merge:");
		for (i = 0; i < count; ++i) {
			git_oid_tostr(buf, 8, git_commit_parent_id(commit, i));
			printf(" %s", buf);
		}
		printf("\n");
	}

	if ((sig = git_commit_author(commit)) != NULL) {
		printf("Author: %s <%s>\n", sig->name, sig->email);
		print_time(&sig->when, "Date:   ");
	}
	printf("\n");

	for (scan = git_commit_message(commit); scan && *scan; ) {
		for (eol = scan; *eol && *eol != '\n'; ++eol) /* find eol */;

		printf("    %.*s\n", (int)(eol - scan), scan);
		scan = *eol ? eol + 1 : NULL;
	}
	printf("\n");
}
Пример #3
0
static int diff_print_oid_range(diff_print_info *pi, const git_diff_delta *delta)
{
	git_buf *out = pi->buf;
	char start_oid[GIT_OID_HEXSZ+1], end_oid[GIT_OID_HEXSZ+1];

	git_oid_tostr(start_oid, pi->oid_strlen, &delta->old_file.oid);
	git_oid_tostr(end_oid, pi->oid_strlen, &delta->new_file.oid);

	/* TODO: Match git diff more closely */
	if (delta->old_file.mode == delta->new_file.mode) {
		git_buf_printf(out, "index %s..%s %o\n",
			start_oid, end_oid, delta->old_file.mode);
	} else {
		if (delta->old_file.mode == 0) {
			git_buf_printf(out, "new file mode %o\n", delta->new_file.mode);
		} else if (delta->new_file.mode == 0) {
			git_buf_printf(out, "deleted file mode %o\n", delta->old_file.mode);
		} else {
			git_buf_printf(out, "old mode %o\n", delta->old_file.mode);
			git_buf_printf(out, "new mode %o\n", delta->new_file.mode);
		}
		git_buf_printf(out, "index %s..%s\n", start_oid, end_oid);
	}

	if (git_buf_oom(out))
		return -1;

	return 0;
}
Пример #4
0
static gboolean
validate_at_head (struct EvTag  *self,
                  git_oid       *specified_oid,
                  GError       **error)
{
  gboolean ret = FALSE;
  git_oid head_oid;
  int r;

  r = git_reference_name_to_id (&head_oid, self->top_repo, "HEAD");
  if (!handle_libgit_ret (r, error))
    goto out;

  /* We have this restriction due to submodules; we require them to be
   * checked out and initialized.
   */
  if (git_oid_cmp (&head_oid, specified_oid) != 0)
    {
      char head_oid_hexstr[GIT_OID_HEXSZ+1];
      char specified_oid_hexstr[GIT_OID_HEXSZ+1];

      g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
                   "Target %s is not HEAD (%s); currently git-evtag can only tag or verify HEAD in a pristine checkout",
                   git_oid_tostr (specified_oid_hexstr, sizeof (specified_oid_hexstr), specified_oid),
                   git_oid_tostr (head_oid_hexstr, sizeof (head_oid_hexstr), &head_oid));
      goto out;
    }

  ret = TRUE;
 out:
  return ret;
}
Пример #5
0
static int prepare_index(git_index *index, char* msg){
    git_oid index_tree;
    git_tree *head_obj;
    git_reference *head;
    char tree_str[GIT_OID_HEXSZ+1], parent_str[GIT_OID_HEXSZ+1];

    // Get the head OID
    git_repository_head(&head, repo);
    git_reference_peel((git_object**)&head_obj, head, GIT_OBJ_COMMIT);
    git_oid_tostr(parent_str, GIT_OID_HEXSZ+1,
                   git_tree_id(head_obj));

    git_reference_free(head);
    git_object_free((git_object*)head_obj);

    // Write the coin
    // TODO: Use C for this?
    system("perl -i -pe 's/(null:)(\\d+)/$1 . ($2+1)/e' LEDGER.txt");
    system("grep -q \"null\" LEDGER.txt || echo \"null:1\" >> LEDGER.txt");

    // Update the index
    check_lg2(git_index_read(index, 0),
              "Could not re-read index from disk", NULL);

    check_lg2(git_index_add_bypath(index, "LEDGER.txt"),
              "Could not add to index", "LEDGER.txt");

    // Write the index and get the tree OID
    git_index_write_tree(&index_tree, index);
    git_oid_tostr(tree_str, GIT_OID_HEXSZ+1, &index_tree);

    snprintf(msg, BUFFER_LENGTH,
             "commit %d%c"
             "tree %s\n"
             "parent %s\n"
             "author null           <*****@*****.**> %d +0000\n"
             "committer null           <*****@*****.**> %d +0000\n"
             "\n"
             "coins now"
             "\x01\x01\x01\x01"
             "\x01\x01\x01\x01"
             "\x01\x01\x01", // Align 32 bit words on GPU
             MSG_LENGTH, 0, tree_str, parent_str,
             (int)time(NULL), (int)time(NULL));
    pad_message(msg, COMMIT_LENGTH, BUFFER_LENGTH);

    return 0;
}
Пример #6
0
static int push_result_lib(git_oid *commit, git_remote *remote){
    git_push *push;
    int retval = 0;
    char cmd[128];

    git_oid_tostr(cmd, GIT_OID_HEXSZ+1, commit);
    strncat(cmd, ":refs/heads/master", 128);
    puts(cmd);

    check_lg2(git_push_new(&push, remote),
              "Error creating push", NULL);
    check_lg2(git_push_add_refspec(push, cmd),
              "Failed to add refspec to push", NULL);

    retval = log_lg2(git_push_finish(push),
                     "Failed to finish push", NULL);

    if(retval || !git_push_unpack_ok(push)){
        puts("Push: unpack failed!");
        retval = 1;
    } else {
        git_push_status_foreach(push, record_push_status_cb, &retval);
    }

    git_push_free(push);

    return retval;
}
Пример #7
0
static int ident_insert_id(
	git_buf *to, const git_buf *from, const git_filter_source *src)
{
	char oid[GIT_OID_HEXSZ+1];
	const char *id_start, *id_end, *from_end = from->ptr + from->size;
	size_t need_size;

	/* replace $Id$ with blob id */

	if (!git_filter_source_id(src))
		return GIT_PASSTHROUGH;

	git_oid_tostr(oid, sizeof(oid), git_filter_source_id(src));

	if (ident_find_id(&id_start, &id_end, from->ptr, from->size) < 0)
		return GIT_PASSTHROUGH;

	need_size = (size_t)(id_start - from->ptr) +
		5 /* "$Id: " */ + GIT_OID_HEXSZ + 1 /* "$" */ +
		(size_t)(from_end - id_end);

	if (git_buf_grow(to, need_size) < 0)
		return -1;

	git_buf_set(to, from->ptr, (size_t)(id_start - from->ptr));
	git_buf_put(to, "$Id: ", 5);
	git_buf_put(to, oid, GIT_OID_HEXSZ);
	git_buf_putc(to, '$');
	git_buf_put(to, id_end, (size_t)(from_end - id_end));

	return git_buf_oom(to) ? -1 : 0;
}
Пример #8
0
void test_object_raw_convert__succeed_on_oid_to_string_conversion_big(void)
{
	const char *exp = "16a0123456789abcdef4b775213c23a8bd74f5e0";
	git_oid in;
	char big[GIT_OID_HEXSZ + 1 + 3]; /* note + 4 => big buffer */
	char *str;

	cl_git_pass(git_oid_fromstr(&in, exp));

	/* place some tail material */
	big[GIT_OID_HEXSZ+0] = 'W'; /* should be '\0' afterwards */
	big[GIT_OID_HEXSZ+1] = 'X'; /* should remain untouched   */
	big[GIT_OID_HEXSZ+2] = 'Y'; /* ditto */
	big[GIT_OID_HEXSZ+3] = 'Z'; /* ditto */

	/* returns big as hex formatted c-string */
	str = git_oid_tostr(big, sizeof(big), &in);
	cl_assert(str && str == big && *(str+GIT_OID_HEXSZ) == '\0');
	cl_assert_equal_s(exp, big);

	/* check tail material is untouched */
	cl_assert(str && str == big && *(str+GIT_OID_HEXSZ+1) == 'X');
	cl_assert(str && str == big && *(str+GIT_OID_HEXSZ+2) == 'Y');
	cl_assert(str && str == big && *(str+GIT_OID_HEXSZ+3) == 'Z');
}
Пример #9
0
/**
 * Invoked 'callback' for each entry in the given FETCH_HEAD file.
 *
 * @param ref_name The name of the ref.
 * @param remote_url The url of the remote.
 * @param oid The id of the remote head that were updated during the
 * last fetch.
 * @param is_merge Is head for merge.
 * @return 0
 */
static int git2r_repository_fetchhead_foreach_cb(
    const char *ref_name,
    const char *remote_url,
    const git_oid *oid,
    unsigned int is_merge,
    void *payload)
{
    git2r_fetch_head_cb_data *cb_data = (git2r_fetch_head_cb_data*)payload;

    /* Check if we have a list to populate */
    if (R_NilValue != cb_data->list) {
        char sha[GIT_OID_HEXSZ + 1];
        SEXP fetch_head;

        SET_VECTOR_ELT(
            cb_data->list,
            cb_data->n,
            fetch_head = NEW_OBJECT(MAKE_CLASS("git_fetch_head")));

        SET_SLOT(fetch_head, Rf_install("ref_name"), mkString(ref_name));
        SET_SLOT(fetch_head, Rf_install("remote_url"), mkString(remote_url));
        git_oid_tostr(sha, sizeof(sha), oid);
        SET_SLOT(fetch_head, Rf_install("sha"), mkString(sha));
        SET_SLOT(fetch_head, Rf_install("is_merge"), ScalarLogical(is_merge));
        SET_SLOT(fetch_head, Rf_install("repo"), cb_data->repo);
    }

    cb_data->n += 1;

    return 0;
}
Пример #10
0
int hiredis_odb_backend__read_header(size_t *len_p, git_otype *type_p, git_odb_backend *_backend, const git_oid *oid)
{
	hiredis_odb_backend *backend;
	int error;
	redisReply *reply;
	char *str_id = calloc(GIT_OID_HEXSZ + 1, sizeof(char));

	assert(len_p && type_p && _backend && oid);

	backend = (hiredis_odb_backend *) _backend;
	error = GIT_ERROR;

	git_oid_tostr(str_id, GIT_OID_HEXSZ, oid);

	reply = redisCommand(backend->db, "HMGET %s:%s:odb:%s %s %s", backend->prefix, backend->repo_path, str_id, "type", "size");

	if (reply && reply->type == REDIS_REPLY_ARRAY) {
		if (reply->element[0]->type != REDIS_REPLY_NIL &&
				reply->element[1]->type != REDIS_REPLY_NIL) {
			*type_p = (git_otype) atoi(reply->element[0]->str);
			*len_p = (size_t) atoi(reply->element[1]->str);
			error = GIT_OK;
		} else {
			giterr_set_str(GITERR_ODB, "Redis odb storage corrupted");
			error = GIT_ENOTFOUND;
		}
	} else {
		giterr_set_str(GITERR_ODB, "Redis odb storage error");
		error = GIT_ERROR;
	}

	free(str_id);
	freeReplyObject(reply);
	return error;
}
Пример #11
0
int hiredis_odb_backend__write(git_odb_backend *_backend, const git_oid *oid, const void *data, size_t len, git_otype type)
{
	hiredis_odb_backend *backend;
	int error;
	redisReply *reply;
	char *str_id = calloc(GIT_OID_HEXSZ + 1, sizeof(char));

	assert(oid && _backend && data);

	backend = (hiredis_odb_backend *) _backend;
	error = GIT_ERROR;

	git_oid_tostr(str_id, GIT_OID_HEXSZ, oid);

	reply = redisCommand(backend->db, "HMSET %s:%s:odb:%s "
			"type %d "
			"size %d "
			"data %b ", backend->prefix, backend->repo_path, str_id,
			(int) type, len, data, len);
	free(str_id);

	error = (reply == NULL || reply->type == REDIS_REPLY_ERROR) ? GIT_ERROR : GIT_OK;

	freeReplyObject(reply);
	return error;
}
Пример #12
0
void set_git_id(const struct git_oid * id)
{
	static char git_id_buffer[GIT_OID_HEXSZ+1];

	git_oid_tostr(git_id_buffer, sizeof(git_id_buffer), id);
	saved_git_id = git_id_buffer;
}
Пример #13
0
/*
 *  call-seq:
 *    ref.peel -> oid
 *
 *  Peels tag objects to the sha that they point at. Replicates
 *  +git show-ref --dereference+.
 */
static VALUE rb_git_ref_peel(VALUE self)
{
	/* Leave room for \0 */
	git_reference *ref;
	git_object *object;
	char oid[GIT_OID_HEXSZ + 1];
	int error;

	Data_Get_Struct(self, git_reference, ref);

	error = git_reference_peel(&object, ref, GIT_OBJ_ANY);
	if (error == GIT_ENOTFOUND)
		return Qnil;
	else
		rugged_exception_check(error);

	if (git_reference_type(ref) == GIT_REF_OID &&
			!git_oid_cmp(git_object_id(object), git_reference_target(ref))) {
		git_object_free(object);
		return Qnil;
	} else {
		git_oid_tostr(oid, sizeof(oid), git_object_id(object));
		git_object_free(object);
		return rb_str_new_utf8(oid);
	}
}
Пример #14
0
void ref_details(git_reference *ref){

  char strid[10];
  const git_oid *id= git_reference_target(ref);
  git_oid_tostr(strid,10,id);
  printf("\ttarget:%s\n",strid);
}
Пример #15
0
int cmd_write_tree(int argc, const char **argv)
{
	please_git_do_it_for_me();

	int verify_index = 1;
	if (argc == 1)
		verify_index = 1;
	else if (argc == 2 && strcmp(argv[1], "--missing-ok") == 0 )
		verify_index = 0;
	else
		please_git_do_it_for_me();
	

	char sha1buf[GIT_OID_HEXSZ + 1];

	git_repository *repo = get_git_repository();
	git_index *index_cur;
	int e = git_repository_index(&index_cur, repo);
	if(e != GIT_OK)
		libgit_error();

	/* check the index */
	if (verify_index) {
		git_odb * odb;
		git_repository_odb(&odb, repo);
		for (unsigned i = 0; i < git_index_entrycount(index_cur); i++) {
			git_index_entry *gie = git_index_get(index_cur, i);

			if (git_odb_exists(odb, &gie->oid) != 1) {
				printf("error: invalid object %06o %s for '%s'\n", gie->mode, git_oid_tostr(sha1buf, GIT_OID_HEXSZ+1, &gie->oid), gie->path);
				printf("fatal: git-write-tree: error building trees\n");
				return EXIT_FAILURE;
			}
		}
	}
	
	/* create the tree */
	git_oid oid;
	e = git_tree_create_fromindex(&oid, index_cur);
	if(e != GIT_OK)
		libgit_error();

	printf("%s\n", git_oid_tostr(sha1buf, GIT_OID_HEXSZ+1, &oid));

	return EXIT_SUCCESS;
}
Пример #16
0
static int cherry_pick_seterr(git_commit *commit, const char *fmt)
{
    char commit_oidstr[GIT_OID_HEXSZ + 1];

    giterr_set(GITERR_CHERRYPICK, fmt,
               git_oid_tostr(commit_oidstr, GIT_OID_HEXSZ + 1, git_commit_id(commit)));

    return -1;
}
Пример #17
0
const char *get_sha(git_repository *repo, const char *branch)
{
	static char git_id_buffer[GIT_OID_HEXSZ+1];
	git_commit *commit;
	if (find_commit(repo, branch, &commit))
		return NULL;
	git_oid_tostr(git_id_buffer, sizeof(git_id_buffer), (const git_oid *)commit);
	return git_id_buffer;
}
Пример #18
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;
}
Пример #19
0
int cmd_ls_files(git_repository *repo, int argc, char **argv)
{
	int i;
	int rc = EXIT_FAILURE;
	int show_cached = 1;
	int err = 0;
	char *file = NULL;
	char buf[GIT_OID_HEXSZ+1];
	git_index *idx = NULL;

	for (i=1;i<argc;i++)
	{
		if (strcmp(argv[i], "--stage") == 0 || strcmp(argv[i], "-s") == 0) show_cached = 0;
		else if (strcmp(argv[i], "--cached") == 0 || strcmp(argv[i], "-c") == 0) show_cached = 1;
		else if (argv[i][0] == '-')
		{
			fprintf(stderr,"Unknown option %s!\n",argv[i]);
			goto out;
		} else
		{
			file = argv[i];
		}
	}

	if (!file) file = "*";

	if ((err = git_repository_index(&idx, repo)) != GIT_OK)
		goto out;

	const char *prefix = "";
	size_t prefix_len = strlen(prefix);

	for (unsigned i = 0; i < git_index_entrycount(idx); i++)
	{
		const git_index_entry *gie = git_index_get_byindex(idx, i);

		if (prefixcmp(gie->path, prefix))
			continue;

		if (pathspeccmp(gie->path,file))
			continue;

		if (!show_cached)
			printf("%06o %s %i\t", gie->mode, git_oid_tostr(buf, GIT_OID_HEXSZ+1, &gie->id), git_index_entry_stage(gie));

		write_name_quoted(gie->path + prefix_len, stdout, '\n');
	}

	rc = EXIT_SUCCESS;
out:
	if (err) libgit_error();

	if (idx) git_index_free(idx);

	return rc;
}
Пример #20
0
static int diff_print_one_raw(
	const git_diff_delta *delta, float progress, void *data)
{
	diff_print_info *pi = data;
	git_buf *out = pi->buf;
	char code = git_diff_status_char(delta->status);
	char start_oid[GIT_OID_HEXSZ+1], end_oid[GIT_OID_HEXSZ+1];

	GIT_UNUSED(progress);

	if ((pi->flags & GIT_DIFF_SHOW_UNMODIFIED) == 0 && code == ' ')
		return 0;

	git_buf_clear(out);

	git_oid_tostr(start_oid, pi->oid_strlen, &delta->old_file.id);
	git_oid_tostr(end_oid, pi->oid_strlen, &delta->new_file.id);

	git_buf_printf(
		out, (pi->oid_strlen <= GIT_OID_HEXSZ) ?
			":%06o %06o %s... %s... %c" : ":%06o %06o %s %s %c",
		delta->old_file.mode, delta->new_file.mode, start_oid, end_oid, code);

	if (delta->similarity > 0)
		git_buf_printf(out, "%03u", delta->similarity);

	if (delta->old_file.path != delta->new_file.path)
		git_buf_printf(
			out, "\t%s %s\n", delta->old_file.path, delta->new_file.path);
	else
		git_buf_printf(
			out, "\t%s\n", delta->old_file.path ?
			delta->old_file.path : delta->new_file.path);

	if (git_buf_oom(out))
		return -1;

	pi->line.origin      = GIT_DIFF_LINE_FILE_HDR;
	pi->line.content     = git_buf_cstr(out);
	pi->line.content_len = git_buf_len(out);

	return pi->print_cb(delta, NULL, &pi->line, pi->payload);
}
Пример #21
0
static int diff_print_one_raw(
	const git_diff_delta *delta, float progress, void *data)
{
	diff_print_info *pi = data;
	git_buf *out = pi->buf;
	char code = git_diff_status_char(delta->status);
	char start_oid[GIT_OID_HEXSZ+1], end_oid[GIT_OID_HEXSZ+1];

	GIT_UNUSED(progress);

	if (code == ' ')
		return 0;

	git_buf_clear(out);

	git_oid_tostr(start_oid, pi->oid_strlen, &delta->old_file.oid);
	git_oid_tostr(end_oid, pi->oid_strlen, &delta->new_file.oid);

	git_buf_printf(
		out, ":%06o %06o %s... %s... %c",
		delta->old_file.mode, delta->new_file.mode, start_oid, end_oid, code);

	if (delta->similarity > 0)
		git_buf_printf(out, "%03u", delta->similarity);

	if (delta->old_file.path != delta->new_file.path)
		git_buf_printf(
			out, "\t%s %s\n", delta->old_file.path, delta->new_file.path);
	else
		git_buf_printf(
			out, "\t%s\n", delta->old_file.path ?
			delta->old_file.path : delta->new_file.path);

	if (git_buf_oom(out))
		return -1;

	if (pi->print_cb(delta, NULL, GIT_DIFF_LINE_FILE_HDR,
			git_buf_cstr(out), git_buf_len(out), pi->payload))
		return callback_error();

	return 0;
}
Пример #22
0
int
read_repo(const char *repo_name)
{
	int i;
	int r;
	int n;
	git_repository *repo;
	git_reference *head;
	git_oid oid;
	git_commit *commit;
	git_tree *tree;
	git_tree_entry *tree_entry;
	char out[41];
	out[40] = '\0';

	// opening the repository
	r = git_repository_open(&repo, repo_name);
	if (r)
		printf("error in opening the repository\n");
	printf("Opened the repository successfully.\n");

	// obtaining the head
	r = git_repository_head(&head, repo);
	if (r)
		printf("error in obtaining the head\n");
	r = git_reference_name_to_oid(&oid, repo, git_reference_name(head));
	if (r)
		printf("error in obtaining the ref id of head\n");
	printf("Obtained the head id %s\n", git_oid_tostr(out, 41, &oid));

	// obtaining the commit from commit id
	r = git_commit_lookup(&commit, repo, &oid);
	if (r)
		printf("error in obtaining the commit from oid\n");
	printf("Obtained the commit.\n");

	// obtaining the tree id from the commit
	oid = *git_commit_tree_oid(commit);

	// get the tree
	r = git_tree_lookup(&tree, repo, &oid);
	if (r)
		printf("error in looking up the tree for oid\n");
	printf("Lookup for tree of oid successful.\n");

	n = git_tree_entrycount(tree);
	for (i=0; i<n; i++) {
		tree_entry = git_tree_entry_byindex(tree, i);
		printf("entry >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> %s %s\n", git_tree_entry_name(tree_entry), git_object_type2string(git_tree_entry_type(tree_entry)));
	}

	git_repository_free(repo);
	return 0;
}
Пример #23
0
int git_odb__error_notfound(const char *message, const git_oid *oid)
{
	if (oid != NULL) {
		char oid_str[GIT_OID_HEXSZ + 1];
		git_oid_tostr(oid_str, sizeof(oid_str), oid);
		giterr_set(GITERR_ODB, "Object not found - %s (%s)", message, oid_str);
	} else
		giterr_set(GITERR_ODB, "Object not found - %s", message);

	return GIT_ENOTFOUND;
}
Пример #24
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));
}
Пример #25
0
void cl_repo_commit_from_index(
	git_oid *out,
	git_repository *repo,
	git_signature *sig,
	git_time_t time,
	const char *msg)
{
	git_index *index;
	git_oid commit_id, tree_id;
	git_object *parent = NULL;
	git_reference *ref = NULL;
	git_tree *tree = NULL;
	char buf[128];
	int free_sig = (sig == NULL);

	/* it is fine if looking up HEAD fails - we make this the first commit */
	git_revparse_ext(&parent, &ref, repo, "HEAD");

	/* write the index content as a tree */
	cl_git_pass(git_repository_index(&index, repo));
	cl_git_pass(git_index_write_tree(&tree_id, index));
	cl_git_pass(git_index_write(index));
	git_index_free(index);

	cl_git_pass(git_tree_lookup(&tree, repo, &tree_id));

	if (sig)
		cl_assert(sig->name && sig->email);
	else if (!time)
		cl_git_pass(git_signature_now(&sig, CL_COMMIT_NAME, CL_COMMIT_EMAIL));
	else
		cl_git_pass(git_signature_new(
			&sig, CL_COMMIT_NAME, CL_COMMIT_EMAIL, time, 0));

	if (!msg) {
		strcpy(buf, CL_COMMIT_MSG);
		git_oid_tostr(buf + strlen(CL_COMMIT_MSG),
			sizeof(buf) - strlen(CL_COMMIT_MSG), &tree_id);
		msg = buf;
	}

	cl_git_pass(git_commit_create_v(
		&commit_id, repo, ref ? git_reference_name(ref) : "HEAD",
		sig, sig, NULL, msg, tree, parent ? 1 : 0, parent));

	if (out)
		git_oid_cpy(out, &commit_id);

	git_object_free(parent);
	git_reference_free(ref);
	if (free_sig)
		git_signature_free(sig);
	git_tree_free(tree);
}
Пример #26
0
static int
tag_callback(const char *tag_name, git_oid *oid, void *data)
{
	char buf[GIT_OID_HEXSZ + 1];
	
	(void) data;
	
	git_oid_tostr(buf, sizeof(buf), oid);
	printf("%s -> %s\n", tag_name, buf);
	return 0;
}
Пример #27
0
static int push_result_shell(git_oid *commit, git_remote *remote){
    char cmd[128], oid[GIT_OID_HEXSZ+1];
    FILE *fp;

    git_oid_tostr(oid, GIT_OID_HEXSZ+1, commit);

    snprintf(cmd, 128, "git push origin %s:master", oid);

    fp = popen(cmd, "r");

    return pclose(fp);
}
Пример #28
0
static int diff_file_content_commit_to_str(
	git_diff_file_content *fc, bool check_status)
{
	char oid[GIT_OID_HEXSZ+1];
	git_buf content = GIT_BUF_INIT;
	const char *status = "";

	if (check_status) {
		int error = 0;
		git_submodule *sm = NULL;
		unsigned int sm_status = 0;
		const git_oid *sm_head;

		if ((error = git_submodule_lookup(&sm, fc->repo, fc->file->path)) < 0) {
			/* GIT_EEXISTS means a "submodule" that has not been git added */
			if (error == GIT_EEXISTS) {
				giterr_clear();
				error = 0;
			}
			return error;
		}

		if ((error = git_submodule_status(&sm_status, fc->repo, fc->file->path, GIT_SUBMODULE_IGNORE_UNSPECIFIED)) < 0) {
			git_submodule_free(sm);
			return error;
		}

		/* update OID if we didn't have it previously */
		if ((fc->file->flags & GIT_DIFF_FLAG_VALID_ID) == 0 &&
			((sm_head = git_submodule_wd_id(sm)) != NULL ||
			 (sm_head = git_submodule_head_id(sm)) != NULL))
		{
			git_oid_cpy(&fc->file->id, sm_head);
			fc->file->flags |= GIT_DIFF_FLAG_VALID_ID;
		}

		if (GIT_SUBMODULE_STATUS_IS_WD_DIRTY(sm_status))
			status = "-dirty";

		git_submodule_free(sm);
	}

	git_oid_tostr(oid, sizeof(oid), &fc->file->id);
	if (git_buf_printf(&content, "Subproject commit %s%s\n", oid, status) < 0)
		return -1;

	fc->map.len  = git_buf_len(&content);
	fc->map.data = git_buf_detach(&content);
	fc->flags |= GIT_DIFF_FLAG__FREE_DATA;

	return 0;
}
Пример #29
0
static void show_tag(const git_tag *tag)
{
	char oidstr[GIT_OID_HEXSZ + 1];

	git_oid_tostr(oidstr, sizeof(oidstr), git_tag_target_id(tag));;
	printf("object %s\n", oidstr);
	printf("type %s\n", git_object_type2string(git_tag_target_type(tag)));
	printf("tag %s\n", git_tag_name(tag));
	print_signature("tagger", git_tag_tagger(tag));

	if (git_tag_message(tag))
		printf("\n%s\n", git_tag_message(tag));
}
Пример #30
0
/**
 * Init slots in S4 class git_tag
 *
 * @param source a tag
 * @param repo S4 class git_repository that contains the tag
 * @param dest S4 class git_tag to initialize
 * @return void
 */
void git2r_tag_init(git_tag *source, SEXP repo, SEXP dest)
{
    const git_signature *tagger;
    const git_oid *oid;
    char sha[GIT_OID_HEXSZ + 1];
    char target[GIT_OID_HEXSZ + 1];

    oid = git_tag_id(source);
    git_oid_tostr(sha, sizeof(sha), oid);
    SET_SLOT(dest, Rf_install("sha"), mkString(sha));

    SET_SLOT(dest, Rf_install("message"), mkString(git_tag_message(source)));
    SET_SLOT(dest, Rf_install("name"), mkString(git_tag_name(source)));

    tagger = git_tag_tagger(source);
    if (tagger)
        git2r_signature_init(tagger, GET_SLOT(dest, Rf_install("tagger")));

    oid = git_tag_target_id(source);
    git_oid_tostr(target, sizeof(target), oid);;
    SET_SLOT(dest, Rf_install("target"), mkString(target));

    SET_SLOT(dest, Rf_install("repo"), repo);
}