diff: convert struct combine_diff_path to object_id
Also, convert a constant to GIT_SHA1_HEXSZ. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
brian m. carlson committed
Mar 13, 2015 at 23:39 UTC
1ff57c13c54bc9d548178e012f77717f87f2655d
4 files changed
+41
-40
combine-diff.c
+28
-28
@@ -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->sha1, q->queue[i]->two->sha1);
47
+ hashcpy(p->oid.hash, q->queue[i]->two->sha1);
48
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);
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].sha1, q->queue[i]->one->sha1);
80
+ hashcpy(p->parent[n].oid.hash, q->queue[i]->one->sha1);
81
p->parent[n].mode = q->queue[i]->one->mode;
82
p->parent[n].status = q->queue[i]->status;
83
@@ -284,7 +284,7 @@ static struct lline *coalesce_lines(struct lline *base, int *lenbase,
284
return base;
285
}
286
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,
288
unsigned long *size, struct userdiff_driver *textconv,
289
const char *path)
290
{
@@ -294,20 +294,20 @@ static char *grab_blob(const unsigned char *sha1, unsigned int mode,
294
if (S_ISGITLINK(mode)) {
295
blob = xmalloc(100);
296
*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)) {
299
/* deleted blob */
300
*size = 0;
301
return xcalloc(1, 1);
302
} else if (textconv) {
303
struct diff_filespec *df = alloc_filespec(path);
304
- fill_filespec(df, sha1, 1, mode);
304
+ fill_filespec(df, oid->hash, 1, mode);
305
*size = fill_textconv(textconv, df, &blob);
306
free_filespec(df);
307
} else {
308
- blob = read_sha1_file(sha1, &type, size);
308
+ blob = read_sha1_file(oid->hash, &type, size);
309
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));
311
}
312
return blob;
313
}
@@ -389,7 +389,7 @@ static void consume_line(void *state_, char *line, unsigned long len)
389
}
390
}
391
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,
393
mmfile_t *result_file,
394
struct sline *sline, unsigned int cnt, int n,
395
int num_parent, int result_deleted,
@@ -897,7 +897,7 @@ static void show_combined_header(struct combine_diff_path *elem,
897
int show_file_header)
898
{
899
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;
901
const char *a_prefix = opt->a_prefix ? opt->a_prefix : "a/";
902
const char *b_prefix = opt->b_prefix ? opt->b_prefix : "b/";
903
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,
914
"", elem->path, line_prefix, c_meta, c_reset);
915
printf("%s%sindex ", line_prefix, c_meta);
916
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,
918
abbrev);
919
printf("%s%s", i ? "," : "", abb);
920
}
921
- abb = find_unique_abbrev(elem->sha1, abbrev);
921
+ abb = find_unique_abbrev(elem->oid.hash, abbrev);
922
printf("..%s%s\n", abb, c_reset);
923
924
if (mode_differs) {
@@ -991,7 +991,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
991
992
/* Read the result of merge first */
993
if (!working_tree_file)
994
- result = grab_blob(elem->sha1, elem->mode, &result_size,
994
+ result = grab_blob(&elem->oid, elem->mode, &result_size,
995
textconv, elem->path);
996
else {
997
/* 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,
1013
result = strbuf_detach(&buf, NULL);
1014
elem->mode = canon_mode(st.st_mode);
1015
} 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,
1019
&result_size, NULL, NULL);
1020
else
1021
- result = grab_blob(sha1, elem->mode,
1021
+ result = grab_blob(&oid, elem->mode,
1022
&result_size, NULL, NULL);
1023
} else if (textconv) {
1024
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,
1090
for (i = 0; !is_binary && i < num_parent; i++) {
1091
char *buf;
1092
unsigned long size;
1093
- buf = grab_blob(elem->parent[i].sha1,
1093
+ buf = grab_blob(&elem->parent[i].oid,
1094
elem->parent[i].mode,
1095
&size, NULL, NULL);
1096
if (buffer_is_binary(buf, size))
@@ -1139,14 +1139,14 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
1139
for (i = 0; i < num_parent; i++) {
1140
int j;
1141
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)) {
1144
reuse_combine_diff(sline, cnt, i, j);
1145
break;
1146
}
1147
}
1148
if (i <= j)
1149
- combine_diff(elem->parent[i].sha1,
1149
+ combine_diff(&elem->parent[i].oid,
1150
elem->parent[i].mode,
1151
&result_file, sline,
1152
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
1206
1207
/* Show sha1's */
1208
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,
1210
opt->abbrev));
1211
- printf(" %s ", diff_unique_abbrev(p->sha1, opt->abbrev));
1211
+ printf(" %s ", diff_unique_abbrev(p->oid.hash, opt->abbrev));
1212
}
1213
1214
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,
1271
for (i = 0; i < num_parent; i++) {
1272
pair->one[i].path = p->path;
1273
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);
1276
pair->one[i].has_more_entries = 1;
1277
}
1278
pair->one[num_parent - 1].has_more_entries = 0;
1279
1280
pair->two->path = p->path;
1281
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);
1284
return pair;
1285
}
1286
diff-lib.c
+5
-5
@@ -124,7 +124,7 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
124
dpath->next = NULL;
125
memcpy(dpath->path, ce->name, path_len);
126
dpath->path[path_len] = '\0';
127
- hashclr(dpath->sha1);
127
+ oidclr(&dpath->oid);
128
memset(&(dpath->parent[0]), 0,
129
sizeof(struct combine_diff_parent)*5);
130
@@ -154,7 +154,7 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
154
if (2 <= stage) {
155
int mode = nce->ce_mode;
156
num_compare_stages++;
157
- hashcpy(dpath->parent[stage-2].sha1, nce->sha1);
157
+ hashcpy(dpath->parent[stage-2].oid.hash, nce->sha1);
158
dpath->parent[stage-2].mode = ce_mode_from_stat(nce, mode);
159
dpath->parent[stage-2].status =
160
DIFF_STATUS_MODIFIED;
@@ -335,14 +335,14 @@ static int show_modified(struct rev_info *revs,
335
memcpy(p->path, new->name, pathlen);
336
p->path[pathlen] = 0;
337
p->mode = mode;
338
- hashclr(p->sha1);
338
+ oidclr(&p->oid);
339
memset(p->parent, 0, 2 * sizeof(struct combine_diff_parent));
340
p->parent[0].status = DIFF_STATUS_MODIFIED;
341
p->parent[0].mode = new->ce_mode;
342
- hashcpy(p->parent[0].sha1, new->sha1);
342
+ hashcpy(p->parent[0].oid.hash, new->sha1);
343
p->parent[1].status = DIFF_STATUS_MODIFIED;
344
p->parent[1].mode = old->ce_mode;
345
- hashcpy(p->parent[1].sha1, old->sha1);
345
+ hashcpy(p->parent[1].oid.hash, old->sha1);
346
show_combined_diff(p, 2, revs->dense_combined_merges, revs);
347
free(p);
348
return 0;
diff.h
+3
-2
@@ -6,6 +6,7 @@
6
7
#include "tree-walk.h"
8
#include "pathspec.h"
9
+#include "object.h"
10
11
struct rev_info;
12
struct diff_options;
@@ -207,11 +208,11 @@ struct combine_diff_path {
208
struct combine_diff_path *next;
209
char *path;
210
unsigned int mode;
210
- unsigned char sha1[20];
211
+ struct object_id oid;
212
struct combine_diff_parent {
213
char status;
214
unsigned int mode;
214
- unsigned char sha1[20];
215
+ struct object_id oid;
216
} parent[FLEX_ARRAY];
217
};
218
#define combine_diff_path_size(n, l) \
tree-diff.c
+5
-5
@@ -64,7 +64,7 @@ static int emit_diff_first_parent_only(struct diff_options *opt, struct combine_
64
{
65
struct combine_diff_parent *p0 = &p->parent[0];
66
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,
68
1, 1, p->path, 0, 0);
69
}
70
else {
@@ -74,11 +74,11 @@ static int emit_diff_first_parent_only(struct diff_options *opt, struct combine_
74
75
if (p->mode) {
76
addremove = '+';
77
- sha1 = p->sha1;
77
+ sha1 = p->oid.hash;
78
mode = p->mode;
79
} else {
80
addremove = '-';
81
- sha1 = p0->sha1;
81
+ sha1 = p0->oid.hash;
82
mode = p0->mode;
83
}
84
@@ -151,7 +151,7 @@ static struct combine_diff_path *path_appendnew(struct combine_diff_path *last,
151
memcpy(p->path + base->len, path, pathlen);
152
p->path[len] = 0;
153
p->mode = mode;
154
- hashcpy(p->sha1, sha1 ? sha1 : null_sha1);
154
+ hashcpy(p->oid.hash, sha1 ? sha1 : null_sha1);
155
156
return p;
157
}
@@ -238,7 +238,7 @@ static struct combine_diff_path *emit_path(struct combine_diff_path *p,
238
}
239
240
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);
242
}
243
244
keep = 1;