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

[PATCH] don't use default revision if a rev was specified

From
Dave Olszewski <cxreg@pobox.com>
Date
Mar 13, 2010, 22:47 UTC
Message-ID
<1268520425-31889-1-git-send-email-cxreg@pobox.com>
In-Reply-To
<4B9C086D.10004@lsrfire.ath.cx>

If a revision is specified, it happens not to have any commits, don't use the default revision. By doing so, surprising and undesired behavior can happen, such as showing the reflog for HEAD when a branch was specified.

Signed-off-by: Dave Olszewski <cxreg@pobox.com>
---
Show 8 quoted lines
>> I was testing a patch along the lines of
>> what Vladimir proposed, which was simply to not set the default rev if a
>> valid user-specified argument was found, whether or not it contains
>> commits.
>
>Sounds more like it.  How did the tests go?  Does it result in empty
>output (which is what I would expect from an empty reflog, now that I
>stopped and thought about it for a second)?
It seems to work ok(tm)
 revision.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/revision.c b/revision.c
index 29721ec..490b484 100644
--- a/revision.c
+++ b/revision.c
@@ -1334,7 +1334,7 @@ static void append_prune_data(const char ***prune_data, const char **av)
  */
 int setup_revisions(int argc, const char **argv, struct rev_info *revs, const char *def)
 {
-	int i, flags, left, seen_dashdash, read_from_stdin;
+	int i, flags, left, seen_dashdash, read_from_stdin, got_rev_arg = 0;
 	const char **prune_data = NULL;
 
 	/* First, search for "--" */
@@ -1460,6 +1460,8 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch
 			append_prune_data(&prune_data, argv + i);
 			break;
 		}
+		else
+			got_rev_arg = 1;
 	}
 
 	if (prune_data)
@@ -1469,7 +1471,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch
 		revs->def = def;
 	if (revs->show_merge)
 		prepare_show_merge(revs);
-	if (revs->def && !revs->pending.nr) {
+	if (revs->def && !revs->pending.nr && !got_rev_arg) {
 		unsigned char sha1[20];
 		struct object *object;
 		unsigned mode;
-- 
1.7.0.2.202.g4e870.dirty
Previous: René ScharfeNext: René Scharfe
Message 7 of 11 in “"git stash list" shows HEAD reflog”
  1. Vladimir PanteleevMar 12, 2010
  2. René ScharfeMar 13, 2010
  3. Dave OlszewskiMar 13, 2010
  4. René ScharfeMar 13, 2010
  5. Dave OlszewskiMar 13, 2010
  6. René ScharfeMar 13, 2010
  7. don't use default revision if a rev was specifiedDave Olszewski, Mar 13, 2010
  8. René ScharfeMar 13, 2010
  9. Junio C HamanoMar 14, 2010
  10. Pete HarlanMar 13, 2010
  11. René ScharfeMar 13, 2010

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.