Skip to content

Commit e86ab2c

Browse files
bk2204gitster
authored andcommitted
wt-status: convert to struct object_id
Convert the remaining uses of unsigned char [20] to struct object_id. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent d0ae910 commit e86ab2c

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

wt-status.c

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,16 +1115,16 @@ static void abbrev_sha1_in_line(struct strbuf *line)
11151115

11161116
split = strbuf_split_max(line, ' ', 3);
11171117
if (split[0] && split[1]) {
1118-
unsigned char sha1[20];
1118+
struct object_id oid;
11191119

11201120
/*
11211121
* strbuf_split_max left a space. Trim it and re-add
11221122
* it after abbreviation.
11231123
*/
11241124
strbuf_trim(split[1]);
1125-
if (!get_sha1(split[1]->buf, sha1)) {
1125+
if (!get_oid(split[1]->buf, &oid)) {
11261126
strbuf_reset(split[1]);
1127-
strbuf_add_unique_abbrev(split[1], sha1,
1127+
strbuf_add_unique_abbrev(split[1], oid.hash,
11281128
DEFAULT_ABBREV);
11291129
strbuf_addch(split[1], ' ');
11301130
strbuf_reset(line);
@@ -1340,7 +1340,7 @@ static void show_bisect_in_progress(struct wt_status *s,
13401340
static char *get_branch(const struct worktree *wt, const char *path)
13411341
{
13421342
struct strbuf sb = STRBUF_INIT;
1343-
unsigned char sha1[20];
1343+
struct object_id oid;
13441344
const char *branch_name;
13451345

13461346
if (strbuf_read_file(&sb, worktree_git_path(wt, "%s", path), 0) <= 0)
@@ -1354,9 +1354,9 @@ static char *get_branch(const struct worktree *wt, const char *path)
13541354
strbuf_remove(&sb, 0, branch_name - sb.buf);
13551355
else if (starts_with(sb.buf, "refs/"))
13561356
;
1357-
else if (!get_sha1_hex(sb.buf, sha1)) {
1357+
else if (!get_oid_hex(sb.buf, &oid)) {
13581358
strbuf_reset(&sb);
1359-
strbuf_add_unique_abbrev(&sb, sha1, DEFAULT_ABBREV);
1359+
strbuf_add_unique_abbrev(&sb, oid.hash, DEFAULT_ABBREV);
13601360
} else if (!strcmp(sb.buf, "detached HEAD")) /* rebase */
13611361
goto got_nothing;
13621362
else /* bisect */
@@ -1370,7 +1370,7 @@ static char *get_branch(const struct worktree *wt, const char *path)
13701370

13711371
struct grab_1st_switch_cbdata {
13721372
struct strbuf buf;
1373-
unsigned char nsha1[20];
1373+
struct object_id noid;
13741374
};
13751375

13761376
static int grab_1st_switch(struct object_id *ooid, struct object_id *noid,
@@ -1387,7 +1387,7 @@ static int grab_1st_switch(struct object_id *ooid, struct object_id *noid,
13871387
return 0;
13881388
target += strlen(" to ");
13891389
strbuf_reset(&cb->buf);
1390-
hashcpy(cb->nsha1, noid->hash);
1390+
oidcpy(&cb->noid, noid);
13911391
end = strchrnul(target, '\n');
13921392
strbuf_add(&cb->buf, target, end - target);
13931393
if (!strcmp(cb->buf.buf, "HEAD")) {
@@ -1402,7 +1402,7 @@ static void wt_status_get_detached_from(struct wt_status_state *state)
14021402
{
14031403
struct grab_1st_switch_cbdata cb;
14041404
struct commit *commit;
1405-
unsigned char sha1[20];
1405+
struct object_id oid;
14061406
char *ref = NULL;
14071407

14081408
strbuf_init(&cb.buf, 0);
@@ -1411,22 +1411,22 @@ static void wt_status_get_detached_from(struct wt_status_state *state)
14111411
return;
14121412
}
14131413

1414-
if (dwim_ref(cb.buf.buf, cb.buf.len, sha1, &ref) == 1 &&
1414+
if (dwim_ref(cb.buf.buf, cb.buf.len, oid.hash, &ref) == 1 &&
14151415
/* sha1 is a commit? match without further lookup */
1416-
(!hashcmp(cb.nsha1, sha1) ||
1416+
(!oidcmp(&cb.noid, &oid) ||
14171417
/* perhaps sha1 is a tag, try to dereference to a commit */
1418-
((commit = lookup_commit_reference_gently(sha1, 1)) != NULL &&
1419-
!hashcmp(cb.nsha1, commit->object.oid.hash)))) {
1418+
((commit = lookup_commit_reference_gently(oid.hash, 1)) != NULL &&
1419+
!oidcmp(&cb.noid, &commit->object.oid)))) {
14201420
const char *from = ref;
14211421
if (!skip_prefix(from, "refs/tags/", &from))
14221422
skip_prefix(from, "refs/remotes/", &from);
14231423
state->detached_from = xstrdup(from);
14241424
} else
14251425
state->detached_from =
1426-
xstrdup(find_unique_abbrev(cb.nsha1, DEFAULT_ABBREV));
1427-
hashcpy(state->detached_sha1, cb.nsha1);
1428-
state->detached_at = !get_sha1("HEAD", sha1) &&
1429-
!hashcmp(sha1, state->detached_sha1);
1426+
xstrdup(find_unique_abbrev(cb.noid.hash, DEFAULT_ABBREV));
1427+
hashcpy(state->detached_sha1, cb.noid.hash);
1428+
state->detached_at = !get_oid("HEAD", &oid) &&
1429+
!hashcmp(oid.hash, state->detached_sha1);
14301430

14311431
free(ref);
14321432
strbuf_release(&cb.buf);
@@ -1476,22 +1476,22 @@ void wt_status_get_state(struct wt_status_state *state,
14761476
int get_detached_from)
14771477
{
14781478
struct stat st;
1479-
unsigned char sha1[20];
1479+
struct object_id oid;
14801480

14811481
if (!stat(git_path_merge_head(), &st)) {
14821482
state->merge_in_progress = 1;
14831483
} else if (wt_status_check_rebase(NULL, state)) {
14841484
; /* all set */
14851485
} else if (!stat(git_path_cherry_pick_head(), &st) &&
1486-
!get_sha1("CHERRY_PICK_HEAD", sha1)) {
1486+
!get_oid("CHERRY_PICK_HEAD", &oid)) {
14871487
state->cherry_pick_in_progress = 1;
1488-
hashcpy(state->cherry_pick_head_sha1, sha1);
1488+
hashcpy(state->cherry_pick_head_sha1, oid.hash);
14891489
}
14901490
wt_status_check_bisect(NULL, state);
14911491
if (!stat(git_path_revert_head(), &st) &&
1492-
!get_sha1("REVERT_HEAD", sha1)) {
1492+
!get_oid("REVERT_HEAD", &oid)) {
14931493
state->revert_in_progress = 1;
1494-
hashcpy(state->revert_head_sha1, sha1);
1494+
hashcpy(state->revert_head_sha1, oid.hash);
14951495
}
14961496

14971497
if (get_detached_from)

0 commit comments

Comments
 (0)