git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Gerrit Pape <pape@smarden.org>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] hash-object: cleanup handling of command line options
Date: Fri, 15 Feb 2008 09:31:10 -0800	[thread overview]
Message-ID: <7vskzugm8x.fsf@gitster.siamese.dyndns.org> (raw)
In-Reply-To: 20080214201355.6021.qmail@6a68c4de06516f.315fe32.mid.smarden.org

Gerrit Pape <pape@smarden.org> 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" &&

  reply	other threads:[~2008-02-15 17:32 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-02-13 19:03 [PATCH] hash-object: don't rely on order of --stdin, -w arguments Gerrit Pape
2008-02-13 19:50 ` Junio C Hamano
2008-02-13 22:49   ` [PATCH/selftest] " Gerrit Pape
2008-02-13 23:25     ` Junio C Hamano
2008-02-14 20:13       ` [PATCH] hash-object: cleanup handling of command line options Gerrit Pape
2008-02-15 17:31         ` Junio C Hamano [this message]
2008-02-21 10:06           ` Gerrit Pape

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7vskzugm8x.fsf@gitster.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=pape@smarden.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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 NNTP newsgroup(s).