|
25 | 25 | #include "submodule.h"
|
26 | 26 | #include "commit-reach.h"
|
27 | 27 | #include "shallow.h"
|
| 28 | +#include "object-file-convert.h" |
28 | 29 |
|
29 | 30 | #define DO_REVS 1
|
30 | 31 | #define DO_NOREV 2
|
@@ -675,6 +676,8 @@ static void print_path(const char *path, const char *prefix, enum format_type fo
|
675 | 676 | int cmd_rev_parse(int argc, const char **argv, const char *prefix)
|
676 | 677 | {
|
677 | 678 | int i, as_is = 0, verify = 0, quiet = 0, revs_count = 0, type = 0;
|
| 679 | + const struct git_hash_algo *output_algo = NULL; |
| 680 | + const struct git_hash_algo *compat = NULL; |
678 | 681 | int did_repo_setup = 0;
|
679 | 682 | int has_dashdash = 0;
|
680 | 683 | int output_prefix = 0;
|
@@ -746,6 +749,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
|
746 | 749 |
|
747 | 750 | prepare_repo_settings(the_repository);
|
748 | 751 | the_repository->settings.command_requires_full_index = 0;
|
| 752 | + compat = the_repository->compat_hash_algo; |
749 | 753 | }
|
750 | 754 |
|
751 | 755 | if (!strcmp(arg, "--")) {
|
@@ -833,6 +837,22 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
|
833 | 837 | flags |= GET_OID_QUIETLY;
|
834 | 838 | continue;
|
835 | 839 | }
|
| 840 | + if (opt_with_value(arg, "--output-object-format", &arg)) { |
| 841 | + if (!arg) |
| 842 | + die(_("no object format specified")); |
| 843 | + if (!strcmp(arg, the_hash_algo->name) || |
| 844 | + !strcmp(arg, "storage")) { |
| 845 | + flags |= GET_OID_HASH_ANY; |
| 846 | + output_algo = the_hash_algo; |
| 847 | + continue; |
| 848 | + } |
| 849 | + else if (compat && !strcmp(arg, compat->name)) { |
| 850 | + flags |= GET_OID_HASH_ANY; |
| 851 | + output_algo = compat; |
| 852 | + continue; |
| 853 | + } |
| 854 | + else die(_("unsupported object format: %s"), arg); |
| 855 | + } |
836 | 856 | if (opt_with_value(arg, "--short", &arg)) {
|
837 | 857 | filter &= ~(DO_FLAGS|DO_NOREV);
|
838 | 858 | verify = 1;
|
@@ -1083,6 +1103,9 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
|
1083 | 1103 | }
|
1084 | 1104 | if (!get_oid_with_context(the_repository, name,
|
1085 | 1105 | flags, &oid, &unused)) {
|
| 1106 | + if (output_algo) |
| 1107 | + repo_oid_to_algop(the_repository, &oid, |
| 1108 | + output_algo, &oid); |
1086 | 1109 | if (verify)
|
1087 | 1110 | revs_count++;
|
1088 | 1111 | else
|
|
0 commit comments