Skip to content

Commit a0d12c4

Browse files
bk2204gitster
authored andcommitted
diff: convert struct diff_filespec to struct object_id
Convert struct diff_filespec's sha1 member to use a struct object_id called "oid" instead. The following Coccinelle semantic patch was used to implement this, followed by the transformations in object_id.cocci: @@ struct diff_filespec o; @@ - o.sha1 + o.oid.hash @@ struct diff_filespec *p; @@ - p->sha1 + p->oid.hash Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent c368dde commit a0d12c4

File tree

13 files changed

+147
-128
lines changed

13 files changed

+147
-128
lines changed

builtin/blame.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ static struct origin *find_origin(struct scoreboard *sb,
599599
p->status);
600600
case 'M':
601601
porigin = get_origin(sb, parent, origin->path);
602-
hashcpy(porigin->blob_sha1, p->one->sha1);
602+
hashcpy(porigin->blob_sha1, p->one->oid.hash);
603603
porigin->mode = p->one->mode;
604604
break;
605605
case 'A':
@@ -645,7 +645,7 @@ static struct origin *find_rename(struct scoreboard *sb,
645645
if ((p->status == 'R' || p->status == 'C') &&
646646
!strcmp(p->two->path, origin->path)) {
647647
porigin = get_origin(sb, parent, p->one->path);
648-
hashcpy(porigin->blob_sha1, p->one->sha1);
648+
hashcpy(porigin->blob_sha1, p->one->oid.hash);
649649
porigin->mode = p->one->mode;
650650
break;
651651
}
@@ -1309,7 +1309,7 @@ static void find_copy_in_parent(struct scoreboard *sb,
13091309
continue;
13101310

13111311
norigin = get_origin(sb, parent, p->one->path);
1312-
hashcpy(norigin->blob_sha1, p->one->sha1);
1312+
hashcpy(norigin->blob_sha1, p->one->oid.hash);
13131313
norigin->mode = p->one->mode;
13141314
fill_origin_blob(&sb->revs->diffopt, norigin, &file_p);
13151315
if (!file_p.ptr)

builtin/fast-export.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ static void show_filemodify(struct diff_queue_struct *q,
368368
print_path(spec->path);
369369
putchar('\n');
370370

371-
if (!hashcmp(ospec->sha1, spec->sha1) &&
371+
if (!oidcmp(&ospec->oid, &spec->oid) &&
372372
ospec->mode == spec->mode)
373373
break;
374374
/* fallthrough */
@@ -383,10 +383,10 @@ static void show_filemodify(struct diff_queue_struct *q,
383383
if (no_data || S_ISGITLINK(spec->mode))
384384
printf("M %06o %s ", spec->mode,
385385
sha1_to_hex(anonymize ?
386-
anonymize_sha1(spec->sha1) :
387-
spec->sha1));
386+
anonymize_sha1(spec->oid.hash) :
387+
spec->oid.hash));
388388
else {
389-
struct object *object = lookup_object(spec->sha1);
389+
struct object *object = lookup_object(spec->oid.hash);
390390
printf("M %06o :%d ", spec->mode,
391391
get_object_mark(object));
392392
}
@@ -572,7 +572,7 @@ static void handle_commit(struct commit *commit, struct rev_info *rev)
572572
/* Export the referenced blobs, and remember the marks. */
573573
for (i = 0; i < diff_queued_diff.nr; i++)
574574
if (!S_ISGITLINK(diff_queued_diff.queue[i]->two->mode))
575-
export_blob(diff_queued_diff.queue[i]->two->sha1);
575+
export_blob(diff_queued_diff.queue[i]->two->oid.hash);
576576

577577
refname = commit->util;
578578
if (anonymize) {

builtin/reset.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,15 @@ static void update_index_from_diff(struct diff_queue_struct *q,
121121

122122
for (i = 0; i < q->nr; i++) {
123123
struct diff_filespec *one = q->queue[i]->one;
124-
int is_missing = !(one->mode && !is_null_sha1(one->sha1));
124+
int is_missing = !(one->mode && !is_null_oid(&one->oid));
125125
struct cache_entry *ce;
126126

127127
if (is_missing && !intent_to_add) {
128128
remove_file_from_cache(one->path);
129129
continue;
130130
}
131131

132-
ce = make_cache_entry(one->mode, one->sha1, one->path,
132+
ce = make_cache_entry(one->mode, one->oid.hash, one->path,
133133
0, 0);
134134
if (!ce)
135135
die(_("make_cache_entry failed for path '%s'"),

combine-diff.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ static struct combine_diff_path *intersect_paths(struct combine_diff_path *curr,
4444
memset(p->parent, 0,
4545
sizeof(p->parent[0]) * num_parent);
4646

47-
hashcpy(p->oid.hash, q->queue[i]->two->sha1);
47+
oidcpy(&p->oid, &q->queue[i]->two->oid);
4848
p->mode = q->queue[i]->two->mode;
49-
hashcpy(p->parent[n].oid.hash, q->queue[i]->one->sha1);
49+
oidcpy(&p->parent[n].oid, &q->queue[i]->one->oid);
5050
p->parent[n].mode = q->queue[i]->one->mode;
5151
p->parent[n].status = q->queue[i]->status;
5252
*tail = p;
@@ -77,7 +77,7 @@ static struct combine_diff_path *intersect_paths(struct combine_diff_path *curr,
7777
continue;
7878
}
7979

80-
hashcpy(p->parent[n].oid.hash, q->queue[i]->one->sha1);
80+
oidcpy(&p->parent[n].oid, &q->queue[i]->one->oid);
8181
p->parent[n].mode = q->queue[i]->one->mode;
8282
p->parent[n].status = q->queue[i]->status;
8383

@@ -1268,15 +1268,15 @@ static struct diff_filepair *combined_pair(struct combine_diff_path *p,
12681268
for (i = 0; i < num_parent; i++) {
12691269
pair->one[i].path = p->path;
12701270
pair->one[i].mode = p->parent[i].mode;
1271-
hashcpy(pair->one[i].sha1, p->parent[i].oid.hash);
1271+
oidcpy(&pair->one[i].oid, &p->parent[i].oid);
12721272
pair->one[i].sha1_valid = !is_null_oid(&p->parent[i].oid);
12731273
pair->one[i].has_more_entries = 1;
12741274
}
12751275
pair->one[num_parent - 1].has_more_entries = 0;
12761276

12771277
pair->two->path = p->path;
12781278
pair->two->mode = p->mode;
1279-
hashcpy(pair->two->sha1, p->oid.hash);
1279+
oidcpy(&pair->two->oid, &p->oid);
12801280
pair->two->sha1_valid = !is_null_oid(&p->oid);
12811281
return pair;
12821282
}

diff.c

Lines changed: 38 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1934,7 +1934,7 @@ static void show_dirstat(struct diff_options *options)
19341934
name = p->two->path ? p->two->path : p->one->path;
19351935

19361936
if (p->one->sha1_valid && p->two->sha1_valid)
1937-
content_changed = hashcmp(p->one->sha1, p->two->sha1);
1937+
content_changed = oidcmp(&p->one->oid, &p->two->oid);
19381938
else
19391939
content_changed = 1;
19401940

@@ -2306,7 +2306,8 @@ static void builtin_diff(const char *name_a,
23062306
const char *add = diff_get_color_opt(o, DIFF_FILE_NEW);
23072307
show_submodule_summary(o->file, one->path ? one->path : two->path,
23082308
line_prefix,
2309-
one->sha1, two->sha1, two->dirty_submodule,
2309+
one->oid.hash, two->oid.hash,
2310+
two->dirty_submodule,
23102311
meta, del, add, reset);
23112312
return;
23122313
}
@@ -2384,7 +2385,7 @@ static void builtin_diff(const char *name_a,
23842385
if (!one->data && !two->data &&
23852386
S_ISREG(one->mode) && S_ISREG(two->mode) &&
23862387
!DIFF_OPT_TST(o, BINARY)) {
2387-
if (!hashcmp(one->sha1, two->sha1)) {
2388+
if (!oidcmp(&one->oid, &two->oid)) {
23882389
if (must_show_header)
23892390
fprintf(o->file, "%s", header.buf);
23902391
goto free_ab_and_return;
@@ -2505,7 +2506,7 @@ static void builtin_diffstat(const char *name_a, const char *name_b,
25052506
return;
25062507
}
25072508

2508-
same_contents = !hashcmp(one->sha1, two->sha1);
2509+
same_contents = !oidcmp(&one->oid, &two->oid);
25092510

25102511
if (diff_filespec_is_binary(one) || diff_filespec_is_binary(two)) {
25112512
data->is_binary = 1;
@@ -2638,7 +2639,7 @@ void fill_filespec(struct diff_filespec *spec, const unsigned char *sha1,
26382639
{
26392640
if (mode) {
26402641
spec->mode = canon_mode(mode);
2641-
hashcpy(spec->sha1, sha1);
2642+
hashcpy(spec->oid.hash, sha1);
26422643
spec->sha1_valid = sha1_valid;
26432644
}
26442645
}
@@ -2721,7 +2722,8 @@ static int diff_populate_gitlink(struct diff_filespec *s, int size_only)
27212722
if (s->dirty_submodule)
27222723
dirty = "-dirty";
27232724

2724-
strbuf_addf(&buf, "Subproject commit %s%s\n", sha1_to_hex(s->sha1), dirty);
2725+
strbuf_addf(&buf, "Subproject commit %s%s\n",
2726+
oid_to_hex(&s->oid), dirty);
27252727
s->size = buf.len;
27262728
if (size_only) {
27272729
s->data = NULL;
@@ -2765,7 +2767,7 @@ int diff_populate_filespec(struct diff_filespec *s, unsigned int flags)
27652767
return diff_populate_gitlink(s, size_only);
27662768

27672769
if (!s->sha1_valid ||
2768-
reuse_worktree_file(s->path, s->sha1, 0)) {
2770+
reuse_worktree_file(s->path, s->oid.hash, 0)) {
27692771
struct strbuf buf = STRBUF_INIT;
27702772
struct stat st;
27712773
int fd;
@@ -2822,19 +2824,20 @@ int diff_populate_filespec(struct diff_filespec *s, unsigned int flags)
28222824
else {
28232825
enum object_type type;
28242826
if (size_only || (flags & CHECK_BINARY)) {
2825-
type = sha1_object_info(s->sha1, &s->size);
2827+
type = sha1_object_info(s->oid.hash, &s->size);
28262828
if (type < 0)
2827-
die("unable to read %s", sha1_to_hex(s->sha1));
2829+
die("unable to read %s",
2830+
oid_to_hex(&s->oid));
28282831
if (size_only)
28292832
return 0;
28302833
if (s->size > big_file_threshold && s->is_binary == -1) {
28312834
s->is_binary = 1;
28322835
return 0;
28332836
}
28342837
}
2835-
s->data = read_sha1_file(s->sha1, &type, &s->size);
2838+
s->data = read_sha1_file(s->oid.hash, &type, &s->size);
28362839
if (!s->data)
2837-
die("unable to read %s", sha1_to_hex(s->sha1));
2840+
die("unable to read %s", oid_to_hex(&s->oid));
28382841
s->should_free = 1;
28392842
}
28402843
return 0;
@@ -2913,7 +2916,7 @@ static struct diff_tempfile *prepare_temp_file(const char *name,
29132916

29142917
if (!S_ISGITLINK(one->mode) &&
29152918
(!one->sha1_valid ||
2916-
reuse_worktree_file(name, one->sha1, 1))) {
2919+
reuse_worktree_file(name, one->oid.hash, 1))) {
29172920
struct stat st;
29182921
if (lstat(name, &st) < 0) {
29192922
if (errno == ENOENT)
@@ -2926,7 +2929,7 @@ static struct diff_tempfile *prepare_temp_file(const char *name,
29262929
die_errno("readlink(%s)", name);
29272930
prep_temp_blob(name, temp, sb.buf, sb.len,
29282931
(one->sha1_valid ?
2929-
one->sha1 : null_sha1),
2932+
one->oid.hash : null_sha1),
29302933
(one->sha1_valid ?
29312934
one->mode : S_IFLNK));
29322935
strbuf_release(&sb);
@@ -2937,7 +2940,7 @@ static struct diff_tempfile *prepare_temp_file(const char *name,
29372940
if (!one->sha1_valid)
29382941
sha1_to_hex_r(temp->hex, null_sha1);
29392942
else
2940-
sha1_to_hex_r(temp->hex, one->sha1);
2943+
sha1_to_hex_r(temp->hex, one->oid.hash);
29412944
/* Even though we may sometimes borrow the
29422945
* contents from the work tree, we always want
29432946
* one->mode. mode is trustworthy even when
@@ -2952,7 +2955,7 @@ static struct diff_tempfile *prepare_temp_file(const char *name,
29522955
if (diff_populate_filespec(one, 0))
29532956
die("cannot read data blob for %s", one->path);
29542957
prep_temp_blob(name, temp, one->data, one->size,
2955-
one->sha1, one->mode);
2958+
one->oid.hash, one->mode);
29562959
}
29572960
return temp;
29582961
}
@@ -3065,7 +3068,7 @@ static void fill_metainfo(struct strbuf *msg,
30653068
default:
30663069
*must_show_header = 0;
30673070
}
3068-
if (one && two && hashcmp(one->sha1, two->sha1)) {
3071+
if (one && two && oidcmp(&one->oid, &two->oid)) {
30693072
int abbrev = DIFF_OPT_TST(o, FULL_INDEX) ? 40 : DEFAULT_ABBREV;
30703073

30713074
if (DIFF_OPT_TST(o, BINARY)) {
@@ -3075,8 +3078,8 @@ static void fill_metainfo(struct strbuf *msg,
30753078
abbrev = 40;
30763079
}
30773080
strbuf_addf(msg, "%s%sindex %s..", line_prefix, set,
3078-
find_unique_abbrev(one->sha1, abbrev));
3079-
strbuf_addstr(msg, find_unique_abbrev(two->sha1, abbrev));
3081+
find_unique_abbrev(one->oid.hash, abbrev));
3082+
strbuf_addstr(msg, find_unique_abbrev(two->oid.hash, abbrev));
30803083
if (one->mode == two->mode)
30813084
strbuf_addf(msg, " %06o", one->mode);
30823085
strbuf_addf(msg, "%s\n", reset);
@@ -3134,17 +3137,17 @@ static void diff_fill_sha1_info(struct diff_filespec *one)
31343137
if (!one->sha1_valid) {
31353138
struct stat st;
31363139
if (one->is_stdin) {
3137-
hashclr(one->sha1);
3140+
oidclr(&one->oid);
31383141
return;
31393142
}
31403143
if (lstat(one->path, &st) < 0)
31413144
die_errno("stat '%s'", one->path);
3142-
if (index_path(one->sha1, one->path, &st, 0))
3145+
if (index_path(one->oid.hash, one->path, &st, 0))
31433146
die("cannot hash %s", one->path);
31443147
}
31453148
}
31463149
else
3147-
hashclr(one->sha1);
3150+
oidclr(&one->oid);
31483151
}
31493152

31503153
static void strip_prefix(int prefix_length, const char **namep, const char **otherp)
@@ -4118,8 +4121,9 @@ static void diff_flush_raw(struct diff_filepair *p, struct diff_options *opt)
41184121
fprintf(opt->file, "%s", diff_line_prefix(opt));
41194122
if (!(opt->output_format & DIFF_FORMAT_NAME_STATUS)) {
41204123
fprintf(opt->file, ":%06o %06o %s ", p->one->mode, p->two->mode,
4121-
diff_unique_abbrev(p->one->sha1, opt->abbrev));
4122-
fprintf(opt->file, "%s ", diff_unique_abbrev(p->two->sha1, opt->abbrev));
4124+
diff_unique_abbrev(p->one->oid.hash, opt->abbrev));
4125+
fprintf(opt->file, "%s ",
4126+
diff_unique_abbrev(p->two->oid.hash, opt->abbrev));
41234127
}
41244128
if (p->score) {
41254129
fprintf(opt->file, "%c%03d%c", p->status, similarity_index(p),
@@ -4169,7 +4173,7 @@ int diff_unmodified_pair(struct diff_filepair *p)
41694173
* dealing with a change.
41704174
*/
41714175
if (one->sha1_valid && two->sha1_valid &&
4172-
!hashcmp(one->sha1, two->sha1) &&
4176+
!oidcmp(&one->oid, &two->oid) &&
41734177
!one->dirty_submodule && !two->dirty_submodule)
41744178
return 1; /* no change */
41754179
if (!one->sha1_valid && !two->sha1_valid)
@@ -4233,7 +4237,7 @@ void diff_debug_filespec(struct diff_filespec *s, int x, const char *one)
42334237
s->path,
42344238
DIFF_FILE_VALID(s) ? "valid" : "invalid",
42354239
s->mode,
4236-
s->sha1_valid ? sha1_to_hex(s->sha1) : "");
4240+
s->sha1_valid ? oid_to_hex(&s->oid) : "");
42374241
fprintf(stderr, "queue[%d] %s size %lu\n",
42384242
x, one ? one : "",
42394243
s->size);
@@ -4303,11 +4307,11 @@ static void diff_resolve_rename_copy(void)
43034307
else
43044308
p->status = DIFF_STATUS_RENAMED;
43054309
}
4306-
else if (hashcmp(p->one->sha1, p->two->sha1) ||
4310+
else if (oidcmp(&p->one->oid, &p->two->oid) ||
43074311
p->one->mode != p->two->mode ||
43084312
p->one->dirty_submodule ||
43094313
p->two->dirty_submodule ||
4310-
is_null_sha1(p->one->sha1))
4314+
is_null_oid(&p->one->oid))
43114315
p->status = DIFF_STATUS_MODIFIED;
43124316
else {
43134317
/* This is a "no-change" entry and should not
@@ -4523,8 +4527,10 @@ static int diff_get_patch_id(struct diff_options *options, unsigned char *sha1)
45234527

45244528
if (diff_filespec_is_binary(p->one) ||
45254529
diff_filespec_is_binary(p->two)) {
4526-
git_SHA1_Update(&ctx, sha1_to_hex(p->one->sha1), 40);
4527-
git_SHA1_Update(&ctx, sha1_to_hex(p->two->sha1), 40);
4530+
git_SHA1_Update(&ctx, oid_to_hex(&p->one->oid),
4531+
40);
4532+
git_SHA1_Update(&ctx, oid_to_hex(&p->two->oid),
4533+
40);
45284534
continue;
45294535
}
45304536

@@ -5113,7 +5119,8 @@ size_t fill_textconv(struct userdiff_driver *driver,
51135119
die("BUG: fill_textconv called with non-textconv driver");
51145120

51155121
if (driver->textconv_cache && df->sha1_valid) {
5116-
*outbuf = notes_cache_get(driver->textconv_cache, df->sha1,
5122+
*outbuf = notes_cache_get(driver->textconv_cache,
5123+
df->oid.hash,
51175124
&size);
51185125
if (*outbuf)
51195126
return size;
@@ -5125,7 +5132,7 @@ size_t fill_textconv(struct userdiff_driver *driver,
51255132

51265133
if (driver->textconv_cache && df->sha1_valid) {
51275134
/* ignore errors, as we might be in a readonly repository */
5128-
notes_cache_put(driver->textconv_cache, df->sha1, *outbuf,
5135+
notes_cache_put(driver->textconv_cache, df->oid.hash, *outbuf,
51295136
size);
51305137
/*
51315138
* we could save up changes and flush them all at the end,

diffcore-break.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ static int should_break(struct diff_filespec *src,
5858
}
5959

6060
if (src->sha1_valid && dst->sha1_valid &&
61-
!hashcmp(src->sha1, dst->sha1))
61+
!oidcmp(&src->oid, &dst->oid))
6262
return 0; /* they are the same */
6363

6464
if (diff_populate_filespec(src, 0) || diff_populate_filespec(dst, 0))

0 commit comments

Comments
 (0)