* [PATCH 1/3] hash-object: add -v/--verbose option
@ 2015-03-02 13:55 Alexander Kuleshov
2015-03-02 13:55 ` [PATCH 2/3] t1007-hash-object: add tests for verbose hash-object Alexander Kuleshov
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Alexander Kuleshov @ 2015-03-02 13:55 UTC (permalink / raw
To: git; +Cc: Junio C Hamano, Alexander Kuleshov
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@gmail.com>
---
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
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/3] t1007-hash-object: add tests for verbose hash-object
2015-03-02 13:55 [PATCH 1/3] hash-object: add -v/--verbose option Alexander Kuleshov
@ 2015-03-02 13:55 ` Alexander Kuleshov
2015-03-02 13:55 ` [PATCH 3/3] Documentation/git-hash-object.txt: add verbose option for hash-object Alexander Kuleshov
2015-03-02 15:12 ` [PATCH 1/3] hash-object: add -v/--verbose option Michael J Gruber
2 siblings, 0 replies; 4+ messages in thread
From: Alexander Kuleshov @ 2015-03-02 13:55 UTC (permalink / raw
To: git; +Cc: Junio C Hamano, Alexander Kuleshov
Signed-off-by: Alexander Kuleshov <kuleshovmail@gmail.com>
---
t/t1007-hash-object.sh | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/t/t1007-hash-object.sh b/t/t1007-hash-object.sh
index f83df8e..fa957bf 100755
--- a/t/t1007-hash-object.sh
+++ b/t/t1007-hash-object.sh
@@ -201,4 +201,15 @@ test_expect_success 'corrupt tag' '
test_must_fail git hash-object -t tag --stdin </dev/null
'
+filename="hello"
+hello_sha1_verbose="$hello_sha1\t$filename"
+
+test_expect_success 'hash-object verbose' '
+ test "$(echo $hello_sha1_verbose)" = "$(git hash-object -v $filename)"
+'
+
+test_expect_success "Can't use --verbose and --stdin together" '
+ echo example | test_must_fail git hash-object --verbose --stdin
+'
+
test_done
--
2.3.1.167.g7f4ba4b.dirty
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 3/3] Documentation/git-hash-object.txt: add verbose option for hash-object
2015-03-02 13:55 [PATCH 1/3] hash-object: add -v/--verbose option Alexander Kuleshov
2015-03-02 13:55 ` [PATCH 2/3] t1007-hash-object: add tests for verbose hash-object Alexander Kuleshov
@ 2015-03-02 13:55 ` Alexander Kuleshov
2015-03-02 15:12 ` [PATCH 1/3] hash-object: add -v/--verbose option Michael J Gruber
2 siblings, 0 replies; 4+ messages in thread
From: Alexander Kuleshov @ 2015-03-02 13:55 UTC (permalink / raw
To: git; +Cc: Junio C Hamano, Alexander Kuleshov
Signed-off-by: Alexander Kuleshov <kuleshovmail@gmail.com>
---
Documentation/git-hash-object.txt | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/Documentation/git-hash-object.txt b/Documentation/git-hash-object.txt
index 02c1f12..efec7c6 100644
--- a/Documentation/git-hash-object.txt
+++ b/Documentation/git-hash-object.txt
@@ -9,8 +9,8 @@ git-hash-object - Compute object ID and optionally creates a blob from a file
SYNOPSIS
--------
[verse]
-'git hash-object' [-t <type>] [-w] [--path=<file>|--no-filters] [--stdin] [--] <file>...
-'git hash-object' [-t <type>] [-w] --stdin-paths [--no-filters] < <list-of-paths>
+'git hash-object' [-t <type>] [-w] [-v] [--path=<file>|--no-filters] [--stdin] [--] <file>...
+'git hash-object' [-t <type>] [-w] [-v] --stdin-paths [--no-filters] < <list-of-paths>
DESCRIPTION
-----------
@@ -31,6 +31,9 @@ OPTIONS
-w::
Actually write the object into the object database.
+-v::
+ Prints file path near the hash.
+
--stdin::
Read the object from standard input instead of from a file.
--
2.3.1.167.g7f4ba4b.dirty
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 1/3] hash-object: add -v/--verbose option
2015-03-02 13:55 [PATCH 1/3] hash-object: add -v/--verbose option Alexander Kuleshov
2015-03-02 13:55 ` [PATCH 2/3] t1007-hash-object: add tests for verbose hash-object Alexander Kuleshov
2015-03-02 13:55 ` [PATCH 3/3] Documentation/git-hash-object.txt: add verbose option for hash-object Alexander Kuleshov
@ 2015-03-02 15:12 ` Michael J Gruber
2 siblings, 0 replies; 4+ messages in thread
From: Michael J Gruber @ 2015-03-02 15:12 UTC (permalink / raw
To: Alexander Kuleshov, git; +Cc: Junio C Hamano
Alexander Kuleshov venit, vidit, dixit 02.03.2015 14:55:
> 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.
Hmmm. You mean it's useful because -v would "dupe" the input stream as
one column in the output stream in this case? Hmmm.
> For example:
>
> $ git hash-object -v test
> e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 test
>
> Signed-off-by: Alexander Kuleshov <kuleshovmail@gmail.com>
> ---
> 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;
> +
Other flags are passed down as argument to hash_fd(). Is there a reason
this one has to be a (file) global?
> /*
> * 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";
> +
I fail to see why those should be incompatible. All these modes just use
hash_fd() which you patch to show the 2nd column with -v.
[And we would write && here to be safe and make the intention clearer.]
> if (flags & HASH_WRITE_OBJECT) {
> prefix = setup_git_directory();
> prefix_length = prefix ? strlen(prefix) : 0;
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2015-03-02 15:12 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-03-02 13:55 [PATCH 1/3] hash-object: add -v/--verbose option Alexander Kuleshov
2015-03-02 13:55 ` [PATCH 2/3] t1007-hash-object: add tests for verbose hash-object Alexander Kuleshov
2015-03-02 13:55 ` [PATCH 3/3] Documentation/git-hash-object.txt: add verbose option for hash-object Alexander Kuleshov
2015-03-02 15:12 ` [PATCH 1/3] hash-object: add -v/--verbose option Michael J Gruber
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).