diff options
-rw-r--r-- | blame.c | 20 | ||||
-rw-r--r-- | builtin/am.c | 2 | ||||
-rw-r--r-- | builtin/commit.c | 2 | ||||
-rw-r--r-- | builtin/diff-tree.c | 16 | ||||
-rw-r--r-- | builtin/diff.c | 8 | ||||
-rw-r--r-- | builtin/fast-export.c | 8 | ||||
-rw-r--r-- | builtin/grep.c | 22 | ||||
-rw-r--r-- | builtin/log.c | 8 | ||||
-rw-r--r-- | builtin/merge.c | 2 | ||||
-rw-r--r-- | builtin/notes.c | 136 | ||||
-rw-r--r-- | cache.h | 7 | ||||
-rw-r--r-- | combine-diff.c | 30 | ||||
-rw-r--r-- | diff-lib.c | 52 | ||||
-rw-r--r-- | diff-no-index.c | 2 | ||||
-rw-r--r-- | diff.c | 76 | ||||
-rw-r--r-- | diff.h | 38 | ||||
-rw-r--r-- | diffcore-rename.c | 6 | ||||
-rw-r--r-- | diffcore.h | 2 | ||||
-rw-r--r-- | grep.c | 19 | ||||
-rw-r--r-- | grep.h | 2 | ||||
-rw-r--r-- | line-log.c | 10 | ||||
-rw-r--r-- | log-tree.c | 12 | ||||
-rw-r--r-- | merge-recursive.c | 2 | ||||
-rw-r--r-- | notes-cache.c | 10 | ||||
-rw-r--r-- | notes-merge.c | 165 | ||||
-rw-r--r-- | notes-merge.h | 20 | ||||
-rw-r--r-- | notes-utils.c | 2 | ||||
-rw-r--r-- | notes-utils.h | 2 | ||||
-rw-r--r-- | notes.c | 202 | ||||
-rw-r--r-- | notes.h | 16 | ||||
-rw-r--r-- | patch-ids.c | 26 | ||||
-rw-r--r-- | patch-ids.h | 4 | ||||
-rw-r--r-- | remote-testsvn.c | 22 | ||||
-rw-r--r-- | revision.c | 16 | ||||
-rw-r--r-- | sequencer.c | 4 | ||||
-rw-r--r-- | tree-diff.c | 93 |
36 files changed, 539 insertions, 525 deletions
@@ -556,9 +556,9 @@ static struct blame_origin *find_origin(struct commit *parent, if (is_null_oid(&origin->commit->object.oid)) do_diff_cache(&parent->tree->object.oid, &diff_opts); else - diff_tree_sha1(parent->tree->object.oid.hash, - origin->commit->tree->object.oid.hash, - "", &diff_opts); + diff_tree_oid(&parent->tree->object.oid, + &origin->commit->tree->object.oid, + "", &diff_opts); diffcore_std(&diff_opts); if (!diff_queued_diff.nr) { @@ -625,9 +625,9 @@ static struct blame_origin *find_rename(struct commit *parent, if (is_null_oid(&origin->commit->object.oid)) do_diff_cache(&parent->tree->object.oid, &diff_opts); else - diff_tree_sha1(parent->tree->object.oid.hash, - origin->commit->tree->object.oid.hash, - "", &diff_opts); + diff_tree_oid(&parent->tree->object.oid, + &origin->commit->tree->object.oid, + "", &diff_opts); diffcore_std(&diff_opts); for (i = 0; i < diff_queued_diff.nr; i++) { @@ -1247,7 +1247,7 @@ static void find_copy_in_parent(struct blame_scoreboard *sb, /* Try "find copies harder" on new path if requested; * we do not want to use diffcore_rename() actually to * match things up; find_copies_harder is set only to - * force diff_tree_sha1() to feed all filepairs to diff_queue, + * force diff_tree_oid() to feed all filepairs to diff_queue, * and this code needs to be after diff_setup_done(), which * usually makes find-copies-harder imply copy detection. */ @@ -1259,9 +1259,9 @@ static void find_copy_in_parent(struct blame_scoreboard *sb, if (is_null_oid(&target->commit->object.oid)) do_diff_cache(&parent->tree->object.oid, &diff_opts); else - diff_tree_sha1(parent->tree->object.oid.hash, - target->commit->tree->object.oid.hash, - "", &diff_opts); + diff_tree_oid(&parent->tree->object.oid, + &target->commit->tree->object.oid, + "", &diff_opts); if (!DIFF_OPT_TST(&diff_opts, FIND_COPIES_HARDER)) diffcore_std(&diff_opts); diff --git a/builtin/am.c b/builtin/am.c index 8881d73615..3985f9a89f 100644 --- a/builtin/am.c +++ b/builtin/am.c @@ -563,7 +563,7 @@ static int copy_notes_for_rebase(const struct am_state *state) goto finish; } - if (copy_note_for_rewrite(c, from_obj.hash, to_obj.hash)) + if (copy_note_for_rewrite(c, &from_obj, &to_obj)) ret = error(_("Failed to copy notes from '%s' to '%s'"), oid_to_hex(&from_obj), oid_to_hex(&to_obj)); } diff --git a/builtin/commit.c b/builtin/commit.c index ef52457eff..e3c9e190b0 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -1806,7 +1806,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix) cfg = init_copy_notes_for_rewrite("amend"); if (cfg) { /* we are amending, so current_head is not NULL */ - copy_note_for_rewrite(cfg, current_head->object.oid.hash, oid.hash); + copy_note_for_rewrite(cfg, ¤t_head->object.oid, &oid); finish_copy_notes_for_rewrite(cfg, "Notes added by 'git commit --amend'"); } run_rewrite_hook(¤t_head->object.oid, &oid); diff --git a/builtin/diff-tree.c b/builtin/diff-tree.c index 492245f428..1fd06eac4b 100644 --- a/builtin/diff-tree.c +++ b/builtin/diff-tree.c @@ -7,7 +7,7 @@ static struct rev_info log_tree_opt; -static int diff_tree_commit_sha1(const struct object_id *oid) +static int diff_tree_commit_oid(const struct object_id *oid) { struct commit *commit = lookup_commit_reference(oid); if (!commit) @@ -49,8 +49,8 @@ static int stdin_diff_trees(struct tree *tree1, const char *p) return -1; printf("%s %s\n", oid_to_hex(&tree1->object.oid), oid_to_hex(&tree2->object.oid)); - diff_tree_sha1(tree1->object.oid.hash, tree2->object.oid.hash, - "", &log_tree_opt.diffopt); + diff_tree_oid(&tree1->object.oid, &tree2->object.oid, + "", &log_tree_opt.diffopt); log_tree_diff_flush(&log_tree_opt); return 0; } @@ -98,7 +98,6 @@ static void diff_tree_tweak_rev(struct rev_info *rev, struct setup_revision_opt int cmd_diff_tree(int argc, const char **argv, const char *prefix) { - int nr_sha1; char line[1000]; struct object *tree1, *tree2; static struct rev_info *opt = &log_tree_opt; @@ -134,15 +133,14 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix) * second one is marked UNINTERESTING, we recover the original * order the user gave, i.e. "a..b", by swapping the trees. */ - nr_sha1 = opt->pending.nr; - switch (nr_sha1) { + switch (opt->pending.nr) { case 0: if (!read_stdin) usage(diff_tree_usage); break; case 1: tree1 = opt->pending.objects[0].item; - diff_tree_commit_sha1(&tree1->oid); + diff_tree_commit_oid(&tree1->oid); break; case 2: tree1 = opt->pending.objects[0].item; @@ -150,9 +148,7 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix) if (tree2->flags & UNINTERESTING) { SWAP(tree2, tree1); } - diff_tree_sha1(tree1->oid.hash, - tree2->oid.hash, - "", &opt->diffopt); + diff_tree_oid(&tree1->oid, &tree2->oid, "", &opt->diffopt); log_tree_diff_flush(opt); break; } diff --git a/builtin/diff.c b/builtin/diff.c index 0c8f86e40d..d9152c21bf 100644 --- a/builtin/diff.c +++ b/builtin/diff.c @@ -56,8 +56,8 @@ static void stuff_change(struct diff_options *opt, one = alloc_filespec(old_path); two = alloc_filespec(new_path); - fill_filespec(one, old_oid->hash, old_oid_valid, old_mode); - fill_filespec(two, new_oid->hash, new_oid_valid, new_mode); + fill_filespec(one, old_oid, old_oid_valid, old_mode); + fill_filespec(two, new_oid, new_oid_valid, new_mode); diff_queue(&diff_queued_diff, one, two); } @@ -174,7 +174,7 @@ static int builtin_diff_tree(struct rev_info *revs, swap = 1; oid[swap] = &ent0->item->oid; oid[1 - swap] = &ent1->item->oid; - diff_tree_sha1(oid[0]->hash, oid[1]->hash, "", &revs->diffopt); + diff_tree_oid(oid[0], oid[1], "", &revs->diffopt); log_tree_diff_flush(revs); return 0; } @@ -194,7 +194,7 @@ static int builtin_diff_combined(struct rev_info *revs, revs->dense_combined_merges = revs->combine_merges = 1; for (i = 1; i < ents; i++) oid_array_append(&parents, &ent[i].item->oid); - diff_tree_combined(ent[0].item->oid.hash, &parents, + diff_tree_combined(&ent[0].item->oid, &parents, revs->dense_combined_merges, revs); oid_array_clear(&parents); return 0; diff --git a/builtin/fast-export.c b/builtin/fast-export.c index 2dfed87454..a932be04f4 100644 --- a/builtin/fast-export.c +++ b/builtin/fast-export.c @@ -562,12 +562,12 @@ static void handle_commit(struct commit *commit, struct rev_info *rev) get_object_mark(&commit->parents->item->object) != 0 && !full_tree) { parse_commit_or_die(commit->parents->item); - diff_tree_sha1(commit->parents->item->tree->object.oid.hash, - commit->tree->object.oid.hash, "", &rev->diffopt); + diff_tree_oid(&commit->parents->item->tree->object.oid, + &commit->tree->object.oid, "", &rev->diffopt); } else - diff_root_tree_sha1(commit->tree->object.oid.hash, - "", &rev->diffopt); + diff_root_tree_oid(&commit->tree->object.oid, + "", &rev->diffopt); /* Export the referenced blobs, and remember the marks. */ for (i = 0; i < diff_queued_diff.nr; i++) diff --git a/builtin/grep.c b/builtin/grep.c index 26d43b4e4c..3e4b9600e8 100644 --- a/builtin/grep.c +++ b/builtin/grep.c @@ -342,7 +342,7 @@ static int grep_oid(struct grep_opt *opt, const struct object_id *oid, #ifndef NO_PTHREADS if (num_threads) { - add_work(opt, GREP_SOURCE_SHA1, pathbuf.buf, path, oid); + add_work(opt, GREP_SOURCE_OID, pathbuf.buf, path, oid); strbuf_release(&pathbuf); return 0; } else @@ -351,7 +351,7 @@ static int grep_oid(struct grep_opt *opt, const struct object_id *oid, struct grep_source gs; int hit; - grep_source_init(&gs, GREP_SOURCE_SHA1, pathbuf.buf, path, oid); + grep_source_init(&gs, GREP_SOURCE_OID, pathbuf.buf, path, oid); strbuf_release(&pathbuf); hit = grep_source(opt, &gs); @@ -587,7 +587,7 @@ static int grep_submodule_launch(struct grep_opt *opt, * with the object's name: 'tree-name:filename'. In order to * provide uniformity of output we want to pass the name of the * parent project's object name to the submodule so the submodule can - * prefix its output with the parent's name and not its own SHA1. + * prefix its output with the parent's name and not its own OID. */ if (gs->identifier && end_of_base) argv_array_pushf(&cp.args, "--parent-basename=%.*s", @@ -600,12 +600,12 @@ static int grep_submodule_launch(struct grep_opt *opt, * If there is a tree identifier for the submodule, add the * rev after adding the submodule options but before the * pathspecs. To do this we listen for the '--' and insert the - * sha1 before pushing the '--' onto the child process argv + * oid before pushing the '--' onto the child process argv * array. */ if (gs->identifier && !strcmp("--", submodule_options.argv[i])) { - argv_array_push(&cp.args, sha1_to_hex(gs->identifier)); + argv_array_push(&cp.args, oid_to_hex(gs->identifier)); } argv_array_push(&cp.args, submodule_options.argv[i]); @@ -635,11 +635,11 @@ static int grep_submodule_launch(struct grep_opt *opt, /* * Prep grep structures for a submodule grep - * sha1: the sha1 of the submodule or NULL if using the working tree + * oid: the oid of the submodule or NULL if using the working tree * filename: name of the submodule including tree name of parent * path: location of the submodule */ -static int grep_submodule(struct grep_opt *opt, const unsigned char *sha1, +static int grep_submodule(struct grep_opt *opt, const struct object_id *oid, const char *filename, const char *path) { if (!is_submodule_initialized(path)) @@ -649,7 +649,7 @@ static int grep_submodule(struct grep_opt *opt, const unsigned char *sha1, * If searching history, check for the presense of the * submodule's gitdir before skipping the submodule. */ - if (sha1) { + if (oid) { const struct submodule *sub = submodule_from_path(null_sha1, path); if (sub) @@ -664,7 +664,7 @@ static int grep_submodule(struct grep_opt *opt, const unsigned char *sha1, #ifndef NO_PTHREADS if (num_threads) { - add_work(opt, GREP_SOURCE_SUBMODULE, filename, path, sha1); + add_work(opt, GREP_SOURCE_SUBMODULE, filename, path, oid); return 0; } else #endif @@ -673,7 +673,7 @@ static int grep_submodule(struct grep_opt *opt, const unsigned char *sha1, int hit; grep_source_init(&gs, GREP_SOURCE_SUBMODULE, - filename, path, sha1); + filename, path, oid); hit = grep_submodule_launch(opt, &gs); grep_source_clear(&gs); @@ -792,7 +792,7 @@ static int grep_tree(struct grep_opt *opt, const struct pathspec *pathspec, check_attr); free(data); } else if (recurse_submodules && S_ISGITLINK(entry.mode)) { - hit |= grep_submodule(opt, entry.oid->hash, base->buf, + hit |= grep_submodule(opt, entry.oid, base->buf, base->buf + tn_len); } diff --git a/builtin/log.c b/builtin/log.c index a33c1a70ab..998437b23d 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -1052,9 +1052,9 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout, diff_setup_done(&opts); - diff_tree_sha1(origin->tree->object.oid.hash, - head->tree->object.oid.hash, - "", &opts); + diff_tree_oid(&origin->tree->object.oid, + &head->tree->object.oid, + "", &opts); diffcore_std(&opts); diff_flush(&opts); @@ -1363,7 +1363,7 @@ static void prepare_bases(struct base_tree_info *bases, struct object_id *patch_id; if (commit->util) continue; - if (commit_patch_id(commit, &diffopt, oid.hash, 0)) + if (commit_patch_id(commit, &diffopt, &oid, 0)) die(_("cannot get patch id")); ALLOC_GROW(bases->patch_id, bases->nr_patch_id + 1, bases->alloc_patch_id); patch_id = bases->patch_id + bases->nr_patch_id; diff --git a/builtin/merge.c b/builtin/merge.c index eab03a026d..84970cd85e 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -415,7 +415,7 @@ static void finish(struct commit *head_commit, DIFF_FORMAT_SUMMARY | DIFF_FORMAT_DIFFSTAT; opts.detect_rename = DIFF_DETECT_RENAME; diff_setup_done(&opts); - diff_tree_sha1(head->hash, new_head->hash, "", &opts); + diff_tree_oid(head, new_head, "", &opts); diffcore_std(&opts); diff_flush(&opts); } diff --git a/builtin/notes.c b/builtin/notes.c index 7196bff0eb..c939a84b76 100644 --- a/builtin/notes.c +++ b/builtin/notes.c @@ -109,11 +109,11 @@ static void free_note_data(struct note_data *d) strbuf_release(&d->buf); } -static int list_each_note(const unsigned char *object_sha1, - const unsigned char *note_sha1, char *note_path, +static int list_each_note(const struct object_id *object_oid, + const struct object_id *note_oid, char *note_path, void *cb_data) { - printf("%s %s\n", sha1_to_hex(note_sha1), sha1_to_hex(object_sha1)); + printf("%s %s\n", oid_to_hex(note_oid), oid_to_hex(object_oid)); return 0; } @@ -129,10 +129,10 @@ static void copy_obj_to_fd(int fd, const unsigned char *sha1) } } -static void write_commented_object(int fd, const unsigned char *object) +static void write_commented_object(int fd, const struct object_id *object) { const char *show_args[5] = - {"show", "--stat", "--no-notes", sha1_to_hex(object), NULL}; + {"show", "--stat", "--no-notes", oid_to_hex(object), NULL}; struct child_process show = CHILD_PROCESS_INIT; struct strbuf buf = STRBUF_INIT; struct strbuf cbuf = STRBUF_INIT; @@ -145,7 +145,7 @@ static void write_commented_object(int fd, const unsigned char *object) show.git_cmd = 1; if (start_command(&show)) die(_("unable to start 'show' for object '%s'"), - sha1_to_hex(object)); + oid_to_hex(object)); if (strbuf_read(&buf, show.out, 0) < 0) die_errno(_("could not read 'show' output")); @@ -157,10 +157,10 @@ static void write_commented_object(int fd, const unsigned char *object) if (finish_command(&show)) die(_("failed to finish 'show' for object '%s'"), - sha1_to_hex(object)); + oid_to_hex(object)); } -static void prepare_note_data(const unsigned char *object, struct note_data *d, +static void prepare_note_data(const struct object_id *object, struct note_data *d, const unsigned char *old_note) { if (d->use_editor || !d->given) { @@ -243,16 +243,16 @@ static int parse_reuse_arg(const struct option *opt, const char *arg, int unset) { struct note_data *d = opt->value; char *buf; - unsigned char object[20]; + struct object_id object; enum object_type type; unsigned long len; if (d->buf.len) strbuf_addch(&d->buf, '\n'); - if (get_sha1(arg, object)) + if (get_oid(arg, &object)) die(_("failed to resolve '%s' as a valid ref."), arg); - if (!(buf = read_sha1_file(object, &type, &len))) { + if (!(buf = read_sha1_file(object.hash, &type, &len))) { free(buf); die(_("failed to read object '%s'."), arg); } @@ -292,7 +292,7 @@ static int notes_copy_from_stdin(int force, const char *rewrite_cmd) } while (strbuf_getline_lf(&buf, stdin) != EOF) { - unsigned char from_obj[20], to_obj[20]; + struct object_id from_obj, to_obj; struct strbuf **split; int err; @@ -301,15 +301,15 @@ static int notes_copy_from_stdin(int force, const char *rewrite_cmd) die(_("malformed input line: '%s'."), buf.buf); strbuf_rtrim(split[0]); strbuf_rtrim(split[1]); - if (get_sha1(split[0]->buf, from_obj)) + if (get_oid(split[0]->buf, &from_obj)) die(_("failed to resolve '%s' as a valid ref."), split[0]->buf); - if (get_sha1(split[1]->buf, to_obj)) + if (get_oid(split[1]->buf, &to_obj)) die(_("failed to resolve '%s' as a valid ref."), split[1]->buf); if (rewrite_cmd) - err = copy_note_for_rewrite(c, from_obj, to_obj); + err = copy_note_for_rewrite(c, &from_obj, &to_obj); else - err = copy_note(t, from_obj, to_obj, force, + err = copy_note(t, &from_obj, &to_obj, force, combine_notes_overwrite); if (err) { @@ -352,8 +352,8 @@ static struct notes_tree *init_notes_check(const char *subcommand, static int list(int argc, const char **argv, const char *prefix) { struct notes_tree *t; - unsigned char object[20]; - const unsigned char *note; + struct object_id object; + const struct object_id *note; int retval = -1; struct option options[] = { OPT_END() @@ -370,15 +370,15 @@ static int list(int argc, const char **argv, const char *prefix) t = init_notes_check("list", 0); if (argc) { - if (get_sha1(argv[0], object)) + if (get_oid(argv[0], &object)) die(_("failed to resolve '%s' as a valid ref."), argv[0]); - note = get_note(t, object); + note = get_note(t, &object); if (note) { - puts(sha1_to_hex(note)); + puts(oid_to_hex(note)); retval = 0; } else retval = error(_("no note found for object %s."), - sha1_to_hex(object)); + oid_to_hex(&object)); } else retval = for_each_note(t, 0, list_each_note, NULL); @@ -393,8 +393,8 @@ static int add(int argc, const char **argv, const char *prefix) int force = 0, allow_empty = 0; const char *object_ref; struct notes_tree *t; - unsigned char object[20], new_note[20]; - const unsigned char *note; + struct object_id object, new_note; + const struct object_id *note; struct note_data d = { 0, 0, NULL, STRBUF_INIT }; struct option options[] = { { OPTION_CALLBACK, 'm', "message", &d, N_("message"), @@ -425,11 +425,11 @@ static int add(int argc, const char **argv, const char *prefix) object_ref = argc > 1 ? argv[1] : "HEAD"; - if (get_sha1(object_ref, object)) + if (get_oid(object_ref, &object)) die(_("failed to resolve '%s' as a valid ref."), object_ref); t = init_notes_check("add", NOTES_INIT_WRITABLE); - note = get_note(t, object); + note = get_note(t, &object); if (note) { if (!force) { @@ -439,7 +439,7 @@ static int add(int argc, const char **argv, const char *prefix) return error(_("Cannot add notes. " "Found existing notes for object %s. " "Use '-f' to overwrite existing notes"), - sha1_to_hex(object)); + oid_to_hex(&object)); } /* * Redirect to "edit" subcommand. @@ -452,19 +452,19 @@ static int add(int argc, const char **argv, const char *prefix) return append_edit(argc, argv, prefix); } fprintf(stderr, _("Overwriting existing notes for object %s\n"), - sha1_to_hex(object)); + oid_to_hex(&object)); } - prepare_note_data(object, &d, note); + prepare_note_data(&object, &d, note->hash); if (d.buf.len || allow_empty) { - write_note_data(&d, new_note); - if (add_note(t, object, new_note, combine_notes_overwrite)) + write_note_data(&d, new_note.hash); + if (add_note(t, &object, &new_note, combine_notes_overwrite)) die("BUG: combine_notes_overwrite failed"); commit_notes(t, "Notes added by 'git notes add'"); } else { fprintf(stderr, _("Removing note for object %s\n"), - sha1_to_hex(object)); - remove_note(t, object); + oid_to_hex(&object)); + remove_note(t, object.hash); commit_notes(t, "Notes removed by 'git notes add'"); } @@ -476,9 +476,9 @@ static int add(int argc, const char **argv, const char *prefix) static int copy(int argc, const char **argv, const char *prefix) { int retval = 0, force = 0, from_stdin = 0; - const unsigned char *from_note, *note; + const struct object_id *from_note, *note; const char *object_ref; - unsigned char object[20], from_obj[20]; + struct object_id object, from_obj; struct notes_tree *t; const char *rewrite_cmd = NULL; struct option options[] = { @@ -511,37 +511,37 @@ static int copy(int argc, const char **argv, const char *prefix) usage_with_options(git_notes_copy_usage, options); } - if (get_sha1(argv[0], from_obj)) + if (get_oid(argv[0], &from_obj)) die(_("failed to resolve '%s' as a valid ref."), argv[0]); object_ref = 1 < argc ? argv[1] : "HEAD"; - if (get_sha1(object_ref, object)) + if (get_oid(object_ref, &object)) die(_("failed to resolve '%s' as a valid ref."), object_ref); t = init_notes_check("copy", NOTES_INIT_WRITABLE); - note = get_note(t, object); + note = get_note(t, &object); if (note) { if (!force) { retval = error(_("Cannot copy notes. Found existing " "notes for object %s. Use '-f' to " "overwrite existing notes"), - sha1_to_hex(object)); + oid_to_hex(&object)); goto out; } fprintf(stderr, _("Overwriting existing notes for object %s\n"), - sha1_to_hex(object)); + oid_to_hex(&object)); } - from_note = get_note(t, from_obj); + from_note = get_note(t, &from_obj); if (!from_note) { retval = error(_("missing notes on source object %s. Cannot " - "copy."), sha1_to_hex(from_obj)); + "copy."), oid_to_hex(&from_obj)); goto out; } - if (add_note(t, object, from_note, combine_notes_overwrite)) + if (add_note(t, &object, from_note, combine_notes_overwrite)) die("BUG: combine_notes_overwrite failed"); commit_notes(t, "Notes added by 'git notes copy'"); out: @@ -554,8 +554,8 @@ static int append_edit(int argc, const char **argv, const char *prefix) int allow_empty = 0; const char *object_ref; struct notes_tree *t; - unsigned char object[20], new_note[20]; - const unsigned char *note; + struct object_id object, new_note; + const struct object_id *note; char *logmsg; const char * const *usage; struct note_data d = { 0, 0, NULL, STRBUF_INIT }; @@ -594,19 +594,19 @@ static int append_edit(int argc, const char **argv, const char *prefix) object_ref = 1 < argc ? argv[1] : "HEAD"; - if (get_sha1(object_ref, object)) + if (get_oid(object_ref, &object)) die(_("failed to resolve '%s' as a valid ref."), object_ref); t = init_notes_check(argv[0], NOTES_INIT_WRITABLE); - note = get_note(t, object); + note = get_note(t, &object); - prepare_note_data(object, &d, edit ? note : NULL); + prepare_note_data(&object, &d, edit && note ? note->hash : NULL); if (note && !edit) { /* Append buf to previous note contents */ unsigned long size; enum object_type type; - char *prev_buf = read_sha1_file(note, &type, &size); + char *prev_buf = read_sha1_file(note->hash, &type, &size); strbuf_grow(&d.buf, size + 1); if (d.buf.len && prev_buf && size) @@ -617,14 +617,14 @@ static int append_edit(int argc, const char **argv, const char *prefix) } if (d.buf.len || allow_empty) { - write_note_data(&d, new_note); - if (add_note(t, object, new_note, combine_notes_overwrite)) + write_note_data(&d, new_note.hash); + if (add_note(t, &object, &new_note, combine_notes_overwrite)) die("BUG: combine_notes_overwrite failed"); logmsg = xstrfmt("Notes added by 'git notes %s'", argv[0]); } else { fprintf(stderr, _("Removing note for object %s\n"), - sha1_to_hex(object)); - remove_note(t, object); + oid_to_hex(&object)); + remove_note(t, object.hash); logmsg = xstrfmt("Notes removed by 'git notes %s'", argv[0]); } commit_notes(t, logmsg); @@ -639,8 +639,8 @@ static int show(int argc, const char **argv, const char *prefix) { const char *object_ref; struct notes_tree *t; - unsigned char object[20]; - const unsigned char *note; + struct object_id object; + const struct object_id *note; int retval; struct option options[] = { OPT_END() @@ -656,17 +656,17 @@ static int show(int argc, const char **argv, const char *prefix) object_ref = argc ? argv[0] : "HEAD"; - if (get_sha1(object_ref, object)) + if (get_oid(object_ref, &object)) die(_("failed to resolve '%s' as a valid ref."), object_ref); t = init_notes_check("show", 0); - note = get_note(t, object); + note = get_note(t, &object); if (!note) retval = error(_("no note found for object %s."), - sha1_to_hex(object)); + oid_to_hex(&object)); else { - const char *show_args[3] = {"show", sha1_to_hex(note), NULL}; + const char *show_args[3] = {"show", oid_to_hex(note), NULL}; retval = execv_git_cmd(show_args); } free_notes(t); @@ -726,7 +726,7 @@ static int merge_commit(struct notes_merge_options *o) if (!o->local_ref) die(_("failed to resolve NOTES_MERGE_REF")); - if (notes_merge_commit(o, t, partial, oid.hash)) + if (notes_merge_commit(o, t, partial, &oid)) die(_("failed to finalize notes merge")); /* Reuse existing commit message in reflog message */ @@ -762,7 +762,7 @@ static int git_config_get_notes_strategy(const char *key, static int merge(int argc, const char **argv, const char *prefix) { struct strbuf remote_ref = STRBUF_INIT, msg = STRBUF_INIT; - unsigned char result_sha1[20]; + struct object_id result_oid; struct notes_tree *t; struct notes_merge_options o; int do_merge = 0, do_commit = 0, do_abort = 0; @@ -844,16 +844,16 @@ static int merge(int argc, const char **argv, const char *prefix) remote_ref.buf, default_notes_ref()); strbuf_add(&(o.commit_msg), msg.buf + 7, msg.len - 7); /* skip "notes: " */ - result = notes_merge(&o, t, result_sha1); + result = notes_merge(&o, t, &result_oid); - if (result >= 0) /* Merge resulted (trivially) in result_sha1 */ + if (result >= 0) /* Merge resulted (trivially) in result_oid */ /* Update default notes ref with new commit */ - update_ref(msg.buf, default_notes_ref(), result_sha1, NULL, + update_ref(msg.buf, default_notes_ref(), result_oid.hash, NULL, 0, UPDATE_REFS_DIE_ON_ERR); else { /* Merge has unresolved conflicts */ const struct worktree *wt; /* Update .git/NOTES_MERGE_PARTIAL with partial merge result */ - update_ref(msg.buf, "NOTES_MERGE_PARTIAL", result_sha1, NULL, + update_ref(msg.buf, "NOTES_MERGE_PARTIAL", result_oid.hash, NULL, 0, UPDATE_REFS_DIE_ON_ERR); /* Store ref-to-be-updated into .git/NOTES_MERGE_REF */ wt = find_shared_symref("NOTES_MERGE_REF", default_notes_ref()); @@ -880,10 +880,10 @@ static int merge(int argc, const char **argv, const char *prefix) static int remove_one_note(struct notes_tree *t, const char *name, unsigned flag) { int status; - unsigned char sha1[20]; - if (get_sha1(name, sha1)) + struct object_id oid; + if (get_oid(name, &oid)) return error(_("Failed to resolve '%s' as a valid ref."), name); - status = remove_note(t, sha1); + status = remove_note(t, oid.hash); if (status) fprintf(stderr, _("Object %s has no note\n"), name); else @@ -1026,6 +1026,13 @@ static inline void oidcpy(struct object_id *dst, const struct object_id *src) hashcpy(dst->hash, src->hash); } +static inline struct object_id *oiddup(const struct object_id *src) +{ + struct object_id *dst = xmalloc(sizeof(struct object_id)); + oidcpy(dst, src); + return dst; +} + static inline void hashclr(unsigned char *hash) { memset(hash, 0, GIT_SHA1_RAWSZ); diff --git a/combine-diff.c b/combine-diff.c index 2848034fe9..ec9d930440 100644 --- a/combine-diff.c +++ b/combine-diff.c @@ -302,7 +302,7 @@ static char *grab_blob(const struct object_id *oid, unsigned int mode, return xcalloc(1, 1); } else if (textconv) { struct diff_filespec *df = alloc_filespec(path); - fill_filespec(df, oid->hash, 1, mode); + fill_filespec(df, oid, 1, mode); *size = fill_textconv(textconv, df, &blob); free_filespec(df); } else { @@ -1022,7 +1022,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent, &result_size, NULL, NULL); } else if (textconv) { struct diff_filespec *df = alloc_filespec(elem->path); - fill_filespec(df, null_sha1, 0, st.st_mode); + fill_filespec(df, &null_oid, 0, st.st_mode); result_size = fill_textconv(textconv, df, &result); free_filespec(df); } else if (0 <= (fd = open(elem->path, O_RDONLY))) { @@ -1311,7 +1311,7 @@ static const char *path_path(void *obj) /* find set of paths that every parent touches */ -static struct combine_diff_path *find_paths_generic(const unsigned char *sha1, +static struct combine_diff_path *find_paths_generic(const struct object_id *oid, const struct oid_array *parents, struct diff_options *opt) { struct combine_diff_path *paths = NULL; @@ -1336,7 +1336,7 @@ static struct combine_diff_path *find_paths_generic(const unsigned char *sha1, opt->output_format = stat_opt; else opt->output_format = DIFF_FORMAT_NO_OUTPUT; - diff_tree_sha1(parents->oid[i].hash, sha1, "", opt); + diff_tree_oid(&parents->oid[i], oid, "", opt); diffcore_std(opt); paths = intersect_paths(paths, i, num_parent); @@ -1360,31 +1360,31 @@ static struct combine_diff_path *find_paths_generic(const unsigned char *sha1, * rename/copy detection, etc, comparing all trees simultaneously (= faster). */ static struct combine_diff_path *find_paths_multitree( - const unsigned char *sha1, const struct oid_array *parents, + const struct object_id *oid, const struct oid_array *parents, struct diff_options *opt) { int i, nparent = parents->nr; - const unsigned char **parents_sha1; + const struct object_id **parents_oid; struct combine_diff_path paths_head; struct strbuf base; - ALLOC_ARRAY(parents_sha1, nparent); + ALLOC_ARRAY(parents_oid, nparent); for (i = 0; i < nparent; i++) - parents_sha1[i] = parents->oid[i].hash; + parents_oid[i] = &parents->oid[i]; /* fake list head, so worker can assume it is non-NULL */ paths_head.next = NULL; strbuf_init(&base, PATH_MAX); - diff_tree_paths(&paths_head, sha1, parents_sha1, nparent, &base, opt); + diff_tree_paths(&paths_head, oid, parents_oid, nparent, &base, opt); strbuf_release(&base); - free(parents_sha1); + free(parents_oid); return paths_head.next; } -void diff_tree_combined(const unsigned char *sha1, +void diff_tree_combined(const struct object_id *oid, const struct oid_array *parents, int dense, struct rev_info *rev) @@ -1448,11 +1448,11 @@ void diff_tree_combined(const unsigned char *sha1, * diff(sha1,parent_i) for all i to do the job, specifically * for parent0. */ - paths = find_paths_generic(sha1, parents, &diffopts); + paths = find_paths_generic(oid, parents, &diffopts); } else { int stat_opt; - paths = find_paths_multitree(sha1, parents, &diffopts); + paths = find_paths_multitree(oid, parents, &diffopts); /* * show stat against the first parent even @@ -1463,7 +1463,7 @@ void diff_tree_combined(const unsigned char *sha1, if (stat_opt) { diffopts.output_format = stat_opt; - diff_tree_sha1(parents->oid[0].hash, sha1, "", &diffopts); + diff_tree_oid(&parents->oid[0], oid, "", &diffopts); diffcore_std(&diffopts); if (opt->orderfile) diffcore_order(opt->orderfile); @@ -1539,6 +1539,6 @@ void diff_tree_combined_merge(const struct commit *commit, int dense, oid_array_append(&parents, &parent->item->object.oid); parent = parent->next; } - diff_tree_combined(commit->object.oid.hash, &parents, dense, rev); + diff_tree_combined(&commit->object.oid, &parents, dense, rev); oid_array_clear(&parents); } diff --git a/diff-lib.c b/diff-lib.c index 76c8f185cd..0c0e20f7c0 100644 --- a/diff-lib.c +++ b/diff-lib.c @@ -101,7 +101,7 @@ int run_diff_files(struct rev_info *revs, unsigned int option) struct cache_entry *ce = active_cache[i]; int changed; unsigned dirty_submodule = 0; - const unsigned char *old_sha1, *new_sha1; + const struct object_id *old_oid, *new_oid; if (diff_can_quit_early(&revs->diffopt)) break; @@ -210,14 +210,14 @@ int run_diff_files(struct rev_info *revs, unsigned int option) continue; } diff_addremove(&revs->diffopt, '-', ce->ce_mode, - ce->oid.hash, + &ce->oid, !is_null_oid(&ce->oid), ce->name, 0); continue; } else if (revs->diffopt.ita_invisible_in_index && ce_intent_to_add(ce)) { diff_addremove(&revs->diffopt, '+', ce->ce_mode, - EMPTY_BLOB_SHA1_BIN, 0, + &empty_tree_oid, 0, ce->name, 0); continue; } @@ -233,12 +233,12 @@ int run_diff_files(struct rev_info *revs, unsigned int option) continue; } oldmode = ce->ce_mode; - old_sha1 = ce->oid.hash; - new_sha1 = changed ? null_sha1 : ce->oid.hash; + old_oid = &ce->oid; + new_oid = changed ? &null_oid : &ce->oid; diff_change(&revs->diffopt, oldmode, newmode, - old_sha1, new_sha1, - !is_null_sha1(old_sha1), - !is_null_sha1(new_sha1), + old_oid, new_oid, + !is_null_oid(old_oid), + !is_null_oid(new_oid), ce->name, 0, dirty_submodule); } @@ -255,21 +255,21 @@ int run_diff_files(struct rev_info *revs, unsigned int option) static void diff_index_show_file(struct rev_info *revs, const char *prefix, const struct cache_entry *ce, - const unsigned char *sha1, int sha1_valid, + const struct object_id *oid, int oid_valid, unsigned int mode, unsigned dirty_submodule) { diff_addremove(&revs->diffopt, prefix[0], mode, - sha1, sha1_valid, ce->name, dirty_submodule); + oid, oid_valid, ce->name, dirty_submodule); } static int get_stat_data(const struct cache_entry *ce, - const unsigned char **sha1p, + const struct object_id **oidp, unsigned int *modep, int cached, int match_missing, unsigned *dirty_submodule, struct diff_options *diffopt) { - const unsigned char *sha1 = ce->oid.hash; + const struct object_id *oid = &ce->oid; unsigned int mode = ce->ce_mode; if (!cached && !ce_uptodate(ce)) { @@ -280,7 +280,7 @@ static int get_stat_data(const struct cache_entry *ce, return -1; else if (changed) { if (match_missing) { - *sha1p = sha1; + *oidp = oid; *modep = mode; return 0; } @@ -290,11 +290,11 @@ static int get_stat_data(const struct cache_entry *ce, 0, dirty_submodule); if (changed) { mode = ce_mode_from_stat(ce, st.st_mode); - sha1 = null_sha1; + oid = &null_oid; } } - *sha1p = sha1; + *oidp = oid; *modep = mode; return 0; } @@ -303,7 +303,7 @@ static void show_new_file(struct rev_info *revs, const struct cache_entry *new, int cached, int match_missing) { - const unsigned char *sha1; + const struct object_id *oid; unsigned int mode; unsigned dirty_submodule = 0; @@ -311,11 +311,11 @@ static void show_new_file(struct rev_info *revs, * New file in the index: it might actually be different in * the working tree. */ - if (get_stat_data(new, &sha1, &mode, cached, match_missing, + if (get_stat_data(new, &oid, &mode, cached, match_missing, &dirty_submodule, &revs->diffopt) < 0) return; - diff_index_show_file(revs, "+", new, sha1, !is_null_sha1(sha1), mode, dirty_submodule); + diff_index_show_file(revs, "+", new, oid, !is_null_oid(oid), mode, dirty_submodule); } static int show_modified(struct rev_info *revs, @@ -325,20 +325,20 @@ static int show_modified(struct rev_info *revs, int cached, int match_missing) { unsigned int mode, oldmode; - const unsigned char *sha1; + const struct object_id *oid; unsigned dirty_submodule = 0; - if (get_stat_data(new, &sha1, &mode, cached, match_missing, + if (get_stat_data(new, &oid, &mode, cached, match_missing, &dirty_submodule, &revs->diffopt) < 0) { if (report_missing) diff_index_show_file(revs, "-", old, - old->oid.hash, 1, old->ce_mode, + &old->oid, 1, old->ce_mode, 0); return -1; } if (revs->combine_merges && !cached && - (hashcmp(sha1, old->oid.hash) || oidcmp(&old->oid, &new->oid))) { + (oidcmp(oid, &old->oid) || oidcmp(&old->oid, &new->oid))) { struct combine_diff_path *p; int pathlen = ce_namelen(new); @@ -362,12 +362,12 @@ static int show_modified(struct rev_info *revs, } oldmode = old->ce_mode; - if (mode == oldmode && !hashcmp(sha1, old->oid.hash) && !dirty_submodule && + if (mode == oldmode && !oidcmp(oid, &old->oid) && !dirty_submodule && !DIFF_OPT_TST(&revs->diffopt, FIND_COPIES_HARDER)) return 0; diff_change(&revs->diffopt, oldmode, mode, - old->oid.hash, sha1, 1, !is_null_sha1(sha1), + &old->oid, oid, 1, !is_null_oid(oid), old->name, 0, dirty_submodule); return 0; } @@ -409,7 +409,7 @@ static void do_oneway_diff(struct unpack_trees_options *o, struct diff_filepair *pair; pair = diff_unmerge(&revs->diffopt, idx->name); if (tree) - fill_filespec(pair->one, tree->oid.hash, 1, + fill_filespec(pair->one, &tree->oid, 1, tree->ce_mode); return; } @@ -426,7 +426,7 @@ static void do_oneway_diff(struct unpack_trees_options *o, * Something removed from the tree? */ if (!idx) { - diff_index_show_file(revs, "-", tree, tree->oid.hash, 1, + diff_index_show_file(revs, "-", tree, &tree->oid, 1, tree->ce_mode, 0); return; } diff --git a/diff-no-index.c b/diff-no-index.c index 79229382b0..80ff17d460 100644 --- a/diff-no-index.c +++ b/diff-no-index.c @@ -82,7 +82,7 @@ static struct diff_filespec *noindex_filespec(const char *name, int mode) if (!name) name = "/dev/null"; s = alloc_filespec(name); - fill_filespec(s, null_sha1, 0, mode); + fill_filespec(s, &null_oid, 0, mode); if (name == file_from_standard_input) populate_from_stdin(s); return s; @@ -2702,13 +2702,13 @@ void free_filespec(struct diff_filespec *spec) } } -void fill_filespec(struct diff_filespec *spec, const unsigned char *sha1, - int sha1_valid, unsigned short mode) +void fill_filespec(struct diff_filespec *spec, const struct object_id *oid, + int oid_valid, unsigned short mode) { if (mode) { spec->mode = canon_mode(mode); - hashcpy(spec->oid.hash, sha1); - spec->oid_valid = sha1_valid; + oidcpy(&spec->oid, oid); + spec->oid_valid = oid_valid; } } @@ -2717,7 +2717,7 @@ void fill_filespec(struct diff_filespec *spec, const unsigned char *sha1, * the work tree has that object contents, return true, so that * prepare_temp_file() does not have to inflate and extract. */ -static int reuse_worktree_file(const char *name, const unsigned char *sha1, int want_file) +static int reuse_worktree_file(const char *name, const struct object_id *oid, int want_file) { const struct cache_entry *ce; struct stat st; @@ -2748,7 +2748,7 @@ static int reuse_worktree_file(const char *name, const unsigned char *sha1, int * objects however would tend to be slower as they need * to be individually opened and inflated. */ - if (!FAST_WORKING_DIRECTORY && !want_file && has_sha1_pack(sha1)) + if (!FAST_WORKING_DIRECTORY && !want_file && has_sha1_pack(oid->hash)) return 0; /* @@ -2768,7 +2768,7 @@ static int reuse_worktree_file(const char *name, const unsigned char *sha1, int * This is not the sha1 we are looking for, or * unreusable because it is not a regular file. */ - if (hashcmp(sha1, ce->oid.hash) || !S_ISREG(ce->ce_mode)) + if (oidcmp(oid, &ce->oid) || !S_ISREG(ce->ce_mode)) return 0; /* @@ -2842,7 +2842,7 @@ int diff_populate_filespec(struct diff_filespec *s, unsigned int flags) return diff_populate_gitlink(s, size_only); if (!s->oid_valid || - reuse_worktree_file(s->path, s->oid.hash, 0)) { + reuse_worktree_file(s->path, &s->oid, 0)) { struct strbuf buf = STRBUF_INIT; struct stat st; int fd; @@ -3008,7 +3008,7 @@ static struct diff_tempfile *prepare_temp_file(const char *name, if (!S_ISGITLINK(one->mode) && (!one->oid_valid || - reuse_worktree_file(name, one->oid.hash, 1))) { + reuse_worktree_file(name, &one->oid, 1))) { struct stat st; if (lstat(name, &st) < 0) { if (errno == ENOENT) @@ -3030,13 +3030,13 @@ static struct diff_tempfile *prepare_temp_file(const char *name, /* we can borrow from the file in the work tree */ temp->name = name; if (!one->oid_valid) - sha1_to_hex_r(temp->hex, null_sha1); + oid_to_hex_r(temp->hex, &null_oid); else oid_to_hex_r(temp->hex, &one->oid); /* Even though we may sometimes borrow the * contents from the work tree, we always want * one->mode. mode is trustworthy even when - * !(one->sha1_valid), as long as + * !(one->oid_valid), as long as * DIFF_FILE_VALID(one). */ xsnprintf(temp->mode, sizeof(temp->mode), "%06o", one->mode); @@ -3239,7 +3239,7 @@ static void run_diff_cmd(const char *pgm, fprintf(o->file, "* Unmerged path %s\n", name); } -static void diff_fill_sha1_info(struct diff_filespec *one) +static void diff_fill_oid_info(struct diff_filespec *one) { if (DIFF_FILE_VALID(one)) { if (!one->oid_valid) { @@ -3298,8 +3298,8 @@ static void run_diff(struct diff_filepair *p, struct diff_options *o) return; } - diff_fill_sha1_info(one); - diff_fill_sha1_info(two); + diff_fill_oid_info(one); + diff_fill_oid_info(two); if (!pgm && DIFF_FILE_VALID(one) && DIFF_FILE_VALID(two) && @@ -3344,8 +3344,8 @@ static void run_diffstat(struct diff_filepair *p, struct diff_options *o, if (o->prefix_length) strip_prefix(o->prefix_length, &name, &other); - diff_fill_sha1_info(p->one); - diff_fill_sha1_info(p->two); + diff_fill_oid_info(p->one); + diff_fill_oid_info(p->two); builtin_diffstat(name, other, p->one, p->two, diffstat, o, p); } @@ -3368,8 +3368,8 @@ static void run_checkdiff(struct diff_filepair *p, struct diff_options *o) if (o->prefix_length) strip_prefix(o->prefix_length, &name, &other); - diff_fill_sha1_info(p->one); - diff_fill_sha1_info(p->two); + diff_fill_oid_info(p->one); + diff_fill_oid_info(p->two); builtin_checkdiff(name, other, attr_path, p->one, p->two, o); } @@ -4582,7 +4582,7 @@ static void patch_id_add_mode(git_SHA_CTX *ctx, unsigned mode) } /* returns 0 upon success, and writes result into sha1 */ -static int diff_get_patch_id(struct diff_options *options, unsigned char *sha1, int diff_header_only) +static int diff_get_patch_id(struct diff_options *options, struct object_id *oid, int diff_header_only) { struct diff_queue_struct *q = &diff_queued_diff; int i; @@ -4614,8 +4614,8 @@ static int diff_get_patch_id(struct diff_options *options, unsigned char *sha1, if (DIFF_PAIR_UNMERGED(p)) continue; - diff_fill_sha1_info(p->one); - diff_fill_sha1_info(p->two); + diff_fill_oid_info(p->one); + diff_fill_oid_info(p->two); len1 = remove_space(p->one->path, strlen(p->one->path)); len2 = remove_space(p->two->path, strlen(p->two->path)); @@ -4654,9 +4654,9 @@ static int diff_get_patch_id(struct diff_options *options, unsigned char *sha1, if (diff_filespec_is_binary(p->one) || diff_filespec_is_binary(p->two)) { git_SHA1_Update(&ctx, oid_to_hex(&p->one->oid), - 40); + GIT_SHA1_HEXSZ); git_SHA1_Update(&ctx, oid_to_hex(&p->two->oid), - 40); + GIT_SHA1_HEXSZ); continue; } @@ -4669,15 +4669,15 @@ static int diff_get_patch_id(struct diff_options *options, unsigned char *sha1, p->one->path); } - git_SHA1_Final(sha1, &ctx); + git_SHA1_Final(oid->hash, &ctx); return 0; } -int diff_flush_patch_id(struct diff_options *options, unsigned char *sha1, int diff_header_only) +int diff_flush_patch_id(struct diff_options *options, struct object_id *oid, int diff_header_only) { struct diff_queue_struct *q = &diff_queued_diff; int i; - int result = diff_get_patch_id(options, sha1, diff_header_only); + int result = diff_get_patch_id(options, oid, diff_header_only); for (i = 0; i < q->nr; i++) diff_free_filepair(q->queue[i]); @@ -5077,8 +5077,8 @@ static int is_submodule_ignored(const char *path, struct diff_options *options) void diff_addremove(struct diff_options *options, int addremove, unsigned mode, - const unsigned char *sha1, - int sha1_valid, + const struct object_id *oid, + int oid_valid, const char *concatpath, unsigned dirty_submodule) { struct diff_filespec *one, *two; @@ -5110,9 +5110,9 @@ void diff_addremove(struct diff_options *options, two = alloc_filespec(concatpath); if (addremove != '+') - fill_filespec(one, sha1, sha1_valid, mode); + fill_filespec(one, oid, oid_valid, mode); if (addremove != '-') { - fill_filespec(two, sha1, sha1_valid, mode); + fill_filespec(two, oid, oid_valid, mode); two->dirty_submodule = dirty_submodule; } @@ -5123,9 +5123,9 @@ void diff_addremove(struct diff_options *options, void diff_change(struct diff_options *options, unsigned old_mode, unsigned new_mode, - const unsigned char *old_sha1, - const unsigned char *new_sha1, - int old_sha1_valid, int new_sha1_valid, + const struct object_id *old_oid, + const struct object_id *new_oid, + int old_oid_valid, int new_oid_valid, const char *concatpath, unsigned old_dirty_submodule, unsigned new_dirty_submodule) { @@ -5138,8 +5138,8 @@ void diff_change(struct diff_options *options, if (DIFF_OPT_TST(options, REVERSE_DIFF)) { SWAP(old_mode, new_mode); - SWAP(old_sha1, new_sha1); - SWAP(old_sha1_valid, new_sha1_valid); + SWAP(old_oid, new_oid); + SWAP(old_oid_valid, new_oid_valid); SWAP(old_dirty_submodule, new_dirty_submodule); } @@ -5149,8 +5149,8 @@ void diff_change(struct diff_options *options, one = alloc_filespec(concatpath); two = alloc_filespec(concatpath); - fill_filespec(one, old_sha1, old_sha1_valid, old_mode); - fill_filespec(two, new_sha1, new_sha1_valid, new_mode); + fill_filespec(one, old_oid, old_oid_valid, old_mode); + fill_filespec(two, new_oid, new_oid_valid, new_mode); one->dirty_submodule = old_dirty_submodule; two->dirty_submodule = new_dirty_submodule; p = diff_queue(&diff_queued_diff, one, two); @@ -5277,7 +5277,7 @@ int textconv_object(const char *path, struct userdiff_driver *textconv; df = alloc_filespec(path); - fill_filespec(df, oid->hash, oid_valid, mode); + fill_filespec(df, oid, oid_valid, mode); textconv = get_textconv(df); if (!textconv) { free_filespec(df); @@ -23,16 +23,16 @@ typedef int (*pathchange_fn_t)(struct diff_options *options, typedef void (*change_fn_t)(struct diff_options *options, unsigned old_mode, unsigned new_mode, - const unsigned char *old_sha1, - const unsigned char *new_sha1, - int old_sha1_valid, int new_sha1_valid, + const struct object_id *old_oid, + const struct object_id *new_oid, + int old_oid_valid, int new_oid_valid, const char *fullpath, unsigned old_dirty_submodule, unsigned new_dirty_submodule); typedef void (*add_remove_fn_t)(struct diff_options *options, int addremove, unsigned mode, - const unsigned char *sha1, - int sha1_valid, + const struct object_id *oid, + int oid_valid, const char *fullpath, unsigned dirty_submodule); typedef void (*diff_format_fn_t)(struct diff_queue_struct *q, @@ -210,13 +210,14 @@ const char *diff_line_prefix(struct diff_options *); extern const char mime_boundary_leader[]; extern struct combine_diff_path *diff_tree_paths( - struct combine_diff_path *p, const unsigned char *sha1, - const unsigned char **parent_sha1, int nparent, + struct combine_diff_path *p, const struct object_id *oid, + const struct object_id **parents_oid, int nparent, struct strbuf *base, struct diff_options *opt); -extern int diff_tree_sha1(const unsigned char *old, const unsigned char *new, - const char *base, struct diff_options *opt); -extern int diff_root_tree_sha1(const unsigned char *new, const char *base, - struct diff_options *opt); +extern int diff_tree_oid(const struct object_id *old_oid, + const struct object_id *new_oid, + const char *base, struct diff_options *opt); +extern int diff_root_tree_oid(const struct object_id *new_oid, const char *base, + struct diff_options *opt); struct combine_diff_path { struct combine_diff_path *next; @@ -236,7 +237,7 @@ struct combine_diff_path { extern void show_combined_diff(struct combine_diff_path *elem, int num_parent, int dense, struct rev_info *); -extern void diff_tree_combined(const unsigned char *sha1, const struct oid_array *parents, int dense, struct rev_info *rev); +extern void diff_tree_combined(const struct object_id *oid, const struct oid_array *parents, int dense, struct rev_info *rev); extern void diff_tree_combined_merge(const struct commit *commit, int dense, struct rev_info *rev); @@ -247,16 +248,15 @@ extern int diff_can_quit_early(struct diff_options *); extern void diff_addremove(struct diff_options *, int addremove, unsigned mode, - const unsigned char *sha1, - int sha1_valid, + const struct object_id *oid, + int oid_valid, const char *fullpath, unsigned dirty_submodule); extern void diff_change(struct diff_options *, unsigned mode1, unsigned mode2, - const unsigned char *sha1, - const unsigned char *sha2, - int sha1_valid, - int sha2_valid, + const struct object_id *old_oid, + const struct object_id *new_oid, + int old_oid_valid, int new_oid_valid, const char *fullpath, unsigned dirty_submodule1, unsigned dirty_submodule2); @@ -355,7 +355,7 @@ extern int run_diff_files(struct rev_info *revs, unsigned int option); extern int run_diff_index(struct rev_info *revs, int cached); extern int do_diff_cache(const struct object_id *, struct diff_options *); -extern int diff_flush_patch_id(struct diff_options *, unsigned char *, int); +extern int diff_flush_patch_id(struct diff_options *, struct object_id *, int); extern int diff_result_code(struct diff_options *, int); diff --git a/diffcore-rename.c b/diffcore-rename.c index f7444c86bd..03d1e8d40b 100644 --- a/diffcore-rename.c +++ b/diffcore-rename.c @@ -60,7 +60,7 @@ static int add_rename_dst(struct diff_filespec *two) memmove(rename_dst + first + 1, rename_dst + first, (rename_dst_nr - first - 1) * sizeof(*rename_dst)); rename_dst[first].two = alloc_filespec(two->path); - fill_filespec(rename_dst[first].two, two->oid.hash, two->oid_valid, + fill_filespec(rename_dst[first].two, &two->oid, two->oid_valid, two->mode); rename_dst[first].pair = NULL; return 0; @@ -464,7 +464,7 @@ void diffcore_rename(struct diff_options *options) strcmp(options->single_follow, p->two->path)) continue; /* not interested */ else if (!DIFF_OPT_TST(options, RENAME_EMPTY) && - is_empty_blob_sha1(p->two->oid.hash)) + is_empty_blob_oid(&p->two->oid)) continue; else if (add_rename_dst(p->two) < 0) { warning("skipping rename detection, detected" @@ -474,7 +474,7 @@ void diffcore_rename(struct diff_options *options) } } else if (!DIFF_OPT_TST(options, RENAME_EMPTY) && - is_empty_blob_sha1(p->one->oid.hash)) + is_empty_blob_oid(&p->one->oid)) continue; else if (!DIFF_PAIR_UNMERGED(p) && !DIFF_FILE_VALID(p->two)) { /* diff --git a/diffcore.h b/diffcore.h index 6230241354..a30da161da 100644 --- a/diffcore.h +++ b/diffcore.h @@ -52,7 +52,7 @@ struct diff_filespec { extern struct diff_filespec *alloc_filespec(const char *); extern void free_filespec(struct diff_filespec *); -extern void fill_filespec(struct diff_filespec *, const unsigned char *, +extern void fill_filespec(struct diff_filespec *, const struct object_id *, int, unsigned short); #define CHECK_SIZE_ONLY 1 @@ -1584,11 +1584,11 @@ static int fill_textconv_grep(struct userdiff_driver *driver, */ df = alloc_filespec(gs->path); switch (gs->type) { - case GREP_SOURCE_SHA1: + case GREP_SOURCE_OID: fill_filespec(df, gs->identifier, 1, 0100644); break; case GREP_SOURCE_FILE: - fill_filespec(df, null_sha1, 0, 0100644); + fill_filespec(df, &null_oid, 0, 0100644); break; default: die("BUG: attempt to textconv something without a path?"); @@ -1928,9 +1928,8 @@ void grep_source_init(struct grep_source *gs, enum grep_source_type type, * If the identifier is non-NULL (in the submodule case) it * will be a SHA1 that needs to be copied. */ - case GREP_SOURCE_SHA1: - gs->identifier = xmalloc(20); - hashcpy(gs->identifier, identifier); + case GREP_SOURCE_OID: + gs->identifier = oiddup(identifier); break; case GREP_SOURCE_BUF: gs->identifier = NULL; @@ -1953,7 +1952,7 @@ void grep_source_clear_data(struct grep_source *gs) { switch (gs->type) { case GREP_SOURCE_FILE: - case GREP_SOURCE_SHA1: + case GREP_SOURCE_OID: case GREP_SOURCE_SUBMODULE: free(gs->buf); gs->buf = NULL; @@ -1965,7 +1964,7 @@ void grep_source_clear_data(struct grep_source *gs) } } -static int grep_source_load_sha1(struct grep_source *gs) +static int grep_source_load_oid(struct grep_source *gs) { enum object_type type; @@ -1976,7 +1975,7 @@ static int grep_source_load_sha1(struct grep_source *gs) if (!gs->buf) return error(_("'%s': unable to read %s"), gs->name, - sha1_to_hex(gs->identifier)); + oid_to_hex(gs->identifier)); return 0; } @@ -2022,8 +2021,8 @@ static int grep_source_load(struct grep_source *gs) switch (gs->type) { case GREP_SOURCE_FILE: return grep_source_load_file(gs); - case GREP_SOURCE_SHA1: - return grep_source_load_sha1(gs); + case GREP_SOURCE_OID: + return grep_source_load_oid(gs); case GREP_SOURCE_BUF: return gs->buf ? 0 : -1; case GREP_SOURCE_SUBMODULE: @@ -191,7 +191,7 @@ struct grep_source { char *name; enum grep_source_type { - GREP_SOURCE_SHA1, + GREP_SOURCE_OID, GREP_SOURCE_FILE, GREP_SOURCE_BUF, GREP_SOURCE_SUBMODULE, diff --git a/line-log.c b/line-log.c index b9087814b8..2588ce0767 100644 --- a/line-log.c +++ b/line-log.c @@ -500,12 +500,12 @@ static struct commit *check_single_commit(struct rev_info *revs) static void fill_blob_sha1(struct commit *commit, struct diff_filespec *spec) { unsigned mode; - unsigned char sha1[20]; + struct object_id oid; if (get_tree_entry(commit->object.oid.hash, spec->path, - sha1, &mode)) + oid.hash, &mode)) die("There is no path %s in the commit", spec->path); - fill_filespec(spec, sha1, 1, mode); + fill_filespec(spec, &oid, 1, mode); return; } @@ -819,8 +819,8 @@ static void queue_diffs(struct line_log_data *range, assert(commit); DIFF_QUEUE_CLEAR(&diff_queued_diff); - diff_tree_sha1(parent ? parent->tree->object.oid.hash : NULL, - commit->tree->object.oid.hash, "", opt); + diff_tree_oid(parent ? &parent->tree->object.oid : NULL, + &commit->tree->object.oid, "", opt); if (opt->detect_rename) { filter_diffs_for_paths(range, 1); if (diff_might_be_rename()) diff --git a/log-tree.c b/log-tree.c index a4ec11c2bf..2903874ecf 100644 --- a/log-tree.c +++ b/log-tree.c @@ -655,7 +655,7 @@ void show_log(struct rev_info *opt) struct strbuf notebuf = STRBUF_INIT; raw = (opt->commit_format == CMIT_FMT_USERFORMAT); - format_display_notes(commit->object.oid.hash, ¬ebuf, + format_display_notes(&commit->object.oid, ¬ebuf, get_log_output_encoding(), raw); ctx.notes_message = notebuf.len ? strbuf_detach(¬ebuf, NULL) @@ -803,7 +803,7 @@ static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log parents = get_saved_parents(opt, commit); if (!parents) { if (opt->show_root_diff) { - diff_root_tree_sha1(oid->hash, "", &opt->diffopt); + diff_root_tree_oid(oid, "", &opt->diffopt); log_tree_diff_flush(opt); } return !opt->loginfo; @@ -822,8 +822,8 @@ static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log * we merged _in_. */ parse_commit_or_die(parents->item); - diff_tree_sha1(parents->item->tree->object.oid.hash, - oid->hash, "", &opt->diffopt); + diff_tree_oid(&parents->item->tree->object.oid, + oid, "", &opt->diffopt); log_tree_diff_flush(opt); return !opt->loginfo; } @@ -837,8 +837,8 @@ static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log struct commit *parent = parents->item; parse_commit_or_die(parent); - diff_tree_sha1(parent->tree->object.oid.hash, - oid->hash, "", &opt->diffopt); + diff_tree_oid(&parent->tree->object.oid, + oid, "", &opt->diffopt); log_tree_diff_flush(opt); showed_log |= !opt->loginfo; diff --git a/merge-recursive.c b/merge-recursive.c index ae5238d82c..5cc86df2d1 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -528,7 +528,7 @@ static struct string_list *get_renames(struct merge_options *o, opts.show_rename_progress = o->show_rename_progress; opts.output_format = DIFF_FORMAT_NO_OUTPUT; diff_setup_done(&opts); - diff_tree_sha1(o_tree->object.oid.hash, tree->object.oid.hash, "", &opts); + diff_tree_oid(&o_tree->object.oid, &tree->object.oid, "", &opts); diffcore_std(&opts); if (opts.needed_rename_limit > o->needed_rename_limit) o->needed_rename_limit = opts.needed_rename_limit; diff --git a/notes-cache.c b/notes-cache.c index 2843e98576..29b4cede5f 100644 --- a/notes-cache.c +++ b/notes-cache.c @@ -69,15 +69,15 @@ int notes_cache_write(struct notes_cache *c) char *notes_cache_get(struct notes_cache *c, struct object_id *key_oid, size_t *outsize) { - const unsigned char *value_sha1; + const struct object_id *value_oid; enum object_type type; char *value; unsigned long size; - value_sha1 = get_note(&c->tree, key_oid->hash); - if (!value_sha1) + value_oid = get_note(&c->tree, key_oid); + if (!value_oid) return NULL; - value = read_sha1_file(value_sha1, &type, &size); + value = read_sha1_file(value_oid->hash, &type, &size); *outsize = size; return value; @@ -90,5 +90,5 @@ int notes_cache_put(struct notes_cache *c, struct object_id *key_oid, if (write_sha1_file(data, size, "blob", value_oid.hash) < 0) return -1; - return add_note(&c->tree, key_oid->hash, value_oid.hash, NULL); + return add_note(&c->tree, key_oid, &value_oid, NULL); } diff --git a/notes-merge.c b/notes-merge.c index 6244f6af9c..70e3fbeefb 100644 --- a/notes-merge.c +++ b/notes-merge.c @@ -22,21 +22,21 @@ void init_notes_merge_options(struct notes_merge_options *o) o->verbosity = NOTES_MERGE_VERBOSITY_DEFAULT; } -static int path_to_sha1(const char *path, unsigned char *sha1) +static int path_to_oid(const char *path, struct object_id *oid) { - char hex_sha1[40]; + char hex_oid[GIT_SHA1_HEXSZ]; int i = 0; - while (*path && i < 40) { + while (*path && i < GIT_SHA1_HEXSZ) { if (*path != '/') - hex_sha1[i++] = *path; + hex_oid[i++] = *path; path++; } - if (*path || i != 40) + if (*path || i != GIT_SHA1_HEXSZ) return -1; - return get_sha1_hex(hex_sha1, sha1); + return get_oid_hex(hex_oid, oid); } -static int verify_notes_filepair(struct diff_filepair *p, unsigned char *sha1) +static int verify_notes_filepair(struct diff_filepair *p, struct object_id *oid) { switch (p->status) { case DIFF_STATUS_MODIFIED: @@ -54,11 +54,11 @@ static int verify_notes_filepair(struct diff_filepair *p, unsigned char *sha1) return -1; } assert(!strcmp(p->one->path, p->two->path)); - return path_to_sha1(p->one->path, sha1); + return path_to_oid(p->one->path, oid); } static struct notes_merge_pair *find_notes_merge_pair_pos( - struct notes_merge_pair *list, int len, unsigned char *obj, + struct notes_merge_pair *list, int len, struct object_id *obj, int insert_new, int *occupied) { /* @@ -75,7 +75,7 @@ static struct notes_merge_pair *find_notes_merge_pair_pos( int i = last_index < len ? last_index : len - 1; int prev_cmp = 0, cmp = -1; while (i >= 0 && i < len) { - cmp = hashcmp(obj, list[i].obj.hash); + cmp = oidcmp(obj, &list[i].obj); if (!cmp) /* obj belongs @ i */ break; else if (cmp < 0 && prev_cmp <= 0) /* obj belongs < i */ @@ -114,8 +114,8 @@ static struct object_id uninitialized = { }; static struct notes_merge_pair *diff_tree_remote(struct notes_merge_options *o, - const unsigned char *base, - const unsigned char *remote, + const struct object_id *base, + const struct object_id *remote, int *num_changes) { struct diff_options opt; @@ -123,13 +123,13 @@ static struct notes_merge_pair *diff_tree_remote(struct notes_merge_options *o, int i, len = 0; trace_printf("\tdiff_tree_remote(base = %.7s, remote = %.7s)\n", - sha1_to_hex(base), sha1_to_hex(remote)); + oid_to_hex(base), oid_to_hex(remote)); diff_setup(&opt); DIFF_OPT_SET(&opt, RECURSIVE); opt.output_format = DIFF_FORMAT_NO_OUTPUT; diff_setup_done(&opt); - diff_tree_sha1(base, remote, "", &opt); + diff_tree_oid(base, remote, "", &opt); diffcore_std(&opt); changes = xcalloc(diff_queued_diff.nr, sizeof(struct notes_merge_pair)); @@ -138,19 +138,19 @@ static struct notes_merge_pair *diff_tree_remote(struct notes_merge_options *o, struct diff_filepair *p = diff_queued_diff.queue[i]; struct notes_merge_pair *mp; int occupied; - unsigned char obj[20]; + struct object_id obj; - if (verify_notes_filepair(p, obj)) { + if (verify_notes_filepair(p, &obj)) { trace_printf("\t\tCannot merge entry '%s' (%c): " "%.7s -> %.7s. Skipping!\n", p->one->path, p->status, oid_to_hex(&p->one->oid), oid_to_hex(&p->two->oid)); continue; } - mp = find_notes_merge_pair_pos(changes, len, obj, 1, &occupied); + mp = find_notes_merge_pair_pos(changes, len, &obj, 1, &occupied); if (occupied) { /* We've found an addition/deletion pair */ - assert(!hashcmp(mp->obj.hash, obj)); + assert(!oidcmp(&mp->obj, &obj)); if (is_null_oid(&p->one->oid)) { /* addition */ assert(is_null_oid(&mp->remote)); oidcpy(&mp->remote, &p->two->oid); @@ -160,7 +160,7 @@ static struct notes_merge_pair *diff_tree_remote(struct notes_merge_options *o, } else assert(!"Invalid existing change recorded"); } else { - hashcpy(mp->obj.hash, obj); + oidcpy(&mp->obj, &obj); oidcpy(&mp->base, &p->one->oid); oidcpy(&mp->local, &uninitialized); oidcpy(&mp->remote, &p->two->oid); @@ -179,45 +179,45 @@ static struct notes_merge_pair *diff_tree_remote(struct notes_merge_options *o, static void diff_tree_local(struct notes_merge_options *o, struct notes_merge_pair *changes, int len, - const unsigned char *base, - const unsigned char *local) + const struct object_id *base, + const struct object_id *local) { struct diff_options opt; int i; trace_printf("\tdiff_tree_local(len = %i, base = %.7s, local = %.7s)\n", - len, sha1_to_hex(base), sha1_to_hex(local)); + len, oid_to_hex(base), oid_to_hex(local)); diff_setup(&opt); DIFF_OPT_SET(&opt, RECURSIVE); opt.output_format = DIFF_FORMAT_NO_OUTPUT; diff_setup_done(&opt); - diff_tree_sha1(base, local, "", &opt); + diff_tree_oid(base, local, "", &opt); diffcore_std(&opt); for (i = 0; i < diff_queued_diff.nr; i++) { struct diff_filepair *p = diff_queued_diff.queue[i]; struct notes_merge_pair *mp; int match; - unsigned char obj[20]; + struct object_id obj; - if (verify_notes_filepair(p, obj)) { + if (verify_notes_filepair(p, &obj)) { trace_printf("\t\tCannot merge entry '%s' (%c): " "%.7s -> %.7s. Skipping!\n", p->one->path, p->status, oid_to_hex(&p->one->oid), oid_to_hex(&p->two->oid)); continue; } - mp = find_notes_merge_pair_pos(changes, len, obj, 0, &match); + mp = find_notes_merge_pair_pos(changes, len, &obj, 0, &match); if (!match) { trace_printf("\t\tIgnoring local-only change for %s: " - "%.7s -> %.7s\n", sha1_to_hex(obj), + "%.7s -> %.7s\n", oid_to_hex(&obj), oid_to_hex(&p->one->oid), oid_to_hex(&p->two->oid)); continue; } - assert(!hashcmp(mp->obj.hash, obj)); + assert(!oidcmp(&mp->obj, &obj)); if (is_null_oid(&p->two->oid)) { /* deletion */ /* * Either this is a true deletion (1), or it is part @@ -292,11 +292,11 @@ static void check_notes_merge_worktree(struct notes_merge_options *o) git_path(NOTES_MERGE_WORKTREE)); } -static void write_buf_to_worktree(const unsigned char *obj, +static void write_buf_to_worktree(const struct object_id *obj, const char *buf, unsigned long size) { int fd; - char *path = git_pathdup(NOTES_MERGE_WORKTREE "/%s", sha1_to_hex(obj)); + char *path = git_pathdup(NOTES_MERGE_WORKTREE "/%s", oid_to_hex(obj)); if (safe_create_leading_directories_const(path)) die_errno("unable to create directory for '%s'", path); @@ -320,19 +320,19 @@ static void write_buf_to_worktree(const unsigned char *obj, free(path); } -static void write_note_to_worktree(const unsigned char *obj, - const unsigned char *note) +static void write_note_to_worktree(const struct object_id *obj, + const struct object_id *note) { enum object_type type; unsigned long size; - void *buf = read_sha1_file(note, &type, &size); + void *buf = read_sha1_file(note->hash, &type, &size); if (!buf) die("cannot read note %s for object %s", - sha1_to_hex(note), sha1_to_hex(obj)); + oid_to_hex(note), oid_to_hex(obj)); if (type != OBJ_BLOB) die("blob expected in note %s for object %s", - sha1_to_hex(note), sha1_to_hex(obj)); + oid_to_hex(note), oid_to_hex(obj)); write_buf_to_worktree(obj, buf, size); free(buf); } @@ -358,7 +358,7 @@ static int ll_merge_in_worktree(struct notes_merge_options *o, if ((status < 0) || !result_buf.ptr) die("Failed to execute internal merge"); - write_buf_to_worktree(p->obj.hash, result_buf.ptr, result_buf.size); + write_buf_to_worktree(&p->obj, result_buf.ptr, result_buf.size); free(result_buf.ptr); return status; @@ -393,7 +393,7 @@ static int merge_one_change_manual(struct notes_merge_options *o, "deleted in %s and modified in %s. Version from %s " "left in tree.\n", oid_to_hex(&p->obj), lref, rref, rref); - write_note_to_worktree(p->obj.hash, p->remote.hash); + write_note_to_worktree(&p->obj, &p->remote); } else if (is_null_oid(&p->remote)) { /* D/F conflict, checkout p->local */ assert(!is_null_oid(&p->local)); @@ -402,7 +402,7 @@ static int merge_one_change_manual(struct notes_merge_options *o, "deleted in %s and modified in %s. Version from %s " "left in tree.\n", oid_to_hex(&p->obj), rref, lref, lref); - write_note_to_worktree(p->obj.hash, p->local.hash); + write_note_to_worktree(&p->obj, &p->local); } else { /* "regular" conflict, checkout result of ll_merge() */ const char *reason = "content"; @@ -444,14 +444,14 @@ static int merge_one_change(struct notes_merge_options *o, if (o->verbosity >= 2) printf("Using remote notes for %s\n", oid_to_hex(&p->obj)); - if (add_note(t, p->obj.hash, p->remote.hash, combine_notes_overwrite)) + if (add_note(t, &p->obj, &p->remote, combine_notes_overwrite)) die("BUG: combine_notes_overwrite failed"); return 0; case NOTES_MERGE_RESOLVE_UNION: if (o->verbosity >= 2) printf("Concatenating local and remote notes for %s\n", oid_to_hex(&p->obj)); - if (add_note(t, p->obj.hash, p->remote.hash, combine_notes_concatenate)) + if (add_note(t, &p->obj, &p->remote, combine_notes_concatenate)) die("failed to concatenate notes " "(combine_notes_concatenate)"); return 0; @@ -459,7 +459,7 @@ static int merge_one_change(struct notes_merge_options *o, if (o->verbosity >= 2) printf("Concatenating unique lines in local and remote " "notes for %s\n", oid_to_hex(&p->obj)); - if (add_note(t, p->obj.hash, p->remote.hash, combine_notes_cat_sort_uniq)) + if (add_note(t, &p->obj, &p->remote, combine_notes_cat_sort_uniq)) die("failed to concatenate notes " "(combine_notes_cat_sort_uniq)"); return 0; @@ -491,7 +491,7 @@ static int merge_changes(struct notes_merge_options *o, !oidcmp(&p->local, &p->base)) { /* no local change; adopt remote change */ trace_printf("\t\t\tno local change, adopted remote\n"); - if (add_note(t, p->obj.hash, p->remote.hash, + if (add_note(t, &p->obj, &p->remote, combine_notes_overwrite)) die("BUG: combine_notes_overwrite failed"); } else { @@ -505,16 +505,17 @@ static int merge_changes(struct notes_merge_options *o, } static int merge_from_diffs(struct notes_merge_options *o, - const unsigned char *base, - const unsigned char *local, - const unsigned char *remote, struct notes_tree *t) + const struct object_id *base, + const struct object_id *local, + const struct object_id *remote, + struct notes_tree *t) { struct notes_merge_pair *changes; int num_changes, conflicts; trace_printf("\tmerge_from_diffs(base = %.7s, local = %.7s, " - "remote = %.7s)\n", sha1_to_hex(base), sha1_to_hex(local), - sha1_to_hex(remote)); + "remote = %.7s)\n", oid_to_hex(base), oid_to_hex(local), + oid_to_hex(remote)); changes = diff_tree_remote(o, base, remote, &num_changes); diff_tree_local(o, changes, num_changes, base, local); @@ -533,17 +534,17 @@ static int merge_from_diffs(struct notes_merge_options *o, int notes_merge(struct notes_merge_options *o, struct notes_tree *local_tree, - unsigned char *result_sha1) + struct object_id *result_oid) { struct object_id local_oid, remote_oid; struct commit *local, *remote; struct commit_list *bases = NULL; - const unsigned char *base_sha1, *base_tree_sha1; + const struct object_id *base_oid, *base_tree_oid; int result = 0; assert(o->local_ref && o->remote_ref); assert(!strcmp(o->local_ref, local_tree->ref)); - hashclr(result_sha1); + oidclr(result_oid); trace_printf("notes_merge(o->local_ref = %s, o->remote_ref = %s)\n", o->local_ref, o->remote_ref); @@ -553,16 +554,16 @@ int notes_merge(struct notes_merge_options *o, die("Failed to resolve local notes ref '%s'", o->local_ref); else if (!check_refname_format(o->local_ref, 0) && is_null_oid(&local_oid)) - local = NULL; /* local_sha1 == null_sha1 indicates unborn ref */ + local = NULL; /* local_oid == null_oid indicates unborn ref */ else if (!(local = lookup_commit_reference(&local_oid))) die("Could not parse local commit %s (%s)", oid_to_hex(&local_oid), o->local_ref); trace_printf("\tlocal commit: %.7s\n", oid_to_hex(&local_oid)); - /* Dereference o->remote_ref into remote_sha1 */ + /* Dereference o->remote_ref into remote_oid */ if (get_oid(o->remote_ref, &remote_oid)) { /* - * Failed to get remote_sha1. If o->remote_ref looks like an + * Failed to get remote_oid. If o->remote_ref looks like an * unborn ref, perform the merge using an empty notes tree. */ if (!check_refname_format(o->remote_ref, 0)) { @@ -583,12 +584,12 @@ int notes_merge(struct notes_merge_options *o, "(%s)", o->remote_ref, o->local_ref); if (!local) { /* result == remote commit */ - hashcpy(result_sha1, remote_oid.hash); + oidcpy(result_oid, &remote_oid); goto found_result; } if (!remote) { /* result == local commit */ - hashcpy(result_sha1, local_oid.hash); + oidcpy(result_oid, &local_oid); goto found_result; } assert(local && remote); @@ -596,48 +597,48 @@ int notes_merge(struct notes_merge_options *o, /* Find merge bases */ bases = get_merge_bases(local, remote); if (!bases) { - base_sha1 = null_sha1; - base_tree_sha1 = EMPTY_TREE_SHA1_BIN; + base_oid = &null_oid; + base_tree_oid = &empty_tree_oid; if (o->verbosity >= 4) printf("No merge base found; doing history-less merge\n"); } else if (!bases->next) { - base_sha1 = bases->item->object.oid.hash; - base_tree_sha1 = bases->item->tree->object.oid.hash; + base_oid = &bases->item->object.oid; + base_tree_oid = &bases->item->tree->object.oid; if (o->verbosity >= 4) printf("One merge base found (%.7s)\n", - sha1_to_hex(base_sha1)); + oid_to_hex(base_oid)); } else { /* TODO: How to handle multiple merge-bases? */ - base_sha1 = bases->item->object.oid.hash; - base_tree_sha1 = bases->item->tree->object.oid.hash; + base_oid = &bases->item->object.oid; + base_tree_oid = &bases->item->tree->object.oid; if (o->verbosity >= 3) printf("Multiple merge bases found. Using the first " - "(%.7s)\n", sha1_to_hex(base_sha1)); + "(%.7s)\n", oid_to_hex(base_oid)); } if (o->verbosity >= 4) printf("Merging remote commit %.7s into local commit %.7s with " "merge-base %.7s\n", oid_to_hex(&remote->object.oid), oid_to_hex(&local->object.oid), - sha1_to_hex(base_sha1)); + oid_to_hex(base_oid)); - if (!hashcmp(remote->object.oid.hash, base_sha1)) { + if (!oidcmp(&remote->object.oid, base_oid)) { /* Already merged; result == local commit */ if (o->verbosity >= 2) printf("Already up-to-date!\n"); - hashcpy(result_sha1, local->object.oid.hash); + oidcpy(result_oid, &local->object.oid); goto found_result; } - if (!hashcmp(local->object.oid.hash, base_sha1)) { + if (!oidcmp(&local->object.oid, base_oid)) { /* Fast-forward; result == remote commit */ if (o->verbosity >= 2) printf("Fast-forward\n"); - hashcpy(result_sha1, remote->object.oid.hash); + oidcpy(result_oid, &remote->object.oid); goto found_result; } - result = merge_from_diffs(o, base_tree_sha1, local->tree->object.oid.hash, - remote->tree->object.oid.hash, local_tree); + result = merge_from_diffs(o, base_tree_oid, &local->tree->object.oid, + &remote->tree->object.oid, local_tree); if (result != 0) { /* non-trivial merge (with or without conflicts) */ /* Commit (partial) result */ @@ -646,28 +647,28 @@ int notes_merge(struct notes_merge_options *o, commit_list_insert(local, &parents); create_notes_commit(local_tree, parents, o->commit_msg.buf, o->commit_msg.len, - result_sha1); + result_oid->hash); } found_result: free_commit_list(bases); strbuf_release(&(o->commit_msg)); - trace_printf("notes_merge(): result = %i, result_sha1 = %.7s\n", - result, sha1_to_hex(result_sha1)); + trace_printf("notes_merge(): result = %i, result_oid = %.7s\n", + result, oid_to_hex(result_oid)); return result; } int notes_merge_commit(struct notes_merge_options *o, struct notes_tree *partial_tree, struct commit *partial_commit, - unsigned char *result_sha1) + struct object_id *result_oid) { /* * Iterate through files in .git/NOTES_MERGE_WORKTREE and add all * found notes to 'partial_tree'. Write the updated notes tree to * the DB, and commit the resulting tree object while reusing the * commit message and parents from 'partial_commit'. - * Finally store the new commit object SHA1 into 'result_sha1'. + * Finally store the new commit object OID into 'result_oid'. */ DIR *dir; struct dirent *e; @@ -693,12 +694,12 @@ int notes_merge_commit(struct notes_merge_options *o, baselen = path.len; while ((e = readdir(dir)) != NULL) { struct stat st; - unsigned char obj_sha1[20], blob_sha1[20]; + struct object_id obj_oid, blob_oid; if (is_dot_or_dotdot(e->d_name)) continue; - if (strlen(e->d_name) != 40 || get_sha1_hex(e->d_name, obj_sha1)) { + if (get_oid_hex(e->d_name, &obj_oid)) { if (o->verbosity >= 3) printf("Skipping non-SHA1 entry '%s%s'\n", path.buf, e->d_name); @@ -709,23 +710,23 @@ int notes_merge_commit(struct notes_merge_options *o, /* write file as blob, and add to partial_tree */ if (stat(path.buf, &st)) die_errno("Failed to stat '%s'", path.buf); - if (index_path(blob_sha1, path.buf, &st, HASH_WRITE_OBJECT)) + if (index_path(blob_oid.hash, path.buf, &st, HASH_WRITE_OBJECT)) die("Failed to write blob object from '%s'", path.buf); - if (add_note(partial_tree, obj_sha1, blob_sha1, NULL)) + if (add_note(partial_tree, &obj_oid, &blob_oid, NULL)) die("Failed to add resolved note '%s' to notes tree", path.buf); if (o->verbosity >= 4) printf("Added resolved note for object %s: %s\n", - sha1_to_hex(obj_sha1), sha1_to_hex(blob_sha1)); + oid_to_hex(&obj_oid), oid_to_hex(&blob_oid)); strbuf_setlen(&path, baselen); } create_notes_commit(partial_tree, partial_commit->parents, - msg, strlen(msg), result_sha1); + msg, strlen(msg), result_oid->hash); unuse_commit_buffer(partial_commit, buffer); if (o->verbosity >= 4) printf("Finalized notes merge commit: %s\n", - sha1_to_hex(result_sha1)); + oid_to_hex(result_oid)); strbuf_release(&path); closedir(dir); return 0; diff --git a/notes-merge.h b/notes-merge.h index 0d890563b5..f815f23451 100644 --- a/notes-merge.h +++ b/notes-merge.h @@ -32,16 +32,16 @@ void init_notes_merge_options(struct notes_merge_options *o); * outcomes: * * 1. The merge trivially results in an existing commit (e.g. fast-forward or - * already-up-to-date). 'local_tree' is untouched, the SHA1 of the result - * is written into 'result_sha1' and 0 is returned. + * already-up-to-date). 'local_tree' is untouched, the OID of the result + * is written into 'result_oid' and 0 is returned. * 2. The merge successfully completes, producing a merge commit. local_tree - * contains the updated notes tree, the SHA1 of the resulting commit is - * written into 'result_sha1', and 1 is returned. + * contains the updated notes tree, the OID of the resulting commit is + * written into 'result_oid', and 1 is returned. * 3. The merge results in conflicts. This is similar to #2 in that the * partial merge result (i.e. merge result minus the unmerged entries) - * are stored in 'local_tree', and the SHA1 or the resulting commit + * are stored in 'local_tree', and the OID or the resulting commit * (to be amended when the conflicts have been resolved) is written into - * 'result_sha1'. The unmerged entries are written into the + * 'result_oid'. The unmerged entries are written into the * .git/NOTES_MERGE_WORKTREE directory with conflict markers. * -1 is returned. * @@ -52,7 +52,7 @@ void init_notes_merge_options(struct notes_merge_options *o); */ int notes_merge(struct notes_merge_options *o, struct notes_tree *local_tree, - unsigned char *result_sha1); + struct object_id *result_oid); /* * Finalize conflict resolution from an earlier notes_merge() @@ -62,13 +62,13 @@ int notes_merge(struct notes_merge_options *o, * call to notes_merge(). * * This function will add the (now resolved) notes in .git/NOTES_MERGE_WORKTREE - * to 'partial_tree', and create a final notes merge commit, the SHA1 of which - * will be stored in 'result_sha1'. + * to 'partial_tree', and create a final notes merge commit, the OID of which + * will be stored in 'result_oid'. */ int notes_merge_commit(struct notes_merge_options *o, struct notes_tree *partial_tree, struct commit *partial_commit, - unsigned char *result_sha1); + struct object_id *result_oid); /* * Abort conflict resolution from an earlier notes_merge() diff --git a/notes-utils.c b/notes-utils.c index 031503d7b2..9ebf841956 100644 --- a/notes-utils.c +++ b/notes-utils.c @@ -158,7 +158,7 @@ struct notes_rewrite_cfg *init_copy_notes_for_rewrite(const char *cmd) } int copy_note_for_rewrite(struct notes_rewrite_cfg *c, - const unsigned char *from_obj, const unsigned char *to_obj) + const struct object_id *from_obj, const struct object_id *to_obj) { int ret = 0; int i; diff --git a/notes-utils.h b/notes-utils.h index fa538e1d95..1190578398 100644 --- a/notes-utils.h +++ b/notes-utils.h @@ -40,7 +40,7 @@ struct notes_rewrite_cfg { int parse_notes_merge_strategy(const char *v, enum notes_merge_strategy *s); struct notes_rewrite_cfg *init_copy_notes_for_rewrite(const char *cmd); int copy_note_for_rewrite(struct notes_rewrite_cfg *c, - const unsigned char *from_obj, const unsigned char *to_obj); + const struct object_id *from_obj, const struct object_id *to_obj); void finish_copy_notes_for_rewrite(struct notes_rewrite_cfg *c, const char *msg); #endif @@ -35,8 +35,8 @@ struct int_node { * subtree. */ struct leaf_node { - unsigned char key_sha1[20]; - unsigned char val_sha1[20]; + struct object_id key_oid; + struct object_id val_oid; }; /* @@ -51,7 +51,7 @@ struct non_note { struct non_note *next; /* grounded (last->next == NULL) */ char *path; unsigned int mode; - unsigned char sha1[20]; + struct object_id oid; }; #define PTR_TYPE_NULL 0 @@ -65,8 +65,10 @@ struct non_note { #define GET_NIBBLE(n, sha1) (((sha1[(n) >> 1]) >> ((~(n) & 0x01) << 2)) & 0x0f) +#define KEY_INDEX (GIT_SHA1_RAWSZ - 1) +#define FANOUT_PATH_SEPARATORS ((GIT_SHA1_HEXSZ / 2) - 1) #define SUBTREE_SHA1_PREFIXCMP(key_sha1, subtree_sha1) \ - (memcmp(key_sha1, subtree_sha1, subtree_sha1[19])) + (memcmp(key_sha1, subtree_sha1, subtree_sha1[KEY_INDEX])) struct notes_tree default_notes_tree; @@ -100,7 +102,7 @@ static void **note_tree_search(struct notes_tree *t, struct int_node **tree, if (GET_PTR_TYPE(p) == PTR_TYPE_SUBTREE) { l = (struct leaf_node *) CLR_PTR_TYPE(p); - if (!SUBTREE_SHA1_PREFIXCMP(key_sha1, l->key_sha1)) { + if (!SUBTREE_SHA1_PREFIXCMP(key_sha1, l->key_oid.hash)) { /* unpack tree and resume search */ (*tree)->a[0] = NULL; load_subtree(t, l, *tree, *n); @@ -118,7 +120,7 @@ static void **note_tree_search(struct notes_tree *t, struct int_node **tree, return note_tree_search(t, tree, n, key_sha1); case PTR_TYPE_SUBTREE: l = (struct leaf_node *) CLR_PTR_TYPE(p); - if (!SUBTREE_SHA1_PREFIXCMP(key_sha1, l->key_sha1)) { + if (!SUBTREE_SHA1_PREFIXCMP(key_sha1, l->key_oid.hash)) { /* unpack tree and resume search */ (*tree)->a[i] = NULL; load_subtree(t, l, *tree, *n); @@ -143,7 +145,7 @@ static struct leaf_node *note_tree_find(struct notes_tree *t, void **p = note_tree_search(t, &tree, &n, key_sha1); if (GET_PTR_TYPE(*p) == PTR_TYPE_NOTE) { struct leaf_node *l = (struct leaf_node *) CLR_PTR_TYPE(*p); - if (!hashcmp(key_sha1, l->key_sha1)) + if (!hashcmp(key_sha1, l->key_oid.hash)) return l; } return NULL; @@ -194,19 +196,19 @@ static void note_tree_remove(struct notes_tree *t, struct leaf_node *entry) { struct leaf_node *l; - struct int_node *parent_stack[20]; + struct int_node *parent_stack[GIT_SHA1_RAWSZ]; unsigned char i, j; - void **p = note_tree_search(t, &tree, &n, entry->key_sha1); + void **p = note_tree_search(t, &tree, &n, entry->key_oid.hash); assert(GET_PTR_TYPE(entry) == 0); /* no type bits set */ if (GET_PTR_TYPE(*p) != PTR_TYPE_NOTE) return; /* type mismatch, nothing to remove */ l = (struct leaf_node *) CLR_PTR_TYPE(*p); - if (hashcmp(l->key_sha1, entry->key_sha1)) + if (oidcmp(&l->key_oid, &entry->key_oid)) return; /* key mismatch, nothing to remove */ /* we have found a matching entry */ - hashcpy(entry->val_sha1, l->val_sha1); + oidcpy(&entry->val_oid, &l->val_oid); free(l); *p = SET_PTR_TYPE(NULL, PTR_TYPE_NULL); @@ -216,14 +218,14 @@ static void note_tree_remove(struct notes_tree *t, /* first, build stack of ancestors between root and current node */ parent_stack[0] = t->root; for (i = 0; i < n; i++) { - j = GET_NIBBLE(i, entry->key_sha1); + j = GET_NIBBLE(i, entry->key_oid.hash); parent_stack[i + 1] = CLR_PTR_TYPE(parent_stack[i]->a[j]); } assert(i == n && parent_stack[i] == tree); /* next, unwind stack until note_tree_consolidate() is done */ while (i > 0 && !note_tree_consolidate(parent_stack[i], parent_stack[i - 1], - GET_NIBBLE(i - 1, entry->key_sha1))) + GET_NIBBLE(i - 1, entry->key_oid.hash))) i--; } @@ -246,7 +248,7 @@ static int note_tree_insert(struct notes_tree *t, struct int_node *tree, { struct int_node *new_node; struct leaf_node *l; - void **p = note_tree_search(t, &tree, &n, entry->key_sha1); + void **p = note_tree_search(t, &tree, &n, entry->key_oid.hash); int ret = 0; assert(GET_PTR_TYPE(entry) == 0); /* no type bits set */ @@ -254,7 +256,7 @@ static int note_tree_insert(struct notes_tree *t, struct int_node *tree, switch (GET_PTR_TYPE(*p)) { case PTR_TYPE_NULL: assert(!*p); - if (is_null_sha1(entry->val_sha1)) + if (is_null_oid(&entry->val_oid)) free(entry); else *p = SET_PTR_TYPE(entry, type); @@ -262,22 +264,22 @@ static int note_tree_insert(struct notes_tree *t, struct int_node *tree, case PTR_TYPE_NOTE: switch (type) { case PTR_TYPE_NOTE: - if (!hashcmp(l->key_sha1, entry->key_sha1)) { + if (!oidcmp(&l->key_oid, &entry->key_oid)) { /* skip concatenation if l == entry */ - if (!hashcmp(l->val_sha1, entry->val_sha1)) + if (!oidcmp(&l->val_oid, &entry->val_oid)) return 0; - ret = combine_notes(l->val_sha1, - entry->val_sha1); - if (!ret && is_null_sha1(l->val_sha1)) + ret = combine_notes(l->val_oid.hash, + entry->val_oid.hash); + if (!ret && is_null_oid(&l->val_oid)) note_tree_remove(t, tree, n, entry); free(entry); return ret; } break; case PTR_TYPE_SUBTREE: - if (!SUBTREE_SHA1_PREFIXCMP(l->key_sha1, - entry->key_sha1)) { + if (!SUBTREE_SHA1_PREFIXCMP(l->key_oid.hash, + entry->key_oid.hash)) { /* unpack 'entry' */ load_subtree(t, entry, tree, n); free(entry); @@ -287,7 +289,7 @@ static int note_tree_insert(struct notes_tree *t, struct int_node *tree, } break; case PTR_TYPE_SUBTREE: - if (!SUBTREE_SHA1_PREFIXCMP(entry->key_sha1, l->key_sha1)) { + if (!SUBTREE_SHA1_PREFIXCMP(entry->key_oid.hash, l->key_oid.hash)) { /* unpack 'l' and restart insert */ *p = NULL; load_subtree(t, l, tree, n); @@ -301,7 +303,7 @@ static int note_tree_insert(struct notes_tree *t, struct int_node *tree, /* non-matching leaf_node */ assert(GET_PTR_TYPE(*p) == PTR_TYPE_NOTE || GET_PTR_TYPE(*p) == PTR_TYPE_SUBTREE); - if (is_null_sha1(entry->val_sha1)) { /* skip insertion of empty note */ + if (is_null_oid(&entry->val_oid)) { /* skip insertion of empty note */ free(entry); return 0; } @@ -341,21 +343,21 @@ static void note_tree_free(struct int_node *tree) * Otherwise, returns number of bytes written to sha1 (i.e. hex_len / 2). * Pads sha1 with NULs up to sha1_len (not included in returned length). */ -static int get_sha1_hex_segment(const char *hex, unsigned int hex_len, - unsigned char *sha1, unsigned int sha1_len) +static int get_oid_hex_segment(const char *hex, unsigned int hex_len, + unsigned char *oid, unsigned int oid_len) { unsigned int i, len = hex_len >> 1; - if (hex_len % 2 != 0 || len > sha1_len) + if (hex_len % 2 != 0 || len > oid_len) return -1; for (i = 0; i < len; i++) { unsigned int val = (hexval(hex[0]) << 4) | hexval(hex[1]); if (val & ~0xff) return -1; - *sha1++ = val; + *oid++ = val; hex += 2; } - for (; i < sha1_len; i++) - *sha1++ = 0; + for (; i < oid_len; i++) + *oid++ = 0; return len; } @@ -373,7 +375,7 @@ static void add_non_note(struct notes_tree *t, char *path, n->next = NULL; n->path = path; n->mode = mode; - hashcpy(n->sha1, sha1); + hashcpy(n->oid.hash, sha1); t->prev_non_note = n; if (!t->first_non_note) { @@ -399,7 +401,7 @@ static void add_non_note(struct notes_tree *t, char *path, if (non_note_cmp(p, n) == 0) { /* n ~= p; overwrite p with n */ assert(strcmp(p->path, n->path) == 0); p->mode = n->mode; - hashcpy(p->sha1, n->sha1); + oidcpy(&p->oid, &n->oid); free(n); t->prev_non_note = p; return; @@ -413,7 +415,7 @@ static void add_non_note(struct notes_tree *t, char *path, static void load_subtree(struct notes_tree *t, struct leaf_node *subtree, struct int_node *node, unsigned int n) { - unsigned char object_sha1[20]; + struct object_id object_oid; unsigned int prefix_len; void *buf; struct tree_desc desc; @@ -422,18 +424,18 @@ static void load_subtree(struct notes_tree *t, struct leaf_node *subtree, unsigned char type; struct leaf_node *l; - buf = fill_tree_descriptor(&desc, subtree->val_sha1); + buf = fill_tree_descriptor(&desc, subtree->val_oid.hash); if (!buf) die("Could not read %s for notes-index", - sha1_to_hex(subtree->val_sha1)); + oid_to_hex(&subtree->val_oid)); - prefix_len = subtree->key_sha1[19]; + prefix_len = subtree->key_oid.hash[KEY_INDEX]; assert(prefix_len * 2 >= n); - memcpy(object_sha1, subtree->key_sha1, prefix_len); + memcpy(object_oid.hash, subtree->key_oid.hash, prefix_len); while (tree_entry(&desc, &entry)) { path_len = strlen(entry.path); - len = get_sha1_hex_segment(entry.path, path_len, - object_sha1 + prefix_len, 20 - prefix_len); + len = get_oid_hex_segment(entry.path, path_len, + object_oid.hash + prefix_len, GIT_SHA1_RAWSZ - prefix_len); if (len < 0) goto handle_non_note; /* entry.path is not a SHA1 */ len += prefix_len; @@ -443,16 +445,16 @@ static void load_subtree(struct notes_tree *t, struct leaf_node *subtree, * If object SHA1 is incomplete (len < 20), and current * component consists of 2 hex chars, assume note subtree */ - if (len <= 20) { + if (len <= GIT_SHA1_RAWSZ) { type = PTR_TYPE_NOTE; l = (struct leaf_node *) xcalloc(1, sizeof(struct leaf_node)); - hashcpy(l->key_sha1, object_sha1); - hashcpy(l->val_sha1, entry.oid->hash); - if (len < 20) { + oidcpy(&l->key_oid, &object_oid); + oidcpy(&l->val_oid, entry.oid); + if (len < GIT_SHA1_RAWSZ) { if (!S_ISDIR(entry.mode) || path_len != 2) goto handle_non_note; /* not subtree */ - l->key_sha1[19] = (unsigned char) len; + l->key_oid.hash[KEY_INDEX] = (unsigned char) len; type = PTR_TYPE_SUBTREE; } if (note_tree_insert(t, node, n, l, type, @@ -460,7 +462,7 @@ static void load_subtree(struct notes_tree *t, struct leaf_node *subtree, die("Failed to load %s %s into notes tree " "from %s", type == PTR_TYPE_NOTE ? "note" : "subtree", - sha1_to_hex(l->key_sha1), t->ref); + oid_to_hex(&l->key_oid), t->ref); } continue; @@ -486,7 +488,7 @@ handle_non_note: */ { struct strbuf non_note_path = STRBUF_INIT; - const char *q = sha1_to_hex(subtree->key_sha1); + const char *q = oid_to_hex(&subtree->key_oid); int i; for (i = 0; i < prefix_len; i++) { strbuf_addch(&non_note_path, *q++); @@ -542,14 +544,14 @@ static unsigned char determine_fanout(struct int_node *tree, unsigned char n, } /* hex SHA1 + 19 * '/' + NUL */ -#define FANOUT_PATH_MAX 40 + 19 + 1 +#define FANOUT_PATH_MAX GIT_SHA1_HEXSZ + FANOUT_PATH_SEPARATORS + 1 static void construct_path_with_fanout(const unsigned char *sha1, unsigned char fanout, char *path) { unsigned int i = 0, j = 0; const char *hex_sha1 = sha1_to_hex(sha1); - assert(fanout < 20); + assert(fanout < GIT_SHA1_RAWSZ); while (fanout) { path[i++] = hex_sha1[j++]; path[i++] = hex_sha1[j++]; @@ -599,15 +601,17 @@ redo: flags & FOR_EACH_NOTE_YIELD_SUBTREES) { /* invoke callback with subtree */ unsigned int path_len = - l->key_sha1[19] * 2 + fanout; + l->key_oid.hash[KEY_INDEX] * 2 + fanout; assert(path_len < FANOUT_PATH_MAX - 1); - construct_path_with_fanout(l->key_sha1, fanout, + construct_path_with_fanout(l->key_oid.hash, + fanout, path); /* Create trailing slash, if needed */ if (path[path_len - 1] != '/') path[path_len++] = '/'; path[path_len] = '\0'; - ret = fn(l->key_sha1, l->val_sha1, path, + ret = fn(&l->key_oid, &l->val_oid, + path, cb_data); } if (n > fanout * 2 || @@ -621,8 +625,10 @@ redo: break; case PTR_TYPE_NOTE: l = (struct leaf_node *) CLR_PTR_TYPE(p); - construct_path_with_fanout(l->key_sha1, fanout, path); - ret = fn(l->key_sha1, l->val_sha1, path, cb_data); + construct_path_with_fanout(l->key_oid.hash, fanout, + path); + ret = fn(&l->key_oid, &l->val_oid, path, + cb_data); break; } if (ret) @@ -650,7 +656,7 @@ static void write_tree_entry(struct strbuf *buf, unsigned int mode, unsigned char *sha1) { strbuf_addf(buf, "%o %.*s%c", mode, path_len, path, '\0'); - strbuf_add(buf, sha1, 20); + strbuf_add(buf, sha1, GIT_SHA1_RAWSZ); } static void tree_write_stack_init_subtree(struct tree_write_stack *tws, @@ -662,7 +668,7 @@ static void tree_write_stack_init_subtree(struct tree_write_stack *tws, n = (struct tree_write_stack *) xmalloc(sizeof(struct tree_write_stack)); n->next = NULL; - strbuf_init(&n->buf, 256 * (32 + 40)); /* assume 256 entries per tree */ + strbuf_init(&n->buf, 256 * (32 + GIT_SHA1_HEXSZ)); /* assume 256 entries per tree */ n->path[0] = n->path[1] = '\0'; tws->next = n; tws->path[0] = path[0]; @@ -673,18 +679,18 @@ static int tree_write_stack_finish_subtree(struct tree_write_stack *tws) { int ret; struct tree_write_stack *n = tws->next; - unsigned char s[20]; + struct object_id s; if (n) { ret = tree_write_stack_finish_subtree(n); if (ret) return ret; - ret = write_sha1_file(n->buf.buf, n->buf.len, tree_type, s); + ret = write_sha1_file(n->buf.buf, n->buf.len, tree_type, s.hash); if (ret) return ret; strbuf_release(&n->buf); free(n); tws->next = NULL; - write_tree_entry(&tws->buf, 040000, tws->path, 2, s); + write_tree_entry(&tws->buf, 040000, tws->path, 2, s.hash); tws->path[0] = tws->path[1] = '\0'; } return 0; @@ -692,7 +698,7 @@ static int tree_write_stack_finish_subtree(struct tree_write_stack *tws) static int write_each_note_helper(struct tree_write_stack *tws, const char *path, unsigned int mode, - const unsigned char *sha1) + const struct object_id *oid) { size_t path_len = strlen(path); unsigned int n = 0; @@ -722,7 +728,7 @@ static int write_each_note_helper(struct tree_write_stack *tws, /* Finally add given entry to the current tree object */ write_tree_entry(&tws->buf, mode, path + 3 * n, path_len - (3 * n), - sha1); + oid->hash); return 0; } @@ -742,7 +748,7 @@ static int write_each_non_note_until(const char *note_path, ; /* do nothing, prefer note to non-note */ else { ret = write_each_note_helper(d->root, n->path, n->mode, - n->sha1); + &n->oid); if (ret) return ret; } @@ -752,8 +758,8 @@ static int write_each_non_note_until(const char *note_path, return 0; } -static int write_each_note(const unsigned char *object_sha1, - const unsigned char *note_sha1, char *note_path, +static int write_each_note(const struct object_id *object_oid, + const struct object_id *note_oid, char *note_path, void *cb_data) { struct write_each_note_data *d = @@ -767,11 +773,11 @@ static int write_each_note(const unsigned char *object_sha1, note_path[note_path_len] = '\0'; mode = 040000; } - assert(note_path_len <= 40 + 19); + assert(note_path_len <= GIT_SHA1_HEXSZ + FANOUT_PATH_SEPARATORS); /* Weave non-note entries into note entries */ return write_each_non_note_until(note_path, d) || - write_each_note_helper(d->root, note_path, mode, note_sha1); + write_each_note_helper(d->root, note_path, mode, note_oid); } struct note_delete_list { @@ -779,20 +785,20 @@ struct note_delete_list { const unsigned char *sha1; }; -static int prune_notes_helper(const unsigned char *object_sha1, - const unsigned char *note_sha1, char *note_path, +static int prune_notes_helper(const struct object_id *object_oid, + const struct object_id *note_oid, char *note_path, void *cb_data) { struct note_delete_list **l = (struct note_delete_list **) cb_data; struct note_delete_list *n; - if (has_sha1_file(object_sha1)) + if (has_object_file(object_oid)) return 0; /* nothing to do for this note */ /* failed to find object => prune this note */ n = (struct note_delete_list *) xmalloc(sizeof(*n)); n->next = *l; - n->sha1 = object_sha1; + n->sha1 = object_oid->hash; *l = n; return 0; } @@ -942,8 +948,8 @@ void string_list_add_refs_by_glob(struct string_list *list, const char *glob) if (has_glob_specials(glob)) { for_each_glob_ref(string_list_add_one_ref, glob, list); } else { - unsigned char sha1[20]; - if (get_sha1(glob, sha1)) + struct object_id oid; + if (get_oid(glob, &oid)) warning("notes ref %s is invalid", glob); if (!unsorted_string_list_has_string(list, glob)) string_list_append(list, glob); @@ -1027,8 +1033,8 @@ void init_notes(struct notes_tree *t, const char *notes_ref, die("Failed to read notes tree referenced by %s (%s)", notes_ref, oid_to_hex(&object_oid)); - hashclr(root_tree.key_sha1); - hashcpy(root_tree.val_sha1, oid.hash); + oidclr(&root_tree.key_oid); + oidcpy(&root_tree.val_oid, &oid); load_subtree(t, &root_tree, t->root, 0); } @@ -1080,8 +1086,8 @@ void init_display_notes(struct display_notes_opt *opt) string_list_clear(&display_notes_refs, 0); } -int add_note(struct notes_tree *t, const unsigned char *object_sha1, - const unsigned char *note_sha1, combine_notes_fn combine_notes) +int add_note(struct notes_tree *t, const struct object_id *object_oid, + const struct object_id *note_oid, combine_notes_fn combine_notes) { struct leaf_node *l; @@ -1092,8 +1098,8 @@ int add_note(struct notes_tree *t, const unsigned char *object_sha1, if (!combine_notes) combine_notes = t->combine_notes; l = (struct leaf_node *) xmalloc(sizeof(struct leaf_node)); - hashcpy(l->key_sha1, object_sha1); - hashcpy(l->val_sha1, note_sha1); + oidcpy(&l->key_oid, object_oid); + oidcpy(&l->val_oid, note_oid); return note_tree_insert(t, t->root, 0, l, PTR_TYPE_NOTE, combine_notes); } @@ -1104,25 +1110,25 @@ int remove_note(struct notes_tree *t, const unsigned char *object_sha1) if (!t) t = &default_notes_tree; assert(t->initialized); - hashcpy(l.key_sha1, object_sha1); - hashclr(l.val_sha1); + hashcpy(l.key_oid.hash, object_sha1); + oidclr(&l.val_oid); note_tree_remove(t, t->root, 0, &l); - if (is_null_sha1(l.val_sha1)) /* no note was removed */ + if (is_null_oid(&l.val_oid)) /* no note was removed */ return 1; t->dirty = 1; return 0; } -const unsigned char *get_note(struct notes_tree *t, - const unsigned char *object_sha1) +const struct object_id *get_note(struct notes_tree *t, + const struct object_id *oid) { struct leaf_node *found; if (!t) t = &default_notes_tree; assert(t->initialized); - found = note_tree_find(t, t->root, 0, object_sha1); - return found ? found->val_sha1 : NULL; + found = note_tree_find(t, t->root, 0, oid->hash); + return found ? &found->val_oid : NULL; } int for_each_note(struct notes_tree *t, int flags, each_note_fn fn, @@ -1146,7 +1152,7 @@ int write_notes_tree(struct notes_tree *t, unsigned char *result) /* Prepare for traversal of current notes tree */ root.next = NULL; /* last forward entry in list is grounded */ - strbuf_init(&root.buf, 256 * (32 + 40)); /* assume 256 entries */ + strbuf_init(&root.buf, 256 * (32 + GIT_SHA1_HEXSZ)); /* assume 256 entries */ root.path[0] = root.path[1] = '\0'; cb_data.root = &root; cb_data.next_non_note = t->first_non_note; @@ -1209,11 +1215,11 @@ void free_notes(struct notes_tree *t) * (raw != 0) gives the %N userformat; otherwise, the note message is given * for human consumption. */ -static void format_note(struct notes_tree *t, const unsigned char *object_sha1, +static void format_note(struct notes_tree *t, const struct object_id *object_oid, struct strbuf *sb, const char *output_encoding, int raw) { static const char utf8[] = "utf-8"; - const unsigned char *sha1; + const struct object_id *oid; char *msg, *msg_p; unsigned long linelen, msglen; enum object_type type; @@ -1223,11 +1229,11 @@ static void format_note(struct notes_tree *t, const unsigned char *object_sha1, if (!t->initialized) init_notes(t, NULL, NULL, 0); - sha1 = get_note(t, object_sha1); - if (!sha1) + oid = get_note(t, object_oid); + if (!oid) return; - if (!(msg = read_sha1_file(sha1, &type, &msglen)) || type != OBJ_BLOB) { + if (!(msg = read_sha1_file(oid->hash, &type, &msglen)) || type != OBJ_BLOB) { free(msg); return; } @@ -1271,22 +1277,22 @@ static void format_note(struct notes_tree *t, const unsigned char *object_sha1, free(msg); } -void format_display_notes(const unsigned char *object_sha1, +void format_display_notes(const struct object_id *object_oid, struct strbuf *sb, const char *output_encoding, int raw) { int i; assert(display_notes_trees); for (i = 0; display_notes_trees[i]; i++) - format_note(display_notes_trees[i], object_sha1, sb, + format_note(display_notes_trees[i], object_oid, sb, output_encoding, raw); } int copy_note(struct notes_tree *t, - const unsigned char *from_obj, const unsigned char *to_obj, + const struct object_id *from_obj, const struct object_id *to_obj, int force, combine_notes_fn combine_notes) { - const unsigned char *note = get_note(t, from_obj); - const unsigned char *existing_note = get_note(t, to_obj); + const struct object_id *note = get_note(t, from_obj); + const struct object_id *existing_note = get_note(t, to_obj); if (!force && existing_note) return 1; @@ -1294,7 +1300,7 @@ int copy_note(struct notes_tree *t, if (note) return add_note(t, to_obj, note, combine_notes); else if (existing_note) - return add_note(t, to_obj, null_sha1, combine_notes); + return add_note(t, to_obj, &null_oid, combine_notes); return 0; } @@ -1311,9 +1317,9 @@ void expand_notes_ref(struct strbuf *sb) void expand_loose_notes_ref(struct strbuf *sb) { - unsigned char object[20]; + struct object_id object; - if (get_sha1(sb->buf, object)) { + if (get_oid(sb->buf, &object)) { /* fallback to expand_notes_ref */ expand_notes_ref(sb); } @@ -121,8 +121,8 @@ void init_notes(struct notes_tree *t, const char *notes_ref, * are not persistent until a subsequent call to write_notes_tree() returns * zero. */ -int add_note(struct notes_tree *t, const unsigned char *object_sha1, - const unsigned char *note_sha1, combine_notes_fn combine_notes); +int add_note(struct notes_tree *t, const struct object_id *object_oid, + const struct object_id *note_oid, combine_notes_fn combine_notes); /* * Remove the given note object from the given notes_tree structure @@ -140,8 +140,8 @@ int remove_note(struct notes_tree *t, const unsigned char *object_sha1); * * Return NULL if the given object has no notes. */ -const unsigned char *get_note(struct notes_tree *t, - const unsigned char *object_sha1); +const struct object_id *get_note(struct notes_tree *t, + const struct object_id *object_oid); /* * Copy a note from one object to another in the given notes_tree. @@ -156,7 +156,7 @@ const unsigned char *get_note(struct notes_tree *t, * zero. */ int copy_note(struct notes_tree *t, - const unsigned char *from_obj, const unsigned char *to_obj, + const struct object_id *from_obj, const struct object_id *to_obj, int force, combine_notes_fn combine_notes); /* @@ -202,8 +202,8 @@ int copy_note(struct notes_tree *t, * - copy_note() * - free_notes() */ -typedef int each_note_fn(const unsigned char *object_sha1, - const unsigned char *note_sha1, char *note_path, +typedef int each_note_fn(const struct object_id *object_oid, + const struct object_id *note_oid, char *note_path, void *cb_data); int for_each_note(struct notes_tree *t, int flags, each_note_fn fn, void *cb_data); @@ -277,7 +277,7 @@ void init_display_notes(struct display_notes_opt *opt); * * You *must* call init_display_notes() before using this function. */ -void format_display_notes(const unsigned char *object_sha1, +void format_display_notes(const struct object_id *object_oid, struct strbuf *sb, const char *output_encoding, int raw); /* diff --git a/patch-ids.c b/patch-ids.c index 92eba7a059..9c0ab9e67a 100644 --- a/patch-ids.c +++ b/patch-ids.c @@ -11,18 +11,18 @@ static int patch_id_defined(struct commit *commit) } int commit_patch_id(struct commit *commit, struct diff_options *options, - unsigned char *sha1, int diff_header_only) + struct object_id *oid, int diff_header_only) { if (!patch_id_defined(commit)) return -1; if (commit->parents) - diff_tree_sha1(commit->parents->item->object.oid.hash, - commit->object.oid.hash, "", options); + diff_tree_oid(&commit->parents->item->object.oid, + &commit->object.oid, "", options); else - diff_root_tree_sha1(commit->object.oid.hash, "", options); + diff_root_tree_oid(&commit->object.oid, "", options); diffcore_std(options); - return diff_flush_patch_id(options, sha1, diff_header_only); + return diff_flush_patch_id(options, oid, diff_header_only); } /* @@ -39,15 +39,15 @@ static int patch_id_cmp(struct patch_id *a, struct patch_id *b, struct diff_options *opt) { - if (is_null_sha1(a->patch_id) && - commit_patch_id(a->commit, opt, a->patch_id, 0)) + if (is_null_oid(&a->patch_id) && + commit_patch_id(a->commit, opt, &a->patch_id, 0)) return error("Could not get patch ID for %s", oid_to_hex(&a->commit->object.oid)); - if (is_null_sha1(b->patch_id) && - commit_patch_id(b->commit, opt, b->patch_id, 0)) + if (is_null_oid(&b->patch_id) && + commit_patch_id(b->commit, opt, &b->patch_id, 0)) return error("Could not get patch ID for %s", oid_to_hex(&b->commit->object.oid)); - return hashcmp(a->patch_id, b->patch_id); + return oidcmp(&a->patch_id, &b->patch_id); } int init_patch_ids(struct patch_ids *ids) @@ -71,13 +71,13 @@ static int init_patch_id_entry(struct patch_id *patch, struct commit *commit, struct patch_ids *ids) { - unsigned char header_only_patch_id[GIT_MAX_RAWSZ]; + struct object_id header_only_patch_id; patch->commit = commit; - if (commit_patch_id(commit, &ids->diffopts, header_only_patch_id, 1)) + if (commit_patch_id(commit, &ids->diffopts, &header_only_patch_id, 1)) return -1; - hashmap_entry_init(patch, sha1hash(header_only_patch_id)); + hashmap_entry_init(patch, sha1hash(header_only_patch_id.hash)); return 0; } diff --git a/patch-ids.h b/patch-ids.h index b9e5751f8e..bec0f727a7 100644 --- a/patch-ids.h +++ b/patch-ids.h @@ -3,7 +3,7 @@ struct patch_id { struct hashmap_entry ent; - unsigned char patch_id[GIT_MAX_RAWSZ]; + struct object_id patch_id; struct commit *commit; }; @@ -13,7 +13,7 @@ struct patch_ids { }; int commit_patch_id(struct commit *commit, struct diff_options *options, - unsigned char *sha1, int); + struct object_id *oid, int); int init_patch_ids(struct patch_ids *); int free_patch_ids(struct patch_ids *); struct patch_id *add_commit_patch_id(struct commit *, struct patch_ids *); diff --git a/remote-testsvn.c b/remote-testsvn.c index 50404ef343..e034ea00d4 100644 --- a/remote-testsvn.c +++ b/remote-testsvn.c @@ -51,17 +51,17 @@ static void terminate_batch(void) } /* NOTE: 'ref' refers to a git reference, while 'rev' refers to a svn revision. */ -static char *read_ref_note(const unsigned char sha1[20]) +static char *read_ref_note(const struct object_id *oid) { - const unsigned char *note_sha1; + const struct object_id *note_oid; char *msg = NULL; unsigned long msglen; enum object_type type; init_notes(NULL, notes_ref, NULL, 0); - if (!(note_sha1 = get_note(NULL, sha1))) + if (!(note_oid = get_note(NULL, oid))) return NULL; /* note tree not found */ - if (!(msg = read_sha1_file(note_sha1, &type, &msglen))) + if (!(msg = read_sha1_file(note_oid->hash, &type, &msglen))) error("Empty notes tree. %s", notes_ref); else if (!msglen || type != OBJ_BLOB) { error("Note contains unusable content. " @@ -99,8 +99,8 @@ static int parse_rev_note(const char *msg, struct rev_note *res) return -1; } -static int note2mark_cb(const unsigned char *object_sha1, - const unsigned char *note_sha1, char *note_path, +static int note2mark_cb(const struct object_id *object_oid, + const struct object_id *note_oid, char *note_path, void *cb_data) { FILE *file = (FILE *)cb_data; @@ -109,14 +109,14 @@ static int note2mark_cb(const unsigned char *object_sha1, enum object_type type; struct rev_note note; - if (!(msg = read_sha1_file(note_sha1, &type, &msglen)) || + if (!(msg = read_sha1_file(note_oid->hash, &type, &msglen)) || !msglen || type != OBJ_BLOB) { free(msg); return 1; } if (parse_rev_note(msg, ¬e)) return 2; - if (fprintf(file, ":%d %s\n", note.rev_nr, sha1_to_hex(object_sha1)) < 1) + if (fprintf(file, ":%d %s\n", note.rev_nr, oid_to_hex(object_oid)) < 1) return 3; return 0; } @@ -170,15 +170,15 @@ static int cmd_import(const char *line) int code; int dumpin_fd; char *note_msg; - unsigned char head_sha1[20]; + struct object_id head_oid; unsigned int startrev; struct child_process svndump_proc = CHILD_PROCESS_INIT; const char *command = "svnrdump"; - if (read_ref(private_ref, head_sha1)) + if (read_ref(private_ref, head_oid.hash)) startrev = 0; else { - note_msg = read_ref_note(head_sha1); + note_msg = read_ref_note(&head_oid); if(note_msg == NULL) { warning("No note found for %s.", private_ref); startrev = 0; diff --git a/revision.c b/revision.c index 3b09cd6ee9..12eb332350 100644 --- a/revision.c +++ b/revision.c @@ -401,8 +401,8 @@ static int tree_difference = REV_TREE_SAME; static void file_add_remove(struct diff_options *options, int addremove, unsigned mode, - const unsigned char *sha1, - int sha1_valid, + const struct object_id *oid, + int oid_valid, const char *fullpath, unsigned dirty_submodule) { int diff = addremove == '+' ? REV_TREE_NEW : REV_TREE_OLD; @@ -414,9 +414,9 @@ static void file_add_remove(struct diff_options *options, static void file_change(struct diff_options *options, unsigned old_mode, unsigned new_mode, - const unsigned char *old_sha1, - const unsigned char *new_sha1, - int old_sha1_valid, int new_sha1_valid, + const struct object_id *old_oid, + const struct object_id *new_oid, + int old_oid_valid, int new_oid_valid, const char *fullpath, unsigned old_dirty_submodule, unsigned new_dirty_submodule) { @@ -455,7 +455,7 @@ static int rev_compare_tree(struct rev_info *revs, tree_difference = REV_TREE_SAME; DIFF_OPT_CLR(&revs->pruning, HAS_CHANGES); - if (diff_tree_sha1(t1->object.oid.hash, t2->object.oid.hash, "", + if (diff_tree_oid(&t1->object.oid, &t2->object.oid, "", &revs->pruning) < 0) return REV_TREE_DIFFERENT; return tree_difference; @@ -471,7 +471,7 @@ static int rev_same_tree_as_empty(struct rev_info *revs, struct commit *commit) tree_difference = REV_TREE_SAME; DIFF_OPT_CLR(&revs->pruning, HAS_CHANGES); - retval = diff_tree_sha1(NULL, t1->object.oid.hash, "", &revs->pruning); + retval = diff_tree_oid(NULL, &t1->object.oid, "", &revs->pruning); return retval >= 0 && (tree_difference == REV_TREE_SAME); } @@ -2944,7 +2944,7 @@ static int commit_match(struct commit *commit, struct rev_info *opt) if (opt->show_notes) { if (!buf.len) strbuf_addstr(&buf, message); - format_display_notes(commit->object.oid.hash, &buf, encoding, 1); + format_display_notes(&commit->object.oid, &buf, encoding, 1); } /* diff --git a/sequencer.c b/sequencer.c index 5282fb849c..d63099d50f 100644 --- a/sequencer.c +++ b/sequencer.c @@ -2130,8 +2130,8 @@ cleanup_head_ref: if (read_oneliner(&buf, rebase_path_orig_head(), 0) && !get_sha1(buf.buf, orig.hash) && !get_sha1("HEAD", head.hash)) { - diff_tree_sha1(orig.hash, head.hash, - "", &log_tree_opt.diffopt); + diff_tree_oid(&orig, &head, "", + &log_tree_opt.diffopt); log_tree_diff_flush(&log_tree_opt); } } diff --git a/tree-diff.c b/tree-diff.c index e164e532b2..467e381724 100644 --- a/tree-diff.c +++ b/tree-diff.c @@ -26,11 +26,12 @@ } while(0) static struct combine_diff_path *ll_diff_tree_paths( - struct combine_diff_path *p, const unsigned char *sha1, - const unsigned char **parents_sha1, int nparent, + struct combine_diff_path *p, const struct object_id *oid, + const struct object_id **parents_oid, int nparent, struct strbuf *base, struct diff_options *opt); -static int ll_diff_tree_sha1(const unsigned char *old, const unsigned char *new, - struct strbuf *base, struct diff_options *opt); +static int ll_diff_tree_oid(const struct object_id *old_oid, + const struct object_id *new_oid, + struct strbuf *base, struct diff_options *opt); /* * Compare two tree entries, taking into account only path/S_ISDIR(mode), @@ -74,25 +75,25 @@ static int emit_diff_first_parent_only(struct diff_options *opt, struct combine_ { struct combine_diff_parent *p0 = &p->parent[0]; if (p->mode && p0->mode) { - opt->change(opt, p0->mode, p->mode, p0->oid.hash, p->oid.hash, + opt->change(opt, p0->mode, p->mode, &p0->oid, &p->oid, 1, 1, p->path, 0, 0); } else { - const unsigned char *sha1; + const struct object_id *oid; unsigned int mode; int addremove; if (p->mode) { addremove = '+'; - sha1 = p->oid.hash; + oid = &p->oid; mode = p->mode; } else { addremove = '-'; - sha1 = p0->oid.hash; + oid = &p0->oid; mode = p0->mode; } - opt->add_remove(opt, addremove, mode, sha1, 1, p->path, 0); + opt->add_remove(opt, addremove, mode, oid, 1, p->path, 0); } return 0; /* we are done with p */ @@ -131,7 +132,7 @@ static int emit_diff_first_parent_only(struct diff_options *opt, struct combine_ */ static struct combine_diff_path *path_appendnew(struct combine_diff_path *last, int nparent, const struct strbuf *base, const char *path, int pathlen, - unsigned mode, const unsigned char *sha1) + unsigned mode, const struct object_id *oid) { struct combine_diff_path *p; size_t len = st_add(base->len, pathlen); @@ -161,7 +162,7 @@ static struct combine_diff_path *path_appendnew(struct combine_diff_path *last, memcpy(p->path + base->len, path, pathlen); p->path[len] = 0; p->mode = mode; - hashcpy(p->oid.hash, sha1 ? sha1 : null_sha1); + oidcpy(&p->oid, oid ? oid : &null_oid); return p; } @@ -183,7 +184,7 @@ static struct combine_diff_path *emit_path(struct combine_diff_path *p, { unsigned mode; const char *path; - const unsigned char *sha1; + const struct object_id *oid; int pathlen; int old_baselen = base->len; int i, isdir, recurse = 0, emitthis = 1; @@ -193,7 +194,7 @@ static struct combine_diff_path *emit_path(struct combine_diff_path *p, if (t) { /* path present in resulting tree */ - sha1 = tree_entry_extract(t, &path, &mode)->hash; + oid = tree_entry_extract(t, &path, &mode); pathlen = tree_entry_len(&t->entry); isdir = S_ISDIR(mode); } else { @@ -208,7 +209,7 @@ static struct combine_diff_path *emit_path(struct combine_diff_path *p, pathlen = tree_entry_len(&tp[imin].entry); isdir = S_ISDIR(mode); - sha1 = NULL; + oid = NULL; mode = 0; } @@ -220,7 +221,7 @@ static struct combine_diff_path *emit_path(struct combine_diff_path *p, if (emitthis) { int keep; struct combine_diff_path *pprev = p; - p = path_appendnew(p, nparent, base, path, pathlen, mode, sha1); + p = path_appendnew(p, nparent, base, path, pathlen, mode, oid); for (i = 0; i < nparent; ++i) { /* @@ -229,7 +230,7 @@ static struct combine_diff_path *emit_path(struct combine_diff_path *p, */ int tpi_valid = tp && !(tp[i].entry.mode & S_IFXMIN_NEQ); - const unsigned char *sha1_i; + const struct object_id *oid_i; unsigned mode_i; p->parent[i].status = @@ -239,16 +240,16 @@ static struct combine_diff_path *emit_path(struct combine_diff_path *p, DIFF_STATUS_ADDED; if (tpi_valid) { - sha1_i = tp[i].entry.oid->hash; + oid_i = tp[i].entry.oid; mode_i = tp[i].entry.mode; } else { - sha1_i = NULL; + oid_i = &null_oid; mode_i = 0; } p->parent[i].mode = mode_i; - hashcpy(p->parent[i].oid.hash, sha1_i ? sha1_i : null_sha1); + oidcpy(&p->parent[i].oid, oid_i); } keep = 1; @@ -273,21 +274,20 @@ static struct combine_diff_path *emit_path(struct combine_diff_path *p, } if (recurse) { - const unsigned char **parents_sha1; + const struct object_id **parents_oid; - FAST_ARRAY_ALLOC(parents_sha1, nparent); + FAST_ARRAY_ALLOC(parents_oid, nparent); for (i = 0; i < nparent; ++i) { /* same rule as in emitthis */ int tpi_valid = tp && !(tp[i].entry.mode & S_IFXMIN_NEQ); - parents_sha1[i] = tpi_valid ? tp[i].entry.oid->hash - : NULL; + parents_oid[i] = tpi_valid ? tp[i].entry.oid : NULL; } strbuf_add(base, path, pathlen); strbuf_addch(base, '/'); - p = ll_diff_tree_paths(p, sha1, parents_sha1, nparent, base, opt); - FAST_ARRAY_FREE(parents_sha1, nparent); + p = ll_diff_tree_paths(p, oid, parents_oid, nparent, base, opt); + FAST_ARRAY_FREE(parents_oid, nparent); } strbuf_setlen(base, old_baselen); @@ -312,7 +312,7 @@ static void skip_uninteresting(struct tree_desc *t, struct strbuf *base, /* - * generate paths for combined diff D(sha1,parents_sha1[]) + * generate paths for combined diff D(sha1,parents_oid[]) * * Resulting paths are appended to combine_diff_path linked list, and also, are * emitted on the go via opt->pathchange() callback, so it is possible to @@ -404,8 +404,8 @@ static inline void update_tp_entries(struct tree_desc *tp, int nparent) } static struct combine_diff_path *ll_diff_tree_paths( - struct combine_diff_path *p, const unsigned char *sha1, - const unsigned char **parents_sha1, int nparent, + struct combine_diff_path *p, const struct object_id *oid, + const struct object_id **parents_oid, int nparent, struct strbuf *base, struct diff_options *opt) { struct tree_desc t, *tp; @@ -419,11 +419,11 @@ static struct combine_diff_path *ll_diff_tree_paths( * load parents first, as they are probably already cached. * * ( log_tree_diff() parses commit->parent before calling here via - * diff_tree_sha1(parent, commit) ) + * diff_tree_oid(parent, commit) ) */ for (i = 0; i < nparent; ++i) - tptree[i] = fill_tree_descriptor(&tp[i], parents_sha1[i]); - ttree = fill_tree_descriptor(&t, sha1); + tptree[i] = fill_tree_descriptor(&tp[i], parents_oid[i]->hash); + ttree = fill_tree_descriptor(&t, oid->hash); /* Enable recursion indefinitely */ opt->pathspec.recursive = DIFF_OPT_TST(opt, RECURSIVE); @@ -548,11 +548,11 @@ static struct combine_diff_path *ll_diff_tree_paths( } struct combine_diff_path *diff_tree_paths( - struct combine_diff_path *p, const unsigned char *sha1, - const unsigned char **parents_sha1, int nparent, + struct combine_diff_path *p, const struct object_id *oid, + const struct object_id **parents_oid, int nparent, struct strbuf *base, struct diff_options *opt) { - p = ll_diff_tree_paths(p, sha1, parents_sha1, nparent, base, opt); + p = ll_diff_tree_paths(p, oid, parents_oid, nparent, base, opt); /* * free pre-allocated last element, if any @@ -577,7 +577,9 @@ static inline int diff_might_be_rename(void) !DIFF_FILE_VALID(diff_queued_diff.queue[0]->one); } -static void try_to_follow_renames(const unsigned char *old, const unsigned char *new, struct strbuf *base, struct diff_options *opt) +static void try_to_follow_renames(const struct object_id *old_oid, + const struct object_id *new_oid, + struct strbuf *base, struct diff_options *opt) { struct diff_options diff_opts; struct diff_queue_struct *q = &diff_queued_diff; @@ -615,7 +617,7 @@ static void try_to_follow_renames(const unsigned char *old, const unsigned char diff_opts.break_opt = opt->break_opt; diff_opts.rename_score = opt->rename_score; diff_setup_done(&diff_opts); - ll_diff_tree_sha1(old, new, base, &diff_opts); + ll_diff_tree_oid(old_oid, new_oid, base, &diff_opts); diffcore_std(&diff_opts); clear_pathspec(&diff_opts.pathspec); @@ -674,15 +676,16 @@ static void try_to_follow_renames(const unsigned char *old, const unsigned char q->nr = 1; } -static int ll_diff_tree_sha1(const unsigned char *old, const unsigned char *new, - struct strbuf *base, struct diff_options *opt) +static int ll_diff_tree_oid(const struct object_id *old_oid, + const struct object_id *new_oid, + struct strbuf *base, struct diff_options *opt) { struct combine_diff_path phead, *p; pathchange_fn_t pathchange_old = opt->pathchange; phead.next = NULL; opt->pathchange = emit_diff_first_parent_only; - diff_tree_paths(&phead, new, &old, 1, base, opt); + diff_tree_paths(&phead, new_oid, &old_oid, 1, base, opt); for (p = phead.next; p;) { struct combine_diff_path *pprev = p; @@ -694,7 +697,9 @@ static int ll_diff_tree_sha1(const unsigned char *old, const unsigned char *new, return 0; } -int diff_tree_sha1(const unsigned char *old, const unsigned char *new, const char *base_str, struct diff_options *opt) +int diff_tree_oid(const struct object_id *old_oid, + const struct object_id *new_oid, + const char *base_str, struct diff_options *opt) { struct strbuf base; int retval; @@ -702,16 +707,16 @@ int diff_tree_sha1(const unsigned char *old, const unsigned char *new, const cha strbuf_init(&base, PATH_MAX); strbuf_addstr(&base, base_str); - retval = ll_diff_tree_sha1(old, new, &base, opt); + retval = ll_diff_tree_oid(old_oid, new_oid, &base, opt); if (!*base_str && DIFF_OPT_TST(opt, FOLLOW_RENAMES) && diff_might_be_rename()) - try_to_follow_renames(old, new, &base, opt); + try_to_follow_renames(old_oid, new_oid, &base, opt); strbuf_release(&base); return retval; } -int diff_root_tree_sha1(const unsigned char *new, const char *base, struct diff_options *opt) +int diff_root_tree_oid(const struct object_id *new_oid, const char *base, struct diff_options *opt) { - return diff_tree_sha1(NULL, new, base, opt); + return diff_tree_oid(NULL, new_oid, base, opt); } |