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>
brian m. carlson committed
Jun 24, 2016 at 23:09 UTC
a0d12c4433e25e87b67df78b45635df8a098fb23
13 files changed
+147
-128
builtin/blame.c
+3
-3
@@ -599,7 +599,7 @@ static struct origin *find_origin(struct scoreboard *sb,
599
p->status);
600
case 'M':
601
porigin = get_origin(sb, parent, origin->path);
602
- hashcpy(porigin->blob_sha1, p->one->sha1);
602
+ hashcpy(porigin->blob_sha1, p->one->oid.hash);
603
porigin->mode = p->one->mode;
604
break;
605
case 'A':
@@ -645,7 +645,7 @@ static struct origin *find_rename(struct scoreboard *sb,
645
if ((p->status == 'R' || p->status == 'C') &&
646
!strcmp(p->two->path, origin->path)) {
647
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);
649
porigin->mode = p->one->mode;
650
break;
651
}
@@ -1309,7 +1309,7 @@ static void find_copy_in_parent(struct scoreboard *sb,
1309
continue;
1310
1311
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);
1313
norigin->mode = p->one->mode;
1314
fill_origin_blob(&sb->revs->diffopt, norigin, &file_p);
1315
if (!file_p.ptr)
builtin/fast-export.c
+5
-5
@@ -368,7 +368,7 @@ static void show_filemodify(struct diff_queue_struct *q,
368
print_path(spec->path);
369
putchar('\n');
370
371
- if (!hashcmp(ospec->sha1, spec->sha1) &&
371
+ if (!oidcmp(&ospec->oid, &spec->oid) &&
372
ospec->mode == spec->mode)
373
break;
374
/* fallthrough */
@@ -383,10 +383,10 @@ static void show_filemodify(struct diff_queue_struct *q,
383
if (no_data || S_ISGITLINK(spec->mode))
384
printf("M %06o %s ", spec->mode,
385
sha1_to_hex(anonymize ?
386
- anonymize_sha1(spec->sha1) :
387
- spec->sha1));
386
+ anonymize_sha1(spec->oid.hash) :
387
+ spec->oid.hash));
388
else {
389
- struct object *object = lookup_object(spec->sha1);
389
+ struct object *object = lookup_object(spec->oid.hash);
390
printf("M %06o :%d ", spec->mode,
391
get_object_mark(object));
392
}
@@ -572,7 +572,7 @@ static void handle_commit(struct commit *commit, struct rev_info *rev)
572
/* Export the referenced blobs, and remember the marks. */
573
for (i = 0; i < diff_queued_diff.nr; i++)
574
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);
576
577
refname = commit->util;
578
if (anonymize) {
builtin/reset.c
+2
-2
@@ -121,7 +121,7 @@ static void update_index_from_diff(struct diff_queue_struct *q,
121
122
for (i = 0; i < q->nr; i++) {
123
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));
125
struct cache_entry *ce;
126
127
if (is_missing && !intent_to_add) {
@@ -129,7 +129,7 @@ static void update_index_from_diff(struct diff_queue_struct *q,
129
continue;
130
}
131
132
- ce = make_cache_entry(one->mode, one->sha1, one->path,
132
+ ce = make_cache_entry(one->mode, one->oid.hash, one->path,
133
0, 0);
134
if (!ce)
135
die(_("make_cache_entry failed for path '%s'"),
combine-diff.c
+5
-5
@@ -44,9 +44,9 @@ static struct combine_diff_path *intersect_paths(struct combine_diff_path *curr,
44
memset(p->parent, 0,
45
sizeof(p->parent[0]) * num_parent);
46
47
- hashcpy(p->oid.hash, q->queue[i]->two->sha1);
47
+ oidcpy(&p->oid, &q->queue[i]->two->oid);
48
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);
50
p->parent[n].mode = q->queue[i]->one->mode;
51
p->parent[n].status = q->queue[i]->status;
52
*tail = p;
@@ -77,7 +77,7 @@ static struct combine_diff_path *intersect_paths(struct combine_diff_path *curr,
77
continue;
78
}
79
80
- hashcpy(p->parent[n].oid.hash, q->queue[i]->one->sha1);
80
+ oidcpy(&p->parent[n].oid, &q->queue[i]->one->oid);
81
p->parent[n].mode = q->queue[i]->one->mode;
82
p->parent[n].status = q->queue[i]->status;
83
@@ -1268,7 +1268,7 @@ static struct diff_filepair *combined_pair(struct combine_diff_path *p,
1268
for (i = 0; i < num_parent; i++) {
1269
pair->one[i].path = p->path;
1270
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);
1272
pair->one[i].sha1_valid = !is_null_oid(&p->parent[i].oid);
1273
pair->one[i].has_more_entries = 1;
1274
}
@@ -1276,7 +1276,7 @@ static struct diff_filepair *combined_pair(struct combine_diff_path *p,
1276
1277
pair->two->path = p->path;
1278
pair->two->mode = p->mode;
1279
- hashcpy(pair->two->sha1, p->oid.hash);
1279
+ oidcpy(&pair->two->oid, &p->oid);
1280
pair->two->sha1_valid = !is_null_oid(&p->oid);
1281
return pair;
1282
}
diff.c
+38
-31
@@ -1934,7 +1934,7 @@ static void show_dirstat(struct diff_options *options)
1934
name = p->two->path ? p->two->path : p->one->path;
1935
1936
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);
1938
else
1939
content_changed = 1;
1940
@@ -2306,7 +2306,8 @@ static void builtin_diff(const char *name_a,
2306
const char *add = diff_get_color_opt(o, DIFF_FILE_NEW);
2307
show_submodule_summary(o->file, one->path ? one->path : two->path,
2308
line_prefix,
2309
- one->sha1, two->sha1, two->dirty_submodule,
2309
+ one->oid.hash, two->oid.hash,
2310
+ two->dirty_submodule,
2311
meta, del, add, reset);
2312
return;
2313
}
@@ -2384,7 +2385,7 @@ static void builtin_diff(const char *name_a,
2385
if (!one->data && !two->data &&
2386
S_ISREG(one->mode) && S_ISREG(two->mode) &&
2387
!DIFF_OPT_TST(o, BINARY)) {
2387
- if (!hashcmp(one->sha1, two->sha1)) {
2388
+ if (!oidcmp(&one->oid, &two->oid)) {
2389
if (must_show_header)
2390
fprintf(o->file, "%s", header.buf);
2391
goto free_ab_and_return;
@@ -2505,7 +2506,7 @@ static void builtin_diffstat(const char *name_a, const char *name_b,
2506
return;
2507
}
2508
2508
- same_contents = !hashcmp(one->sha1, two->sha1);
2509
+ same_contents = !oidcmp(&one->oid, &two->oid);
2510
2511
if (diff_filespec_is_binary(one) || diff_filespec_is_binary(two)) {
2512
data->is_binary = 1;
@@ -2638,7 +2639,7 @@ void fill_filespec(struct diff_filespec *spec, const unsigned char *sha1,
2639
{
2640
if (mode) {
2641
spec->mode = canon_mode(mode);
2641
- hashcpy(spec->sha1, sha1);
2642
+ hashcpy(spec->oid.hash, sha1);
2643
spec->sha1_valid = sha1_valid;
2644
}
2645
}
@@ -2721,7 +2722,8 @@ static int diff_populate_gitlink(struct diff_filespec *s, int size_only)
2722
if (s->dirty_submodule)
2723
dirty = "-dirty";
2724
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);
2727
s->size = buf.len;
2728
if (size_only) {
2729
s->data = NULL;
@@ -2765,7 +2767,7 @@ int diff_populate_filespec(struct diff_filespec *s, unsigned int flags)
2767
return diff_populate_gitlink(s, size_only);
2768
2769
if (!s->sha1_valid ||
2768
- reuse_worktree_file(s->path, s->sha1, 0)) {
2770
+ reuse_worktree_file(s->path, s->oid.hash, 0)) {
2771
struct strbuf buf = STRBUF_INIT;
2772
struct stat st;
2773
int fd;
@@ -2822,9 +2824,10 @@ int diff_populate_filespec(struct diff_filespec *s, unsigned int flags)
2824
else {
2825
enum object_type type;
2826
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);
2828
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));
2831
if (size_only)
2832
return 0;
2833
if (s->size > big_file_threshold && s->is_binary == -1) {
@@ -2832,9 +2835,9 @@ int diff_populate_filespec(struct diff_filespec *s, unsigned int flags)
2835
return 0;
2836
}
2837
}
2835
- s->data = read_sha1_file(s->sha1, &type, &s->size);
2838
+ s->data = read_sha1_file(s->oid.hash, &type, &s->size);
2839
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));
2841
s->should_free = 1;
2842
}
2843
return 0;
@@ -2913,7 +2916,7 @@ static struct diff_tempfile *prepare_temp_file(const char *name,
2916
2917
if (!S_ISGITLINK(one->mode) &&
2918
(!one->sha1_valid ||
2916
- reuse_worktree_file(name, one->sha1, 1))) {
2919
+ reuse_worktree_file(name, one->oid.hash, 1))) {
2920
struct stat st;
2921
if (lstat(name, &st) < 0) {
2922
if (errno == ENOENT)
@@ -2926,7 +2929,7 @@ static struct diff_tempfile *prepare_temp_file(const char *name,
2929
die_errno("readlink(%s)", name);
2930
prep_temp_blob(name, temp, sb.buf, sb.len,
2931
(one->sha1_valid ?
2929
- one->sha1 : null_sha1),
2932
+ one->oid.hash : null_sha1),
2933
(one->sha1_valid ?
2934
one->mode : S_IFLNK));
2935
strbuf_release(&sb);
@@ -2937,7 +2940,7 @@ static struct diff_tempfile *prepare_temp_file(const char *name,
2940
if (!one->sha1_valid)
2941
sha1_to_hex_r(temp->hex, null_sha1);
2942
else
2940
- sha1_to_hex_r(temp->hex, one->sha1);
2943
+ sha1_to_hex_r(temp->hex, one->oid.hash);
2944
/* Even though we may sometimes borrow the
2945
* contents from the work tree, we always want
2946
* one->mode. mode is trustworthy even when
@@ -2952,7 +2955,7 @@ static struct diff_tempfile *prepare_temp_file(const char *name,
2955
if (diff_populate_filespec(one, 0))
2956
die("cannot read data blob for %s", one->path);
2957
prep_temp_blob(name, temp, one->data, one->size,
2955
- one->sha1, one->mode);
2958
+ one->oid.hash, one->mode);
2959
}
2960
return temp;
2961
}
@@ -3065,7 +3068,7 @@ static void fill_metainfo(struct strbuf *msg,
3068
default:
3069
*must_show_header = 0;
3070
}
3068
- if (one && two && hashcmp(one->sha1, two->sha1)) {
3071
+ if (one && two && oidcmp(&one->oid, &two->oid)) {
3072
int abbrev = DIFF_OPT_TST(o, FULL_INDEX) ? 40 : DEFAULT_ABBREV;
3073
3074
if (DIFF_OPT_TST(o, BINARY)) {
@@ -3075,8 +3078,8 @@ static void fill_metainfo(struct strbuf *msg,
3078
abbrev = 40;
3079
}
3080
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));
3083
if (one->mode == two->mode)
3084
strbuf_addf(msg, " %06o", one->mode);
3085
strbuf_addf(msg, "%s\n", reset);
@@ -3134,17 +3137,17 @@ static void diff_fill_sha1_info(struct diff_filespec *one)
3137
if (!one->sha1_valid) {
3138
struct stat st;
3139
if (one->is_stdin) {
3137
- hashclr(one->sha1);
3140
+ oidclr(&one->oid);
3141
return;
3142
}
3143
if (lstat(one->path, &st) < 0)
3144
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))
3146
die("cannot hash %s", one->path);
3147
}
3148
}
3149
else
3147
- hashclr(one->sha1);
3150
+ oidclr(&one->oid);
3151
}
3152
3153
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)
4121
fprintf(opt->file, "%s", diff_line_prefix(opt));
4122
if (!(opt->output_format & DIFF_FORMAT_NAME_STATUS)) {
4123
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));
4127
}
4128
if (p->score) {
4129
fprintf(opt->file, "%c%03d%c", p->status, similarity_index(p),
@@ -4169,7 +4173,7 @@ int diff_unmodified_pair(struct diff_filepair *p)
4173
* dealing with a change.
4174
*/
4175
if (one->sha1_valid && two->sha1_valid &&
4172
- !hashcmp(one->sha1, two->sha1) &&
4176
+ !oidcmp(&one->oid, &two->oid) &&
4177
!one->dirty_submodule && !two->dirty_submodule)
4178
return 1; /* no change */
4179
if (!one->sha1_valid && !two->sha1_valid)
@@ -4233,7 +4237,7 @@ void diff_debug_filespec(struct diff_filespec *s, int x, const char *one)
4237
s->path,
4238
DIFF_FILE_VALID(s) ? "valid" : "invalid",
4239
s->mode,
4236
- s->sha1_valid ? sha1_to_hex(s->sha1) : "");
4240
+ s->sha1_valid ? oid_to_hex(&s->oid) : "");
4241
fprintf(stderr, "queue[%d] %s size %lu\n",
4242
x, one ? one : "",
4243
s->size);
@@ -4303,11 +4307,11 @@ static void diff_resolve_rename_copy(void)
4307
else
4308
p->status = DIFF_STATUS_RENAMED;
4309
}
4306
- else if (hashcmp(p->one->sha1, p->two->sha1) ||
4310
+ else if (oidcmp(&p->one->oid, &p->two->oid) ||
4311
p->one->mode != p->two->mode ||
4312
p->one->dirty_submodule ||
4313
p->two->dirty_submodule ||
4310
- is_null_sha1(p->one->sha1))
4314
+ is_null_oid(&p->one->oid))
4315
p->status = DIFF_STATUS_MODIFIED;
4316
else {
4317
/* 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)
4527
4528
if (diff_filespec_is_binary(p->one) ||
4529
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);
4534
continue;
4535
}
4536
@@ -5113,7 +5119,8 @@ size_t fill_textconv(struct userdiff_driver *driver,
5119
die("BUG: fill_textconv called with non-textconv driver");
5120
5121
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,
5124
&size);
5125
if (*outbuf)
5126
return size;
@@ -5125,7 +5132,7 @@ size_t fill_textconv(struct userdiff_driver *driver,
5132
5133
if (driver->textconv_cache && df->sha1_valid) {
5134
/* 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,
5136
size);
5137
/*
5138
* we could save up changes and flush them all at the end,
diffcore-break.c
+1
-1
@@ -58,7 +58,7 @@ static int should_break(struct diff_filespec *src,
58
}
59
60
if (src->sha1_valid && dst->sha1_valid &&
61
- !hashcmp(src->sha1, dst->sha1))
61
+ !oidcmp(&src->oid, &dst->oid))
62
return 0; /* they are the same */
63
64
if (diff_populate_filespec(src, 0) || diff_populate_filespec(dst, 0))
diffcore-rename.c
+8
-6
@@ -60,7 +60,8 @@ static int add_rename_dst(struct diff_filespec *two)
60
memmove(rename_dst + first + 1, rename_dst + first,
61
(rename_dst_nr - first - 1) * sizeof(*rename_dst));
62
rename_dst[first].two = alloc_filespec(two->path);
63
- fill_filespec(rename_dst[first].two, two->sha1, two->sha1_valid, two->mode);
63
+ fill_filespec(rename_dst[first].two, two->oid.hash, two->sha1_valid,
64
+ two->mode);
65
rename_dst[first].pair = NULL;
66
return 0;
67
}
@@ -263,9 +264,10 @@ static unsigned int hash_filespec(struct diff_filespec *filespec)
264
if (!filespec->sha1_valid) {
265
if (diff_populate_filespec(filespec, 0))
266
return 0;
266
- hash_sha1_file(filespec->data, filespec->size, "blob", filespec->sha1);
267
+ hash_sha1_file(filespec->data, filespec->size, "blob",
268
+ filespec->oid.hash);
269
}
268
- return sha1hash(filespec->sha1);
270
+ return sha1hash(filespec->oid.hash);
271
}
272
273
static int find_identical_files(struct hashmap *srcs,
@@ -287,7 +289,7 @@ static int find_identical_files(struct hashmap *srcs,
289
struct diff_filespec *source = p->filespec;
290
291
/* False hash collision? */
290
- if (hashcmp(source->sha1, target->sha1))
292
+ if (oidcmp(&source->oid, &target->oid))
293
continue;
294
/* Non-regular files? If so, the modes must match! */
295
if (!S_ISREG(source->mode) || !S_ISREG(target->mode)) {
@@ -466,7 +468,7 @@ void diffcore_rename(struct diff_options *options)
468
strcmp(options->single_follow, p->two->path))
469
continue; /* not interested */
470
else if (!DIFF_OPT_TST(options, RENAME_EMPTY) &&
469
- is_empty_blob_sha1(p->two->sha1))
471
+ is_empty_blob_sha1(p->two->oid.hash))
472
continue;
473
else if (add_rename_dst(p->two) < 0) {
474
warning("skipping rename detection, detected"
@@ -476,7 +478,7 @@ void diffcore_rename(struct diff_options *options)
478
}
479
}
480
else if (!DIFF_OPT_TST(options, RENAME_EMPTY) &&
479
- is_empty_blob_sha1(p->one->sha1))
481
+ is_empty_blob_sha1(p->one->oid.hash))
482
continue;
483
else if (!DIFF_PAIR_UNMERGED(p) && !DIFF_FILE_VALID(p->two)) {
484
/*
diffcore.h
+1
-1
@@ -25,7 +25,7 @@
25
struct userdiff_driver;
26
27
struct diff_filespec {
28
- unsigned char sha1[20];
28
+ struct object_id oid;
29
char *path;
30
void *data;
31
void *cnt_data;
line-log.c
+1
-1
@@ -520,7 +520,7 @@ static void fill_line_ends(struct diff_filespec *spec, long *lines,
520
char *data = NULL;
521
522
if (diff_populate_filespec(spec, 0))
523
- die("Cannot read blob %s", sha1_to_hex(spec->sha1));
523
+ die("Cannot read blob %s", oid_to_hex(&spec->oid));
524
525
ALLOC_ARRAY(ends, size);
526
ends[cur++] = 0;
merge-recursive.c
+58
-49
@@ -134,11 +134,13 @@ static inline void setup_rename_conflict_info(enum rename_type rename_type,
134
int ostage2 = ostage1 ^ 1;
135
136
ci->ren1_other.path = pair1->one->path;
137
- hashcpy(ci->ren1_other.sha1, src_entry1->stages[ostage1].sha);
137
+ hashcpy(ci->ren1_other.oid.hash,
138
+ src_entry1->stages[ostage1].sha);
139
ci->ren1_other.mode = src_entry1->stages[ostage1].mode;
140
141
ci->ren2_other.path = pair2->one->path;
141
- hashcpy(ci->ren2_other.sha1, src_entry2->stages[ostage2].sha);
142
+ hashcpy(ci->ren2_other.oid.hash,
143
+ src_entry2->stages[ostage2].sha);
144
ci->ren2_other.mode = src_entry2->stages[ostage2].mode;
145
}
146
}
@@ -552,13 +554,13 @@ static int update_stages(const char *path, const struct diff_filespec *o,
554
if (remove_file_from_cache(path))
555
return -1;
556
if (o)
555
- if (add_cacheinfo(o->mode, o->sha1, path, 1, 0, options))
557
+ if (add_cacheinfo(o->mode, o->oid.hash, path, 1, 0, options))
558
return -1;
559
if (a)
558
- if (add_cacheinfo(a->mode, a->sha1, path, 2, 0, options))
560
+ if (add_cacheinfo(a->mode, a->oid.hash, path, 2, 0, options))
561
return -1;
562
if (b)
561
- if (add_cacheinfo(b->mode, b->sha1, path, 3, 0, options))
563
+ if (add_cacheinfo(b->mode, b->oid.hash, path, 3, 0, options))
564
return -1;
565
return 0;
566
}
@@ -572,9 +574,9 @@ static void update_entry(struct stage_data *entry,
574
entry->stages[1].mode = o->mode;
575
entry->stages[2].mode = a->mode;
576
entry->stages[3].mode = b->mode;
575
- hashcpy(entry->stages[1].sha, o->sha1);
576
- hashcpy(entry->stages[2].sha, a->sha1);
577
- hashcpy(entry->stages[3].sha, b->sha1);
577
+ hashcpy(entry->stages[1].sha, o->oid.hash);
578
+ hashcpy(entry->stages[2].sha, a->oid.hash);
579
+ hashcpy(entry->stages[3].sha, b->oid.hash);
580
}
581
582
static int remove_file(struct merge_options *o, int clean,
@@ -871,9 +873,9 @@ static int merge_3way(struct merge_options *o,
873
name2 = mkpathdup("%s", branch2);
874
}
875
874
- read_mmblob(&orig, one->sha1);
875
- read_mmblob(&src1, a->sha1);
876
- read_mmblob(&src2, b->sha1);
876
+ read_mmblob(&orig, one->oid.hash);
877
+ read_mmblob(&src1, a->oid.hash);
878
+ read_mmblob(&src2, b->oid.hash);
879
880
merge_status = ll_merge(result_buf, a->path, &orig, base_name,
881
&src1, name1, &src2, name2, &ll_opts);
@@ -902,13 +904,13 @@ static struct merge_file_info merge_file_1(struct merge_options *o,
904
result.clean = 0;
905
if (S_ISREG(a->mode)) {
906
result.mode = a->mode;
905
- hashcpy(result.sha, a->sha1);
907
+ hashcpy(result.sha, a->oid.hash);
908
} else {
909
result.mode = b->mode;
908
- hashcpy(result.sha, b->sha1);
910
+ hashcpy(result.sha, b->oid.hash);
911
}
912
} else {
911
- if (!sha_eq(a->sha1, one->sha1) && !sha_eq(b->sha1, one->sha1))
913
+ if (!sha_eq(a->oid.hash, one->oid.hash) && !sha_eq(b->oid.hash, one->oid.hash))
914
result.merge = 1;
915
916
/*
@@ -924,10 +926,10 @@ static struct merge_file_info merge_file_1(struct merge_options *o,
926
}
927
}
928
927
- if (sha_eq(a->sha1, b->sha1) || sha_eq(a->sha1, one->sha1))
928
- hashcpy(result.sha, b->sha1);
929
- else if (sha_eq(b->sha1, one->sha1))
930
- hashcpy(result.sha, a->sha1);
929
+ if (sha_eq(a->oid.hash, b->oid.hash) || sha_eq(a->oid.hash, one->oid.hash))
930
+ hashcpy(result.sha, b->oid.hash);
931
+ else if (sha_eq(b->oid.hash, one->oid.hash))
932
+ hashcpy(result.sha, a->oid.hash);
933
else if (S_ISREG(a->mode)) {
934
mmbuffer_t result_buf;
935
int merge_status;
@@ -947,13 +949,15 @@ static struct merge_file_info merge_file_1(struct merge_options *o,
949
result.clean = (merge_status == 0);
950
} else if (S_ISGITLINK(a->mode)) {
951
result.clean = merge_submodule(result.sha,
950
- one->path, one->sha1,
951
- a->sha1, b->sha1,
952
+ one->path,
953
+ one->oid.hash,
954
+ a->oid.hash,
955
+ b->oid.hash,
956
!o->call_depth);
957
} else if (S_ISLNK(a->mode)) {
954
- hashcpy(result.sha, a->sha1);
958
+ hashcpy(result.sha, a->oid.hash);
959
956
- if (!sha_eq(a->sha1, b->sha1))
960
+ if (!sha_eq(a->oid.hash, b->oid.hash))
961
result.clean = 0;
962
} else {
963
die(_("unsupported object type in the tree"));
@@ -1000,11 +1004,11 @@ static struct merge_file_info merge_file_one(struct merge_options *o,
1004
struct diff_filespec one, a, b;
1005
1006
one.path = a.path = b.path = (char *)path;
1003
- hashcpy(one.sha1, o_sha);
1007
+ hashcpy(one.oid.hash, o_sha);
1008
one.mode = o_mode;
1005
- hashcpy(a.sha1, a_sha);
1009
+ hashcpy(a.oid.hash, a_sha);
1010
a.mode = a_mode;
1007
- hashcpy(b.sha1, b_sha);
1011
+ hashcpy(b.oid.hash, b_sha);
1012
b.mode = b_mode;
1013
return merge_file_1(o, &one, &a, &b, branch1, branch2);
1014
}
@@ -1079,16 +1083,16 @@ static void conflict_rename_delete(struct merge_options *o,
1083
int b_mode = 0;
1084
1085
if (rename_branch == o->branch1) {
1082
- a_sha = dest->sha1;
1086
+ a_sha = dest->oid.hash;
1087
a_mode = dest->mode;
1088
} else {
1085
- b_sha = dest->sha1;
1089
+ b_sha = dest->oid.hash;
1090
b_mode = dest->mode;
1091
}
1092
1093
handle_change_delete(o,
1094
o->call_depth ? orig->path : dest->path,
1091
- orig->sha1, orig->mode,
1095
+ orig->oid.hash, orig->mode,
1096
a_sha, a_mode,
1097
b_sha, b_mode,
1098
_("rename"), _("renamed"));
@@ -1111,7 +1115,7 @@ static struct diff_filespec *filespec_from_entry(struct diff_filespec *target,
1115
unsigned mode = entry->stages[stage].mode;
1116
if (mode == 0 || is_null_sha1(sha))
1117
return NULL;
1114
- hashcpy(target->sha1, sha);
1118
+ hashcpy(target->oid.hash, sha);
1119
target->mode = mode;
1120
return target;
1121
}
@@ -1140,7 +1144,7 @@ static void handle_file(struct merge_options *o,
1144
add = filespec_from_entry(&other, dst_entry, stage ^ 1);
1145
if (add) {
1146
char *add_name = unique_path(o, rename->path, other_branch);
1143
- update_file(o, 0, add->sha1, add->mode, add_name);
1147
+ update_file(o, 0, add->oid.hash, add->mode, add_name);
1148
1149
remove_file(o, 0, rename->path, 0);
1150
dst_name = unique_path(o, rename->path, cur_branch);
@@ -1151,7 +1155,7 @@ static void handle_file(struct merge_options *o,
1155
rename->path, other_branch, dst_name);
1156
}
1157
}
1154
- update_file(o, 0, rename->sha1, rename->mode, dst_name);
1158
+ update_file(o, 0, rename->oid.hash, rename->mode, dst_name);
1159
if (stage == 2)
1160
update_stages(rename->path, NULL, rename, add);
1161
else
@@ -1180,9 +1184,9 @@ static void conflict_rename_rename_1to2(struct merge_options *o,
1184
struct diff_filespec other;
1185
struct diff_filespec *add;
1186
mfi = merge_file_one(o, one->path,
1183
- one->sha1, one->mode,
1184
- a->sha1, a->mode,
1185
- b->sha1, b->mode,
1187
+ one->oid.hash, one->mode,
1188
+ a->oid.hash, a->mode,
1189
+ b->oid.hash, b->mode,
1190
ci->branch1, ci->branch2);
1191
/*
1192
* FIXME: For rename/add-source conflicts (if we could detect
@@ -1202,12 +1206,12 @@ static void conflict_rename_rename_1to2(struct merge_options *o,
1206
*/
1207
add = filespec_from_entry(&other, ci->dst_entry1, 2 ^ 1);
1208
if (add)
1205
- update_file(o, 0, add->sha1, add->mode, a->path);
1209
+ update_file(o, 0, add->oid.hash, add->mode, a->path);
1210
else
1211
remove_file_from_cache(a->path);
1212
add = filespec_from_entry(&other, ci->dst_entry2, 3 ^ 1);
1213
if (add)
1210
- update_file(o, 0, add->sha1, add->mode, b->path);
1214
+ update_file(o, 0, add->oid.hash, add->mode, b->path);
1215
else
1216
remove_file_from_cache(b->path);
1217
} else {
@@ -1421,13 +1425,15 @@ static int process_renames(struct merge_options *o,
1425
remove_file(o, 1, ren1_src,
1426
renamed_stage == 2 || !was_tracked(ren1_src));
1427
1424
- hashcpy(src_other.sha1, ren1->src_entry->stages[other_stage].sha);
1428
+ hashcpy(src_other.oid.hash,
1429
+ ren1->src_entry->stages[other_stage].sha);
1430
src_other.mode = ren1->src_entry->stages[other_stage].mode;
1426
- hashcpy(dst_other.sha1, ren1->dst_entry->stages[other_stage].sha);
1431
+ hashcpy(dst_other.oid.hash,
1432
+ ren1->dst_entry->stages[other_stage].sha);
1433
dst_other.mode = ren1->dst_entry->stages[other_stage].mode;
1434
try_merge = 0;
1435
1430
- if (sha_eq(src_other.sha1, null_sha1)) {
1436
+ if (sha_eq(src_other.oid.hash, null_sha1)) {
1437
setup_rename_conflict_info(RENAME_DELETE,
1438
ren1->pair,
1439
NULL,
@@ -1439,7 +1445,7 @@ static int process_renames(struct merge_options *o,
1445
NULL,
1446
NULL);
1447
} else if ((dst_other.mode == ren1->pair->two->mode) &&
1442
- sha_eq(dst_other.sha1, ren1->pair->two->sha1)) {
1448
+ sha_eq(dst_other.oid.hash, ren1->pair->two->oid.hash)) {
1449
/*
1450
* Added file on the other side identical to
1451
* the file being renamed: clean merge.
@@ -1449,12 +1455,12 @@ static int process_renames(struct merge_options *o,
1455
* update_file().
1456
*/
1457
update_file_flags(o,
1452
- ren1->pair->two->sha1,
1458
+ ren1->pair->two->oid.hash,
1459
ren1->pair->two->mode,
1460
ren1_dst,
1461
1, /* update_cache */
1462
0 /* update_wd */);
1457
- } else if (!sha_eq(dst_other.sha1, null_sha1)) {
1463
+ } else if (!sha_eq(dst_other.oid.hash, null_sha1)) {
1464
clean_merge = 0;
1465
try_merge = 1;
1466
output(o, 1, _("CONFLICT (rename/add): Rename %s->%s in %s. "
@@ -1464,8 +1470,10 @@ static int process_renames(struct merge_options *o,
1470
if (o->call_depth) {
1471
struct merge_file_info mfi;
1472
mfi = merge_file_one(o, ren1_dst, null_sha1, 0,
1467
- ren1->pair->two->sha1, ren1->pair->two->mode,
1468
- dst_other.sha1, dst_other.mode,
1473
+ ren1->pair->two->oid.hash,
1474
+ ren1->pair->two->mode,
1475
+ dst_other.oid.hash,
1476
+ dst_other.mode,
1477
branch1, branch2);
1478
output(o, 1, _("Adding merged %s"), ren1_dst);
1479
update_file(o, 0, mfi.sha, mfi.mode, ren1_dst);
@@ -1473,7 +1481,8 @@ static int process_renames(struct merge_options *o,
1481
} else {
1482
char *new_path = unique_path(o, ren1_dst, branch2);
1483
output(o, 1, _("Adding as %s instead"), new_path);
1476
- update_file(o, 0, dst_other.sha1, dst_other.mode, new_path);
1484
+ update_file(o, 0, dst_other.oid.hash,
1485
+ dst_other.mode, new_path);
1486
free(new_path);
1487
}
1488
} else
@@ -1599,11 +1608,11 @@ static int merge_content(struct merge_options *o,
1608
o_sha = (unsigned char *)null_sha1;
1609
}
1610
one.path = a.path = b.path = (char *)path;
1602
- hashcpy(one.sha1, o_sha);
1611
+ hashcpy(one.oid.hash, o_sha);
1612
one.mode = o_mode;
1604
- hashcpy(a.sha1, a_sha);
1613
+ hashcpy(a.oid.hash, a_sha);
1614
a.mode = a_mode;
1606
- hashcpy(b.sha1, b_sha);
1615
+ hashcpy(b.oid.hash, b_sha);
1616
b.mode = b_mode;
1617
1618
if (rename_conflict_info) {
@@ -1664,7 +1673,7 @@ static int merge_content(struct merge_options *o,
1673
else {
1674
int file_from_stage2 = was_tracked(path);
1675
struct diff_filespec merged;
1667
- hashcpy(merged.sha1, mfi.sha);
1676
+ hashcpy(merged.oid.hash, mfi.sha);
1677
merged.mode = mfi.mode;
1678
1679
update_stages(path, NULL,
notes-merge.c
+21
-21
@@ -41,14 +41,14 @@ static int verify_notes_filepair(struct diff_filepair *p, unsigned char *sha1)
41
switch (p->status) {
42
case DIFF_STATUS_MODIFIED:
43
assert(p->one->mode == p->two->mode);
44
- assert(!is_null_sha1(p->one->sha1));
45
- assert(!is_null_sha1(p->two->sha1));
44
+ assert(!is_null_oid(&p->one->oid));
45
+ assert(!is_null_oid(&p->two->oid));
46
break;
47
case DIFF_STATUS_ADDED:
48
- assert(is_null_sha1(p->one->sha1));
48
+ assert(is_null_oid(&p->one->oid));
49
break;
50
case DIFF_STATUS_DELETED:
51
- assert(is_null_sha1(p->two->sha1));
51
+ assert(is_null_oid(&p->two->oid));
52
break;
53
default:
54
return -1;
@@ -142,27 +142,27 @@ static struct notes_merge_pair *diff_tree_remote(struct notes_merge_options *o,
142
if (verify_notes_filepair(p, obj)) {
143
trace_printf("\t\tCannot merge entry '%s' (%c): "
144
"%.7s -> %.7s. Skipping!\n", p->one->path,
145
- p->status, sha1_to_hex(p->one->sha1),
146
- sha1_to_hex(p->two->sha1));
145
+ p->status, oid_to_hex(&p->one->oid),
146
+ oid_to_hex(&p->two->oid));
147
continue;
148
}
149
mp = find_notes_merge_pair_pos(changes, len, obj, 1, &occupied);
150
if (occupied) {
151
/* We've found an addition/deletion pair */
152
assert(!hashcmp(mp->obj, obj));
153
- if (is_null_sha1(p->one->sha1)) { /* addition */
153
+ if (is_null_oid(&p->one->oid)) { /* addition */
154
assert(is_null_sha1(mp->remote));
155
- hashcpy(mp->remote, p->two->sha1);
156
- } else if (is_null_sha1(p->two->sha1)) { /* deletion */
155
+ hashcpy(mp->remote, p->two->oid.hash);
156
+ } else if (is_null_oid(&p->two->oid)) { /* deletion */
157
assert(is_null_sha1(mp->base));
158
- hashcpy(mp->base, p->one->sha1);
158
+ hashcpy(mp->base, p->one->oid.hash);
159
} else
160
assert(!"Invalid existing change recorded");
161
} else {
162
hashcpy(mp->obj, obj);
163
- hashcpy(mp->base, p->one->sha1);
163
+ hashcpy(mp->base, p->one->oid.hash);
164
hashcpy(mp->local, uninitialized);
165
- hashcpy(mp->remote, p->two->sha1);
165
+ hashcpy(mp->remote, p->two->oid.hash);
166
len++;
167
}
168
trace_printf("\t\tStored remote change for %s: %.7s -> %.7s\n",
@@ -203,21 +203,21 @@ static void diff_tree_local(struct notes_merge_options *o,
203
if (verify_notes_filepair(p, obj)) {
204
trace_printf("\t\tCannot merge entry '%s' (%c): "
205
"%.7s -> %.7s. Skipping!\n", p->one->path,
206
- p->status, sha1_to_hex(p->one->sha1),
207
- sha1_to_hex(p->two->sha1));
206
+ p->status, oid_to_hex(&p->one->oid),
207
+ oid_to_hex(&p->two->oid));
208
continue;
209
}
210
mp = find_notes_merge_pair_pos(changes, len, obj, 0, &match);
211
if (!match) {
212
trace_printf("\t\tIgnoring local-only change for %s: "
213
"%.7s -> %.7s\n", sha1_to_hex(obj),
214
- sha1_to_hex(p->one->sha1),
215
- sha1_to_hex(p->two->sha1));
214
+ oid_to_hex(&p->one->oid),
215
+ oid_to_hex(&p->two->oid));
216
continue;
217
}
218
219
assert(!hashcmp(mp->obj, obj));
220
- if (is_null_sha1(p->two->sha1)) { /* deletion */
220
+ if (is_null_oid(&p->two->oid)) { /* deletion */
221
/*
222
* Either this is a true deletion (1), or it is part
223
* of an A/D pair (2), or D/A pair (3):
@@ -229,7 +229,7 @@ static void diff_tree_local(struct notes_merge_options *o,
229
*/
230
if (!hashcmp(mp->local, uninitialized))
231
hashclr(mp->local);
232
- } else if (is_null_sha1(p->one->sha1)) { /* addition */
232
+ } else if (is_null_oid(&p->one->oid)) { /* addition */
233
/*
234
* Either this is a true addition (1), or it is part
235
* of an A/D pair (2), or D/A pair (3):
@@ -240,16 +240,16 @@ static void diff_tree_local(struct notes_merge_options *o,
240
*/
241
assert(is_null_sha1(mp->local) ||
242
!hashcmp(mp->local, uninitialized));
243
- hashcpy(mp->local, p->two->sha1);
243
+ hashcpy(mp->local, p->two->oid.hash);
244
} else { /* modification */
245
/*
246
* This is a true modification. p->one->sha1 shall
247
* match mp->base, and mp->local shall be uninitialized.
248
* Set mp->local to p->two->sha1.
249
*/
250
- assert(!hashcmp(p->one->sha1, mp->base));
250
+ assert(!hashcmp(p->one->oid.hash, mp->base));
251
assert(!hashcmp(mp->local, uninitialized));
252
- hashcpy(mp->local, p->two->sha1);
252
+ hashcpy(mp->local, p->two->oid.hash);
253
}
254
trace_printf("\t\tStored local change for %s: %.7s -> %.7s\n",
255
sha1_to_hex(mp->obj), sha1_to_hex(mp->base),
submodule.c
+2
-2
@@ -445,7 +445,7 @@ static void collect_submodules_from_diff(struct diff_queue_struct *q,
445
struct diff_filepair *p = q->queue[i];
446
if (!S_ISGITLINK(p->two->mode))
447
continue;
448
- if (submodule_needs_pushing(p->two->path, p->two->sha1))
448
+ if (submodule_needs_pushing(p->two->path, p->two->oid.hash))
449
string_list_insert(needs_pushing, p->two->path);
450
}
451
}
@@ -577,7 +577,7 @@ static void submodule_collect_changed_cb(struct diff_queue_struct *q,
577
* being moved around. */
578
struct string_list_item *path;
579
path = unsorted_string_list_lookup(&changed_submodule_paths, p->two->path);
580
- if (!path && !is_submodule_commit_present(p->two->path, p->two->sha1))
580
+ if (!path && !is_submodule_commit_present(p->two->path, p->two->oid.hash))
581
string_list_append(&changed_submodule_paths, xstrdup(p->two->path));
582
} else {
583
/* Submodule is new or was moved here */
wt-status.c
+2
-1
@@ -432,7 +432,8 @@ static void wt_status_collect_changed_cb(struct diff_queue_struct *q,
432
d->worktree_status = p->status;
433
d->dirty_submodule = p->two->dirty_submodule;
434
if (S_ISGITLINK(p->two->mode))
435
- d->new_submodule_commits = !!hashcmp(p->one->sha1, p->two->sha1);
435
+ d->new_submodule_commits = !!oidcmp(&p->one->oid,
436
+ &p->two->oid);
437
}
438
}
439