Skip to content

Commit 1ff57c1

Browse files
bk2204gitster
authored andcommitted
diff: convert struct combine_diff_path to object_id
Also, convert a constant to GIT_SHA1_HEXSZ. Signed-off-by: brian m. carlson <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent fa33c3a commit 1ff57c1

File tree

4 files changed

+41
-40
lines changed

4 files changed

+41
-40
lines changed

combine-diff.c

Lines changed: 28 additions & 28 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->sha1, q->queue[i]->two->sha1);
47+
hashcpy(p->oid.hash, q->queue[i]->two->sha1);
4848
p->mode = q->queue[i]->two->mode;
49-
hashcpy(p->parent[n].sha1, q->queue[i]->one->sha1);
49+
hashcpy(p->parent[n].oid.hash, q->queue[i]->one->sha1);
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].sha1, q->queue[i]->one->sha1);
80+
hashcpy(p->parent[n].oid.hash, q->queue[i]->one->sha1);
8181
p->parent[n].mode = q->queue[i]->one->mode;
8282
p->parent[n].status = q->queue[i]->status;
8383

@@ -284,7 +284,7 @@ static struct lline *coalesce_lines(struct lline *base, int *lenbase,
284284
return base;
285285
}
286286

287-
static char *grab_blob(const unsigned char *sha1, unsigned int mode,
287+
static char *grab_blob(const struct object_id *oid, unsigned int mode,
288288
unsigned long *size, struct userdiff_driver *textconv,
289289
const char *path)
290290
{
@@ -294,20 +294,20 @@ static char *grab_blob(const unsigned char *sha1, unsigned int mode,
294294
if (S_ISGITLINK(mode)) {
295295
blob = xmalloc(100);
296296
*size = snprintf(blob, 100,
297-
"Subproject commit %s\n", sha1_to_hex(sha1));
298-
} else if (is_null_sha1(sha1)) {
297+
"Subproject commit %s\n", oid_to_hex(oid));
298+
} else if (is_null_oid(oid)) {
299299
/* deleted blob */
300300
*size = 0;
301301
return xcalloc(1, 1);
302302
} else if (textconv) {
303303
struct diff_filespec *df = alloc_filespec(path);
304-
fill_filespec(df, sha1, 1, mode);
304+
fill_filespec(df, oid->hash, 1, mode);
305305
*size = fill_textconv(textconv, df, &blob);
306306
free_filespec(df);
307307
} else {
308-
blob = read_sha1_file(sha1, &type, size);
308+
blob = read_sha1_file(oid->hash, &type, size);
309309
if (type != OBJ_BLOB)
310-
die("object '%s' is not a blob!", sha1_to_hex(sha1));
310+
die("object '%s' is not a blob!", oid_to_hex(oid));
311311
}
312312
return blob;
313313
}
@@ -389,7 +389,7 @@ static void consume_line(void *state_, char *line, unsigned long len)
389389
}
390390
}
391391

392-
static void combine_diff(const unsigned char *parent, unsigned int mode,
392+
static void combine_diff(const struct object_id *parent, unsigned int mode,
393393
mmfile_t *result_file,
394394
struct sline *sline, unsigned int cnt, int n,
395395
int num_parent, int result_deleted,
@@ -897,7 +897,7 @@ static void show_combined_header(struct combine_diff_path *elem,
897897
int show_file_header)
898898
{
899899
struct diff_options *opt = &rev->diffopt;
900-
int abbrev = DIFF_OPT_TST(opt, FULL_INDEX) ? 40 : DEFAULT_ABBREV;
900+
int abbrev = DIFF_OPT_TST(opt, FULL_INDEX) ? GIT_SHA1_HEXSZ : DEFAULT_ABBREV;
901901
const char *a_prefix = opt->a_prefix ? opt->a_prefix : "a/";
902902
const char *b_prefix = opt->b_prefix ? opt->b_prefix : "b/";
903903
const char *c_meta = diff_get_color_opt(opt, DIFF_METAINFO);
@@ -914,11 +914,11 @@ static void show_combined_header(struct combine_diff_path *elem,
914914
"", elem->path, line_prefix, c_meta, c_reset);
915915
printf("%s%sindex ", line_prefix, c_meta);
916916
for (i = 0; i < num_parent; i++) {
917-
abb = find_unique_abbrev(elem->parent[i].sha1,
917+
abb = find_unique_abbrev(elem->parent[i].oid.hash,
918918
abbrev);
919919
printf("%s%s", i ? "," : "", abb);
920920
}
921-
abb = find_unique_abbrev(elem->sha1, abbrev);
921+
abb = find_unique_abbrev(elem->oid.hash, abbrev);
922922
printf("..%s%s\n", abb, c_reset);
923923

924924
if (mode_differs) {
@@ -991,7 +991,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
991991

992992
/* Read the result of merge first */
993993
if (!working_tree_file)
994-
result = grab_blob(elem->sha1, elem->mode, &result_size,
994+
result = grab_blob(&elem->oid, elem->mode, &result_size,
995995
textconv, elem->path);
996996
else {
997997
/* Used by diff-tree to read from the working tree */
@@ -1013,12 +1013,12 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
10131013
result = strbuf_detach(&buf, NULL);
10141014
elem->mode = canon_mode(st.st_mode);
10151015
} else if (S_ISDIR(st.st_mode)) {
1016-
unsigned char sha1[20];
1017-
if (resolve_gitlink_ref(elem->path, "HEAD", sha1) < 0)
1018-
result = grab_blob(elem->sha1, elem->mode,
1016+
struct object_id oid;
1017+
if (resolve_gitlink_ref(elem->path, "HEAD", oid.hash) < 0)
1018+
result = grab_blob(&elem->oid, elem->mode,
10191019
&result_size, NULL, NULL);
10201020
else
1021-
result = grab_blob(sha1, elem->mode,
1021+
result = grab_blob(&oid, elem->mode,
10221022
&result_size, NULL, NULL);
10231023
} else if (textconv) {
10241024
struct diff_filespec *df = alloc_filespec(elem->path);
@@ -1090,7 +1090,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
10901090
for (i = 0; !is_binary && i < num_parent; i++) {
10911091
char *buf;
10921092
unsigned long size;
1093-
buf = grab_blob(elem->parent[i].sha1,
1093+
buf = grab_blob(&elem->parent[i].oid,
10941094
elem->parent[i].mode,
10951095
&size, NULL, NULL);
10961096
if (buffer_is_binary(buf, size))
@@ -1139,14 +1139,14 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
11391139
for (i = 0; i < num_parent; i++) {
11401140
int j;
11411141
for (j = 0; j < i; j++) {
1142-
if (!hashcmp(elem->parent[i].sha1,
1143-
elem->parent[j].sha1)) {
1142+
if (!oidcmp(&elem->parent[i].oid,
1143+
&elem->parent[j].oid)) {
11441144
reuse_combine_diff(sline, cnt, i, j);
11451145
break;
11461146
}
11471147
}
11481148
if (i <= j)
1149-
combine_diff(elem->parent[i].sha1,
1149+
combine_diff(&elem->parent[i].oid,
11501150
elem->parent[i].mode,
11511151
&result_file, sline,
11521152
cnt, i, num_parent, result_deleted,
@@ -1206,9 +1206,9 @@ static void show_raw_diff(struct combine_diff_path *p, int num_parent, struct re
12061206

12071207
/* Show sha1's */
12081208
for (i = 0; i < num_parent; i++)
1209-
printf(" %s", diff_unique_abbrev(p->parent[i].sha1,
1209+
printf(" %s", diff_unique_abbrev(p->parent[i].oid.hash,
12101210
opt->abbrev));
1211-
printf(" %s ", diff_unique_abbrev(p->sha1, opt->abbrev));
1211+
printf(" %s ", diff_unique_abbrev(p->oid.hash, opt->abbrev));
12121212
}
12131213

12141214
if (opt->output_format & (DIFF_FORMAT_RAW | DIFF_FORMAT_NAME_STATUS)) {
@@ -1271,16 +1271,16 @@ static struct diff_filepair *combined_pair(struct combine_diff_path *p,
12711271
for (i = 0; i < num_parent; i++) {
12721272
pair->one[i].path = p->path;
12731273
pair->one[i].mode = p->parent[i].mode;
1274-
hashcpy(pair->one[i].sha1, p->parent[i].sha1);
1275-
pair->one[i].sha1_valid = !is_null_sha1(p->parent[i].sha1);
1274+
hashcpy(pair->one[i].sha1, p->parent[i].oid.hash);
1275+
pair->one[i].sha1_valid = !is_null_oid(&p->parent[i].oid);
12761276
pair->one[i].has_more_entries = 1;
12771277
}
12781278
pair->one[num_parent - 1].has_more_entries = 0;
12791279

12801280
pair->two->path = p->path;
12811281
pair->two->mode = p->mode;
1282-
hashcpy(pair->two->sha1, p->sha1);
1283-
pair->two->sha1_valid = !is_null_sha1(p->sha1);
1282+
hashcpy(pair->two->sha1, p->oid.hash);
1283+
pair->two->sha1_valid = !is_null_oid(&p->oid);
12841284
return pair;
12851285
}
12861286

diff-lib.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
124124
dpath->next = NULL;
125125
memcpy(dpath->path, ce->name, path_len);
126126
dpath->path[path_len] = '\0';
127-
hashclr(dpath->sha1);
127+
oidclr(&dpath->oid);
128128
memset(&(dpath->parent[0]), 0,
129129
sizeof(struct combine_diff_parent)*5);
130130

@@ -154,7 +154,7 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
154154
if (2 <= stage) {
155155
int mode = nce->ce_mode;
156156
num_compare_stages++;
157-
hashcpy(dpath->parent[stage-2].sha1, nce->sha1);
157+
hashcpy(dpath->parent[stage-2].oid.hash, nce->sha1);
158158
dpath->parent[stage-2].mode = ce_mode_from_stat(nce, mode);
159159
dpath->parent[stage-2].status =
160160
DIFF_STATUS_MODIFIED;
@@ -335,14 +335,14 @@ static int show_modified(struct rev_info *revs,
335335
memcpy(p->path, new->name, pathlen);
336336
p->path[pathlen] = 0;
337337
p->mode = mode;
338-
hashclr(p->sha1);
338+
oidclr(&p->oid);
339339
memset(p->parent, 0, 2 * sizeof(struct combine_diff_parent));
340340
p->parent[0].status = DIFF_STATUS_MODIFIED;
341341
p->parent[0].mode = new->ce_mode;
342-
hashcpy(p->parent[0].sha1, new->sha1);
342+
hashcpy(p->parent[0].oid.hash, new->sha1);
343343
p->parent[1].status = DIFF_STATUS_MODIFIED;
344344
p->parent[1].mode = old->ce_mode;
345-
hashcpy(p->parent[1].sha1, old->sha1);
345+
hashcpy(p->parent[1].oid.hash, old->sha1);
346346
show_combined_diff(p, 2, revs->dense_combined_merges, revs);
347347
free(p);
348348
return 0;

diff.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include "tree-walk.h"
88
#include "pathspec.h"
9+
#include "object.h"
910

1011
struct rev_info;
1112
struct diff_options;
@@ -207,11 +208,11 @@ struct combine_diff_path {
207208
struct combine_diff_path *next;
208209
char *path;
209210
unsigned int mode;
210-
unsigned char sha1[20];
211+
struct object_id oid;
211212
struct combine_diff_parent {
212213
char status;
213214
unsigned int mode;
214-
unsigned char sha1[20];
215+
struct object_id oid;
215216
} parent[FLEX_ARRAY];
216217
};
217218
#define combine_diff_path_size(n, l) \

tree-diff.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ static int emit_diff_first_parent_only(struct diff_options *opt, struct combine_
6464
{
6565
struct combine_diff_parent *p0 = &p->parent[0];
6666
if (p->mode && p0->mode) {
67-
opt->change(opt, p0->mode, p->mode, p0->sha1, p->sha1,
67+
opt->change(opt, p0->mode, p->mode, p0->oid.hash, p->oid.hash,
6868
1, 1, p->path, 0, 0);
6969
}
7070
else {
@@ -74,11 +74,11 @@ static int emit_diff_first_parent_only(struct diff_options *opt, struct combine_
7474

7575
if (p->mode) {
7676
addremove = '+';
77-
sha1 = p->sha1;
77+
sha1 = p->oid.hash;
7878
mode = p->mode;
7979
} else {
8080
addremove = '-';
81-
sha1 = p0->sha1;
81+
sha1 = p0->oid.hash;
8282
mode = p0->mode;
8383
}
8484

@@ -151,7 +151,7 @@ static struct combine_diff_path *path_appendnew(struct combine_diff_path *last,
151151
memcpy(p->path + base->len, path, pathlen);
152152
p->path[len] = 0;
153153
p->mode = mode;
154-
hashcpy(p->sha1, sha1 ? sha1 : null_sha1);
154+
hashcpy(p->oid.hash, sha1 ? sha1 : null_sha1);
155155

156156
return p;
157157
}
@@ -238,7 +238,7 @@ static struct combine_diff_path *emit_path(struct combine_diff_path *p,
238238
}
239239

240240
p->parent[i].mode = mode_i;
241-
hashcpy(p->parent[i].sha1, sha1_i ? sha1_i : null_sha1);
241+
hashcpy(p->parent[i].oid.hash, sha1_i ? sha1_i : null_sha1);
242242
}
243243

244244
keep = 1;

0 commit comments

Comments
 (0)