Re: [ANNOUNCE] tig-0.11

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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;
 	}
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux