void test_object_raw_convert__convert_oid_partially(void) { const char *exp = "16a0123456789abcdef4b775213c23a8bd74f5e0"; git_oid in; char big[GIT_OID_HEXSZ + 1 + 3]; /* note + 4 => big buffer */ cl_git_pass(git_oid_fromstr(&in, exp)); git_oid_nfmt(big, sizeof(big), &in); cl_assert_equal_s(exp, big); git_oid_nfmt(big, GIT_OID_HEXSZ + 1, &in); cl_assert_equal_s(exp, big); check_partial_oid(big, 1, &in, "1"); check_partial_oid(big, 2, &in, "16"); check_partial_oid(big, 3, &in, "16a"); check_partial_oid(big, 4, &in, "16a0"); check_partial_oid(big, 5, &in, "16a01"); check_partial_oid(big, GIT_OID_HEXSZ, &in, exp); check_partial_oid( big, GIT_OID_HEXSZ - 1, &in, "16a0123456789abcdef4b775213c23a8bd74f5e"); check_partial_oid( big, GIT_OID_HEXSZ - 2, &in, "16a0123456789abcdef4b775213c23a8bd74f5"); check_partial_oid( big, GIT_OID_HEXSZ - 3, &in, "16a0123456789abcdef4b775213c23a8bd74f"); }
static void check_partial_oid( char *buffer, size_t count, const git_oid *oid, const char *expected) { git_oid_nfmt(buffer, count, oid); buffer[count] = '\0'; cl_assert_equal_s(expected, buffer); }
int git_cherrypick( git_repository *repo, git_commit *commit, const git_cherrypick_options *given_opts) { git_cherrypick_options opts; git_reference *our_ref = NULL; git_commit *our_commit = NULL; char commit_oidstr[GIT_OID_HEXSZ + 1]; const char *commit_msg, *commit_summary; git_buf their_label = GIT_BUF_INIT; git_index *index = NULL; git_indexwriter indexwriter = GIT_INDEXWRITER_INIT; int error = 0; assert(repo && commit); GITERR_CHECK_VERSION(given_opts, GIT_CHERRYPICK_OPTIONS_VERSION, "git_cherrypick_options"); if ((error = git_repository__ensure_not_bare(repo, "cherry-pick")) < 0) return error; if ((commit_msg = git_commit_message(commit)) == NULL || (commit_summary = git_commit_summary(commit)) == NULL) { error = -1; goto on_error; } git_oid_nfmt(commit_oidstr, sizeof(commit_oidstr), git_commit_id(commit)); if ((error = write_merge_msg(repo, commit_msg)) < 0 || (error = git_buf_printf(&their_label, "%.7s... %s", commit_oidstr, commit_summary)) < 0 || (error = cherrypick_normalize_opts(repo, &opts, given_opts, git_buf_cstr(&their_label))) < 0 || (error = git_indexwriter_init_for_operation(&indexwriter, repo, &opts.checkout_opts.checkout_strategy)) < 0 || (error = write_cherrypick_head(repo, commit_oidstr)) < 0 || (error = git_repository_head(&our_ref, repo)) < 0 || (error = git_reference_peel((git_object **)&our_commit, our_ref, GIT_OBJ_COMMIT)) < 0 || (error = git_cherrypick_commit(&index, repo, commit, our_commit, opts.mainline, &opts.merge_opts)) < 0 || (error = git_merge__check_result(repo, index)) < 0 || (error = git_merge__append_conflicts_to_merge_msg(repo, index)) < 0 || (error = git_checkout_index(repo, index, &opts.checkout_opts)) < 0 || (error = git_indexwriter_commit(&indexwriter)) < 0) goto on_error; goto done; on_error: cherrypick_state_cleanup(repo); done: git_indexwriter_cleanup(&indexwriter); git_index_free(index); git_commit_free(our_commit); git_reference_free(our_ref); git_buf_free(&their_label); return error; }
static int tree_insert(git_treebuilder *dir, const char *name, int mkunique, git_oid *id, unsigned mode) { int ret; struct membuffer uniquename = { 0 }; if (mkunique && git_treebuilder_get(dir, name)) { char hex[8]; git_oid_nfmt(hex, 7, id); hex[7] = 0; put_format(&uniquename, "%s~%s", name, hex); name = mb_cstring(&uniquename); } ret = git_treebuilder_insert(NULL, dir, name, id, mode); free_buffer(&uniquename); return ret; }
int hiredis_refdb_backend__write(git_refdb_backend *_backend, const git_reference *ref, int force, const git_signature *who, const char *message, const git_oid *old, const char *old_target) { hiredis_refdb_backend *backend; int error = GIT_OK; redisReply *reply; const char *name = git_reference_name(ref); const git_oid *target; const char *symbolic_target; char oid_str[GIT_OID_HEXSZ + 1]; assert(ref && _backend); backend = (hiredis_refdb_backend *) _backend; target = git_reference_target(ref); /* FIXME handle force correctly */ if (target) { git_oid_nfmt(oid_str, sizeof(oid_str), target); reply = redisCommand(backend->db, "HMSET %s:%s:refdb:%s type %d target %s", backend->prefix, backend->repo_path, name, GIT_REF_OID, oid_str); } else { symbolic_target = git_reference_symbolic_target(ref); reply = redisCommand(backend->db, "HMSET %s:%s:refdb:%s type %d target %s", backend->prefix, backend->repo_path, name, GIT_REF_SYMBOLIC, symbolic_target); } if(reply->type == REDIS_REPLY_ERROR) { giterr_set_str(GITERR_REFERENCE, "Redis refdb storage error"); error = GIT_ERROR; } freeReplyObject(reply); return error; }