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>
brian m. carlson committed
Feb 21, 2017 at 23:47 UTC
e86ab2c1cd60ec4b9214e5cd8450a474fa175f5c
1 file changed
+22
-22
wt-status.c
+22
-22
@@ -1115,16 +1115,16 @@ static void abbrev_sha1_in_line(struct strbuf *line)
1115
1116
split = strbuf_split_max(line, ' ', 3);
1117
if (split[0] && split[1]) {
1118
- unsigned char sha1[20];
1118
+ struct object_id oid;
1119
1120
/*
1121
* strbuf_split_max left a space. Trim it and re-add
1122
* it after abbreviation.
1123
*/
1124
strbuf_trim(split[1]);
1125
- if (!get_sha1(split[1]->buf, sha1)) {
1125
+ if (!get_oid(split[1]->buf, &oid)) {
1126
strbuf_reset(split[1]);
1127
- strbuf_add_unique_abbrev(split[1], sha1,
1127
+ strbuf_add_unique_abbrev(split[1], oid.hash,
1128
DEFAULT_ABBREV);
1129
strbuf_addch(split[1], ' ');
1130
strbuf_reset(line);
@@ -1340,7 +1340,7 @@ static void show_bisect_in_progress(struct wt_status *s,
1340
static char *get_branch(const struct worktree *wt, const char *path)
1341
{
1342
struct strbuf sb = STRBUF_INIT;
1343
- unsigned char sha1[20];
1343
+ struct object_id oid;
1344
const char *branch_name;
1345
1346
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)
1354
strbuf_remove(&sb, 0, branch_name - sb.buf);
1355
else if (starts_with(sb.buf, "refs/"))
1356
;
1357
- else if (!get_sha1_hex(sb.buf, sha1)) {
1357
+ else if (!get_oid_hex(sb.buf, &oid)) {
1358
strbuf_reset(&sb);
1359
- strbuf_add_unique_abbrev(&sb, sha1, DEFAULT_ABBREV);
1359
+ strbuf_add_unique_abbrev(&sb, oid.hash, DEFAULT_ABBREV);
1360
} else if (!strcmp(sb.buf, "detached HEAD")) /* rebase */
1361
goto got_nothing;
1362
else /* bisect */
@@ -1370,7 +1370,7 @@ got_nothing:
1370
1371
struct grab_1st_switch_cbdata {
1372
struct strbuf buf;
1373
- unsigned char nsha1[20];
1373
+ struct object_id noid;
1374
};
1375
1376
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,
1387
return 0;
1388
target += strlen(" to ");
1389
strbuf_reset(&cb->buf);
1390
- hashcpy(cb->nsha1, noid->hash);
1390
+ oidcpy(&cb->noid, noid);
1391
end = strchrnul(target, '\n');
1392
strbuf_add(&cb->buf, target, end - target);
1393
if (!strcmp(cb->buf.buf, "HEAD")) {
@@ -1402,7 +1402,7 @@ static void wt_status_get_detached_from(struct wt_status_state *state)
1402
{
1403
struct grab_1st_switch_cbdata cb;
1404
struct commit *commit;
1405
- unsigned char sha1[20];
1405
+ struct object_id oid;
1406
char *ref = NULL;
1407
1408
strbuf_init(&cb.buf, 0);
@@ -1411,22 +1411,22 @@ static void wt_status_get_detached_from(struct wt_status_state *state)
1411
return;
1412
}
1413
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 &&
1415
/* sha1 is a commit? match without further lookup */
1416
- (!hashcmp(cb.nsha1, sha1) ||
1416
+ (!oidcmp(&cb.noid, &oid) ||
1417
/* 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)))) {
1420
const char *from = ref;
1421
if (!skip_prefix(from, "refs/tags/", &from))
1422
skip_prefix(from, "refs/remotes/", &from);
1423
state->detached_from = xstrdup(from);
1424
} else
1425
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);
1430
1431
free(ref);
1432
strbuf_release(&cb.buf);
@@ -1476,22 +1476,22 @@ void wt_status_get_state(struct wt_status_state *state,
1476
int get_detached_from)
1477
{
1478
struct stat st;
1479
- unsigned char sha1[20];
1479
+ struct object_id oid;
1480
1481
if (!stat(git_path_merge_head(), &st)) {
1482
state->merge_in_progress = 1;
1483
} else if (wt_status_check_rebase(NULL, state)) {
1484
; /* all set */
1485
} else if (!stat(git_path_cherry_pick_head(), &st) &&
1486
- !get_sha1("CHERRY_PICK_HEAD", sha1)) {
1486
+ !get_oid("CHERRY_PICK_HEAD", &oid)) {
1487
state->cherry_pick_in_progress = 1;
1488
- hashcpy(state->cherry_pick_head_sha1, sha1);
1488
+ hashcpy(state->cherry_pick_head_sha1, oid.hash);
1489
}
1490
wt_status_check_bisect(NULL, state);
1491
if (!stat(git_path_revert_head(), &st) &&
1492
- !get_sha1("REVERT_HEAD", sha1)) {
1492
+ !get_oid("REVERT_HEAD", &oid)) {
1493
state->revert_in_progress = 1;
1494
- hashcpy(state->revert_head_sha1, sha1);
1494
+ hashcpy(state->revert_head_sha1, oid.hash);
1495
}
1496
1497
if (get_detached_from)