git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: Jonas Fonseca <fonseca@diku.dk>
Cc: git@vger.kernel.org
Subject: Re: [ANNOUNCE] tig-0.11
Date: Thu, 10 Apr 2008 00:02:13 -0400	[thread overview]
Message-ID: <20080410040213.GA29618@sigill.intra.peff.net> (raw)
In-Reply-To: <20080406200533.GA20537@diku.dk>

On Sun, Apr 06, 2008 at 10:05:33PM +0200, Jonas Fonseca wrote:

> stay up to date. Finally, add a blame view accessible from the command
> line (tig blame [rev] file), status view as well as the tree view (by
> pressing 'B').

Hi Jonas,

Thanks for all your hard work.  I have really been enjoying the new
blame view; blame was the only reason I ever used git-gui, and now I can
stay in the terminal all the time.

One feature that I have often wanted when using the blame view is to
restart the blame from the parent commit of a blamed commit. That is,
given a line like:

  2007-08-22 19:36 Jonas Fonseca       776bf2a   15│ #include "config.h"

I look at 776bf2a, and realize that there was some other interesting
form of the line _before_ that commit. So I want to start reblaming at
776bf2a^.

Below is an initial attempt at a patch, but it has some problems:

  - the interface is a bit klunky. Since commits may have multiple
    parents, it seemed wrong to always just choose the first parent.
    I chose '1' to reblame from the first parent and '2' from the second
    (and obviously 3-9 could do the same).

    My thought was that the same functionality could be applied to the
    commit viewer to jump to the parent. But maybe grabbing a string and
    appending it to the commit id would make the most sense.

  - it reloads the blame view with new parameters, which will put the
    cursor back at line 1. It would be nice to stay at approximately the
    same line (approximate because the line numbers will change; just
    staying at the same line number makes sense to me).

    I tried a few things, but it looks like we throw out the line
    numbers when we do a reload. I tried saving the line number and
    trying to scroll to it afterwards, but there is some trickery
    required because we have to wait until the view is loaded again. Is
    there any sane way to do this within the current framework?

  - opening a blame view, blaming a parent, and then opening the diff
    viewer can cause a segfault. I assume I'm violating some assumption
    through my open_view() call. Since the patch is only about 15 lines,
    I'm hoping there's something obvious you can comment on.

-Peff

---
diff --git a/tig.c b/tig.c
index a3d2232..7a5497a 100644
--- a/tig.c
+++ b/tig.c
@@ -371,6 +371,8 @@ sq_quote(char buf[SIZEOF_STR], size_t bufsize, const char *src)
 	REQ_(STATUS_MERGE,	"Merge file using external tool"), \
 	REQ_(TREE_PARENT,	"Switch to parent directory in tree view"), \
 	REQ_(EDIT,		"Open in editor"), \
+	REQ_(PARENT_ONE,	"Go to first parent"), \
+	REQ_(PARENT_TWO,	"Go to second parent"), \
 	REQ_(NONE,		"Do nothing")
 
 
@@ -771,6 +773,8 @@ static struct keybinding default_keybindings[] = {
 	{ 'M',		REQ_STATUS_MERGE },
 	{ ',',		REQ_TREE_PARENT },
 	{ 'e',		REQ_EDIT },
+	{ '1',		REQ_PARENT_ONE },
+	{ '2',		REQ_PARENT_TWO },
 
 	/* Using the ncurses SIGWINCH handler. */
 	{ KEY_RESIZE,	REQ_SCREEN_RESIZE },
@@ -3678,6 +3682,32 @@ blame_request(struct view *view, enum request request, struct line *line)
 		open_view(view, REQ_VIEW_DIFF, flags);
 		break;
 
+	case REQ_PARENT_ONE:
+	case REQ_PARENT_TWO:
+		if (!blame->commit) {
+			report("No commit loaded yet");
+			break;
+		}
+
+		if (!strcmp(blame->commit->id, "0000000000000000000000000000000000000000")) {
+			report("No commit selected");
+			break;
+		}
+
+		string_ncopy(opt_ref, blame->commit->id, 40);
+		switch (request) {
+		case REQ_PARENT_ONE:
+			string_add(opt_ref, 40, "^1");
+			break;
+		case REQ_PARENT_TWO:
+			string_add(opt_ref, 40, "^2");
+			break;
+		default:
+			break;
+		}
+		open_view(view, REQ_VIEW_BLAME, flags|OPEN_RELOAD);
+		break;
+
 	default:
 		return request;
 	}

  reply	other threads:[~2008-04-10  4:03 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-04-06 20:05 [ANNOUNCE] tig-0.11 Jonas Fonseca
2008-04-10  4:02 ` Jeff King [this message]
2008-04-10  8:56   ` Jonas Fonseca
2008-05-03 21:11 ` Pascal Obry
2008-05-04 19:02   ` 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

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

  git send-email \
    --in-reply-to=20080410040213.GA29618@sigill.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.
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).