This patch provides ability to pass -v/--verbose option to the git hash-object command. hash-object will print not only hash, but also file path of a file from what hash was calculated. It can be useful in scripting, especially with --stdin-paths option. For example: $ git hash-object -v test e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 test Signed-off-by: Alexander Kuleshov <kuleshovmail@xxxxxxxxx> --- builtin/hash-object.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/builtin/hash-object.c b/builtin/hash-object.c index 207b90c..97961ee 100644 --- a/builtin/hash-object.c +++ b/builtin/hash-object.c @@ -10,6 +10,8 @@ #include "parse-options.h" #include "exec_cmd.h" +static int verbose; + /* * This is to create corrupt objects for debugging and as such it * needs to bypass the data conversion performed by, and the type @@ -43,7 +45,10 @@ static void hash_fd(int fd, const char *type, const char *path, unsigned flags, die((flags & HASH_WRITE_OBJECT) ? "Unable to add %s to database" : "Unable to hash %s", path); - printf("%s\n", sha1_to_hex(sha1)); + if (verbose) + printf("%s\t%s\n", sha1_to_hex(sha1), path); + else + printf("%s\n", sha1_to_hex(sha1)); maybe_flush_or_die(stdout, "hash to stdout"); } @@ -79,7 +84,7 @@ static void hash_stdin_paths(const char *type, int no_filters, unsigned flags, int cmd_hash_object(int argc, const char **argv, const char *prefix) { static const char * const hash_object_usage[] = { - N_("git hash-object [-t <type>] [-w] [--path=<file> | --no-filters] [--stdin] [--] <file>..."), + N_("git hash-object [-t <type>] [-w] [-v] [--path=<file> | --no-filters] [--stdin] [--] <file>..."), N_("git hash-object --stdin-paths < <list-of-paths>"), NULL }; @@ -99,6 +104,7 @@ int cmd_hash_object(int argc, const char **argv, const char *prefix) OPT_BOOL( 0 , "no-filters", &no_filters, N_("store file as is without filters")), OPT_BOOL( 0, "literally", &literally, N_("just hash any random garbage to create corrupt objects for debugging Git")), OPT_STRING( 0 , "path", &vpath, N_("file"), N_("process file as it were from this path")), + OPT__VERBOSE(&verbose, N_("show hash and file path")), OPT_END() }; int i; @@ -108,6 +114,11 @@ int cmd_hash_object(int argc, const char **argv, const char *prefix) argc = parse_options(argc, argv, NULL, hash_object_options, hash_object_usage, 0); + if (verbose & literally) + errstr = "Can't use --verbose with --literally"; + else if (verbose & hashstdin) + errstr = "Can't use --verbose with --stdin"; + if (flags & HASH_WRITE_OBJECT) { prefix = setup_git_directory(); prefix_length = prefix ? strlen(prefix) : 0; -- 2.3.1.167.g7f4ba4b.dirty -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html