builtin/blame: convert struct origin to use struct object_id
Convert struct origin to use struct object_id by applying the following semantic patch and the object_id transforms from contrib, plus the actual change to the struct: @@ struct origin E1; @@ - E1.blob_sha1 + E1.blob_oid.hash @@ struct origin *E1; @@ - E1->blob_sha1 + E1->blob_oid.hash Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
brian m. carlson committed
Sep 5, 2016 at 20:07 UTC
a7bcfa126b686ea9f16bbba75e53261330f1aa58
1 file changed
+20
-20
builtin/blame.c
+20
-20
@@ -120,7 +120,7 @@ struct origin {
120
*/
121
struct blame_entry *suspects;
122
mmfile_t file;
123
- unsigned char blob_sha1[20];
123
+ struct object_id blob_oid;
124
unsigned mode;
125
/* guilty gets set when shipping any suspects to the final
126
* blame list instead of other commits
@@ -188,15 +188,16 @@ static void fill_origin_blob(struct diff_options *opt,
188
189
num_read_blob++;
190
if (DIFF_OPT_TST(opt, ALLOW_TEXTCONV) &&
191
- textconv_object(o->path, o->mode, o->blob_sha1, 1, &file->ptr, &file_size))
191
+ textconv_object(o->path, o->mode, o->blob_oid.hash, 1, &file->ptr, &file_size))
192
;
193
else
194
- file->ptr = read_sha1_file(o->blob_sha1, &type, &file_size);
194
+ file->ptr = read_sha1_file(o->blob_oid.hash, &type,
195
+ &file_size);
196
file->size = file_size;
197
198
if (!file->ptr)
199
die("Cannot read blob %s for path %s",
199
- sha1_to_hex(o->blob_sha1),
200
+ oid_to_hex(&o->blob_oid),
201
o->path);
202
o->file = *file;
203
}
@@ -508,17 +509,17 @@ static struct origin *get_origin(struct scoreboard *sb,
509
*/
510
static int fill_blob_sha1_and_mode(struct origin *origin)
511
{
511
- if (!is_null_sha1(origin->blob_sha1))
512
+ if (!is_null_oid(&origin->blob_oid))
513
return 0;
514
if (get_tree_entry(origin->commit->object.oid.hash,
515
origin->path,
515
- origin->blob_sha1, &origin->mode))
516
+ origin->blob_oid.hash, &origin->mode))
517
goto error_out;
517
- if (sha1_object_info(origin->blob_sha1, NULL) != OBJ_BLOB)
518
+ if (sha1_object_info(origin->blob_oid.hash, NULL) != OBJ_BLOB)
519
goto error_out;
520
return 0;
521
error_out:
521
- hashclr(origin->blob_sha1);
522
+ oidclr(&origin->blob_oid);
523
origin->mode = S_IFINVALID;
524
return -1;
525
}
@@ -572,7 +573,7 @@ static struct origin *find_origin(struct scoreboard *sb,
573
if (!diff_queued_diff.nr) {
574
/* The path is the same as parent */
575
porigin = get_origin(sb, parent, origin->path);
575
- hashcpy(porigin->blob_sha1, origin->blob_sha1);
576
+ oidcpy(&porigin->blob_oid, &origin->blob_oid);
577
porigin->mode = origin->mode;
578
} else {
579
/*
@@ -598,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);
601
- hashcpy(porigin->blob_sha1, p->one->oid.hash);
602
+ oidcpy(&porigin->blob_oid, &p->one->oid);
603
porigin->mode = p->one->mode;
604
break;
605
case 'A':
@@ -644,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);
647
- hashcpy(porigin->blob_sha1, p->one->oid.hash);
648
+ oidcpy(&porigin->blob_oid, &p->one->oid);
649
porigin->mode = p->one->mode;
650
break;
651
}
@@ -1308,7 +1309,7 @@ static void find_copy_in_parent(struct scoreboard *sb,
1309
continue;
1310
1311
norigin = get_origin(sb, parent, p->one->path);
1311
- hashcpy(norigin->blob_sha1, p->one->oid.hash);
1312
+ oidcpy(&norigin->blob_oid, &p->one->oid);
1313
norigin->mode = p->one->mode;
1314
fill_origin_blob(&sb->revs->diffopt, norigin, &file_p);
1315
if (!file_p.ptr)
@@ -1458,15 +1459,14 @@ static void pass_blame(struct scoreboard *sb, struct origin *origin, int opt)
1459
porigin = find(sb, p, origin);
1460
if (!porigin)
1461
continue;
1461
- if (!hashcmp(porigin->blob_sha1, origin->blob_sha1)) {
1462
+ if (!oidcmp(&porigin->blob_oid, &origin->blob_oid)) {
1463
pass_whole_blame(sb, origin, porigin);
1464
origin_decref(porigin);
1465
goto finish;
1466
}
1467
for (j = same = 0; j < i; j++)
1468
if (sg_origin[j] &&
1468
- !hashcmp(sg_origin[j]->blob_sha1,
1469
- porigin->blob_sha1)) {
1469
+ !oidcmp(&sg_origin[j]->blob_oid, &porigin->blob_oid)) {
1470
same = 1;
1471
break;
1472
}
@@ -2388,7 +2388,7 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt,
2388
convert_to_git(path, buf.buf, buf.len, &buf, 0);
2389
origin->file.ptr = buf.buf;
2390
origin->file.size = buf.len;
2391
- pretend_sha1_file(buf.buf, buf.len, OBJ_BLOB, origin->blob_sha1);
2391
+ pretend_sha1_file(buf.buf, buf.len, OBJ_BLOB, origin->blob_oid.hash);
2392
2393
/*
2394
* Read the current index, replace the path entry with
@@ -2410,7 +2410,7 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt,
2410
}
2411
size = cache_entry_size(len);
2412
ce = xcalloc(1, size);
2413
- hashcpy(ce->oid.hash, origin->blob_sha1);
2413
+ oidcpy(&ce->oid, &origin->blob_oid);
2414
memcpy(ce->name, path, len);
2415
ce->ce_flags = create_ce_flags(0);
2416
ce->ce_namelen = len;
@@ -2793,16 +2793,16 @@ parse_done:
2793
die("no such path %s in %s", path, final_commit_name);
2794
2795
if (DIFF_OPT_TST(&sb.revs->diffopt, ALLOW_TEXTCONV) &&
2796
- textconv_object(path, o->mode, o->blob_sha1, 1, (char **) &sb.final_buf,
2796
+ textconv_object(path, o->mode, o->blob_oid.hash, 1, (char **) &sb.final_buf,
2797
&sb.final_buf_size))
2798
;
2799
else
2800
- sb.final_buf = read_sha1_file(o->blob_sha1, &type,
2800
+ sb.final_buf = read_sha1_file(o->blob_oid.hash, &type,
2801
&sb.final_buf_size);
2802
2803
if (!sb.final_buf)
2804
die("Cannot read blob %s for path %s",
2805
- sha1_to_hex(o->blob_sha1),
2805
+ oid_to_hex(&o->blob_oid),
2806
path);
2807
}
2808
num_read_blob++;