builtin/rev-parse: rewrite to take an object_id argument

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Michael Haggerty committed May 25, 2015 at 18:38 UTC e23b0368635263e59d9ca0f1186e498a57c2c079
1 file changed +17 -24
builtin/rev-parse.c
+17 -24
@@ -190,17 +190,17 @@ static int show_default(void)
190 return 0;
191 }
192
193 -static int show_reference(const char *refname, const unsigned char *sha1, int flag, void *cb_data)
193 +static int show_reference(const char *refname, const struct object_id *oid, int flag, void *cb_data)
194 {
195 if (ref_excluded(ref_excludes, refname))
196 return 0;
197 - show_rev(NORMAL, sha1, refname);
197 + show_rev(NORMAL, oid->hash, refname);
198 return 0;
199 }
200
201 -static int anti_reference(const char *refname, const unsigned char *sha1, int flag, void *cb_data)
201 +static int anti_reference(const char *refname, const struct object_id *oid, int flag, void *cb_data)
202 {
203 - show_rev(REVERSED, sha1, refname);
203 + show_rev(REVERSED, oid->hash, refname);
204 return 0;
205 }
206
@@ -511,10 +511,6 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
511 unsigned int flags = 0;
512 const char *name = NULL;
513 struct object_context unused;
514 - struct each_ref_fn_sha1_adapter wrapped_show_reference =
515 - {show_reference, NULL};
516 - struct each_ref_fn_sha1_adapter wrapped_anti_reference =
517 - {anti_reference, NULL};
514
515 if (argc > 1 && !strcmp("--parseopt", argv[1]))
516 return cmd_parseopt(argc - 1, argv + 1, prefix);
@@ -656,7 +652,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
652 continue;
653 }
654 if (!strcmp(arg, "--all")) {
659 - for_each_ref(each_ref_fn_adapter, &wrapped_show_reference);
655 + for_each_ref(show_reference, NULL);
656 continue;
657 }
658 if (starts_with(arg, "--disambiguate=")) {
@@ -664,48 +660,45 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
660 continue;
661 }
662 if (!strcmp(arg, "--bisect")) {
667 - for_each_ref_in("refs/bisect/bad",
668 - each_ref_fn_adapter, &wrapped_show_reference);
669 - for_each_ref_in("refs/bisect/good",
670 - each_ref_fn_adapter, &wrapped_anti_reference);
663 + for_each_ref_in("refs/bisect/bad", show_reference, NULL);
664 + for_each_ref_in("refs/bisect/good", anti_reference, NULL);
665 continue;
666 }
667 if (starts_with(arg, "--branches=")) {
674 - for_each_glob_ref_in(each_ref_fn_adapter, arg + 11,
675 - "refs/heads/", &wrapped_show_reference);
668 + for_each_glob_ref_in(show_reference, arg + 11,
669 + "refs/heads/", NULL);
670 clear_ref_exclusion(&ref_excludes);
671 continue;
672 }
673 if (!strcmp(arg, "--branches")) {
680 - for_each_branch_ref(each_ref_fn_adapter, &wrapped_show_reference);
674 + for_each_branch_ref(show_reference, NULL);
675 clear_ref_exclusion(&ref_excludes);
676 continue;
677 }
678 if (starts_with(arg, "--tags=")) {
685 - for_each_glob_ref_in(each_ref_fn_adapter, arg + 7,
686 - "refs/tags/", &wrapped_show_reference);
679 + for_each_glob_ref_in(show_reference, arg + 7,
680 + "refs/tags/", NULL);
681 clear_ref_exclusion(&ref_excludes);
682 continue;
683 }
684 if (!strcmp(arg, "--tags")) {
691 - for_each_tag_ref(each_ref_fn_adapter, &wrapped_show_reference);
685 + for_each_tag_ref(show_reference, NULL);
686 clear_ref_exclusion(&ref_excludes);
687 continue;
688 }
689 if (starts_with(arg, "--glob=")) {
696 - for_each_glob_ref(each_ref_fn_adapter, arg + 7,
697 - &wrapped_show_reference);
690 + for_each_glob_ref(show_reference, arg + 7, NULL);
691 clear_ref_exclusion(&ref_excludes);
692 continue;
693 }
694 if (starts_with(arg, "--remotes=")) {
702 - for_each_glob_ref_in(each_ref_fn_adapter, arg + 10,
703 - "refs/remotes/", &wrapped_show_reference);
695 + for_each_glob_ref_in(show_reference, arg + 10,
696 + "refs/remotes/", NULL);
697 clear_ref_exclusion(&ref_excludes);
698 continue;
699 }
700 if (!strcmp(arg, "--remotes")) {
708 - for_each_remote_ref(each_ref_fn_adapter, &wrapped_show_reference);
701 + for_each_remote_ref(show_reference, NULL);
702 clear_ref_exclusion(&ref_excludes);
703 continue;
704 }