Skip to content

Commit e1fae93

Browse files
committed
Merge branch 'bc/object-id'
"uchar [40]" to "struct object_id" conversion continues. * bc/object-id: wt-status: convert to struct object_id builtin/merge-base: convert to struct object_id Convert object iteration callbacks to struct object_id sha1_file: introduce an nth_packed_object_oid function refs: simplify parsing of reflog entries refs: convert each_reflog_ent_fn to struct object_id reflog-walk: convert struct reflog_info to struct object_id builtin/replace: convert to struct object_id Convert remaining callers of resolve_refdup to object_id builtin/merge: convert to struct object_id builtin/clone: convert to struct object_id builtin/branch: convert to struct object_id builtin/grep: convert to struct object_id builtin/fmt-merge-message: convert to struct object_id builtin/fast-export: convert to struct object_id builtin/describe: convert to struct object_id builtin/diff-tree: convert to struct object_id builtin/commit: convert to struct object_id hex: introduce parse_oid_hex
2 parents 0a4ae91 + e86ab2c commit e1fae93

33 files changed

+494
-462
lines changed

builtin/branch.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ static const char * const builtin_branch_usage[] = {
3333
};
3434

3535
static const char *head;
36-
static unsigned char head_sha1[20];
36+
static struct object_id head_oid;
3737

3838
static int branch_use_color = -1;
3939
static char branch_colors[][COLOR_MAXLEN] = {
@@ -118,13 +118,13 @@ static int branch_merged(int kind, const char *name,
118118
if (kind == FILTER_REFS_BRANCHES) {
119119
struct branch *branch = branch_get(name);
120120
const char *upstream = branch_get_upstream(branch, NULL);
121-
unsigned char sha1[20];
121+
struct object_id oid;
122122

123123
if (upstream &&
124124
(reference_name = reference_name_to_free =
125125
resolve_refdup(upstream, RESOLVE_REF_READING,
126-
sha1, NULL)) != NULL)
127-
reference_rev = lookup_commit_reference(sha1);
126+
oid.hash, NULL)) != NULL)
127+
reference_rev = lookup_commit_reference(oid.hash);
128128
}
129129
if (!reference_rev)
130130
reference_rev = head_rev;
@@ -154,10 +154,10 @@ static int branch_merged(int kind, const char *name,
154154
}
155155

156156
static int check_branch_commit(const char *branchname, const char *refname,
157-
const unsigned char *sha1, struct commit *head_rev,
157+
const struct object_id *oid, struct commit *head_rev,
158158
int kinds, int force)
159159
{
160-
struct commit *rev = lookup_commit_reference(sha1);
160+
struct commit *rev = lookup_commit_reference(oid->hash);
161161
if (!rev) {
162162
error(_("Couldn't look up commit object for '%s'"), refname);
163163
return -1;
@@ -184,7 +184,7 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
184184
int quiet)
185185
{
186186
struct commit *head_rev = NULL;
187-
unsigned char sha1[20];
187+
struct object_id oid;
188188
char *name = NULL;
189189
const char *fmt;
190190
int i;
@@ -211,7 +211,7 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
211211
}
212212

213213
if (!force) {
214-
head_rev = lookup_commit_reference(head_sha1);
214+
head_rev = lookup_commit_reference(head_oid.hash);
215215
if (!head_rev)
216216
die(_("Couldn't look up commit object for HEAD"));
217217
}
@@ -239,7 +239,7 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
239239
RESOLVE_REF_READING
240240
| RESOLVE_REF_NO_RECURSE
241241
| RESOLVE_REF_ALLOW_BAD_NAME,
242-
sha1, &flags);
242+
oid.hash, &flags);
243243
if (!target) {
244244
error(remote_branch
245245
? _("remote-tracking branch '%s' not found.")
@@ -249,13 +249,13 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
249249
}
250250

251251
if (!(flags & (REF_ISSYMREF|REF_ISBROKEN)) &&
252-
check_branch_commit(bname.buf, name, sha1, head_rev, kinds,
252+
check_branch_commit(bname.buf, name, &oid, head_rev, kinds,
253253
force)) {
254254
ret = 1;
255255
goto next;
256256
}
257257

258-
if (delete_ref(NULL, name, is_null_sha1(sha1) ? NULL : sha1,
258+
if (delete_ref(NULL, name, is_null_oid(&oid) ? NULL : oid.hash,
259259
REF_NODEREF)) {
260260
error(remote_branch
261261
? _("Error deleting remote-tracking branch '%s'")
@@ -271,7 +271,7 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
271271
bname.buf,
272272
(flags & REF_ISBROKEN) ? "broken"
273273
: (flags & REF_ISSYMREF) ? target
274-
: find_unique_abbrev(sha1, DEFAULT_ABBREV));
274+
: find_unique_abbrev(oid.hash, DEFAULT_ABBREV));
275275
}
276276
delete_branch_config(bname.buf);
277277

@@ -604,7 +604,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
604604

605605
track = git_branch_track;
606606

607-
head = resolve_refdup("HEAD", 0, head_sha1, NULL);
607+
head = resolve_refdup("HEAD", 0, head_oid.hash, NULL);
608608
if (!head)
609609
die(_("Failed to resolve HEAD as a valid ref."));
610610
if (!strcmp(head, "HEAD"))

builtin/cat-file.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -409,20 +409,20 @@ static int batch_object_cb(const unsigned char sha1[20], void *vdata)
409409
return 0;
410410
}
411411

412-
static int batch_loose_object(const unsigned char *sha1,
412+
static int batch_loose_object(const struct object_id *oid,
413413
const char *path,
414414
void *data)
415415
{
416-
sha1_array_append(data, sha1);
416+
sha1_array_append(data, oid->hash);
417417
return 0;
418418
}
419419

420-
static int batch_packed_object(const unsigned char *sha1,
420+
static int batch_packed_object(const struct object_id *oid,
421421
struct packed_git *pack,
422422
uint32_t pos,
423423
void *data)
424424
{
425-
sha1_array_append(data, sha1);
425+
sha1_array_append(data, oid->hash);
426426
return 0;
427427
}
428428

builtin/clone.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ static void update_head(const struct ref *our, const struct ref *remote,
681681

682682
static int checkout(int submodule_progress)
683683
{
684-
unsigned char sha1[20];
684+
struct object_id oid;
685685
char *head;
686686
struct lock_file *lock_file;
687687
struct unpack_trees_options opts;
@@ -692,15 +692,15 @@ static int checkout(int submodule_progress)
692692
if (option_no_checkout)
693693
return 0;
694694

695-
head = resolve_refdup("HEAD", RESOLVE_REF_READING, sha1, NULL);
695+
head = resolve_refdup("HEAD", RESOLVE_REF_READING, oid.hash, NULL);
696696
if (!head) {
697697
warning(_("remote HEAD refers to nonexistent ref, "
698698
"unable to checkout.\n"));
699699
return 0;
700700
}
701701
if (!strcmp(head, "HEAD")) {
702702
if (advice_detached_head)
703-
detach_advice(sha1_to_hex(sha1));
703+
detach_advice(oid_to_hex(&oid));
704704
} else {
705705
if (!starts_with(head, "refs/heads/"))
706706
die(_("HEAD not found below refs/heads!"));
@@ -721,7 +721,7 @@ static int checkout(int submodule_progress)
721721
opts.src_index = &the_index;
722722
opts.dst_index = &the_index;
723723

724-
tree = parse_tree_indirect(sha1);
724+
tree = parse_tree_indirect(oid.hash);
725725
parse_tree(tree);
726726
init_tree_desc(&t, tree->buffer, tree->size);
727727
if (unpack_trees(1, &t, &opts) < 0)
@@ -731,7 +731,7 @@ static int checkout(int submodule_progress)
731731
die(_("unable to write new index file"));
732732

733733
err |= run_hook_le(NULL, "post-checkout", sha1_to_hex(null_sha1),
734-
sha1_to_hex(sha1), "1", NULL);
734+
oid_to_hex(&oid), "1", NULL);
735735

736736
if (!err && option_recursive) {
737737
struct argv_array args = ARGV_ARRAY_INIT;

builtin/commit.c

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ static const char *prepare_index(int argc, const char **argv, const char *prefix
496496
static int run_status(FILE *fp, const char *index_file, const char *prefix, int nowarn,
497497
struct wt_status *s)
498498
{
499-
unsigned char sha1[20];
499+
struct object_id oid;
500500

501501
if (s->relative_paths)
502502
s->prefix = prefix;
@@ -509,9 +509,9 @@ static int run_status(FILE *fp, const char *index_file, const char *prefix, int
509509
s->index_file = index_file;
510510
s->fp = fp;
511511
s->nowarn = nowarn;
512-
s->is_initial = get_sha1(s->reference, sha1) ? 1 : 0;
512+
s->is_initial = get_sha1(s->reference, oid.hash) ? 1 : 0;
513513
if (!s->is_initial)
514-
hashcpy(s->sha1_commit, sha1);
514+
hashcpy(s->sha1_commit, oid.hash);
515515
s->status_format = status_format;
516516
s->ignore_submodule_arg = ignore_submodule_arg;
517517

@@ -885,7 +885,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
885885
commitable = run_status(s->fp, index_file, prefix, 1, s);
886886
s->use_color = saved_color_setting;
887887
} else {
888-
unsigned char sha1[20];
888+
struct object_id oid;
889889
const char *parent = "HEAD";
890890

891891
if (!active_nr && read_cache() < 0)
@@ -894,7 +894,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
894894
if (amend)
895895
parent = "HEAD^1";
896896

897-
if (get_sha1(parent, sha1)) {
897+
if (get_sha1(parent, oid.hash)) {
898898
int i, ita_nr = 0;
899899

900900
for (i = 0; i < active_nr; i++)
@@ -1332,7 +1332,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
13321332
{
13331333
static struct wt_status s;
13341334
int fd;
1335-
unsigned char sha1[20];
1335+
struct object_id oid;
13361336
static struct option builtin_status_options[] = {
13371337
OPT__VERBOSE(&verbose, N_("be verbose")),
13381338
OPT_SET_INT('s', "short", &status_format,
@@ -1382,9 +1382,9 @@ int cmd_status(int argc, const char **argv, const char *prefix)
13821382

13831383
fd = hold_locked_index(&index_lock, 0);
13841384

1385-
s.is_initial = get_sha1(s.reference, sha1) ? 1 : 0;
1385+
s.is_initial = get_sha1(s.reference, oid.hash) ? 1 : 0;
13861386
if (!s.is_initial)
1387-
hashcpy(s.sha1_commit, sha1);
1387+
hashcpy(s.sha1_commit, oid.hash);
13881388

13891389
s.ignore_submodule_arg = ignore_submodule_arg;
13901390
s.status_format = status_format;
@@ -1418,19 +1418,19 @@ static const char *implicit_ident_advice(void)
14181418

14191419
}
14201420

1421-
static void print_summary(const char *prefix, const unsigned char *sha1,
1421+
static void print_summary(const char *prefix, const struct object_id *oid,
14221422
int initial_commit)
14231423
{
14241424
struct rev_info rev;
14251425
struct commit *commit;
14261426
struct strbuf format = STRBUF_INIT;
1427-
unsigned char junk_sha1[20];
1427+
struct object_id junk_oid;
14281428
const char *head;
14291429
struct pretty_print_context pctx = {0};
14301430
struct strbuf author_ident = STRBUF_INIT;
14311431
struct strbuf committer_ident = STRBUF_INIT;
14321432

1433-
commit = lookup_commit(sha1);
1433+
commit = lookup_commit(oid->hash);
14341434
if (!commit)
14351435
die(_("couldn't look up newly created commit"));
14361436
if (parse_commit(commit))
@@ -1477,7 +1477,7 @@ static void print_summary(const char *prefix, const unsigned char *sha1,
14771477
rev.diffopt.break_opt = 0;
14781478
diff_setup_done(&rev.diffopt);
14791479

1480-
head = resolve_ref_unsafe("HEAD", 0, junk_sha1, NULL);
1480+
head = resolve_ref_unsafe("HEAD", 0, junk_oid.hash, NULL);
14811481
if (!strcmp(head, "HEAD"))
14821482
head = _("detached HEAD");
14831483
else
@@ -1522,8 +1522,8 @@ static int git_commit_config(const char *k, const char *v, void *cb)
15221522
return git_status_config(k, v, s);
15231523
}
15241524

1525-
static int run_rewrite_hook(const unsigned char *oldsha1,
1526-
const unsigned char *newsha1)
1525+
static int run_rewrite_hook(const struct object_id *oldoid,
1526+
const struct object_id *newoid)
15271527
{
15281528
struct child_process proc = CHILD_PROCESS_INIT;
15291529
const char *argv[3];
@@ -1544,7 +1544,7 @@ static int run_rewrite_hook(const unsigned char *oldsha1,
15441544
code = start_command(&proc);
15451545
if (code)
15461546
return code;
1547-
strbuf_addf(&sb, "%s %s\n", sha1_to_hex(oldsha1), sha1_to_hex(newsha1));
1547+
strbuf_addf(&sb, "%s %s\n", oid_to_hex(oldoid), oid_to_hex(newoid));
15481548
sigchain_push(SIGPIPE, SIG_IGN);
15491549
write_in_full(proc.in, sb.buf, sb.len);
15501550
close(proc.in);
@@ -1636,7 +1636,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
16361636
struct strbuf author_ident = STRBUF_INIT;
16371637
const char *index_file, *reflog_msg;
16381638
char *nl;
1639-
unsigned char sha1[20];
1639+
struct object_id oid;
16401640
struct commit_list *parents = NULL;
16411641
struct stat statbuf;
16421642
struct commit *current_head = NULL;
@@ -1651,10 +1651,10 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
16511651
status_format = STATUS_FORMAT_NONE; /* Ignore status.short */
16521652
s.colopts = 0;
16531653

1654-
if (get_sha1("HEAD", sha1))
1654+
if (get_sha1("HEAD", oid.hash))
16551655
current_head = NULL;
16561656
else {
1657-
current_head = lookup_commit_or_die(sha1, "HEAD");
1657+
current_head = lookup_commit_or_die(oid.hash, "HEAD");
16581658
if (parse_commit(current_head))
16591659
die(_("could not parse HEAD commit"));
16601660
}
@@ -1759,7 +1759,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
17591759
}
17601760

17611761
if (commit_tree_extended(sb.buf, sb.len, active_cache_tree->sha1,
1762-
parents, sha1, author_ident.buf, sign_commit, extra)) {
1762+
parents, oid.hash, author_ident.buf, sign_commit, extra)) {
17631763
rollback_index_files();
17641764
die(_("failed to write commit object"));
17651765
}
@@ -1776,7 +1776,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
17761776

17771777
transaction = ref_transaction_begin(&err);
17781778
if (!transaction ||
1779-
ref_transaction_update(transaction, "HEAD", sha1,
1779+
ref_transaction_update(transaction, "HEAD", oid.hash,
17801780
current_head
17811781
? current_head->object.oid.hash : null_sha1,
17821782
0, sb.buf, &err) ||
@@ -1805,13 +1805,13 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
18051805
cfg = init_copy_notes_for_rewrite("amend");
18061806
if (cfg) {
18071807
/* we are amending, so current_head is not NULL */
1808-
copy_note_for_rewrite(cfg, current_head->object.oid.hash, sha1);
1808+
copy_note_for_rewrite(cfg, current_head->object.oid.hash, oid.hash);
18091809
finish_copy_notes_for_rewrite(cfg, "Notes added by 'git commit --amend'");
18101810
}
1811-
run_rewrite_hook(current_head->object.oid.hash, sha1);
1811+
run_rewrite_hook(&current_head->object.oid, &oid);
18121812
}
18131813
if (!quiet)
1814-
print_summary(prefix, sha1, !current_head);
1814+
print_summary(prefix, &oid, !current_head);
18151815

18161816
strbuf_release(&err);
18171817
return 0;

builtin/count-objects.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ static void loose_garbage(const char *path)
5353
report_garbage(PACKDIR_FILE_GARBAGE, path);
5454
}
5555

56-
static int count_loose(const unsigned char *sha1, const char *path, void *data)
56+
static int count_loose(const struct object_id *oid, const char *path, void *data)
5757
{
5858
struct stat st;
5959

@@ -62,7 +62,7 @@ static int count_loose(const unsigned char *sha1, const char *path, void *data)
6262
else {
6363
loose_size += on_disk_bytes(st);
6464
loose++;
65-
if (verbose && has_sha1_pack(sha1))
65+
if (verbose && has_sha1_pack(oid->hash))
6666
packed_loose++;
6767
}
6868
return 0;

0 commit comments

Comments
 (0)