Re: [PATCH] hash-object: cleanup handling of command line options

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Gerrit Pape <pape@xxxxxxxxxxx> writes:

> This regresses the use case of running:
>
>    $ git hash-object --stdin Makefile <cache.h
>
> to obtain hash values for cache.h and then Makefile.  It used to
> report the object names in order, but now it always processes
> --stdin at the end.

Isn't this change of behaviour more serious than the made up
"--stdin --stdin" example?  The made-up insane usage is rejected
with your patch now, so it would be fine, but that is so insane
that we probably even did not need to explicitly reject.  On the
other hand, running "--stdin file2 <file1" and expecting the
output to be given for file1 first and then file2 is much less
insane, and it would make more sense to reject it if we cannot
support that earlier behaviour.  Not rejecting such a use and
doing different thing from what we used to will break existing
uses silently.

I suppose we could first see if there is -w in the first pass
and then in the second pass do exactly what we used to do, if we
want to fix this without regressing at all.  Then there won't
be any regression, even "--stdin --stdin" would keep working.

Except for one case.

Earlier you could "hash-object --stdin -w cache.h <Makefile" to
get the hash of Makefile without writing to the object store,
and get the hash of cache.h and write that to the object store.

With such a fix with less regression, we will get the two object
names in the right order (--stdin first and then explicit
filename, as the user wanted to have), but now we write what we
get from --stdin to the object database, even though the user
did _not_ want to (that is why he wrote -w after --stdin, not
before).

Hmmmm.  Why is it so bad if "--stdin -w" and "-w --stdin" works
differently?

Having said all that, I think "--stdin file2 <file1" behaviour
can be kept without regressing by a patch like this on top of
your fix, and we can drop the first "regression warning" in the
commit log message if we did so.

---

 hash-object.c          |    5 +++++
 t/t5303-hash-object.sh |    4 ++--
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/hash-object.c b/hash-object.c
index 67d9922..61e7160 100644
--- a/hash-object.c
+++ b/hash-object.c
@@ -75,6 +75,11 @@ int main(int argc, char **argv)
 		}
 		else {
 			const char *arg = argv[i];
+
+			if (hashstdin) {
+				hash_stdin(type, write_object);
+				hashstdin = 0;
+			}
 			if (0 <= prefix_length)
 				arg = prefix_filename(prefix, prefix_length,
 						      arg);
diff --git a/t/t5303-hash-object.sh b/t/t5303-hash-object.sh
index 14be455..7c4f9fa 100755
--- a/t/t5303-hash-object.sh
+++ b/t/t5303-hash-object.sh
@@ -21,8 +21,8 @@ test_expect_success \
 test_expect_success \
     'git hash-object --stdin file0 <file1 first operates on file0, then file1' \
     'echo foo > file0 &&
-    obname0=$(git hash-object file0) &&
-    obname1=$(echo bar | git hash-object --stdin) &&
+    obname0=$(echo bar | git hash-object --stdin) &&
+    obname1=$(git hash-object file0) &&
     obname0new=$(echo bar | git hash-object --stdin file0 | sed -n -e 1p) &&
     obname1new=$(echo bar | git hash-object --stdin file0 | sed -n -e 2p) &&
     test "$obname0" = "$obname0new" &&
-
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

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux