Skip to content

Commit a63d31b

Browse files
committed
Merge branch 'bc/cocci'
Conversion from unsigned char sha1[20] to struct object_id continues. * bc/cocci: diff: convert prep_temp_blob() to struct object_id merge-recursive: convert merge_recursive_generic() to object_id merge-recursive: convert leaf functions to use struct object_id merge-recursive: convert struct merge_file_info to object_id merge-recursive: convert struct stage_data to use object_id diff: rename struct diff_filespec's sha1_valid member diff: convert struct diff_filespec to struct object_id coccinelle: apply object_id Coccinelle transformations coccinelle: convert hashcpy() with null_sha1 to hashclr() contrib/coccinelle: add basic Coccinelle transforms hex: add oid_to_hex_r()
2 parents 63641fb + 09bdff2 commit a63d31b

25 files changed

+403
-283
lines changed

bisect.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,7 @@ static void handle_bad_merge_base(void)
754754
static void handle_skipped_merge_base(const unsigned char *mb)
755755
{
756756
char *mb_hex = sha1_to_hex(mb);
757-
char *bad_hex = sha1_to_hex(current_bad_oid->hash);
757+
char *bad_hex = oid_to_hex(current_bad_oid);
758758
char *good_hex = join_sha1_array_hex(&good_revs, ' ');
759759

760760
warning(_("the merge base between %s and [%s] "

builtin/blame.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@ static struct origin *find_origin(struct scoreboard *sb,
598598
p->status);
599599
case 'M':
600600
porigin = get_origin(sb, parent, origin->path);
601-
hashcpy(porigin->blob_sha1, p->one->sha1);
601+
hashcpy(porigin->blob_sha1, p->one->oid.hash);
602602
porigin->mode = p->one->mode;
603603
break;
604604
case 'A':
@@ -644,7 +644,7 @@ static struct origin *find_rename(struct scoreboard *sb,
644644
if ((p->status == 'R' || p->status == 'C') &&
645645
!strcmp(p->two->path, origin->path)) {
646646
porigin = get_origin(sb, parent, p->one->path);
647-
hashcpy(porigin->blob_sha1, p->one->sha1);
647+
hashcpy(porigin->blob_sha1, p->one->oid.hash);
648648
porigin->mode = p->one->mode;
649649
break;
650650
}
@@ -1308,7 +1308,7 @@ static void find_copy_in_parent(struct scoreboard *sb,
13081308
continue;
13091309

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

builtin/fast-export.c

+5-5
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/merge-recursive.c

+10-10
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ static const char builtin_merge_recursive_usage[] =
99

1010
static const char *better_branch_name(const char *branch)
1111
{
12-
static char githead_env[8 + 40 + 1];
12+
static char githead_env[8 + GIT_SHA1_HEXSZ + 1];
1313
char *name;
1414

15-
if (strlen(branch) != 40)
15+
if (strlen(branch) != GIT_SHA1_HEXSZ)
1616
return branch;
1717
xsnprintf(githead_env, sizeof(githead_env), "GITHEAD_%s", branch);
1818
name = getenv(githead_env);
@@ -21,10 +21,10 @@ static const char *better_branch_name(const char *branch)
2121

2222
int cmd_merge_recursive(int argc, const char **argv, const char *prefix)
2323
{
24-
const unsigned char *bases[21];
24+
const struct object_id *bases[21];
2525
unsigned bases_count = 0;
2626
int i, failed;
27-
unsigned char h1[20], h2[20];
27+
struct object_id h1, h2;
2828
struct merge_options o;
2929
struct commit *result;
3030

@@ -46,10 +46,10 @@ int cmd_merge_recursive(int argc, const char **argv, const char *prefix)
4646
continue;
4747
}
4848
if (bases_count < ARRAY_SIZE(bases)-1) {
49-
unsigned char *sha = xmalloc(20);
50-
if (get_sha1(argv[i], sha))
49+
struct object_id *oid = xmalloc(sizeof(struct object_id));
50+
if (get_oid(argv[i], oid))
5151
die("Could not parse object '%s'", argv[i]);
52-
bases[bases_count++] = sha;
52+
bases[bases_count++] = oid;
5353
}
5454
else
5555
warning("Cannot handle more than %d bases. "
@@ -62,9 +62,9 @@ int cmd_merge_recursive(int argc, const char **argv, const char *prefix)
6262
o.branch1 = argv[++i];
6363
o.branch2 = argv[++i];
6464

65-
if (get_sha1(o.branch1, h1))
65+
if (get_oid(o.branch1, &h1))
6666
die("Could not resolve ref '%s'", o.branch1);
67-
if (get_sha1(o.branch2, h2))
67+
if (get_oid(o.branch2, &h2))
6868
die("Could not resolve ref '%s'", o.branch2);
6969

7070
o.branch1 = better_branch_name(o.branch1);
@@ -73,7 +73,7 @@ int cmd_merge_recursive(int argc, const char **argv, const char *prefix)
7373
if (o.verbosity >= 3)
7474
printf("Merging %s with %s\n", o.branch1, o.branch2);
7575

76-
failed = merge_recursive_generic(&o, h1, h2, bases_count, bases, &result);
76+
failed = merge_recursive_generic(&o, &h1, &h2, bases_count, bases, &result);
7777
if (failed < 0)
7878
return 128; /* die() error code */
7979
return failed;

builtin/merge.c

+7-8
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ static void merge_name(const char *remote, struct strbuf *msg)
501501
if (ref_exists(truname.buf)) {
502502
strbuf_addf(msg,
503503
"%s\t\tbranch '%s'%s of .\n",
504-
sha1_to_hex(remote_head->object.oid.hash),
504+
oid_to_hex(&remote_head->object.oid),
505505
truname.buf + 11,
506506
(early ? " (early part)" : ""));
507507
strbuf_release(&truname);
@@ -515,15 +515,15 @@ static void merge_name(const char *remote, struct strbuf *msg)
515515
desc = merge_remote_util(remote_head);
516516
if (desc && desc->obj && desc->obj->type == OBJ_TAG) {
517517
strbuf_addf(msg, "%s\t\t%s '%s'\n",
518-
sha1_to_hex(desc->obj->oid.hash),
518+
oid_to_hex(&desc->obj->oid),
519519
typename(desc->obj->type),
520520
remote);
521521
goto cleanup;
522522
}
523523
}
524524

525525
strbuf_addf(msg, "%s\t\tcommit '%s'\n",
526-
sha1_to_hex(remote_head->object.oid.hash), remote);
526+
oid_to_hex(&remote_head->object.oid), remote);
527527
cleanup:
528528
strbuf_release(&buf);
529529
strbuf_release(&bname);
@@ -1366,7 +1366,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
13661366
for (p = remoteheads; p; p = p->next) {
13671367
struct commit *commit = p->item;
13681368
strbuf_addf(&buf, "GITHEAD_%s",
1369-
sha1_to_hex(commit->object.oid.hash));
1369+
oid_to_hex(&commit->object.oid));
13701370
setenv(buf.buf, merge_remote_util(commit)->name, 1);
13711371
strbuf_reset(&buf);
13721372
if (fast_forward != FF_ONLY &&
@@ -1425,7 +1425,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
14251425
goto done;
14261426
} else if (fast_forward != FF_NO && !remoteheads->next &&
14271427
!common->next &&
1428-
!hashcmp(common->item->object.oid.hash, head_commit->object.oid.hash)) {
1428+
!oidcmp(&common->item->object.oid, &head_commit->object.oid)) {
14291429
/* Again the most common case of merging one remote. */
14301430
struct strbuf msg = STRBUF_INIT;
14311431
struct commit *commit;
@@ -1499,8 +1499,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
14991499
* HEAD^^" would be missed.
15001500
*/
15011501
common_one = get_merge_bases(head_commit, j->item);
1502-
if (hashcmp(common_one->item->object.oid.hash,
1503-
j->item->object.oid.hash)) {
1502+
if (oidcmp(&common_one->item->object.oid, &j->item->object.oid)) {
15041503
up_to_date = 0;
15051504
break;
15061505
}
@@ -1530,7 +1529,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
15301529
* Stash away the local changes so that we can try more than one.
15311530
*/
15321531
save_state(stash))
1533-
hashcpy(stash, null_sha1);
1532+
hashclr(stash);
15341533

15351534
for (i = 0; i < use_strategies_nr; i++) {
15361535
int ret;

builtin/reset.c

+2-2
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'"),

builtin/unpack-objects.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ static void unpack_delta_entry(enum object_type type, unsigned long delta_size,
355355
return; /* we are done */
356356
else {
357357
/* cannot resolve yet --- queue it */
358-
hashcpy(obj_list[nr].sha1, null_sha1);
358+
hashclr(obj_list[nr].sha1);
359359
add_delta_to_list(nr, base_sha1, 0, delta_data, delta_size);
360360
return;
361361
}
@@ -406,7 +406,7 @@ static void unpack_delta_entry(enum object_type type, unsigned long delta_size,
406406
* The delta base object is itself a delta that
407407
* has not been resolved yet.
408408
*/
409-
hashcpy(obj_list[nr].sha1, null_sha1);
409+
hashclr(obj_list[nr].sha1);
410410
add_delta_to_list(nr, null_sha1, base_offset, delta_data, delta_size);
411411
return;
412412
}

cache.h

+1
Original file line numberDiff line numberDiff line change
@@ -1193,6 +1193,7 @@ extern int get_oid_hex(const char *hex, struct object_id *sha1);
11931193
* printf("%s -> %s", sha1_to_hex(one), sha1_to_hex(two));
11941194
*/
11951195
extern char *sha1_to_hex_r(char *out, const unsigned char *sha1);
1196+
extern char *oid_to_hex_r(char *out, const struct object_id *oid);
11961197
extern char *sha1_to_hex(const unsigned char *sha1); /* static buffer result! */
11971198
extern char *oid_to_hex(const struct object_id *oid); /* same static buffer as sha1_to_hex */
11981199

combine-diff.c

+7-7
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,16 +1268,16 @@ 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);
1272-
pair->one[i].sha1_valid = !is_null_oid(&p->parent[i].oid);
1271+
oidcpy(&pair->one[i].oid, &p->parent[i].oid);
1272+
pair->one[i].oid_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);
1280-
pair->two->sha1_valid = !is_null_oid(&p->oid);
1279+
oidcpy(&pair->two->oid, &p->oid);
1280+
pair->two->oid_valid = !is_null_oid(&p->oid);
12811281
return pair;
12821282
}
12831283

contrib/coccinelle/README

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
This directory provides examples of Coccinelle (http://coccinelle.lip6.fr/)
2+
semantic patches that might be useful to developers.

contrib/coccinelle/object_id.cocci

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
@@
2+
expression E1;
3+
@@
4+
- is_null_sha1(E1.hash)
5+
+ is_null_oid(&E1)
6+
7+
@@
8+
expression E1;
9+
@@
10+
- is_null_sha1(E1->hash)
11+
+ is_null_oid(E1)
12+
13+
@@
14+
expression E1;
15+
@@
16+
- sha1_to_hex(E1.hash)
17+
+ oid_to_hex(&E1)
18+
19+
@@
20+
expression E1;
21+
@@
22+
- sha1_to_hex(E1->hash)
23+
+ oid_to_hex(E1)
24+
25+
@@
26+
expression E1;
27+
@@
28+
- sha1_to_hex_r(E1.hash)
29+
+ oid_to_hex_r(&E1)
30+
31+
@@
32+
expression E1;
33+
@@
34+
- sha1_to_hex_r(E1->hash)
35+
+ oid_to_hex_r(E1)
36+
37+
@@
38+
expression E1;
39+
@@
40+
- hashclr(E1.hash)
41+
+ oidclr(&E1)
42+
43+
@@
44+
expression E1;
45+
@@
46+
- hashclr(E1->hash)
47+
+ oidclr(E1)
48+
49+
@@
50+
expression E1, E2;
51+
@@
52+
- hashcmp(E1.hash, E2.hash)
53+
+ oidcmp(&E1, &E2)
54+
55+
@@
56+
expression E1, E2;
57+
@@
58+
- hashcmp(E1->hash, E2->hash)
59+
+ oidcmp(E1, E2)
60+
61+
@@
62+
expression E1, E2;
63+
@@
64+
- hashcmp(E1->hash, E2.hash)
65+
+ oidcmp(E1, &E2)
66+
67+
@@
68+
expression E1, E2;
69+
@@
70+
- hashcmp(E1.hash, E2->hash)
71+
+ oidcmp(&E1, E2)
72+
73+
@@
74+
expression E1, E2;
75+
@@
76+
- hashcpy(E1.hash, E2.hash)
77+
+ oidcpy(&E1, &E2)
78+
79+
@@
80+
expression E1, E2;
81+
@@
82+
- hashcpy(E1->hash, E2->hash)
83+
+ oidcpy(E1, E2)
84+
85+
@@
86+
expression E1, E2;
87+
@@
88+
- hashcpy(E1->hash, E2.hash)
89+
+ oidcpy(E1, &E2)
90+
91+
@@
92+
expression E1, E2;
93+
@@
94+
- hashcpy(E1.hash, E2->hash)
95+
+ oidcpy(&E1, E2)

0 commit comments

Comments
 (0)