builtin/log: convert some static functions to use 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
Sep 5, 2016 at 20:07 UTC
d801627b0c66138eab33a1cf8cd61d056ee946f1
1 file changed
+22
-22
builtin/log.c
+22
-22
@@ -464,9 +464,9 @@ static void show_tagger(char *buf, int len, struct rev_info *rev)
464
strbuf_release(&out);
465
}
466
467
-static int show_blob_object(const unsigned char *sha1, struct rev_info *rev, const char *obj_name)
467
+static int show_blob_object(const struct object_id *oid, struct rev_info *rev, const char *obj_name)
468
{
469
- unsigned char sha1c[20];
469
+ struct object_id oidc;
470
struct object_context obj_context;
471
char *buf;
472
unsigned long size;
@@ -474,13 +474,13 @@ static int show_blob_object(const unsigned char *sha1, struct rev_info *rev, con
474
fflush(rev->diffopt.file);
475
if (!DIFF_OPT_TOUCHED(&rev->diffopt, ALLOW_TEXTCONV) ||
476
!DIFF_OPT_TST(&rev->diffopt, ALLOW_TEXTCONV))
477
- return stream_blob_to_fd(1, sha1, NULL, 0);
477
+ return stream_blob_to_fd(1, oid->hash, NULL, 0);
478
479
- if (get_sha1_with_context(obj_name, 0, sha1c, &obj_context))
479
+ if (get_sha1_with_context(obj_name, 0, oidc.hash, &obj_context))
480
die(_("Not a valid object name %s"), obj_name);
481
if (!obj_context.path[0] ||
482
- !textconv_object(obj_context.path, obj_context.mode, sha1c, 1, &buf, &size))
483
- return stream_blob_to_fd(1, sha1, NULL, 0);
482
+ !textconv_object(obj_context.path, obj_context.mode, oidc.hash, 1, &buf, &size))
483
+ return stream_blob_to_fd(1, oid->hash, NULL, 0);
484
485
if (!buf)
486
die(_("git show %s: bad file"), obj_name);
@@ -489,15 +489,15 @@ static int show_blob_object(const unsigned char *sha1, struct rev_info *rev, con
489
return 0;
490
}
491
492
-static int show_tag_object(const unsigned char *sha1, struct rev_info *rev)
492
+static int show_tag_object(const struct object_id *oid, struct rev_info *rev)
493
{
494
unsigned long size;
495
enum object_type type;
496
- char *buf = read_sha1_file(sha1, &type, &size);
496
+ char *buf = read_sha1_file(oid->hash, &type, &size);
497
int offset = 0;
498
499
if (!buf)
500
- return error(_("Could not read object %s"), sha1_to_hex(sha1));
500
+ return error(_("Could not read object %s"), oid_to_hex(oid));
501
502
assert(type == OBJ_TAG);
503
while (offset < size && buf[offset] != '\n') {
@@ -574,7 +574,7 @@ int cmd_show(int argc, const char **argv, const char *prefix)
574
const char *name = objects[i].name;
575
switch (o->type) {
576
case OBJ_BLOB:
577
- ret = show_blob_object(o->oid.hash, &rev, name);
577
+ ret = show_blob_object(&o->oid, &rev, name);
578
break;
579
case OBJ_TAG: {
580
struct tag *t = (struct tag *)o;
@@ -585,7 +585,7 @@ int cmd_show(int argc, const char **argv, const char *prefix)
585
diff_get_color_opt(&rev.diffopt, DIFF_COMMIT),
586
t->tag,
587
diff_get_color_opt(&rev.diffopt, DIFF_RESET));
588
- ret = show_tag_object(o->oid.hash, &rev);
588
+ ret = show_tag_object(&o->oid, &rev);
589
rev.shown_one = 1;
590
if (ret)
591
break;
@@ -1248,11 +1248,11 @@ static struct commit *get_base_commit(const char *base_commit,
1248
if (upstream) {
1249
struct commit_list *base_list;
1250
struct commit *commit;
1251
- unsigned char sha1[20];
1251
+ struct object_id oid;
1252
1253
- if (get_sha1(upstream, sha1))
1253
+ if (get_oid(upstream, &oid))
1254
die(_("Failed to resolve '%s' as a valid ref."), upstream);
1255
- commit = lookup_commit_or_die(sha1, "upstream base");
1255
+ commit = lookup_commit_or_die(oid.hash, "upstream base");
1256
base_list = get_merge_bases_many(commit, total, list);
1257
/* There should be one and only one merge base. */
1258
if (!base_list || base_list->next)
@@ -1339,15 +1339,15 @@ static void prepare_bases(struct base_tree_info *bases,
1339
* and stuff them in bases structure.
1340
*/
1341
while ((commit = get_revision(&revs)) != NULL) {
1342
- unsigned char sha1[20];
1342
+ struct object_id oid;
1343
struct object_id *patch_id;
1344
if (commit->util)
1345
continue;
1346
- if (commit_patch_id(commit, &diffopt, sha1, 0))
1346
+ if (commit_patch_id(commit, &diffopt, oid.hash, 0))
1347
die(_("cannot get patch id"));
1348
ALLOC_GROW(bases->patch_id, bases->nr_patch_id + 1, bases->alloc_patch_id);
1349
patch_id = bases->patch_id + bases->nr_patch_id;
1350
- hashcpy(patch_id->hash, sha1);
1350
+ oidcpy(patch_id, &oid);
1351
bases->nr_patch_id++;
1352
}
1353
}
@@ -1628,10 +1628,10 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
1628
check_head = 1;
1629
1630
if (check_head) {
1631
- unsigned char sha1[20];
1631
+ struct object_id oid;
1632
const char *ref, *v;
1633
ref = resolve_ref_unsafe("HEAD", RESOLVE_REF_READING,
1634
- sha1, NULL);
1634
+ oid.hash, NULL);
1635
if (ref && skip_prefix(ref, "refs/heads/", &v))
1636
branch_name = xstrdup(v);
1637
else
@@ -1802,9 +1802,9 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
1802
1803
static int add_pending_commit(const char *arg, struct rev_info *revs, int flags)
1804
{
1805
- unsigned char sha1[20];
1806
- if (get_sha1(arg, sha1) == 0) {
1807
- struct commit *commit = lookup_commit_reference(sha1);
1805
+ struct object_id oid;
1806
+ if (get_oid(arg, &oid) == 0) {
1807
+ struct commit *commit = lookup_commit_reference(oid.hash);
1808
if (commit) {
1809
commit->object.flags |= flags;
1810
add_pending_object(revs, &commit->object, arg);