Merge branch 'bc/object-id' into bw/submodule-config-cleanup

* bc/object-id:
  sha1_name: convert uses of 40 to GIT_SHA1_HEXSZ
  sha1_name: convert GET_SHA1* flags to GET_OID*
  sha1_name: convert get_sha1* to get_oid*
  Convert remaining callers of get_sha1 to get_oid.
  builtin/unpack-file: convert to struct object_id
  bisect: convert bisect_checkout to struct object_id
  builtin/update_ref: convert to struct object_id
  sequencer: convert to struct object_id
  remote: convert struct push_cas to struct object_id
  submodule: convert submodule config lookup to use object_id
  builtin/merge-tree: convert remaining caller of get_sha1 to object_id
  builtin/fsck: convert remaining caller of get_sha1 to object_id
  tag: convert gpg_verify_tag to use struct object_id
  commit: convert lookup_commit_graft to struct object_id
This commit is contained in:
Junio C Hamano 2017-08-02 14:34:28 -07:00
Родитель dcc6108c3f ac53fe8601
Коммит a46ddc992b
45 изменённых файлов: 365 добавлений и 373 удалений

Просмотреть файл

@ -3551,7 +3551,7 @@ static int try_threeway(struct apply_state *state,
/* Preimage the patch was prepared for */
if (patch->is_new)
write_sha1_file("", 0, blob_type, pre_oid.hash);
else if (get_sha1(patch->old_sha1_prefix, pre_oid.hash) ||
else if (get_oid(patch->old_sha1_prefix, &pre_oid) ||
read_blob_object(&buf, &pre_oid, patch->old_mode))
return error(_("repository lacks the necessary blob to fall back on 3-way merge."));
@ -4075,7 +4075,7 @@ static int build_fake_ancestor(struct apply_state *state, struct patch *list)
else
return error(_("sha1 information is lacking or "
"useless for submodule %s"), name);
} else if (!get_sha1_blob(patch->old_sha1_prefix, oid.hash)) {
} else if (!get_oid_blob(patch->old_sha1_prefix, &oid)) {
; /* ok */
} else if (!patch->lines_added && !patch->lines_deleted) {
/* mode-only change: update the current */

Просмотреть файл

@ -358,7 +358,7 @@ static void parse_treeish_arg(const char **argv,
free(ref);
}
if (get_sha1(name, oid.hash))
if (get_oid(name, &oid))
die("Not a valid object name");
commit = lookup_commit_reference_gently(&oid, 1);

Просмотреть файл

@ -680,16 +680,16 @@ static int is_expected_rev(const struct object_id *oid)
return res;
}
static int bisect_checkout(const unsigned char *bisect_rev, int no_checkout)
static int bisect_checkout(const struct object_id *bisect_rev, int no_checkout)
{
char bisect_rev_hex[GIT_MAX_HEXSZ + 1];
memcpy(bisect_rev_hex, sha1_to_hex(bisect_rev), GIT_SHA1_HEXSZ + 1);
update_ref(NULL, "BISECT_EXPECTED_REV", bisect_rev, NULL, 0, UPDATE_REFS_DIE_ON_ERR);
memcpy(bisect_rev_hex, oid_to_hex(bisect_rev), GIT_SHA1_HEXSZ + 1);
update_ref(NULL, "BISECT_EXPECTED_REV", bisect_rev->hash, NULL, 0, UPDATE_REFS_DIE_ON_ERR);
argv_checkout[2] = bisect_rev_hex;
if (no_checkout) {
update_ref(NULL, "BISECT_HEAD", bisect_rev, NULL, 0, UPDATE_REFS_DIE_ON_ERR);
update_ref(NULL, "BISECT_HEAD", bisect_rev->hash, NULL, 0, UPDATE_REFS_DIE_ON_ERR);
} else {
int res;
res = run_command_v_opt(argv_checkout, RUN_GIT_CMD);
@ -796,7 +796,7 @@ static void check_merge_bases(int no_checkout)
handle_skipped_merge_base(mb);
} else {
printf(_("Bisecting: a merge base must be tested\n"));
exit(bisect_checkout(mb->hash, no_checkout));
exit(bisect_checkout(mb, no_checkout));
}
}
@ -939,7 +939,7 @@ int bisect_next_all(const char *prefix, int no_checkout)
struct rev_info revs;
struct commit_list *tried;
int reaches = 0, all = 0, nr, steps;
const unsigned char *bisect_rev;
struct object_id *bisect_rev;
char *steps_msg;
read_bisect_terms(&term_bad, &term_good);
@ -977,11 +977,11 @@ int bisect_next_all(const char *prefix, int no_checkout)
exit(4);
}
bisect_rev = revs.commits->item->object.oid.hash;
bisect_rev = &revs.commits->item->object.oid;
if (!hashcmp(bisect_rev, current_bad_oid->hash)) {
if (!oidcmp(bisect_rev, current_bad_oid)) {
exit_if_skipped_commits(tried, current_bad_oid);
printf("%s is the first %s commit\n", sha1_to_hex(bisect_rev),
printf("%s is the first %s commit\n", oid_to_hex(bisect_rev),
term_bad);
show_diff_tree(prefix, revs.commits->item);
/* This means the bisection process succeeded. */

Просмотреть файл

@ -1131,7 +1131,7 @@ static int index_has_changes(struct strbuf *sb)
struct object_id head;
int i;
if (!get_sha1_tree("HEAD", head.hash)) {
if (!get_oid_tree("HEAD", &head)) {
struct diff_options opt;
diff_setup(&opt);
@ -1432,7 +1432,7 @@ static void write_index_patch(const struct am_state *state)
struct rev_info rev_info;
FILE *fp;
if (!get_sha1_tree("HEAD", head.hash))
if (!get_oid_tree("HEAD", &head))
tree = lookup_tree(&head);
else
tree = lookup_tree(&empty_tree_oid);
@ -1661,7 +1661,7 @@ static void do_commit(const struct am_state *state)
if (write_cache_as_tree(tree.hash, 0, NULL))
die(_("git write-tree failed to write a tree"));
if (!get_sha1_commit("HEAD", parent.hash)) {
if (!get_oid_commit("HEAD", &parent)) {
old_oid = &parent;
commit_list_insert(lookup_commit(&parent), &parents);
} else {

Просмотреть файл

@ -63,8 +63,8 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
if (unknown_type)
flags |= OBJECT_INFO_ALLOW_UNKNOWN_TYPE;
if (get_sha1_with_context(obj_name, GET_SHA1_RECORD_PATH,
oid.hash, &obj_context))
if (get_oid_with_context(obj_name, GET_OID_RECORD_PATH,
&oid, &obj_context))
die("Not a valid object name %s", obj_name);
if (!path)
@ -361,10 +361,10 @@ static void batch_one_object(const char *obj_name, struct batch_options *opt,
struct expand_data *data)
{
struct object_context ctx;
int flags = opt->follow_symlinks ? GET_SHA1_FOLLOW_SYMLINKS : 0;
int flags = opt->follow_symlinks ? GET_OID_FOLLOW_SYMLINKS : 0;
enum follow_symlinks_result result;
result = get_sha1_with_context(obj_name, flags, data->oid.hash, &ctx);
result = get_oid_with_context(obj_name, flags, &data->oid, &ctx);
if (result != FOUND) {
switch (result) {
case MISSING_OBJECT:

Просмотреть файл

@ -56,7 +56,7 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix)
struct object_id oid;
if (argc <= ++i)
usage(commit_tree_usage);
if (get_sha1_commit(argv[i], oid.hash))
if (get_oid_commit(argv[i], &oid))
die("Not a valid object name %s", argv[i]);
assert_sha1_type(oid.hash, OBJ_COMMIT);
new_parent(lookup_commit(&oid), &parents);
@ -106,7 +106,7 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix)
continue;
}
if (get_sha1_tree(arg, tree_oid.hash))
if (get_oid_tree(arg, &tree_oid))
die("Not a valid object name %s", arg);
if (got_tree)
die("Cannot give more than one trees");

Просмотреть файл

@ -510,7 +510,7 @@ static int run_status(FILE *fp, const char *index_file, const char *prefix, int
s->index_file = index_file;
s->fp = fp;
s->nowarn = nowarn;
s->is_initial = get_sha1(s->reference, oid.hash) ? 1 : 0;
s->is_initial = get_oid(s->reference, &oid) ? 1 : 0;
if (!s->is_initial)
hashcpy(s->sha1_commit, oid.hash);
s->status_format = status_format;
@ -891,7 +891,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
if (amend)
parent = "HEAD^1";
if (get_sha1(parent, oid.hash)) {
if (get_oid(parent, &oid)) {
int i, ita_nr = 0;
for (i = 0; i < active_nr; i++)
@ -1387,7 +1387,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
fd = hold_locked_index(&index_lock, 0);
s.is_initial = get_sha1(s.reference, oid.hash) ? 1 : 0;
s.is_initial = get_oid(s.reference, &oid) ? 1 : 0;
if (!s.is_initial)
hashcpy(s.sha1_commit, oid.hash);
@ -1657,7 +1657,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
status_format = STATUS_FORMAT_NONE; /* Ignore status.short */
s.colopts = 0;
if (get_sha1("HEAD", oid.hash))
if (get_oid("HEAD", &oid))
current_head = NULL;
else {
current_head = lookup_commit_or_die(&oid, "HEAD");

Просмотреть файл

@ -738,12 +738,12 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
heads = 0;
for (i = 0; i < argc; i++) {
const char *arg = argv[i];
unsigned char sha1[20];
if (!get_sha1(arg, sha1)) {
struct object *obj = lookup_object(sha1);
struct object_id oid;
if (!get_oid(arg, &oid)) {
struct object *obj = lookup_object(oid.hash);
if (!obj || !(obj->flags & HAS_OBJ)) {
error("%s: object missing", sha1_to_hex(sha1));
error("%s: object missing", oid_to_hex(&oid));
errors_found |= ERROR_OBJECT;
continue;
}

Просмотреть файл

@ -643,7 +643,7 @@ static int grep_objects(struct grep_opt *opt, const struct pathspec *pathspec,
/* load the gitmodules file for this rev */
if (recurse_submodules) {
submodule_free();
gitmodules_config_sha1(real_obj->oid.hash);
gitmodules_config_oid(&real_obj->oid);
}
if (grep_object(opt, pathspec, real_obj, list->objects[i].name, list->objects[i].path,
repo)) {
@ -983,8 +983,8 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
break;
}
if (get_sha1_with_context(arg, GET_SHA1_RECORD_PATH,
oid.hash, &oc)) {
if (get_oid_with_context(arg, GET_OID_RECORD_PATH,
&oid, &oc)) {
if (seen_dashdash)
die(_("unable to resolve revision: %s"), arg);
break;

Просмотреть файл

@ -484,8 +484,8 @@ static int show_blob_object(const struct object_id *oid, struct rev_info *rev, c
!DIFF_OPT_TST(&rev->diffopt, ALLOW_TEXTCONV))
return stream_blob_to_fd(1, oid, NULL, 0);
if (get_sha1_with_context(obj_name, GET_SHA1_RECORD_PATH,
oidc.hash, &obj_context))
if (get_oid_with_context(obj_name, GET_OID_RECORD_PATH,
&oidc, &obj_context))
die(_("Not a valid object name %s"), obj_name);
if (!obj_context.path ||
!textconv_object(obj_context.path, obj_context.mode, &oidc, 1, &buf, &size)) {

Просмотреть файл

@ -347,12 +347,12 @@ static void merge_trees(struct tree_desc t[3], const char *base)
static void *get_tree_descriptor(struct tree_desc *desc, const char *rev)
{
unsigned char sha1[20];
struct object_id oid;
void *buf;
if (get_sha1(rev, sha1))
if (get_oid(rev, &oid))
die("unknown rev %s", rev);
buf = fill_tree_descriptor(desc, sha1);
buf = fill_tree_descriptor(desc, oid.hash);
if (!buf)
die("%s is not a tree", rev);
return buf;

Просмотреть файл

@ -919,9 +919,9 @@ static int update_shallow_ref(struct command *cmd, struct shallow_info *si)
*/
static int head_has_history(void)
{
unsigned char sha1[20];
struct object_id oid;
return !get_sha1("HEAD", sha1);
return !get_oid("HEAD", &oid);
}
static const char *push_to_deploy(unsigned char *sha1,

Просмотреть файл

@ -50,7 +50,7 @@ static int show_reference(const char *refname, const struct object_id *oid,
struct object_id object;
enum object_type obj_type, repl_type;
if (get_sha1(refname, object.hash))
if (get_oid(refname, &object))
return error("Failed to resolve '%s' as a valid ref.", refname);
obj_type = sha1_object_info(object.hash, NULL);
@ -365,7 +365,7 @@ static void check_one_mergetag(struct commit *commit,
/* iterate over new parents */
for (i = 1; i < mergetag_data->argc; i++) {
struct object_id oid;
if (get_sha1(mergetag_data->argv[i], oid.hash) < 0)
if (get_oid(mergetag_data->argv[i], &oid) < 0)
die(_("Not a valid object name: '%s'"), mergetag_data->argv[i]);
if (!oidcmp(&tag->tagged->oid, &oid))
return; /* found */

Просмотреть файл

@ -219,8 +219,8 @@ static void parse_args(struct pathspec *pathspec,
* has to be unambiguous. If there is a single argument, it
* can not be a tree
*/
else if ((!argv[1] && !get_sha1_committish(argv[0], unused.hash)) ||
(argv[1] && !get_sha1_treeish(argv[0], unused.hash))) {
else if ((!argv[1] && !get_oid_committish(argv[0], &unused)) ||
(argv[1] && !get_oid_treeish(argv[0], &unused))) {
/*
* Ok, argv[0] looks like a commit/tree; it should not
* be a filename.
@ -310,13 +310,13 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
load_submodule_cache();
unborn = !strcmp(rev, "HEAD") && get_sha1("HEAD", oid.hash);
unborn = !strcmp(rev, "HEAD") && get_oid("HEAD", &oid);
if (unborn) {
/* reset on unborn branch: treat as reset to empty tree */
hashcpy(oid.hash, EMPTY_TREE_SHA1_BIN);
} else if (!pathspec.nr) {
struct commit *commit;
if (get_sha1_committish(rev, oid.hash))
if (get_oid_committish(rev, &oid))
die(_("Failed to resolve '%s' as a valid revision."), rev);
commit = lookup_commit_reference(&oid);
if (!commit)
@ -324,7 +324,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
oidcpy(&oid, &commit->object.oid);
} else {
struct tree *tree;
if (get_sha1_treeish(rev, oid.hash))
if (get_oid_treeish(rev, &oid))
die(_("Failed to resolve '%s' as a valid tree."), rev);
tree = parse_tree_indirect(&oid);
if (!tree)

Просмотреть файл

@ -274,7 +274,7 @@ static int try_difference(const char *arg)
return 0;
}
if (!get_sha1_committish(this, oid.hash) && !get_sha1_committish(next, end.hash)) {
if (!get_oid_committish(this, &oid) && !get_oid_committish(next, &end)) {
show_rev(NORMAL, &end, next);
show_rev(symmetric ? NORMAL : REVERSED, &oid, this);
if (symmetric) {
@ -328,7 +328,7 @@ static int try_parent_shorthands(const char *arg)
return 0;
*dotdot = 0;
if (get_sha1_committish(arg, oid.hash)) {
if (get_oid_committish(arg, &oid)) {
*dotdot = '^';
return 0;
}
@ -702,7 +702,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
}
if (!strcmp(arg, "--quiet") || !strcmp(arg, "-q")) {
quiet = 1;
flags |= GET_SHA1_QUIETLY;
flags |= GET_OID_QUIETLY;
continue;
}
if (opt_with_value(arg, "--short", &arg)) {
@ -911,7 +911,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
name++;
type = REVERSED;
}
if (!get_sha1_with_context(name, flags, oid.hash, &unused)) {
if (!get_oid_with_context(name, flags, &oid, &unused)) {
if (verify)
revs_count++;
else

Просмотреть файл

@ -393,7 +393,7 @@ static int append_head_ref(const char *refname, const struct object_id *oid,
/* If both heads/foo and tags/foo exists, get_sha1 would
* get confused.
*/
if (get_sha1(refname + ofs, tmp.hash) || oidcmp(&tmp, oid))
if (get_oid(refname + ofs, &tmp) || oidcmp(&tmp, oid))
ofs = 5;
return append_ref(refname + ofs, oid, 0);
}
@ -408,7 +408,7 @@ static int append_remote_ref(const char *refname, const struct object_id *oid,
/* If both heads/foo and tags/foo exists, get_sha1 would
* get confused.
*/
if (get_sha1(refname + ofs, tmp.hash) || oidcmp(&tmp, oid))
if (get_oid(refname + ofs, &tmp) || oidcmp(&tmp, oid))
ofs = 5;
return append_ref(refname + ofs, oid, 0);
}
@ -514,7 +514,7 @@ static int show_independent(struct commit **rev,
static void append_one_rev(const char *av)
{
struct object_id revkey;
if (!get_sha1(av, revkey.hash)) {
if (!get_oid(av, &revkey)) {
append_ref(av, &revkey, 0);
return;
}
@ -808,7 +808,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
die(Q_("cannot handle more than %d rev.",
"cannot handle more than %d revs.",
MAX_REVS), MAX_REVS);
if (get_sha1(ref_name[num_rev], revkey.hash))
if (get_oid(ref_name[num_rev], &revkey))
die(_("'%s' is not a valid ref."), ref_name[num_rev]);
commit = lookup_commit_reference(&revkey);
if (!commit)

Просмотреть файл

@ -350,7 +350,7 @@ static void init_submodule(const char *path, const char *prefix, int quiet)
} else
displaypath = xstrdup(path);
sub = submodule_from_path(null_sha1, path);
sub = submodule_from_path(&null_oid, path);
if (!sub)
die(_("No url found for submodule path '%s' in .gitmodules"),
@ -476,7 +476,7 @@ static int module_name(int argc, const char **argv, const char *prefix)
usage(_("git submodule--helper name <path>"));
gitmodules_config();
sub = submodule_from_path(null_sha1, argv[1]);
sub = submodule_from_path(&null_oid, argv[1]);
if (!sub)
die(_("no submodule mapping found in .gitmodules for path '%s'"),
@ -795,7 +795,7 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,
goto cleanup;
}
sub = submodule_from_path(null_sha1, ce->name);
sub = submodule_from_path(&null_oid, ce->name);
if (suc->recursive_prefix)
displaypath = relative_path(suc->recursive_prefix,
@ -1069,7 +1069,7 @@ static const char *remote_submodule_branch(const char *path)
gitmodules_config();
git_config(submodule_config, NULL);
sub = submodule_from_path(null_sha1, path);
sub = submodule_from_path(&null_oid, path);
if (!sub)
return NULL;

Просмотреть файл

@ -111,7 +111,7 @@ static int verify_tag(const char *name, const char *ref,
if (fmt_pretty)
flags = GPG_VERIFY_OMIT_STATUS;
if (gpg_verify_tag(oid->hash, name, flags))
if (gpg_verify_tag(oid, name, flags))
return -1;
if (fmt_pretty)

Просмотреть файл

@ -1,7 +1,7 @@
#include "builtin.h"
#include "config.h"
static char *create_temp_file(unsigned char *sha1)
static char *create_temp_file(struct object_id *oid)
{
static char path[50];
void *buf;
@ -9,9 +9,9 @@ static char *create_temp_file(unsigned char *sha1)
unsigned long size;
int fd;
buf = read_sha1_file(sha1, &type, &size);
buf = read_sha1_file(oid->hash, &type, &size);
if (!buf || type != OBJ_BLOB)
die("unable to read blob object %s", sha1_to_hex(sha1));
die("unable to read blob object %s", oid_to_hex(oid));
xsnprintf(path, sizeof(path), ".merge_file_XXXXXX");
fd = xmkstemp(path);
@ -23,15 +23,15 @@ static char *create_temp_file(unsigned char *sha1)
int cmd_unpack_file(int argc, const char **argv, const char *prefix)
{
unsigned char sha1[20];
struct object_id oid;
if (argc != 2 || !strcmp(argv[1], "-h"))
usage("git unpack-file <sha1>");
if (get_sha1(argv[1], sha1))
if (get_oid(argv[1], &oid))
die("Not a valid object name %s", argv[1]);
git_config(git_default_config, NULL);
puts(create_temp_file(sha1));
puts(create_temp_file(&oid));
return 0;
}

Просмотреть файл

@ -94,8 +94,8 @@ static char *parse_refname(struct strbuf *input, const char **next)
* provided but cannot be converted to a SHA-1, die. flags can
* include PARSE_SHA1_OLD and/or PARSE_SHA1_ALLOW_EMPTY.
*/
static int parse_next_sha1(struct strbuf *input, const char **next,
unsigned char *sha1,
static int parse_next_oid(struct strbuf *input, const char **next,
struct object_id *oid,
const char *command, const char *refname,
int flags)
{
@ -115,11 +115,11 @@ static int parse_next_sha1(struct strbuf *input, const char **next,
(*next)++;
*next = parse_arg(*next, &arg);
if (arg.len) {
if (get_sha1(arg.buf, sha1))
if (get_oid(arg.buf, oid))
goto invalid;
} else {
/* Without -z, an empty value means all zeros: */
hashclr(sha1);
oidclr(oid);
}
} else {
/* With -z, read the next NUL-terminated line */
@ -133,13 +133,13 @@ static int parse_next_sha1(struct strbuf *input, const char **next,
*next += arg.len;
if (arg.len) {
if (get_sha1(arg.buf, sha1))
if (get_oid(arg.buf, oid))
goto invalid;
} else if (flags & PARSE_SHA1_ALLOW_EMPTY) {
/* With -z, treat an empty value as all zeros: */
warning("%s %s: missing <newvalue>, treating as zero",
command, refname);
hashclr(sha1);
oidclr(oid);
} else {
/*
* With -z, an empty non-required value means
@ -182,26 +182,25 @@ static const char *parse_cmd_update(struct ref_transaction *transaction,
{
struct strbuf err = STRBUF_INIT;
char *refname;
unsigned char new_sha1[20];
unsigned char old_sha1[20];
struct object_id new_oid, old_oid;
int have_old;
refname = parse_refname(input, &next);
if (!refname)
die("update: missing <ref>");
if (parse_next_sha1(input, &next, new_sha1, "update", refname,
if (parse_next_oid(input, &next, &new_oid, "update", refname,
PARSE_SHA1_ALLOW_EMPTY))
die("update %s: missing <newvalue>", refname);
have_old = !parse_next_sha1(input, &next, old_sha1, "update", refname,
have_old = !parse_next_oid(input, &next, &old_oid, "update", refname,
PARSE_SHA1_OLD);
if (*next != line_termination)
die("update %s: extra input: %s", refname, next);
if (ref_transaction_update(transaction, refname,
new_sha1, have_old ? old_sha1 : NULL,
new_oid.hash, have_old ? old_oid.hash : NULL,
update_flags | create_reflog_flag,
msg, &err))
die("%s", err.buf);
@ -218,22 +217,22 @@ static const char *parse_cmd_create(struct ref_transaction *transaction,
{
struct strbuf err = STRBUF_INIT;
char *refname;
unsigned char new_sha1[20];
struct object_id new_oid;
refname = parse_refname(input, &next);
if (!refname)
die("create: missing <ref>");
if (parse_next_sha1(input, &next, new_sha1, "create", refname, 0))
if (parse_next_oid(input, &next, &new_oid, "create", refname, 0))
die("create %s: missing <newvalue>", refname);
if (is_null_sha1(new_sha1))
if (is_null_oid(&new_oid))
die("create %s: zero <newvalue>", refname);
if (*next != line_termination)
die("create %s: extra input: %s", refname, next);
if (ref_transaction_create(transaction, refname, new_sha1,
if (ref_transaction_create(transaction, refname, new_oid.hash,
update_flags | create_reflog_flag,
msg, &err))
die("%s", err.buf);
@ -250,18 +249,18 @@ static const char *parse_cmd_delete(struct ref_transaction *transaction,
{
struct strbuf err = STRBUF_INIT;
char *refname;
unsigned char old_sha1[20];
struct object_id old_oid;
int have_old;
refname = parse_refname(input, &next);
if (!refname)
die("delete: missing <ref>");
if (parse_next_sha1(input, &next, old_sha1, "delete", refname,
if (parse_next_oid(input, &next, &old_oid, "delete", refname,
PARSE_SHA1_OLD)) {
have_old = 0;
} else {
if (is_null_sha1(old_sha1))
if (is_null_oid(&old_oid))
die("delete %s: zero <oldvalue>", refname);
have_old = 1;
}
@ -270,7 +269,7 @@ static const char *parse_cmd_delete(struct ref_transaction *transaction,
die("delete %s: extra input: %s", refname, next);
if (ref_transaction_delete(transaction, refname,
have_old ? old_sha1 : NULL,
have_old ? old_oid.hash : NULL,
update_flags, msg, &err))
die("%s", err.buf);
@ -286,20 +285,20 @@ static const char *parse_cmd_verify(struct ref_transaction *transaction,
{
struct strbuf err = STRBUF_INIT;
char *refname;
unsigned char old_sha1[20];
struct object_id old_oid;
refname = parse_refname(input, &next);
if (!refname)
die("verify: missing <ref>");
if (parse_next_sha1(input, &next, old_sha1, "verify", refname,
if (parse_next_oid(input, &next, &old_oid, "verify", refname,
PARSE_SHA1_OLD))
hashclr(old_sha1);
oidclr(&old_oid);
if (*next != line_termination)
die("verify %s: extra input: %s", refname, next);
if (ref_transaction_verify(transaction, refname, old_sha1,
if (ref_transaction_verify(transaction, refname, old_oid.hash,
update_flags, &err))
die("%s", err.buf);
@ -355,7 +354,7 @@ static void update_refs_stdin(struct ref_transaction *transaction)
int cmd_update_ref(int argc, const char **argv, const char *prefix)
{
const char *refname, *oldval;
unsigned char sha1[20], oldsha1[20];
struct object_id oid, oldoid;
int delete = 0, no_deref = 0, read_stdin = 0, end_null = 0;
unsigned int flags = 0;
int create_reflog = 0;
@ -412,7 +411,7 @@ int cmd_update_ref(int argc, const char **argv, const char *prefix)
refname = argv[0];
value = argv[1];
oldval = argv[2];
if (get_sha1(value, sha1))
if (get_oid(value, &oid))
die("%s: not a valid SHA1", value);
}
@ -422,8 +421,8 @@ int cmd_update_ref(int argc, const char **argv, const char *prefix)
* The empty string implies that the reference
* must not already exist:
*/
hashclr(oldsha1);
else if (get_sha1(oldval, oldsha1))
oidclr(&oldoid);
else if (get_oid(oldval, &oldoid))
die("%s: not a valid old SHA1", oldval);
}
@ -435,10 +434,10 @@ int cmd_update_ref(int argc, const char **argv, const char *prefix)
* NULL_SHA1 as "don't care" here:
*/
return delete_ref(msg, refname,
(oldval && !is_null_sha1(oldsha1)) ? oldsha1 : NULL,
(oldval && !is_null_oid(&oldoid)) ? oldoid.hash : NULL,
flags);
else
return update_ref(msg, refname, sha1, oldval ? oldsha1 : NULL,
return update_ref(msg, refname, oid.hash, oldval ? oldoid.hash : NULL,
flags | create_reflog_flag,
UPDATE_REFS_DIE_ON_ERR);
}

Просмотреть файл

@ -56,20 +56,21 @@ int cmd_verify_tag(int argc, const char **argv, const char *prefix)
}
while (i < argc) {
unsigned char sha1[20];
struct object_id oid;
const char *name = argv[i++];
if (get_sha1(name, sha1)) {
if (get_oid(name, &oid)) {
had_error = !!error("tag '%s' not found.", name);
continue;
}
if (gpg_verify_tag(sha1, name, flags)) {
if (gpg_verify_tag(&oid, name, flags)) {
had_error = 1;
continue;
}
if (fmt_pretty)
pretty_print_ref(name, sha1, fmt_pretty);
pretty_print_ref(name, oid.hash, fmt_pretty);
}
return had_error;
}

45
cache.h
Просмотреть файл

@ -1283,38 +1283,37 @@ struct object_context {
*/
struct strbuf symlink_path;
/*
* If GET_SHA1_RECORD_PATH is set, this will record path (if any)
* If GET_OID_RECORD_PATH is set, this will record path (if any)
* found when resolving the name. The caller is responsible for
* releasing the memory.
*/
char *path;
};
#define GET_SHA1_QUIETLY 01
#define GET_SHA1_COMMIT 02
#define GET_SHA1_COMMITTISH 04
#define GET_SHA1_TREE 010
#define GET_SHA1_TREEISH 020
#define GET_SHA1_BLOB 040
#define GET_SHA1_FOLLOW_SYMLINKS 0100
#define GET_SHA1_RECORD_PATH 0200
#define GET_SHA1_ONLY_TO_DIE 04000
#define GET_OID_QUIETLY 01
#define GET_OID_COMMIT 02
#define GET_OID_COMMITTISH 04
#define GET_OID_TREE 010
#define GET_OID_TREEISH 020
#define GET_OID_BLOB 040
#define GET_OID_FOLLOW_SYMLINKS 0100
#define GET_OID_RECORD_PATH 0200
#define GET_OID_ONLY_TO_DIE 04000
#define GET_SHA1_DISAMBIGUATORS \
(GET_SHA1_COMMIT | GET_SHA1_COMMITTISH | \
GET_SHA1_TREE | GET_SHA1_TREEISH | \
GET_SHA1_BLOB)
extern int get_sha1(const char *str, unsigned char *sha1);
extern int get_sha1_commit(const char *str, unsigned char *sha1);
extern int get_sha1_committish(const char *str, unsigned char *sha1);
extern int get_sha1_tree(const char *str, unsigned char *sha1);
extern int get_sha1_treeish(const char *str, unsigned char *sha1);
extern int get_sha1_blob(const char *str, unsigned char *sha1);
extern void maybe_die_on_misspelt_object_name(const char *name, const char *prefix);
extern int get_sha1_with_context(const char *str, unsigned flags, unsigned char *sha1, struct object_context *oc);
#define GET_OID_DISAMBIGUATORS \
(GET_OID_COMMIT | GET_OID_COMMITTISH | \
GET_OID_TREE | GET_OID_TREEISH | \
GET_OID_BLOB)
extern int get_oid(const char *str, struct object_id *oid);
extern int get_oid_commit(const char *str, struct object_id *oid);
extern int get_oid_committish(const char *str, struct object_id *oid);
extern int get_oid_tree(const char *str, struct object_id *oid);
extern int get_oid_treeish(const char *str, struct object_id *oid);
extern int get_oid_blob(const char *str, struct object_id *oid);
extern void maybe_die_on_misspelt_object_name(const char *name, const char *prefix);
extern int get_oid_with_context(const char *str, unsigned flags, struct object_id *oid, struct object_context *oc);
typedef int each_abbrev_fn(const struct object_id *oid, void *);
extern int for_each_abbrev(const char *prefix, each_abbrev_fn, void *);

Просмотреть файл

@ -59,7 +59,7 @@ struct commit *lookup_commit_reference_by_name(const char *name)
struct object_id oid;
struct commit *commit;
if (get_sha1_committish(name, oid.hash))
if (get_oid_committish(name, &oid))
return NULL;
commit = lookup_commit_reference(&oid);
if (parse_commit(commit))
@ -199,11 +199,11 @@ static void prepare_commit_graft(void)
commit_graft_prepared = 1;
}
struct commit_graft *lookup_commit_graft(const unsigned char *sha1)
struct commit_graft *lookup_commit_graft(const struct object_id *oid)
{
int pos;
prepare_commit_graft();
pos = commit_graft_pos(sha1);
pos = commit_graft_pos(oid->hash);
if (pos < 0)
return NULL;
return commit_graft[pos];
@ -335,7 +335,7 @@ int parse_commit_buffer(struct commit *item, const void *buffer, unsigned long s
bufptr += tree_entry_len + 1; /* "tree " + "hex sha1" + "\n" */
pptr = &item->parents;
graft = lookup_commit_graft(item->object.oid.hash);
graft = lookup_commit_graft(&item->object.oid);
while (bufptr + parent_entry_len < tail && !memcmp(bufptr, "parent ", 7)) {
struct commit *new_parent;
@ -1587,7 +1587,7 @@ struct commit *get_merge_parent(const char *name)
struct object *obj;
struct commit *commit;
struct object_id oid;
if (get_sha1(name, oid.hash))
if (get_oid(name, &oid))
return NULL;
obj = parse_object(&oid);
commit = (struct commit *)peel_to_type(name, 0, obj, OBJ_COMMIT);

Просмотреть файл

@ -249,7 +249,7 @@ typedef int (*each_commit_graft_fn)(const struct commit_graft *, void *);
struct commit_graft *read_graft_line(char *buf, int len);
int register_commit_graft(struct commit_graft *, int);
struct commit_graft *lookup_commit_graft(const unsigned char *sha1);
struct commit_graft *lookup_commit_graft(const struct object_id *oid);
extern struct commit_list *get_merge_bases(struct commit *rev1, struct commit *rev2);
extern struct commit_list *get_merge_bases_many(struct commit *one, int n, struct commit **twos);

Просмотреть файл

@ -1460,9 +1460,9 @@ int git_config_from_mem(config_fn_t fn, const enum config_origin_type origin_typ
return do_config_from(&top, fn, data);
}
int git_config_from_blob_sha1(config_fn_t fn,
int git_config_from_blob_oid(config_fn_t fn,
const char *name,
const unsigned char *sha1,
const struct object_id *oid,
void *data)
{
enum object_type type;
@ -1470,7 +1470,7 @@ int git_config_from_blob_sha1(config_fn_t fn,
unsigned long size;
int ret;
buf = read_sha1_file(sha1, &type, &size);
buf = read_sha1_file(oid->hash, &type, &size);
if (!buf)
return error("unable to load config blob object '%s'", name);
if (type != OBJ_BLOB) {
@ -1488,11 +1488,11 @@ static int git_config_from_blob_ref(config_fn_t fn,
const char *name,
void *data)
{
unsigned char sha1[20];
struct object_id oid;
if (get_sha1(name, sha1) < 0)
if (get_oid(name, &oid) < 0)
return error("unable to resolve config blob '%s'", name);
return git_config_from_blob_sha1(fn, name, sha1, data);
return git_config_from_blob_oid(fn, name, &oid, data);
}
const char *git_etc_gitconfig(void)

Просмотреть файл

@ -39,8 +39,8 @@ extern int git_default_config(const char *, const char *, void *);
extern int git_config_from_file(config_fn_t fn, const char *, void *);
extern int git_config_from_mem(config_fn_t fn, const enum config_origin_type,
const char *name, const char *buf, size_t len, void *data);
extern int git_config_from_blob_sha1(config_fn_t fn, const char *name,
const unsigned char *sha1, void *data);
extern int git_config_from_blob_oid(config_fn_t fn, const char *name,
const struct object_id *oid, void *data);
extern void git_config_push_parameter(const char *text);
extern int git_config_from_parameters(config_fn_t fn, void *data);
extern void read_early_config(config_fn_t cb, void *data);

2
fsck.c
Просмотреть файл

@ -736,7 +736,7 @@ static int fsck_commit_buffer(struct commit *commit, const char *buffer,
buffer += 41;
parent_line_count++;
}
graft = lookup_commit_graft(commit->object.oid.hash);
graft = lookup_commit_graft(&commit->object.oid);
parent_count = commit_list_count(commit->parents);
if (graft) {
if (graft->nr_parent == -1 && !parent_count)

Просмотреть файл

@ -214,17 +214,17 @@ static int read_mailmap_blob(struct string_list *map,
const char *name,
char **repo_abbrev)
{
unsigned char sha1[20];
struct object_id oid;
char *buf;
unsigned long size;
enum object_type type;
if (!name)
return 0;
if (get_sha1(name, sha1) < 0)
if (get_oid(name, &oid) < 0)
return 0;
buf = read_sha1_file(sha1, &type, &size);
buf = read_sha1_file(oid.hash, &type, &size);
if (!buf)
return error("unable to read mailmap object at %s", name);
if (type != OBJ_BLOB)

Просмотреть файл

@ -1026,7 +1026,7 @@ void init_notes(struct notes_tree *t, const char *notes_ref,
t->dirty = 0;
if (flags & NOTES_INIT_EMPTY || !notes_ref ||
get_sha1_treeish(notes_ref, object_oid.hash))
get_oid_treeish(notes_ref, &object_oid))
return;
if (flags & NOTES_INIT_WRITABLE && read_ref(notes_ref, object_oid.hash))
die("Cannot use notes ref %s", notes_ref);

2
refs.c
Просмотреть файл

@ -818,7 +818,7 @@ int read_ref_at(const char *refname, unsigned int flags, timestamp_t at_time, in
for_each_reflog_ent_reverse(refname, read_ref_at_ent, &cb);
if (!cb.reccnt) {
if (flags & GET_SHA1_QUIETLY)
if (flags & GET_OID_QUIETLY)
exit(128);
else
die("Log for %s is empty.", refname);

Просмотреть файл

@ -1081,7 +1081,7 @@ static int try_explicit_object_name(const char *name,
return 0;
}
if (get_sha1(name, oid.hash))
if (get_oid(name, &oid))
return -1;
if (match) {
@ -2297,8 +2297,8 @@ static int parse_push_cas_option(struct push_cas_option *cas, const char *arg, i
if (!*colon)
entry->use_tracking = 1;
else if (!colon[1])
hashclr(entry->expect);
else if (get_sha1(colon + 1, entry->expect))
oidclr(&entry->expect);
else if (get_oid(colon + 1, &entry->expect))
return error("cannot parse expected object name '%s'", colon + 1);
return 0;
}
@ -2345,7 +2345,7 @@ static void apply_cas(struct push_cas_option *cas,
continue;
ref->expect_old_sha1 = 1;
if (!entry->use_tracking)
hashcpy(ref->old_oid_expect.hash, cas->entry[i].expect);
oidcpy(&ref->old_oid_expect, &entry->expect);
else if (remote_tracking(remote, ref->name, &ref->old_oid_expect))
oidclr(&ref->old_oid_expect);
return;

Просмотреть файл

@ -282,7 +282,7 @@ struct ref *get_stale_heads(struct refspec *refs, int ref_count, struct ref *fet
struct push_cas_option {
unsigned use_tracking_for_rest:1;
struct push_cas {
unsigned char expect[20];
struct object_id expect;
unsigned use_tracking:1;
char *refname;
} *entry;

Просмотреть файл

@ -160,7 +160,7 @@ int repo_submodule_init(struct repository *submodule,
struct strbuf worktree = STRBUF_INIT;
int ret = 0;
sub = submodule_from_cache(superproject, null_sha1, path);
sub = submodule_from_cache(superproject, &null_oid, path);
if (!sub) {
ret = -1;
goto out;

Просмотреть файл

@ -1303,7 +1303,7 @@ static int add_parents_only(struct rev_info *revs, const char *arg_, int flags,
flags ^= UNINTERESTING | BOTTOM;
arg++;
}
if (get_sha1_committish(arg, oid.hash))
if (get_oid_committish(arg, &oid))
return 0;
while (1) {
it = get_reference(revs, arg, &oid, 0);
@ -1452,7 +1452,7 @@ static int handle_dotdot_1(const char *arg, char *dotdot,
unsigned int a_flags, b_flags;
int symmetric = 0;
unsigned int flags_exclude = flags ^ (UNINTERESTING | BOTTOM);
unsigned int oc_flags = GET_SHA1_COMMITTISH | GET_SHA1_RECORD_PATH;
unsigned int oc_flags = GET_OID_COMMITTISH | GET_OID_RECORD_PATH;
a_name = arg;
if (!*a_name)
@ -1466,8 +1466,8 @@ static int handle_dotdot_1(const char *arg, char *dotdot,
if (!*b_name)
b_name = "HEAD";
if (get_sha1_with_context(a_name, oc_flags, a_oid.hash, a_oc) ||
get_sha1_with_context(b_name, oc_flags, b_oid.hash, b_oc))
if (get_oid_with_context(a_name, oc_flags, &a_oid, a_oc) ||
get_oid_with_context(b_name, oc_flags, &b_oid, b_oc))
return -1;
if (!cant_be_filename) {
@ -1548,7 +1548,7 @@ int handle_revision_arg(const char *arg_, struct rev_info *revs, int flags, unsi
int local_flags;
const char *arg = arg_;
int cant_be_filename = revarg_opt & REVARG_CANNOT_BE_FILENAME;
unsigned get_sha1_flags = GET_SHA1_RECORD_PATH;
unsigned get_sha1_flags = GET_OID_RECORD_PATH;
flags = flags & UNINTERESTING ? flags | BOTTOM : flags & ~BOTTOM;
@ -1599,9 +1599,9 @@ int handle_revision_arg(const char *arg_, struct rev_info *revs, int flags, unsi
}
if (revarg_opt & REVARG_COMMITTISH)
get_sha1_flags |= GET_SHA1_COMMITTISH;
get_sha1_flags |= GET_OID_COMMITTISH;
if (get_sha1_with_context(arg, get_sha1_flags, oid.hash, &oc))
if (get_oid_with_context(arg, get_sha1_flags, &oid, &oc))
return revs->ignore_missing ? 0 : -1;
if (!cant_be_filename)
verify_non_filename(revs->prefix, arg);
@ -2319,7 +2319,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
struct object_id oid;
struct object *object;
struct object_context oc;
if (get_sha1_with_context(revs->def, 0, oid.hash, &oc))
if (get_oid_with_context(revs->def, 0, &oid, &oc))
diagnose_missing_default(revs->def);
object = get_reference(revs, revs->def, &oid, 0);
add_pending_object_with_mode(revs, object, revs->def, oc.mode);

Просмотреть файл

@ -691,7 +691,7 @@ static int run_git_commit(const char *defmsg, struct replay_opts *opts,
static int is_original_commit_empty(struct commit *commit)
{
const unsigned char *ptree_sha1;
const struct object_id *ptree_oid;
if (parse_commit(commit))
return error(_("could not parse commit %s\n"),
@ -701,12 +701,12 @@ static int is_original_commit_empty(struct commit *commit)
if (parse_commit(parent))
return error(_("could not parse parent commit %s\n"),
oid_to_hex(&parent->object.oid));
ptree_sha1 = parent->tree->object.oid.hash;
ptree_oid = &parent->tree->object.oid;
} else {
ptree_sha1 = EMPTY_TREE_SHA1_BIN; /* commit is root */
ptree_oid = &empty_tree_oid; /* commit is root */
}
return !hashcmp(ptree_sha1, commit->tree->object.oid.hash);
return !oidcmp(ptree_oid, &commit->tree->object.oid);
}
/*
@ -896,18 +896,18 @@ static int update_squash_messages(enum todo_command command,
static void flush_rewritten_pending(void) {
struct strbuf buf = STRBUF_INIT;
unsigned char newsha1[20];
struct object_id newoid;
FILE *out;
if (strbuf_read_file(&buf, rebase_path_rewritten_pending(), 82) > 0 &&
!get_sha1("HEAD", newsha1) &&
if (strbuf_read_file(&buf, rebase_path_rewritten_pending(), (GIT_MAX_HEXSZ + 1) * 2) > 0 &&
!get_oid("HEAD", &newoid) &&
(out = fopen_or_warn(rebase_path_rewritten_list(), "a"))) {
char *bol = buf.buf, *eol;
while (*bol) {
eol = strchrnul(bol, '\n');
fprintf(out, "%.*s %s\n", (int)(eol - bol),
bol, sha1_to_hex(newsha1));
bol, oid_to_hex(&newoid));
if (!*eol)
break;
bol = eol + 1;
@ -1594,36 +1594,37 @@ static int rollback_is_safe(void)
return !oidcmp(&actual_head, &expected_head);
}
static int reset_for_rollback(const unsigned char *sha1)
static int reset_for_rollback(const struct object_id *oid)
{
const char *argv[4]; /* reset --merge <arg> + NULL */
argv[0] = "reset";
argv[1] = "--merge";
argv[2] = sha1_to_hex(sha1);
argv[2] = oid_to_hex(oid);
argv[3] = NULL;
return run_command_v_opt(argv, RUN_GIT_CMD);
}
static int rollback_single_pick(void)
{
unsigned char head_sha1[20];
struct object_id head_oid;
if (!file_exists(git_path_cherry_pick_head()) &&
!file_exists(git_path_revert_head()))
return error(_("no cherry-pick or revert in progress"));
if (read_ref_full("HEAD", 0, head_sha1, NULL))
if (read_ref_full("HEAD", 0, head_oid.hash, NULL))
return error(_("cannot resolve HEAD"));
if (is_null_sha1(head_sha1))
if (is_null_oid(&head_oid))
return error(_("cannot abort from a branch yet to be born"));
return reset_for_rollback(head_sha1);
return reset_for_rollback(&head_oid);
}
int sequencer_rollback(struct replay_opts *opts)
{
FILE *f;
unsigned char sha1[20];
struct object_id oid;
struct strbuf buf = STRBUF_INIT;
const char *p;
f = fopen(git_path_head_file(), "r");
if (!f && errno == ENOENT) {
@ -1643,12 +1644,12 @@ int sequencer_rollback(struct replay_opts *opts)
goto fail;
}
fclose(f);
if (get_sha1_hex(buf.buf, sha1) || buf.buf[40] != '\0') {
if (parse_oid_hex(buf.buf, &oid, &p) || *p != '\0') {
error(_("stored pre-cherry-pick HEAD file '%s' is corrupt"),
git_path_head_file());
goto fail;
}
if (is_null_sha1(sha1)) {
if (is_null_oid(&oid)) {
error(_("cannot abort from a branch yet to be born"));
goto fail;
}
@ -1658,7 +1659,7 @@ int sequencer_rollback(struct replay_opts *opts)
warning(_("You seem to have moved HEAD. "
"Not rewinding, check your HEAD!"));
} else
if (reset_for_rollback(sha1))
if (reset_for_rollback(&oid))
goto fail;
strbuf_release(&buf);
return sequencer_remove_state(opts);
@ -1788,13 +1789,13 @@ static int make_patch(struct commit *commit, struct replay_opts *opts)
static int intend_to_amend(void)
{
unsigned char head[20];
struct object_id head;
char *p;
if (get_sha1("HEAD", head))
if (get_oid("HEAD", &head))
return error(_("cannot read HEAD"));
p = sha1_to_hex(head);
p = oid_to_hex(&head);
return write_message(p, strlen(p), rebase_path_amend(), 1);
}
@ -2079,10 +2080,10 @@ static int pick_commits(struct todo_list *todo_list, struct replay_opts *opts)
if (read_oneliner(&head_ref, rebase_path_head_name(), 0) &&
starts_with(head_ref.buf, "refs/")) {
const char *msg;
unsigned char head[20], orig[20];
struct object_id head, orig;
int res;
if (get_sha1("HEAD", head)) {
if (get_oid("HEAD", &head)) {
res = error(_("cannot read HEAD"));
cleanup_head_ref:
strbuf_release(&head_ref);
@ -2090,7 +2091,7 @@ cleanup_head_ref:
return res;
}
if (!read_oneliner(&buf, rebase_path_orig_head(), 0) ||
get_sha1_hex(buf.buf, orig)) {
get_oid_hex(buf.buf, &orig)) {
res = error(_("could not read orig-head"));
goto cleanup_head_ref;
}
@ -2101,7 +2102,7 @@ cleanup_head_ref:
}
msg = reflog_message(opts, "finish", "%s onto %s",
head_ref.buf, buf.buf);
if (update_ref(msg, head_ref.buf, head, orig,
if (update_ref(msg, head_ref.buf, head.hash, orig.hash,
REF_NODEREF, UPDATE_REFS_MSG_ON_ERR)) {
res = error(_("could not update %s"),
head_ref.buf);
@ -2129,8 +2130,8 @@ cleanup_head_ref:
log_tree_opt.disable_stdin = 1;
if (read_oneliner(&buf, rebase_path_orig_head(), 0) &&
!get_sha1(buf.buf, orig.hash) &&
!get_sha1("HEAD", head.hash)) {
!get_oid(buf.buf, &orig) &&
!get_oid("HEAD", &head)) {
diff_tree_oid(&orig, &head, "",
&log_tree_opt.diffopt);
log_tree_diff_flush(&log_tree_opt);
@ -2205,16 +2206,16 @@ static int commit_staged_changes(struct replay_opts *opts)
if (file_exists(rebase_path_amend())) {
struct strbuf rev = STRBUF_INIT;
unsigned char head[20], to_amend[20];
struct object_id head, to_amend;
if (get_sha1("HEAD", head))
if (get_oid("HEAD", &head))
return error(_("cannot amend non-existing commit"));
if (!read_oneliner(&rev, rebase_path_amend(), 0))
return error(_("invalid file: '%s'"), rebase_path_amend());
if (get_sha1_hex(rev.buf, to_amend))
if (get_oid_hex(rev.buf, &to_amend))
return error(_("invalid contents: '%s'"),
rebase_path_amend());
if (hashcmp(head, to_amend))
if (oidcmp(&head, &to_amend))
return error(_("\nYou have uncommitted changes in your "
"working tree. Please, commit them\n"
"first and then run 'git rebase "
@ -2266,7 +2267,7 @@ int sequencer_continue(struct replay_opts *opts)
struct object_id oid;
if (read_oneliner(&buf, rebase_path_stopped_sha(), 1) &&
!get_sha1_committish(buf.buf, oid.hash))
!get_oid_committish(buf.buf, &oid))
record_in_rewritten(&oid, peek_command(&todo_list, 0));
strbuf_release(&buf);
}

Просмотреть файл

@ -10,7 +10,7 @@
#include "dir.h"
#include "sha1-array.h"
static int get_sha1_oneline(const char *, unsigned char *, struct commit_list *);
static int get_oid_oneline(const char *, struct object_id *, struct commit_list *);
typedef int (*disambiguate_hint_fn)(const struct object_id *, void *);
@ -200,7 +200,7 @@ static void find_short_packed_object(struct disambiguate_state *ds)
#define SHORT_NAME_AMBIGUOUS (-2)
static int finish_object_disambiguation(struct disambiguate_state *ds,
unsigned char *sha1)
struct object_id *oid)
{
if (ds->ambiguous)
return SHORT_NAME_AMBIGUOUS;
@ -229,7 +229,7 @@ static int finish_object_disambiguation(struct disambiguate_state *ds,
if (!ds->candidate_ok)
return SHORT_NAME_AMBIGUOUS;
hashcpy(sha1, ds->candidate.hash);
oidcpy(oid, &ds->candidate);
return 0;
}
@ -385,35 +385,35 @@ static int show_ambiguous_object(const struct object_id *oid, void *data)
return 0;
}
static int get_short_sha1(const char *name, int len, unsigned char *sha1,
static int get_short_oid(const char *name, int len, struct object_id *oid,
unsigned flags)
{
int status;
struct disambiguate_state ds;
int quietly = !!(flags & GET_SHA1_QUIETLY);
int quietly = !!(flags & GET_OID_QUIETLY);
if (init_object_disambiguation(name, len, &ds) < 0)
return -1;
if (HAS_MULTI_BITS(flags & GET_SHA1_DISAMBIGUATORS))
die("BUG: multiple get_short_sha1 disambiguator flags");
if (HAS_MULTI_BITS(flags & GET_OID_DISAMBIGUATORS))
die("BUG: multiple get_short_oid disambiguator flags");
if (flags & GET_SHA1_COMMIT)
if (flags & GET_OID_COMMIT)
ds.fn = disambiguate_commit_only;
else if (flags & GET_SHA1_COMMITTISH)
else if (flags & GET_OID_COMMITTISH)
ds.fn = disambiguate_committish_only;
else if (flags & GET_SHA1_TREE)
else if (flags & GET_OID_TREE)
ds.fn = disambiguate_tree_only;
else if (flags & GET_SHA1_TREEISH)
else if (flags & GET_OID_TREEISH)
ds.fn = disambiguate_treeish_only;
else if (flags & GET_SHA1_BLOB)
else if (flags & GET_OID_BLOB)
ds.fn = disambiguate_blob_only;
else
ds.fn = default_disambiguate_hint;
find_short_object_filename(&ds);
find_short_packed_object(&ds);
status = finish_object_disambiguation(&ds, sha1);
status = finish_object_disambiguation(&ds, oid);
if (!quietly && (status == SHORT_NAME_AMBIGUOUS)) {
error(_("short SHA1 %s is ambiguous"), ds.hex_pfx);
@ -500,12 +500,12 @@ int find_unique_abbrev_r(char *hex, const unsigned char *sha1, int len)
}
sha1_to_hex_r(hex, sha1);
if (len == 40 || !len)
return 40;
if (len == GIT_SHA1_HEXSZ || !len)
return GIT_SHA1_HEXSZ;
exists = has_sha1_file(sha1);
while (len < 40) {
unsigned char sha1_ret[20];
status = get_short_sha1(hex, len, sha1_ret, GET_SHA1_QUIETLY);
while (len < GIT_SHA1_HEXSZ) {
struct object_id oid_ret;
status = get_short_oid(hex, len, &oid_ret, GET_OID_QUIETLY);
if (exists
? !status
: status == SHORT_NAME_NOT_FOUND) {
@ -578,10 +578,10 @@ static inline int push_mark(const char *string, int len)
return at_mark(string, len, suffix, ARRAY_SIZE(suffix));
}
static int get_sha1_1(const char *name, int len, unsigned char *sha1, unsigned lookup_flags);
static int get_oid_1(const char *name, int len, struct object_id *oid, unsigned lookup_flags);
static int interpret_nth_prior_checkout(const char *name, int namelen, struct strbuf *buf);
static int get_sha1_basic(const char *str, int len, unsigned char *sha1,
static int get_oid_basic(const char *str, int len, struct object_id *oid,
unsigned int flags)
{
static const char *warn_msg = "refname '%.*s' is ambiguous.";
@ -595,14 +595,14 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1,
"where \"$br\" is somehow empty and a 40-hex ref is created. Please\n"
"examine these refs and maybe delete them. Turn this message off by\n"
"running \"git config advice.objectNameWarning false\"");
unsigned char tmp_sha1[20];
struct object_id tmp_oid;
char *real_ref = NULL;
int refs_found = 0;
int at, reflog_len, nth_prior = 0;
if (len == 40 && !get_sha1_hex(str, sha1)) {
if (len == GIT_SHA1_HEXSZ && !get_oid_hex(str, oid)) {
if (warn_ambiguous_refs && warn_on_object_refname_ambiguity) {
refs_found = dwim_ref(str, len, tmp_sha1, &real_ref);
refs_found = dwim_ref(str, len, tmp_oid.hash, &real_ref);
if (refs_found > 0) {
warning(warn_msg, len, str);
if (advice_object_name_warning)
@ -644,7 +644,7 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1,
int detached;
if (interpret_nth_prior_checkout(str, len, &buf) > 0) {
detached = (buf.len == 40 && !get_sha1_hex(buf.buf, sha1));
detached = (buf.len == GIT_SHA1_HEXSZ && !get_oid_hex(buf.buf, oid));
strbuf_release(&buf);
if (detached)
return 0;
@ -653,18 +653,18 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1,
if (!len && reflog_len)
/* allow "@{...}" to mean the current branch reflog */
refs_found = dwim_ref("HEAD", 4, sha1, &real_ref);
refs_found = dwim_ref("HEAD", 4, oid->hash, &real_ref);
else if (reflog_len)
refs_found = dwim_log(str, len, sha1, &real_ref);
refs_found = dwim_log(str, len, oid->hash, &real_ref);
else
refs_found = dwim_ref(str, len, sha1, &real_ref);
refs_found = dwim_ref(str, len, oid->hash, &real_ref);
if (!refs_found)
return -1;
if (warn_ambiguous_refs && !(flags & GET_SHA1_QUIETLY) &&
if (warn_ambiguous_refs && !(flags & GET_OID_QUIETLY) &&
(refs_found > 1 ||
!get_short_sha1(str, len, tmp_sha1, GET_SHA1_QUIETLY)))
!get_short_oid(str, len, &tmp_oid, GET_OID_QUIETLY)))
warning(warn_msg, len, str);
if (reflog_len) {
@ -696,7 +696,7 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1,
return -1;
}
}
if (read_ref_at(real_ref, flags, at_time, nth, sha1, NULL,
if (read_ref_at(real_ref, flags, at_time, nth, oid->hash, NULL,
&co_time, &co_tz, &co_cnt)) {
if (!len) {
if (starts_with(real_ref, "refs/heads/")) {
@ -709,13 +709,13 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1,
}
}
if (at_time) {
if (!(flags & GET_SHA1_QUIETLY)) {
if (!(flags & GET_OID_QUIETLY)) {
warning("Log for '%.*s' only goes "
"back to %s.", len, str,
show_date(co_time, co_tz, DATE_MODE(RFC2822)));
}
} else {
if (flags & GET_SHA1_QUIETLY) {
if (flags & GET_OID_QUIETLY) {
exit(128);
}
die("Log for '%.*s' only has %d entries.",
@ -729,10 +729,10 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1,
}
static int get_parent(const char *name, int len,
unsigned char *result, int idx)
struct object_id *result, int idx)
{
struct object_id oid;
int ret = get_sha1_1(name, len, oid.hash, GET_SHA1_COMMITTISH);
int ret = get_oid_1(name, len, &oid, GET_OID_COMMITTISH);
struct commit *commit;
struct commit_list *p;
@ -742,13 +742,13 @@ static int get_parent(const char *name, int len,
if (parse_commit(commit))
return -1;
if (!idx) {
hashcpy(result, commit->object.oid.hash);
oidcpy(result, &commit->object.oid);
return 0;
}
p = commit->parents;
while (p) {
if (!--idx) {
hashcpy(result, p->item->object.oid.hash);
oidcpy(result, &p->item->object.oid);
return 0;
}
p = p->next;
@ -757,13 +757,13 @@ static int get_parent(const char *name, int len,
}
static int get_nth_ancestor(const char *name, int len,
unsigned char *result, int generation)
struct object_id *result, int generation)
{
struct object_id oid;
struct commit *commit;
int ret;
ret = get_sha1_1(name, len, oid.hash, GET_SHA1_COMMITTISH);
ret = get_oid_1(name, len, &oid, GET_OID_COMMITTISH);
if (ret)
return ret;
commit = lookup_commit_reference(&oid);
@ -775,7 +775,7 @@ static int get_nth_ancestor(const char *name, int len,
return -1;
commit = commit->parents->item;
}
hashcpy(result, commit->object.oid.hash);
oidcpy(result, &commit->object.oid);
return 0;
}
@ -804,7 +804,7 @@ struct object *peel_to_type(const char *name, int namelen,
}
}
static int peel_onion(const char *name, int len, unsigned char *sha1,
static int peel_onion(const char *name, int len, struct object_id *oid,
unsigned lookup_flags)
{
struct object_id outer;
@ -849,13 +849,13 @@ static int peel_onion(const char *name, int len, unsigned char *sha1,
else
return -1;
lookup_flags &= ~GET_SHA1_DISAMBIGUATORS;
lookup_flags &= ~GET_OID_DISAMBIGUATORS;
if (expected_type == OBJ_COMMIT)
lookup_flags |= GET_SHA1_COMMITTISH;
lookup_flags |= GET_OID_COMMITTISH;
else if (expected_type == OBJ_TREE)
lookup_flags |= GET_SHA1_TREEISH;
lookup_flags |= GET_OID_TREEISH;
if (get_sha1_1(name, sp - name - 2, outer.hash, lookup_flags))
if (get_oid_1(name, sp - name - 2, &outer, lookup_flags))
return -1;
o = parse_object(&outer);
@ -865,7 +865,7 @@ static int peel_onion(const char *name, int len, unsigned char *sha1,
o = deref_tag(o, name, sp - name - 2);
if (!o || (!o->parsed && !parse_object(&o->oid)))
return -1;
hashcpy(sha1, o->oid.hash);
oidcpy(oid, &o->oid);
return 0;
}
@ -878,7 +878,7 @@ static int peel_onion(const char *name, int len, unsigned char *sha1,
if (!o)
return -1;
hashcpy(sha1, o->oid.hash);
oidcpy(oid, &o->oid);
if (sp[0] == '/') {
/* "$commit^{/foo}" */
char *prefix;
@ -894,17 +894,17 @@ static int peel_onion(const char *name, int len, unsigned char *sha1,
prefix = xstrndup(sp + 1, name + len - 1 - (sp + 1));
commit_list_insert((struct commit *)o, &list);
ret = get_sha1_oneline(prefix, sha1, list);
ret = get_oid_oneline(prefix, oid, list);
free(prefix);
return ret;
}
return 0;
}
static int get_describe_name(const char *name, int len, unsigned char *sha1)
static int get_describe_name(const char *name, int len, struct object_id *oid)
{
const char *cp;
unsigned flags = GET_SHA1_QUIETLY | GET_SHA1_COMMIT;
unsigned flags = GET_OID_QUIETLY | GET_OID_COMMIT;
for (cp = name + len - 1; name + 2 <= cp; cp--) {
char ch = *cp;
@ -915,14 +915,14 @@ static int get_describe_name(const char *name, int len, unsigned char *sha1)
if (ch == 'g' && cp[-1] == '-') {
cp++;
len -= cp - name;
return get_short_sha1(cp, len, sha1, flags);
return get_short_oid(cp, len, oid, flags);
}
}
}
return -1;
}
static int get_sha1_1(const char *name, int len, unsigned char *sha1, unsigned lookup_flags)
static int get_oid_1(const char *name, int len, struct object_id *oid, unsigned lookup_flags)
{
int ret, has_suffix;
const char *cp;
@ -949,25 +949,25 @@ static int get_sha1_1(const char *name, int len, unsigned char *sha1, unsigned l
if (!num && len1 == len - 1)
num = 1;
if (has_suffix == '^')
return get_parent(name, len1, sha1, num);
return get_parent(name, len1, oid, num);
/* else if (has_suffix == '~') -- goes without saying */
return get_nth_ancestor(name, len1, sha1, num);
return get_nth_ancestor(name, len1, oid, num);
}
ret = peel_onion(name, len, sha1, lookup_flags);
ret = peel_onion(name, len, oid, lookup_flags);
if (!ret)
return 0;
ret = get_sha1_basic(name, len, sha1, lookup_flags);
ret = get_oid_basic(name, len, oid, lookup_flags);
if (!ret)
return 0;
/* It could be describe output that is "SOMETHING-gXXXX" */
ret = get_describe_name(name, len, sha1);
ret = get_describe_name(name, len, oid);
if (!ret)
return 0;
return get_short_sha1(name, len, sha1, lookup_flags);
return get_short_oid(name, len, oid, lookup_flags);
}
/*
@ -1004,7 +1004,7 @@ static int handle_one_ref(const char *path, const struct object_id *oid,
return 0;
}
static int get_sha1_oneline(const char *prefix, unsigned char *sha1,
static int get_oid_oneline(const char *prefix, struct object_id *oid,
struct commit_list *list)
{
struct commit_list *backup = NULL, *l;
@ -1044,7 +1044,7 @@ static int get_sha1_oneline(const char *prefix, unsigned char *sha1,
unuse_commit_buffer(commit, buf);
if (matches) {
hashcpy(sha1, commit->object.oid.hash);
oidcpy(oid, &commit->object.oid);
found = 1;
break;
}
@ -1140,7 +1140,7 @@ int get_oid_mb(const char *name, struct object_id *oid)
struct strbuf sb;
strbuf_init(&sb, dots - name);
strbuf_add(&sb, name, dots - name);
st = get_sha1_committish(sb.buf, oid_tmp.hash);
st = get_oid_committish(sb.buf, &oid_tmp);
strbuf_release(&sb);
}
if (st)
@ -1149,7 +1149,7 @@ int get_oid_mb(const char *name, struct object_id *oid)
if (!one)
return -1;
if (get_sha1_committish(dots[3] ? (dots + 3) : "HEAD", oid_tmp.hash))
if (get_oid_committish(dots[3] ? (dots + 3) : "HEAD", &oid_tmp))
return -1;
two = lookup_commit_reference_gently(&oid_tmp, 0);
if (!two)
@ -1338,21 +1338,13 @@ int strbuf_check_branch_ref(struct strbuf *sb, const char *name)
}
/*
* This is like "get_sha1_basic()", except it allows "sha1 expressions",
* This is like "get_oid_basic()", except it allows "object ID expressions",
* notably "xyz^" for "parent of xyz"
*/
int get_sha1(const char *name, unsigned char *sha1)
{
struct object_context unused;
return get_sha1_with_context(name, 0, sha1, &unused);
}
/*
* This is like "get_sha1()", but for struct object_id.
*/
int get_oid(const char *name, struct object_id *oid)
{
return get_sha1(name, oid->hash);
struct object_context unused;
return get_oid_with_context(name, 0, oid, &unused);
}
@ -1366,49 +1358,49 @@ int get_oid(const char *name, struct object_id *oid)
* commit-ish. It is merely to give a hint to the disambiguation
* machinery.
*/
int get_sha1_committish(const char *name, unsigned char *sha1)
int get_oid_committish(const char *name, struct object_id *oid)
{
struct object_context unused;
return get_sha1_with_context(name, GET_SHA1_COMMITTISH,
sha1, &unused);
return get_oid_with_context(name, GET_OID_COMMITTISH,
oid, &unused);
}
int get_sha1_treeish(const char *name, unsigned char *sha1)
int get_oid_treeish(const char *name, struct object_id *oid)
{
struct object_context unused;
return get_sha1_with_context(name, GET_SHA1_TREEISH,
sha1, &unused);
return get_oid_with_context(name, GET_OID_TREEISH,
oid, &unused);
}
int get_sha1_commit(const char *name, unsigned char *sha1)
int get_oid_commit(const char *name, struct object_id *oid)
{
struct object_context unused;
return get_sha1_with_context(name, GET_SHA1_COMMIT,
sha1, &unused);
return get_oid_with_context(name, GET_OID_COMMIT,
oid, &unused);
}
int get_sha1_tree(const char *name, unsigned char *sha1)
int get_oid_tree(const char *name, struct object_id *oid)
{
struct object_context unused;
return get_sha1_with_context(name, GET_SHA1_TREE,
sha1, &unused);
return get_oid_with_context(name, GET_OID_TREE,
oid, &unused);
}
int get_sha1_blob(const char *name, unsigned char *sha1)
int get_oid_blob(const char *name, struct object_id *oid)
{
struct object_context unused;
return get_sha1_with_context(name, GET_SHA1_BLOB,
sha1, &unused);
return get_oid_with_context(name, GET_OID_BLOB,
oid, &unused);
}
/* Must be called only when object_name:filename doesn't exist. */
static void diagnose_invalid_sha1_path(const char *prefix,
static void diagnose_invalid_oid_path(const char *prefix,
const char *filename,
const unsigned char *tree_sha1,
const struct object_id *tree_oid,
const char *object_name,
int object_name_len)
{
unsigned char sha1[20];
struct object_id oid;
unsigned mode;
if (!prefix)
@ -1420,8 +1412,8 @@ static void diagnose_invalid_sha1_path(const char *prefix,
if (is_missing_file_error(errno)) {
char *fullname = xstrfmt("%s%s", prefix, filename);
if (!get_tree_entry(tree_sha1, fullname,
sha1, &mode)) {
if (!get_tree_entry(tree_oid->hash, fullname,
oid.hash, &mode)) {
die("Path '%s' exists, but not '%s'.\n"
"Did you mean '%.*s:%s' aka '%.*s:./%s'?",
fullname,
@ -1504,24 +1496,24 @@ static char *resolve_relative_path(const char *rel)
rel);
}
static int get_sha1_with_context_1(const char *name,
static int get_oid_with_context_1(const char *name,
unsigned flags,
const char *prefix,
unsigned char *sha1,
struct object_id *oid,
struct object_context *oc)
{
int ret, bracket_depth;
int namelen = strlen(name);
const char *cp;
int only_to_die = flags & GET_SHA1_ONLY_TO_DIE;
int only_to_die = flags & GET_OID_ONLY_TO_DIE;
if (only_to_die)
flags |= GET_SHA1_QUIETLY;
flags |= GET_OID_QUIETLY;
memset(oc, 0, sizeof(*oc));
oc->mode = S_IFINVALID;
strbuf_init(&oc->symlink_path, 0);
ret = get_sha1_1(name, namelen, sha1, flags);
ret = get_oid_1(name, namelen, oid, flags);
if (!ret)
return ret;
/*
@ -1541,7 +1533,7 @@ static int get_sha1_with_context_1(const char *name,
for_each_ref(handle_one_ref, &list);
commit_list_sort_by_date(&list);
return get_sha1_oneline(name + 2, sha1, list);
return get_oid_oneline(name + 2, oid, list);
}
if (namelen < 3 ||
name[2] != ':' ||
@ -1559,7 +1551,7 @@ static int get_sha1_with_context_1(const char *name,
namelen = strlen(cp);
}
if (flags & GET_SHA1_RECORD_PATH)
if (flags & GET_OID_RECORD_PATH)
oc->path = xstrdup(cp);
if (!active_cache)
@ -1573,7 +1565,7 @@ static int get_sha1_with_context_1(const char *name,
memcmp(ce->name, cp, namelen))
break;
if (ce_stage(ce) == stage) {
hashcpy(sha1, ce->oid.hash);
oidcpy(oid, &ce->oid);
oc->mode = ce->ce_mode;
free(new_path);
return 0;
@ -1594,36 +1586,36 @@ static int get_sha1_with_context_1(const char *name,
break;
}
if (*cp == ':') {
unsigned char tree_sha1[20];
struct object_id tree_oid;
int len = cp - name;
unsigned sub_flags = flags;
sub_flags &= ~GET_SHA1_DISAMBIGUATORS;
sub_flags |= GET_SHA1_TREEISH;
sub_flags &= ~GET_OID_DISAMBIGUATORS;
sub_flags |= GET_OID_TREEISH;
if (!get_sha1_1(name, len, tree_sha1, sub_flags)) {
if (!get_oid_1(name, len, &tree_oid, sub_flags)) {
const char *filename = cp+1;
char *new_filename = NULL;
new_filename = resolve_relative_path(filename);
if (new_filename)
filename = new_filename;
if (flags & GET_SHA1_FOLLOW_SYMLINKS) {
ret = get_tree_entry_follow_symlinks(tree_sha1,
filename, sha1, &oc->symlink_path,
if (flags & GET_OID_FOLLOW_SYMLINKS) {
ret = get_tree_entry_follow_symlinks(tree_oid.hash,
filename, oid->hash, &oc->symlink_path,
&oc->mode);
} else {
ret = get_tree_entry(tree_sha1, filename,
sha1, &oc->mode);
ret = get_tree_entry(tree_oid.hash, filename,
oid->hash, &oc->mode);
if (ret && only_to_die) {
diagnose_invalid_sha1_path(prefix,
diagnose_invalid_oid_path(prefix,
filename,
tree_sha1,
&tree_oid,
name, len);
}
}
hashcpy(oc->tree, tree_sha1);
if (flags & GET_SHA1_RECORD_PATH)
hashcpy(oc->tree, tree_oid.hash);
if (flags & GET_OID_RECORD_PATH)
oc->path = xstrdup(filename);
free(new_filename);
@ -1646,13 +1638,13 @@ static int get_sha1_with_context_1(const char *name,
void maybe_die_on_misspelt_object_name(const char *name, const char *prefix)
{
struct object_context oc;
unsigned char sha1[20];
get_sha1_with_context_1(name, GET_SHA1_ONLY_TO_DIE, prefix, sha1, &oc);
struct object_id oid;
get_oid_with_context_1(name, GET_OID_ONLY_TO_DIE, prefix, &oid, &oc);
}
int get_sha1_with_context(const char *str, unsigned flags, unsigned char *sha1, struct object_context *oc)
int get_oid_with_context(const char *str, unsigned flags, struct object_id *oid, struct object_context *oc)
{
if (flags & GET_SHA1_FOLLOW_SYMLINKS && flags & GET_SHA1_ONLY_TO_DIE)
if (flags & GET_OID_FOLLOW_SYMLINKS && flags & GET_OID_ONLY_TO_DIE)
die("BUG: incompatible flags for get_sha1_with_context");
return get_sha1_with_context_1(str, flags, NULL, sha1, oc);
return get_oid_with_context_1(str, flags, NULL, oid, oc);
}

Просмотреть файл

@ -107,7 +107,7 @@ struct commit_list *get_shallow_commits(struct object_array *heads, int depth,
cur_depth++;
if ((depth != INFINITE_DEPTH && cur_depth >= depth) ||
(is_repository_shallow() && !commit->parents &&
(graft = lookup_commit_graft(commit->object.oid.hash)) != NULL &&
(graft = lookup_commit_graft(&commit->object.oid)) != NULL &&
graft->nr_parent < 0)) {
commit_list_insert(commit, &result);
commit->object.flags |= shallow_flag;
@ -398,7 +398,7 @@ void prepare_shallow_info(struct shallow_info *info, struct oid_array *sa)
for (i = 0; i < sa->nr; i++) {
if (has_object_file(sa->oid + i)) {
struct commit_graft *graft;
graft = lookup_commit_graft(sa->oid[i].hash);
graft = lookup_commit_graft(&sa->oid[i]);
if (graft && graft->nr_parent < 0)
continue;
info->ours[info->nr_ours++] = i;

Просмотреть файл

@ -449,19 +449,19 @@ static int parse_config(const char *var, const char *value, void *data)
return ret;
}
int gitmodule_sha1_from_commit(const unsigned char *treeish_name,
unsigned char *gitmodules_sha1,
int gitmodule_oid_from_commit(const struct object_id *treeish_name,
struct object_id *gitmodules_oid,
struct strbuf *rev)
{
int ret = 0;
if (is_null_sha1(treeish_name)) {
hashclr(gitmodules_sha1);
if (is_null_oid(treeish_name)) {
oidclr(gitmodules_oid);
return 1;
}
strbuf_addf(rev, "%s:.gitmodules", sha1_to_hex(treeish_name));
if (get_sha1(rev->buf, gitmodules_sha1) >= 0)
strbuf_addf(rev, "%s:.gitmodules", oid_to_hex(treeish_name));
if (get_oid(rev->buf, gitmodules_oid) >= 0)
ret = 1;
return ret;
@ -472,13 +472,13 @@ int gitmodule_sha1_from_commit(const unsigned char *treeish_name,
* revisions.
*/
static const struct submodule *config_from(struct submodule_cache *cache,
const unsigned char *treeish_name, const char *key,
const struct object_id *treeish_name, const char *key,
enum lookup_type lookup_type)
{
struct strbuf rev = STRBUF_INIT;
unsigned long config_size;
char *config = NULL;
unsigned char sha1[20];
struct object_id oid;
enum object_type type;
const struct submodule *submodule = NULL;
struct parse_config_parameter parameter;
@ -498,28 +498,28 @@ static const struct submodule *config_from(struct submodule_cache *cache,
return entry->config;
}
if (!gitmodule_sha1_from_commit(treeish_name, sha1, &rev))
if (!gitmodule_oid_from_commit(treeish_name, &oid, &rev))
goto out;
switch (lookup_type) {
case lookup_name:
submodule = cache_lookup_name(cache, sha1, key);
submodule = cache_lookup_name(cache, oid.hash, key);
break;
case lookup_path:
submodule = cache_lookup_path(cache, sha1, key);
submodule = cache_lookup_path(cache, oid.hash, key);
break;
}
if (submodule)
goto out;
config = read_sha1_file(sha1, &type, &config_size);
config = read_sha1_file(oid.hash, &type, &config_size);
if (!config || type != OBJ_BLOB)
goto out;
/* fill the submodule config into the cache */
parameter.cache = cache;
parameter.treeish_name = treeish_name;
parameter.gitmodules_sha1 = sha1;
parameter.treeish_name = treeish_name->hash;
parameter.gitmodules_sha1 = oid.hash;
parameter.overwrite = 0;
git_config_from_mem(parse_config, CONFIG_ORIGIN_SUBMODULE_BLOB, rev.buf,
config, config_size, &parameter);
@ -528,9 +528,9 @@ static const struct submodule *config_from(struct submodule_cache *cache,
switch (lookup_type) {
case lookup_name:
return cache_lookup_name(cache, sha1, key);
return cache_lookup_name(cache, oid.hash, key);
case lookup_path:
return cache_lookup_path(cache, sha1, key);
return cache_lookup_path(cache, oid.hash, key);
default:
return NULL;
}
@ -572,14 +572,14 @@ int parse_submodule_config_option(const char *var, const char *value)
return submodule_config_option(the_repository, var, value);
}
const struct submodule *submodule_from_name(const unsigned char *treeish_name,
const struct submodule *submodule_from_name(const struct object_id *treeish_name,
const char *name)
{
submodule_cache_check_init(the_repository);
return config_from(the_repository->submodule_cache, treeish_name, name, lookup_name);
}
const struct submodule *submodule_from_path(const unsigned char *treeish_name,
const struct submodule *submodule_from_path(const struct object_id *treeish_name,
const char *path)
{
submodule_cache_check_init(the_repository);
@ -587,7 +587,7 @@ const struct submodule *submodule_from_path(const unsigned char *treeish_name,
}
const struct submodule *submodule_from_cache(struct repository *repo,
const unsigned char *treeish_name,
const struct object_id *treeish_name,
const char *key)
{
submodule_cache_check_init(repo);

Просмотреть файл

@ -38,14 +38,14 @@ extern int parse_submodule_config_option(const char *var, const char *value);
extern int submodule_config_option(struct repository *repo,
const char *var, const char *value);
extern const struct submodule *submodule_from_name(
const unsigned char *commit_or_tree, const char *name);
const struct object_id *commit_or_tree, const char *name);
extern const struct submodule *submodule_from_path(
const unsigned char *commit_or_tree, const char *path);
const struct object_id *commit_or_tree, const char *path);
extern const struct submodule *submodule_from_cache(struct repository *repo,
const unsigned char *treeish_name,
const struct object_id *treeish_name,
const char *key);
extern int gitmodule_sha1_from_commit(const unsigned char *commit_sha1,
unsigned char *gitmodules_sha1,
extern int gitmodule_oid_from_commit(const struct object_id *commit_oid,
struct object_id *gitmodules_oid,
struct strbuf *rev);
extern void submodule_free(void);

Просмотреть файл

@ -85,7 +85,7 @@ int update_path_in_gitmodules(const char *oldpath, const char *newpath)
if (is_gitmodules_unmerged(&the_index))
die(_("Cannot change unmerged .gitmodules, resolve merge conflicts first"));
submodule = submodule_from_path(null_sha1, oldpath);
submodule = submodule_from_path(&null_oid, oldpath);
if (!submodule || !submodule->name) {
warning(_("Could not find section in .gitmodules where path=%s"), oldpath);
return -1;
@ -119,7 +119,7 @@ int remove_path_from_gitmodules(const char *path)
if (is_gitmodules_unmerged(&the_index))
die(_("Cannot change unmerged .gitmodules, resolve merge conflicts first"));
submodule = submodule_from_path(null_sha1, path);
submodule = submodule_from_path(&null_oid, path);
if (!submodule || !submodule->name) {
warning(_("Could not find section in .gitmodules where path=%s"), path);
return -1;
@ -163,7 +163,7 @@ done:
void set_diffopt_flags_from_submodule_config(struct diff_options *diffopt,
const char *path)
{
const struct submodule *submodule = submodule_from_path(null_sha1, path);
const struct submodule *submodule = submodule_from_path(&null_oid, path);
if (submodule) {
if (submodule->ignore)
handle_ignore_submodules_arg(diffopt, submodule->ignore);
@ -258,14 +258,14 @@ void gitmodules_config(void)
repo_read_gitmodules(the_repository);
}
void gitmodules_config_sha1(const unsigned char *commit_sha1)
void gitmodules_config_oid(const struct object_id *commit_oid)
{
struct strbuf rev = STRBUF_INIT;
unsigned char sha1[20];
struct object_id oid;
if (gitmodule_sha1_from_commit(commit_sha1, sha1, &rev)) {
git_config_from_blob_sha1(git_modules_config, rev.buf,
sha1, NULL);
if (gitmodule_oid_from_commit(commit_oid, &oid, &rev)) {
git_config_from_blob_oid(submodule_config, rev.buf,
&oid, NULL);
}
strbuf_release(&rev);
}
@ -281,7 +281,7 @@ int is_submodule_active(struct repository *repo, const char *path)
const struct string_list *sl;
const struct submodule *module;
module = submodule_from_cache(repo, null_sha1, path);
module = submodule_from_cache(repo, &null_oid, path);
/* early return if there isn't a path->module mapping */
if (!module)
@ -721,7 +721,7 @@ const struct submodule *submodule_from_ce(const struct cache_entry *ce)
if (!should_update_submodules())
return NULL;
return submodule_from_path(null_sha1, ce->name);
return submodule_from_path(&null_oid, ce->name);
}
static struct oid_array *submodule_commits(struct string_list *submodules,
@ -1176,9 +1176,9 @@ static int get_next_submodule(struct child_process *cp,
if (!S_ISGITLINK(ce->ce_mode))
continue;
submodule = submodule_from_path(null_sha1, ce->name);
submodule = submodule_from_path(&null_oid, ce->name);
if (!submodule)
submodule = submodule_from_name(null_sha1, ce->name);
submodule = submodule_from_name(&null_oid, ce->name);
default_argv = "yes";
if (spf->command_line_option == RECURSE_SUBMODULES_DEFAULT) {
@ -1552,7 +1552,7 @@ int submodule_move_head(const char *path,
if (old && !is_submodule_populated_gently(path, error_code_ptr))
return 0;
sub = submodule_from_path(null_sha1, path);
sub = submodule_from_path(&null_oid, path);
if (!sub)
die("BUG: could not get submodule information for '%s'", path);
@ -1829,7 +1829,7 @@ static void relocate_single_git_dir_into_superproject(const char *prefix,
real_old_git_dir = real_pathdup(old_git_dir, 1);
sub = submodule_from_path(null_sha1, path);
sub = submodule_from_path(&null_oid, path);
if (!sub)
die(_("could not lookup name for submodule '%s'"), path);
@ -1885,7 +1885,7 @@ void absorb_git_dir_into_superproject(const char *prefix,
* superproject did not rewrite the git file links yet,
* fix it now.
*/
sub = submodule_from_path(null_sha1, path);
sub = submodule_from_path(&null_oid, path);
if (!sub)
die(_("could not lookup name for submodule '%s'"), path);
connect_work_tree_and_git_dir(path,
@ -2028,7 +2028,7 @@ int submodule_to_gitdir(struct strbuf *buf, const char *submodule)
}
if (!is_git_directory(buf->buf)) {
gitmodules_config();
sub = submodule_from_path(null_sha1, submodule);
sub = submodule_from_path(&null_oid, submodule);
if (!sub) {
ret = -1;
goto cleanup;

Просмотреть файл

@ -49,7 +49,7 @@ int option_parse_recurse_submodules_worktree_updater(const struct option *opt,
void load_submodule_cache(void);
extern void gitmodules_config(void);
extern void repo_read_gitmodules(struct repository *repo);
extern void gitmodules_config_sha1(const unsigned char *commit_sha1);
extern void gitmodules_config_oid(const struct object_id *commit_oid);
extern int is_submodule_active(struct repository *repo, const char *path);
/*
* Determine if a submodule has been populated at a given 'path' by checking if

Просмотреть файл

@ -41,7 +41,7 @@ int cmd_main(int argc, const char **argv)
git_config(git_test_config, NULL);
while (*arg) {
unsigned char commit_sha1[20];
struct object_id commit_oid;
const struct submodule *submodule;
const char *commit;
const char *path_or_name;
@ -50,14 +50,14 @@ int cmd_main(int argc, const char **argv)
path_or_name = arg[1];
if (commit[0] == '\0')
hashclr(commit_sha1);
else if (get_sha1(commit, commit_sha1) < 0)
oidclr(&commit_oid);
else if (get_oid(commit, &commit_oid) < 0)
die_usage(argc, argv, "Commit not found.");
if (lookup_name) {
submodule = submodule_from_name(commit_sha1, path_or_name);
submodule = submodule_from_name(&commit_oid, path_or_name);
} else
submodule = submodule_from_path(commit_sha1, path_or_name);
submodule = submodule_from_path(&commit_oid, path_or_name);
if (!submodule)
die_usage(argc, argv, "Submodule not found.");

10
tag.c
Просмотреть файл

@ -33,7 +33,7 @@ static int run_gpg_verify(const char *buf, unsigned long size, unsigned flags)
return ret;
}
int gpg_verify_tag(const unsigned char *sha1, const char *name_to_report,
int gpg_verify_tag(const struct object_id *oid, const char *name_to_report,
unsigned flags)
{
enum object_type type;
@ -41,20 +41,20 @@ int gpg_verify_tag(const unsigned char *sha1, const char *name_to_report,
unsigned long size;
int ret;
type = sha1_object_info(sha1, NULL);
type = sha1_object_info(oid->hash, NULL);
if (type != OBJ_TAG)
return error("%s: cannot verify a non-tag object of type %s.",
name_to_report ?
name_to_report :
find_unique_abbrev(sha1, DEFAULT_ABBREV),
find_unique_abbrev(oid->hash, DEFAULT_ABBREV),
typename(type));
buf = read_sha1_file(sha1, &type, &size);
buf = read_sha1_file(oid->hash, &type, &size);
if (!buf)
return error("%s: unable to read file.",
name_to_report ?
name_to_report :
find_unique_abbrev(sha1, DEFAULT_ABBREV));
find_unique_abbrev(oid->hash, DEFAULT_ABBREV));
ret = run_gpg_verify(buf, size, flags);

2
tag.h
Просмотреть файл

@ -17,7 +17,7 @@ extern int parse_tag_buffer(struct tag *item, const void *data, unsigned long si
extern int parse_tag(struct tag *item);
extern struct object *deref_tag(struct object *, const char *, int);
extern struct object *deref_tag_noverify(struct object *);
extern int gpg_verify_tag(const unsigned char *sha1,
extern int gpg_verify_tag(const struct object_id *oid,
const char *name_to_report, unsigned flags);
#endif /* TAG_H */

Просмотреть файл

@ -927,7 +927,7 @@ static int push_refs_with_export(struct transport *transport,
struct object_id oid;
private = apply_refspecs(data->refspecs, data->refspec_nr, ref->name);
if (private && !get_sha1(private, oid.hash)) {
if (private && !get_oid(private, &oid)) {
strbuf_addf(&buf, "^%s", private);
string_list_append(&revlist_args, strbuf_detach(&buf, NULL));
oidcpy(&ref->old_oid, &oid);