git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Jeff King <peff@peff.net>
To: Jonas Fonseca <fonseca@diku.dk>
Cc: git@vger.kernel.org
Subject: [tig PATCH] fix off-by-one on parent selection
Date: Mon, 10 May 2010 04:55:04 -0400	[thread overview]
Message-ID: <20100510085504.GA2283@coredump.intra.peff.net> (raw)

Originally, we use "git rev-list -1 --parents" to get the
list of parents, and therefore the 0th slot was the commit
in question, the 1st slot was the 1st parent, and so forth.

Commit 0a46941 switched this to use --pretty=format:%P, so
that the menu-selection code could be easily used (which
counts items starting from 0). However, we only use the menu
code in the case of multiple parents.  For a single parent,
this introduced an off-by-one where we look just past the
parent we want.

This patch fixes it by explicitly selecting the 0th parent
for the single parent case.

Signed-off-by: Jeff King <peff@peff.net>
---
This is an old bug, but I finally got a chance to track it down.

There is a related buglet elsewhere in select_commit_parent. Now that we
ask git to print only the parents, we will get no output at all for a
parent-less commit. This will cause iobuf_read to return an error, and
we will print "Failed to get parent information" instead of "The
selected commit has no parents" (or "Path '%s' does not exist" if we are
blaming the parent of a commit that introduced a file).

AFAICT, fixing it would mean improving iobuf_read to differentiate "no
output" from "there were errors". I'll leave that sort of infrastructure
refactoring to you if you want to do it. The resulting bug is quite
minor.

 tig.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/tig.c b/tig.c
index 074e414..60932d4 100644
--- a/tig.c
+++ b/tig.c
@@ -4012,7 +4012,9 @@ select_commit_parent(const char *id, char rev[SIZEOF_REV], const char *path)
 		return FALSE;
 	}
 
-	if (parents > 1 && !open_commit_parent_menu(buf, &parents))
+	if (parents == 1)
+		parents = 0;
+	else if (!open_commit_parent_menu(buf, &parents))
 		return FALSE;
 
 	string_copy_rev(rev, &buf[41 * parents]);
-- 
1.7.1.248.gf52fc

             reply	other threads:[~2010-05-10  8:55 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-05-10  8:55 Jeff King [this message]
2010-05-22 17:19 ` [tig PATCH] fix off-by-one on parent selection Jonas Fonseca
2010-05-23  7:40   ` Jeff King
2010-05-23  7:55     ` Jeff King
2010-06-05 19:56       ` [PATCH] Improve parent blame to detect renames by using the previous information Jonas Fonseca
2010-06-05 19:57         ` [TIG PATCH] " Jonas Fonseca
2010-06-06 22:35         ` [PATCH] " Jeff King
2010-06-09 16:10           ` Jonas Fonseca
2010-06-10  2:23           ` Jonas Fonseca

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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=20100510085504.GA2283@coredump.intra.peff.net \
    --to=peff@peff.net \
    --cc=fonseca@diku.dk \
    --cc=git@vger.kernel.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.
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).