git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 15, 2008, 17:31 UTC
Message-ID
<7vskzugm8x.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<20080214201355.6021.qmail@6a68c4de06516f.315fe32.mid.smarden.org>
Gerrit Pape <pape@smarden.org> writes:
Show 7 quoted lines
> 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" &&
Previous: Gerrit PapeNext: Gerrit Pape
Message 6 of 7 in “hash-object: don't rely on order of --stdin, -w arguments”
  1. hash-object: don't rely on order of --stdin, -w argumentsGerrit Pape, Feb 13, 2008
  2. Junio C HamanoFeb 13, 2008
  3. hash-object: don't rely on order of --stdin, -w argumentsGerrit Pape, Feb 13, 2008
  4. Junio C HamanoFeb 13, 2008
  5. hash-object: cleanup handling of command line optionsGerrit Pape, Feb 14, 2008
  6. Junio C HamanoFeb 15, 2008
  7. hash-object: cleanup handling of command line optionsGerrit Pape, Feb 21, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.