threads / discuss / 13798

[tig] Feeding specific revisions to tig

Subject: [tig] Feeding specific revisions to tig

## tl;dr

11 messages between Jun 4, 2008 and Sep 15, 2011.

replies: 10people: 3as markdown or json

Jean-Baptiste Quenot· Jun 4, 2008, 18:52 UTC · lore
Hi there,

In order to track changes between my development branch and the stable branch that goes to production, I'm using git-cherry-pick and git-cherry to list the changesets available for merging.

Ideally I'd like to feed this list of commits to tig, so that I can watch the commit diff and summary easily and switch from one commit to another. But tig only behaves as a pager, and does not help for this.

To make it short I'd like to do something like this:
git-cherry origin/stable origin/trunk | sed -ne 's/^+ //p' | tig
And browse every available commit with tig.
Does it make sense?
Cheers,
-- 
Jean-Baptiste Quenot
http://jbq.caraldi.com/
Jeff King· Jun 4, 2008, 19:29 UTC · re: Jean-Baptiste Quenot · lore

Re: [tig] Feeding specific revisions to tig

On Wed, Jun 04, 2008 at 08:52:14PM +0200, Jean-Baptiste Quenot wrote:
> Ideally I'd like to feed this list of commits to tig, so that I can
> watch the commit diff and summary easily and switch from one commit to
> another.  But tig only behaves as a pager, and does not help for this.
I think there are two issues here, but both are solvable:
  1. You want to see _just_ these commits, but not the whole ancestry
     chain. In that case, you want to use --no-walk. E.g.:
       tig --no-walk commit1 commit2 ...
     Though it seems there are a few display artifacts. If I do
       tig --no-walk tig-0.1 tig-0.2
     I get the 2 commits I expect, but also two "extra" blank
     commits at the bottom.
  2. tig works like a pager when stdin is not a tty. You can work
     around this by using xargs to give the commits to it on the
     command line, and then redirect stdin from the tty.
       ... | xargs sh -c 'tig --no-walk "$@" </dev/tty'
     which is kind of a lot to type. It might be nice for "tig -T"
     to open /dev/tty unconditionally instead of looking at stdin,
     so you could just do:
       ... | xargs tig -T --no-walk
-Peff
Jean-Baptiste Quenot· Jun 4, 2008, 20:04 UTC · re: Jeff King · lore

Re: [tig] Feeding specific revisions to tig

2008/6/4 Jeff King <peff@peff.net>:
Show 19 quoted lines
> On Wed, Jun 04, 2008 at 08:52:14PM +0200, Jean-Baptiste Quenot wrote:
>
>> Ideally I'd like to feed this list of commits to tig, so that I can
>> watch the commit diff and summary easily and switch from one commit to
>> another.  But tig only behaves as a pager, and does not help for this.
>
> I think there are two issues here, but both are solvable:
>
>  1. You want to see _just_ these commits, but not the whole ancestry
>     chain. In that case, you want to use --no-walk. E.g.:
>
>       tig --no-walk commit1 commit2 ...
>
>     Though it seems there are a few display artifacts. If I do
>
>       tig --no-walk tig-0.1 tig-0.2
>
>     I get the 2 commits I expect, but also two "extra" blank
>     commits at the bottom.

I confirm there are extra blank lines at the bottom. As many as real commit lines.

Show 5 quoted lines
>  2. tig works like a pager when stdin is not a tty. You can work
>     around this by using xargs to give the commits to it on the
>     command line, and then redirect stdin from the tty.
>
>       ... | xargs sh -c 'tig --no-walk "$@" </dev/tty'

Thanks for the suggestion. However, my list of commits is too long, the shell errors out with "tig: command too long". I'd like to feed tig with a list of commits from stdin, or from a file.

Something like: ... | tig --no-walk -F -

Which means: take the list of revisions from specified file, or here - for stdin, a la grep.

Cheers,
-- 
Jean-Baptiste Quenot
http://jbq.caraldi.com/
Jeff King· Jun 4, 2008, 23:08 UTC · re: Jean-Baptiste Quenot · lore

Re: [tig] Feeding specific revisions to tig

On Wed, Jun 04, 2008 at 10:04:45PM +0200, Jean-Baptiste Quenot wrote:
Show 8 quoted lines
> Thanks for the suggestion.  However, my list of commits is too long,
> the shell errors out with "tig: command too long".  I'd like to feed
> tig with a list of commits from stdin, or from a file.
> 
> Something like: ... | tig --no-walk -F -
> 
> Which means: take the list of revisions from specified file, or here -
> for stdin, a la grep.

Ah. Adding "-F" probably wouldn't be that much work, but tig spawns "git log" internally, so you would probably end up with the same problem there. Converting tig to use "git rev-list --stdin" would fix that, but is probably a bit of major surgery.

-Peff
Jonas Fonseca· Aug 6, 2008, 11:06 UTC · re: Jeff King · lore

Re: [tig] Feeding specific revisions to tig

Sorry for restarting this old thread ...
On Thu, Jun 5, 2008 at 01:08, Jeff King <peff@peff.net> wrote:
Show 15 quoted lines
> On Wed, Jun 04, 2008 at 10:04:45PM +0200, Jean-Baptiste Quenot wrote:
>
>> Thanks for the suggestion.  However, my list of commits is too long,
>> the shell errors out with "tig: command too long".  I'd like to feed
>> tig with a list of commits from stdin, or from a file.
>>
>> Something like: ... | tig --no-walk -F -
>>
>> Which means: take the list of revisions from specified file, or here -
>> for stdin, a la grep.
>
> Ah. Adding "-F" probably wouldn't be that much work, but tig spawns "git
> log" internally, so you would probably end up with the same problem
> there. Converting tig to use "git rev-list --stdin" would fix that, but
> is probably a bit of major surgery.

git-rev-list expects a commit as an argument while git-log does not. I have been gradually changing the option parsing code to move towards using git-rev-parse for splitting up arguments so it will be possible to support refreshing better and pass user arguments to the diff engine etc. When the code will get there it probably won't be that hard to switch to use git-rev-list.

I actually added something that let's you alter the command executed for each view. So here is another possibility that can be used:

function tignowalk ()
{
   tmp=$(mktemp) # or .git/tigfiles or similar
   # Safe stuff from "stdin" and run tig with custom rev-list command
   cat > "$tmp
   TIG_MAIN_CMD="git rev-list --pretty=raw --no-walk --stdin < $tmp"
tig < /dev/tty
   rm "$tmp"
}
And then:
   printf "tig-0.2\ntig-0.1" | tignowalk
On Wed, Jun 4, 2008 at 22:04, Jean-Baptiste Quenot <jbq@caraldi.com> wrote:
Show 10 quoted lines
> 2008/6/4 Jeff King <peff@peff.net>:
>>     Though it seems there are a few display artifacts. If I do
>>
>>       tig --no-walk tig-0.1 tig-0.2
>>
>>     I get the 2 commits I expect, but also two "extra" blank
>>     commits at the bottom.
>
> I confirm there are extra blank lines at the bottom.  As many as real
> commit lines.

The problem is that --no-walk doesn't seem to play nice with the --boundary flag that tig add by default. When the user requests --no-walk boundary commits are probably not interesting. My fix below has more information. I don't know if having only the "commit" line show up is a bug in git. At least there are no tests to confirm this or not.

commit ad9f9954419b5d3f595580d5184db59a00711f92
Author: Jonas Fonseca <fonseca@diku.dk>
Date:   Tue Aug 5 23:40:21 2008 +0200
    Clean up incomplete commits from main view listed for --no-walk
    When --no-walk is given on the command line by the user it causes
    boundary commits to be output with just the commit line, i.e:
      > git rev-list --pretty=raw --boundary --no-walk HEAD
      commit 60e8ea56880fc2e42008075d516c356ef605bc60
      tree 5b76086e4deaf62d3f7baffc6f49840f61d4e79c
      parent 145194bdfc8bf0b58185bbe28bc0097ce429de4d
      author Jonas Fonseca <fonseca@diku.dk> 1217797175 +0200
      committer Jonas Fonseca <fonseca@diku.dk> 1217797402 +0200
          Remove the global opt_request variable
      commit -145194bdfc8bf0b58185bbe28bc0097ce429de4d
diff --git a/NEWS b/NEWS
index b7a8df1..d93fb04 100644
--- a/NEWS
+++ b/NEWS
@@ -22,6 +22,7 @@ Bug fixes:
    keybinding to launch the merge tool in the status view.
  - Fix problem with $(cmd) usage in shell code. Some shells (jsh)
    installed as /bin/sh does not support it.
+ - Do not show incomplete boundary commits when --no-walk is used.
  - Documentation: Rename gitlink macro to support AsciiDoc 8.2.3.

 tig-0.11
diff --git a/tig.c b/tig.c
index 6846519..6b111e4 100644
--- a/tig.c
+++ b/tig.c
@@ -4983,6 +4983,14 @@ main_read(struct view *view, char *line)
 	if (!line) {
 		if (!view->lines && !view->parent)
 			die("No revisions match the given arguments.");
+		if (view->lines > 0) {
+			commit = view->line[view->lines - 1].data;
+			if (!*commit->author) {
+				view->lines--;
+				free(commit);
+				graph->commit = NULL;
+			}
+		}
 		update_rev_graph(graph);
 		return TRUE;
 	}
-- 
Jonas Fonseca
Jeff King· Aug 8, 2008, 21:19 UTC · re: Jonas Fonseca · lore

Re: [tig] Feeding specific revisions to tig

On Wed, Aug 06, 2008 at 01:06:51PM +0200, Jonas Fonseca wrote:
> Sorry for restarting this old thread ...
I am glad you got a chance to look at it. :)
Show 12 quoted lines
> I actually added something that let's you alter the command executed
> for each view. So here is another possibility that can be used:
> 
> function tignowalk ()
> {
>    tmp=$(mktemp) # or .git/tigfiles or similar
>    # Safe stuff from "stdin" and run tig with custom rev-list command
>    cat > "$tmp
>    TIG_MAIN_CMD="git rev-list --pretty=raw --no-walk --stdin < $tmp"
> tig < /dev/tty
>    rm "$tmp"
> }

Neat, if a bit hack-ish. :) You are missing a closing quotation mark after

  cat > "$tmp

and the line break between TIG_MAIN_CMD and tig is obviously problematic (presumably an artifact of the email, but it confused my cut and paste efforts for a minute). One other thing to note is that even though you try to handle a $tmp with whitespace in the cat and rm commands, I suspect it would fail when tig hands TIG_MAIN_CMD to the shell. That would require double-quoting.

So here is my cut-and-pastable version:
  tignowalk() {
    tmp=$(mktemp)
    cat >"$tmp"
    TIG_MAIN_CMD="git rev-list --pretty=raw --no-walk --stdin <$tmp" \
      tig </dev/tty
    rm "$tmp"
  }
The output looks great, though. Doing
  git show-ref --heads | cut -d' ' -f2 | tignowalk
is nice. :)
Show 6 quoted lines
> The problem is that --no-walk doesn't seem to play nice with the
> --boundary flag that tig add by default. When the user requests
> --no-walk boundary commits are probably not interesting. My fix below
> has more information. I don't know if having only the "commit" line
> show up is a bug in git. At least there are no tests to confirm this
> or not.
Sorry, I don't know if that is intentional or not.
-Peff
Jonas Fonseca· Aug 10, 2008, 09:16 UTC · re: Jeff King · lore

Re: [tig] Feeding specific revisions to tig

On Fri, Aug 8, 2008 at 23:19, Jeff King <peff@peff.net> wrote:
Show 25 quoted lines
> On Wed, Aug 06, 2008 at 01:06:51PM +0200, Jonas Fonseca wrote:
>> I actually added something that let's you alter the command executed
>> for each view. So here is another possibility that can be used:
>>
>> function tignowalk ()
>> {
>>    tmp=$(mktemp) # or .git/tigfiles or similar
>>    # Safe stuff from "stdin" and run tig with custom rev-list command
>>    cat > "$tmp
>>    TIG_MAIN_CMD="git rev-list --pretty=raw --no-walk --stdin < $tmp"
>> tig < /dev/tty
>>    rm "$tmp"
>> }
>
> Neat, if a bit hack-ish. :) You are missing a closing quotation mark
> after
>
>  cat > "$tmp
>
> and the line break between TIG_MAIN_CMD and tig is obviously problematic
> (presumably an artifact of the email, but it confused my cut and paste
> efforts for a minute). One other thing to note is that even though you
> try to handle a $tmp with whitespace in the cat and rm commands, I
> suspect it would fail when tig hands TIG_MAIN_CMD to the shell. That
> would require double-quoting.

Yes, this way to "hook" into tig is a bit hackish and gives some problems with handling files. But then again, it is hidden away in env. variables, which seems very effective in not getting it too exposed. :)

Show 9 quoted lines
> So here is my cut-and-pastable version:
>
>  tignowalk() {
>    tmp=$(mktemp)
>    cat >"$tmp"
>    TIG_MAIN_CMD="git rev-list --pretty=raw --no-walk --stdin <$tmp" \
>      tig </dev/tty
>    rm "$tmp"
>  }
Thanks for the fixed up version.
-- 
Jonas Fonseca
Jean-Baptiste Quenot· Apr 23, 2009, 14:55 UTC · re: Jonas Fonseca · lore

Re: [tig] Feeding specific revisions to tig

2008/8/10 Jonas Fonseca <jonas.fonseca@gmail.com>:
Show 11 quoted lines
>> So here is my cut-and-pastable version:
>>
>>  tignowalk() {
>>    tmp=$(mktemp)
>>    cat >"$tmp"
>>    TIG_MAIN_CMD="git rev-list --pretty=raw --no-walk --stdin <$tmp" \
>>      tig </dev/tty
>>    rm "$tmp"
>>  }
>
> Thanks for the fixed up version.

Restarting this old thread again. Starting from 0.13 the *tignowalk()* hack does not work anymore. What's the preferred way to feed specific revisions using stdin now?

-- 
Jean-Baptiste Quenot
http://jbq.caraldi.com/
Jonas Fonseca· Apr 27, 2009, 10:21 UTC · re: Jean-Baptiste Quenot · lore

Re: [tig] Feeding specific revisions to tig

Sorry for the slow reply ...
On Thu, Apr 23, 2009 at 16:55, Jean-Baptiste Quenot <jbq@caraldi.com> wrote:
Show 16 quoted lines
> 2008/8/10 Jonas Fonseca <jonas.fonseca@gmail.com>:
>>> So here is my cut-and-pastable version:
>>>
>>>  tignowalk() {
>>>    tmp=$(mktemp)
>>>    cat >"$tmp"
>>>    TIG_MAIN_CMD="git rev-list --pretty=raw --no-walk --stdin <$tmp" \
>>>      tig </dev/tty
>>>    rm "$tmp"
>>>  }
>>
>> Thanks for the fixed up version.
>
> Restarting this old thread again.  Starting from 0.13 the
> *tignowalk()* hack does not work anymore.  What's the preferred way to
> feed specific revisions using stdin now?
I don't know if it is preferred, but it works. First add a git alias:
[alias]
        tignowalk-helper = !git rev-list --pretty=raw --no-walk --stdin<
Then modify tignowalk by replacing the line calling tig to say:
TIG_MAIN_CMD="git tignowalk-helper $tmp" tig </dev/tty

... and it should work. Maybe more git alias functionality can simplify the hack.

-- 
Jonas Fonseca
Jean-Baptiste Quenot· Apr 28, 2009, 08:15 UTC · re: Jonas Fonseca · lore

Re: [tig] Feeding specific revisions to tig

2009/4/27 Jonas Fonseca <jonas.fonseca@gmail.com>:
> On Thu, Apr 23, 2009 at 16:55, Jean-Baptiste Quenot <jbq@caraldi.com> wrote:
Show 15 quoted lines
>> Restarting this old thread again.  Starting from 0.13 the
>> *tignowalk()* hack does not work anymore.  What's the preferred way to
>> feed specific revisions using stdin now?
>
> I don't know if it is preferred, but it works. First add a git alias:
>
> [alias]
>        tignowalk-helper = !git rev-list --pretty=raw --no-walk --stdin<
>
> Then modify tignowalk by replacing the line calling tig to say:
>
> TIG_MAIN_CMD="git tignowalk-helper $tmp" tig </dev/tty
>
> ... and it should work. Maybe more git alias functionality can
> simplify the hack.
Works a treat, thanks!
I wonder how you managed to invent this trick though :-)
-- 
Jean-Baptiste Quenot
http://jbq.caraldi.com/
Jean-Baptiste Quenot· Sep 15, 2011, 15:10 UTC · re: Jonas Fonseca · lore

Re: [tig] Feeding specific revisions to tig

2009/4/27 Jonas Fonseca <jonas.fonseca@gmail.com>:
Show 18 quoted lines
> Sorry for the slow reply ...
>
> On Thu, Apr 23, 2009 at 16:55, Jean-Baptiste Quenot <jbq@caraldi.com> wrote:
>> Restarting this old thread again.  Starting from 0.13 the
>> *tignowalk()* hack does not work anymore.  What's the preferred way to
>> feed specific revisions using stdin now?
>
> I don't know if it is preferred, but it works. First add a git alias:
>
> [alias]
>        tignowalk-helper = !git rev-list --pretty=raw --no-walk --stdin<
>
> Then modify tignowalk by replacing the line calling tig to say:
>
> TIG_MAIN_CMD="git tignowalk-helper $tmp" tig </dev/tty
>
> ... and it should work. Maybe more git alias functionality can
> simplify the hack.

Restarting this thread again... it seems like every new version of tig breaks this usecase :-)

Any idea how to feed specific revisions to tig 0.18? The trick does not work anymore, as support for TIG_MAIN_CMD was dropped.

-- 
Jean-Baptiste Quenot

← back to recent threads