{"thread":{"id":"38679","subject":"[PATCH 1/3] hash-object: add -v/--verbose option","startedAt":"2015-03-02T13:55:00Z","lastAt":"2015-03-02T15:12:10Z","messageCount":4,"participants":["Alexander Kuleshov","Michael J Gruber"],"isPatch":true,"patchVersion":1,"patchTotal":3},"messages":[{"id":"256839","messageId":"1425304500-14117-1-git-send-email-kuleshovmail@gmail.com","threadId":"38679","inReplyTo":null,"subject":"[PATCH 1/3] hash-object: add -v/--verbose option","fromName":"Alexander Kuleshov","fromEmail":"kuleshovmail@gmail.com","sentAt":"2015-03-02T13:55:00Z","receivedAt":"2015-03-02T13:55:00Z","isPatch":true,"sender":{"key":"kuleshovmail@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2699235?v=4"},"body":"This patch provides ability to pass -v/--verbose option to the\ngit hash-object command. hash-object will print not only hash,\nbut also file path of a file from what hash was calculated.\n\nIt can be useful in scripting, especially with --stdin-paths\noption.\n\nFor example:\n\n$ git hash-object -v test\ne69de29bb2d1d6434b8b29ae775ad8c2e48c5391\ttest\n\nSigned-off-by: Alexander Kuleshov <kuleshovmail@gmail.com>\n---\n builtin/hash-object.c | 15 +++++++++++++--\n 1 file changed, 13 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin/hash-object.c b/builtin/hash-object.c\nindex 207b90c..97961ee 100644\n--- a/builtin/hash-object.c\n+++ b/builtin/hash-object.c\n@@ -10,6 +10,8 @@\n #include \"parse-options.h\"\n #include \"exec_cmd.h\"\n \n+static int verbose;\n+\n /*\n  * This is to create corrupt objects for debugging and as such it\n  * needs to bypass the data conversion performed by, and the type\n@@ -43,7 +45,10 @@ static void hash_fd(int fd, const char *type, const char *path, unsigned flags,\n \t\tdie((flags & HASH_WRITE_OBJECT)\n \t\t    ? \"Unable to add %s to database\"\n \t\t    : \"Unable to hash %s\", path);\n-\tprintf(\"%s\\n\", sha1_to_hex(sha1));\n+\tif (verbose)\n+\t\tprintf(\"%s\\t%s\\n\", sha1_to_hex(sha1), path);\n+\telse\n+\t\tprintf(\"%s\\n\", sha1_to_hex(sha1));\n \tmaybe_flush_or_die(stdout, \"hash to stdout\");\n }\n \n@@ -79,7 +84,7 @@ static void hash_stdin_paths(const char *type, int no_filters, unsigned flags,\n int cmd_hash_object(int argc, const char **argv, const char *prefix)\n {\n \tstatic const char * const hash_object_usage[] = {\n-\t\tN_(\"git hash-object [-t <type>] [-w] [--path=<file> | --no-filters] [--stdin] [--] <file>...\"),\n+\t\tN_(\"git hash-object [-t <type>] [-w] [-v] [--path=<file> | --no-filters] [--stdin] [--] <file>...\"),\n \t\tN_(\"git hash-object  --stdin-paths < <list-of-paths>\"),\n \t\tNULL\n \t};\n@@ -99,6 +104,7 @@ int cmd_hash_object(int argc, const char **argv, const char *prefix)\n \t\tOPT_BOOL( 0 , \"no-filters\", &no_filters, N_(\"store file as is without filters\")),\n \t\tOPT_BOOL( 0, \"literally\", &literally, N_(\"just hash any random garbage to create corrupt objects for debugging Git\")),\n \t\tOPT_STRING( 0 , \"path\", &vpath, N_(\"file\"), N_(\"process file as it were from this path\")),\n+\t\tOPT__VERBOSE(&verbose, N_(\"show hash and file path\")),\n \t\tOPT_END()\n \t};\n \tint i;\n@@ -108,6 +114,11 @@ int cmd_hash_object(int argc, const char **argv, const char *prefix)\n \targc = parse_options(argc, argv, NULL, hash_object_options,\n \t\t\t     hash_object_usage, 0);\n \n+\tif (verbose & literally)\n+\t\terrstr = \"Can't use --verbose with --literally\";\n+\telse if (verbose & hashstdin)\n+\t\terrstr = \"Can't use --verbose with --stdin\";\n+\n \tif (flags & HASH_WRITE_OBJECT) {\n \t\tprefix = setup_git_directory();\n \t\tprefix_length = prefix ? strlen(prefix) : 0;\n-- \n2.3.1.167.g7f4ba4b.dirty\n"},{"id":"256840","messageId":"1425304523-14425-1-git-send-email-kuleshovmail@gmail.com","threadId":"38679","inReplyTo":"1425304500-14117-1-git-send-email-kuleshovmail@gmail.com","subject":"[PATCH 2/3] t1007-hash-object: add tests for verbose hash-object","fromName":"Alexander Kuleshov","fromEmail":"kuleshovmail@gmail.com","sentAt":"2015-03-02T13:55:23Z","receivedAt":"2015-03-02T13:55:23Z","isPatch":true,"sender":{"key":"kuleshovmail@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2699235?v=4"},"body":"Signed-off-by: Alexander Kuleshov <kuleshovmail@gmail.com>\n---\n t/t1007-hash-object.sh | 11 +++++++++++\n 1 file changed, 11 insertions(+)\n\ndiff --git a/t/t1007-hash-object.sh b/t/t1007-hash-object.sh\nindex f83df8e..fa957bf 100755\n--- a/t/t1007-hash-object.sh\n+++ b/t/t1007-hash-object.sh\n@@ -201,4 +201,15 @@ test_expect_success 'corrupt tag' '\n \ttest_must_fail git hash-object -t tag --stdin </dev/null\n '\n \n+filename=\"hello\"\n+hello_sha1_verbose=\"$hello_sha1\\t$filename\"\n+\n+test_expect_success 'hash-object verbose' '\n+\ttest \"$(echo $hello_sha1_verbose)\" = \"$(git hash-object -v $filename)\"\n+'\n+\n+test_expect_success \"Can't use --verbose and --stdin together\" '\n+\techo example | test_must_fail git hash-object --verbose --stdin\n+'\n+\n test_done\n-- \n2.3.1.167.g7f4ba4b.dirty\n"},{"id":"256841","messageId":"1425304535-14484-1-git-send-email-kuleshovmail@gmail.com","threadId":"38679","inReplyTo":"1425304500-14117-1-git-send-email-kuleshovmail@gmail.com","subject":"[PATCH 3/3] Documentation/git-hash-object.txt: add verbose option for hash-object","fromName":"Alexander Kuleshov","fromEmail":"kuleshovmail@gmail.com","sentAt":"2015-03-02T13:55:35Z","receivedAt":"2015-03-02T13:55:35Z","isPatch":true,"sender":{"key":"kuleshovmail@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2699235?v=4"},"body":"Signed-off-by: Alexander Kuleshov <kuleshovmail@gmail.com>\n---\n Documentation/git-hash-object.txt | 7 +++++--\n 1 file changed, 5 insertions(+), 2 deletions(-)\n\ndiff --git a/Documentation/git-hash-object.txt b/Documentation/git-hash-object.txt\nindex 02c1f12..efec7c6 100644\n--- a/Documentation/git-hash-object.txt\n+++ b/Documentation/git-hash-object.txt\n@@ -9,8 +9,8 @@ git-hash-object - Compute object ID and optionally creates a blob from a file\n SYNOPSIS\n --------\n [verse]\n-'git hash-object' [-t <type>] [-w] [--path=<file>|--no-filters] [--stdin] [--] <file>...\n-'git hash-object' [-t <type>] [-w] --stdin-paths [--no-filters] < <list-of-paths>\n+'git hash-object' [-t <type>] [-w] [-v] [--path=<file>|--no-filters] [--stdin] [--] <file>...\n+'git hash-object' [-t <type>] [-w] [-v] --stdin-paths [--no-filters] < <list-of-paths>\n \n DESCRIPTION\n -----------\n@@ -31,6 +31,9 @@ OPTIONS\n -w::\n \tActually write the object into the object database.\n \n+-v::\n+\tPrints file path near the hash.\n+\n --stdin::\n \tRead the object from standard input instead of from a file.\n \n-- \n2.3.1.167.g7f4ba4b.dirty\n"},{"id":"256846","messageId":"54F47DCA.7020402@drmicha.warpmail.net","threadId":"38679","inReplyTo":"1425304500-14117-1-git-send-email-kuleshovmail@gmail.com","subject":"Re: [PATCH 1/3] hash-object: add -v/--verbose option","fromName":"Michael J Gruber","fromEmail":"git@drmicha.warpmail.net","sentAt":"2015-03-02T15:12:10Z","receivedAt":"2015-03-02T15:12:10Z","isPatch":true,"sender":{"key":"git@grubix.eu","avatar":"https://avatars.githubusercontent.com/u/233215?v=4"},"body":"Alexander Kuleshov venit, vidit, dixit 02.03.2015 14:55:\n> This patch provides ability to pass -v/--verbose option to the\n> git hash-object command. hash-object will print not only hash,\n> but also file path of a file from what hash was calculated.\n> \n> It can be useful in scripting, especially with --stdin-paths\n> option.\n\nHmmm. You mean it's useful because -v would \"dupe\" the input stream as\none column in the output stream in this case? Hmmm.\n\n> For example:\n> \n> $ git hash-object -v test\n> e69de29bb2d1d6434b8b29ae775ad8c2e48c5391\ttest\n> \n> Signed-off-by: Alexander Kuleshov <kuleshovmail@gmail.com>\n> ---\n>  builtin/hash-object.c | 15 +++++++++++++--\n>  1 file changed, 13 insertions(+), 2 deletions(-)\n> \n> diff --git a/builtin/hash-object.c b/builtin/hash-object.c\n> index 207b90c..97961ee 100644\n> --- a/builtin/hash-object.c\n> +++ b/builtin/hash-object.c\n> @@ -10,6 +10,8 @@\n>  #include \"parse-options.h\"\n>  #include \"exec_cmd.h\"\n>  \n> +static int verbose;\n> +\n\nOther flags are passed down as argument to hash_fd(). Is there a reason\nthis one has to be a (file) global?\n\n>  /*\n>   * This is to create corrupt objects for debugging and as such it\n>   * needs to bypass the data conversion performed by, and the type\n> @@ -43,7 +45,10 @@ static void hash_fd(int fd, const char *type, const char *path, unsigned flags,\n>  \t\tdie((flags & HASH_WRITE_OBJECT)\n>  \t\t    ? \"Unable to add %s to database\"\n>  \t\t    : \"Unable to hash %s\", path);\n> -\tprintf(\"%s\\n\", sha1_to_hex(sha1));\n> +\tif (verbose)\n> +\t\tprintf(\"%s\\t%s\\n\", sha1_to_hex(sha1), path);\n> +\telse\n> +\t\tprintf(\"%s\\n\", sha1_to_hex(sha1));\n>  \tmaybe_flush_or_die(stdout, \"hash to stdout\");\n>  }\n>  \n> @@ -79,7 +84,7 @@ static void hash_stdin_paths(const char *type, int no_filters, unsigned flags,\n>  int cmd_hash_object(int argc, const char **argv, const char *prefix)\n>  {\n>  \tstatic const char * const hash_object_usage[] = {\n> -\t\tN_(\"git hash-object [-t <type>] [-w] [--path=<file> | --no-filters] [--stdin] [--] <file>...\"),\n> +\t\tN_(\"git hash-object [-t <type>] [-w] [-v] [--path=<file> | --no-filters] [--stdin] [--] <file>...\"),\n>  \t\tN_(\"git hash-object  --stdin-paths < <list-of-paths>\"),\n>  \t\tNULL\n>  \t};\n> @@ -99,6 +104,7 @@ int cmd_hash_object(int argc, const char **argv, const char *prefix)\n>  \t\tOPT_BOOL( 0 , \"no-filters\", &no_filters, N_(\"store file as is without filters\")),\n>  \t\tOPT_BOOL( 0, \"literally\", &literally, N_(\"just hash any random garbage to create corrupt objects for debugging Git\")),\n>  \t\tOPT_STRING( 0 , \"path\", &vpath, N_(\"file\"), N_(\"process file as it were from this path\")),\n> +\t\tOPT__VERBOSE(&verbose, N_(\"show hash and file path\")),\n>  \t\tOPT_END()\n>  \t};\n>  \tint i;\n> @@ -108,6 +114,11 @@ int cmd_hash_object(int argc, const char **argv, const char *prefix)\n>  \targc = parse_options(argc, argv, NULL, hash_object_options,\n>  \t\t\t     hash_object_usage, 0);\n>  \n> +\tif (verbose & literally)\n> +\t\terrstr = \"Can't use --verbose with --literally\";\n> +\telse if (verbose & hashstdin)\n> +\t\terrstr = \"Can't use --verbose with --stdin\";\n> +\n\nI fail to see why those should be incompatible. All these modes just use\nhash_fd() which you patch to show the 2nd column with -v.\n\n[And we would write && here to be safe and make the intention clearer.]\n\n>  \tif (flags & HASH_WRITE_OBJECT) {\n>  \t\tprefix = setup_git_directory();\n>  \t\tprefix_length = prefix ? strlen(prefix) : 0;\n> \n"}]}