threads / discuss / 35247

Show patch in gitk --first-parent ?

Subject: Show patch in gitk --first-parent ?

## tl;dr

6 messages between Oct 30, 2013 and Oct 31, 2013.

replies: 5people: 4as markdown or json

Karl Wiberg· Oct 30, 2013, 12:39 UTC · lore
Hi all,

With "gitk --first-parent", I get a graph that only follows the first parent of every merge---perfect if you always merge topic branches into the main branch. However, the diff shown is still the normal merge diff, and not the diff between the new tree and the first parent's tree---is it possible to make it do that instead?

(With "git log --first-parent -p -m", I get precisely the diffs I want, but everything is fully expanded so it's hard to navigate.)

-- 
Karl Wiberg, kha@treskal.com
   subrabbit.wordpress.com
   www.treskal.com/kalle
Stefan Haller· Oct 30, 2013, 14:30 UTC · re: Karl Wiberg · lore

Re: Show patch in gitk --first-parent ?

Karl Wiberg <kha@treskal.com> wrote:
Show 5 quoted lines
> With "gitk --first-parent", I get a graph that only follows the first
> parent of every merge---perfect if you always merge topic branches
> into the main branch. However, the diff shown is still the normal
> merge diff, and not the diff between the new tree and the first
> parent's tree---is it possible to make it do that instead?

I once posted a patch that adds a "First parent" checkbox to gitk's window: <http://comments.gmane.org/gmane.comp.version-control.git/160920>

The patch no longer applies today, but I can send an updated version that does, if there's interest.

The topic didn't go anywhere for two reasons:
1) There's the confusion about history traversal option (the existing
--first-parent command-line option) versus diff option (the new check
box); they have similar names, but control different things (and it
should be possible to control these independently).
2) Space is short in the diff pane; you need to make the window rather
wide to see them all.

I didn't have the energy to drive these to a resolution back then; if you could do that, it would be great. Personally I'm using my own gitk with my patch applied, and I do use the "First parent" checkbox rather often.

-- 
Stefan Haller
Berlin, Germany
http://www.haller-berlin.de/
Karl Wiberg· Oct 30, 2013, 17:10 UTC · re: Stefan Haller · lore

Re: Show patch in gitk --first-parent ?

On Wed, Oct 30, 2013 at 3:30 PM, Stefan Haller <lists@haller-berlin.de> wrote:
Show 6 quoted lines
> I once posted a patch that adds a "First parent" checkbox to gitk's
> window:
> <http://comments.gmane.org/gmane.comp.version-control.git/160920>
>
> The patch no longer applies today, but I can send an updated version
> that does, if there's interest.

Please do. I don't have the time to attempt to drive inclusion of the patch (I'd have to start by reading up on tcl and gitk), but if you have a patch ready, I'd like to try it.

Show 14 quoted lines
> The topic didn't go anywhere for two reasons:
>
> 1) There's the confusion about history traversal option (the
> existing --first-parent command-line option) versus diff option (the
> new check box); they have similar names, but control different
> things (and it should be possible to control these independently).
>
> 2) Space is short in the diff pane; you need to make the window
> rather wide to see them all.
>
> I didn't have the energy to drive these to a resolution back then;
> if you could do that, it would be great. Personally I'm using my own
> gitk with my patch applied, and I do use the "First parent" checkbox
> rather often.

Hmmm, I wonder... a related feature I'd like to have is to see the combined diff of two or more commits. I guess the fully general form of this is to allow the user to select one "after" commit and zero or more "before" commits, and then present the resulting diff.

For example, when the user clicks on the shortlog of a commit, gitk could automatically select its parents (by painting their dots in the DAG differently, say). The user could then click on any commit dot in the dag to toggle it between being included in and excluded from the "before" set. (A simpler variant would be to limit the "before" set to exactly one commit as soon as the user changes it at all.)

As I said, I don't have time to do this myself; I just thought I'd toss the idea out there, since good ideas are so scarce and competent programmers with free time on their hands are so plentiful.

-- 
Karl Wiberg, kha@treskal.com
   subrabbit.wordpress.com
   www.treskal.com/kalle
Stefan Haller· Oct 31, 2013, 14:59 UTC · re: Karl Wiberg · lore

[PATCH] gitk: Add "First parent" checkbox

Sometimes it's desirable to see what changes were introduced by a merge commit, rather than how conflicts were resolved. This adds a checkbox which, when turned on, makes gitk show the equivalent of "git show --first-parent <commit>" for merge commits.

Signed-off-by: Stefan Haller <stefan@haller-berlin.de>
---
This is the same patch as the one I sent in
<http://comments.gmane.org/gmane.comp.version-control.git/160920>, with
the same issues discussed in that thread. I just brought it up to date
with current master.
 gitk | 25 ++++++++++++++++++++++---
 1 file changed, 22 insertions(+), 3 deletions(-)
diff --git a/gitk b/gitk
index 5cd00d8..3466054 100755
--- a/gitk
+++ b/gitk
@@ -2336,6 +2336,10 @@ proc makewindow {} {
 	pack .bleft.mid.worddiff -side left -padx 5
     }

+    ${NS}::checkbutton .bleft.mid.firstparent -text [mc "First parent"] \
+	-command changefirstparent -variable firstparent
+    pack .bleft.mid.firstparent -side left -padx 5
+
     set ctext .bleft.bottom.ctext
     text $ctext -background $bgcolor -foreground $fgcolor \
 	-state disabled -font textfont \
@@ -7080,6 +7084,7 @@ proc selectline {l isnew {desired_loc {}}} {
     global cmitmode showneartags allcommits
     global targetrow targetid lastscrollrows
     global autoselect autosellen jump_to_here
+    global firstparent

     catch {unset pending_select}
     $canv delete hover
@@ -7221,7 +7226,7 @@ proc selectline {l isnew {desired_loc {}}} {
     init_flist [mc "Comments"]
     if {$cmitmode eq "tree"} {
 	gettree $id
-    } elseif {[llength $olds] <= 1} {
+    } elseif {[llength $olds] <= 1 || $firstparent} {
 	startdiff $id
     } else {
 	mergediff $id
@@ -7624,7 +7629,7 @@ proc diffcmd {ids flags} {
 proc gettreediffs {ids} {
     global treediff treepending limitdiffs vfilelimit curview

-    set cmd [diffcmd $ids {--no-commit-id}]
+    set cmd [diffcmd $ids {--no-commit-id -m --first-parent}]
     if {$limitdiffs && $vfilelimit($curview) ne {}} {
 	    set cmd [concat $cmd -- $vfilelimit($curview)]
     }
@@ -7710,12 +7715,20 @@ proc changeworddiff {name ix op} {
     reselectline
 }

+proc changefirstparent {} {
+    global treediffs
+    catch {unset treediffs}
+
+    reselectline
+}
+
 proc getblobdiffs {ids} {
     global blobdifffd diffids env
     global diffinhdr treediffs
     global diffcontext
     global ignorespace
     global worddiff
+    global firstparent
     global limitdiffs vfilelimit curview
     global diffencoding targetline diffnparents
     global git_version currdiffsubmod
@@ -7728,13 +7741,18 @@ proc getblobdiffs {ids} {
     if {[package vcompare $git_version "1.6.6"] >= 0} {
 	set submodule "--submodule"
     }
-    set cmd [diffcmd $ids "-p $textconv $submodule  -C --cc --no-commit-id -U$diffcontext"]
+    set cmd [diffcmd $ids "-p $textconv $submodule  -C --no-commit-id -U$diffcontext"]
     if {$ignorespace} {
 	append cmd " -w"
     }
     if {$worddiff ne [mc "Line diff"]} {
 	append cmd " --word-diff=porcelain"
     }
+    if {$firstparent} {
+	append cmd " -m --first-parent"
+    } else {
+	append cmd " --cc"
+    }
     if {$limitdiffs && $vfilelimit($curview) ne {}} {
 	set cmd [concat $cmd -- $vfilelimit($curview)]
     }
@@ -11865,6 +11883,7 @@ set diffcontext 3
 set mergecolors {red blue green purple brown "#009090" magenta "#808000" "#009000" "#ff0080" cyan "#b07070" "#70b0f0" "#70f0b0" "#f0b070" "#ff70b0"}
 set ignorespace 0
 set worddiff ""
+set firstparent 0
 set markbgcolor "#e0e0ff"

 set headbgcolor green
--
1.8.3.2.747.g15edaa9
Andreas Schwab· Oct 30, 2013, 17:55 UTC · re: Karl Wiberg · lore

Re: Show patch in gitk --first-parent ?

Karl Wiberg <kha@treskal.com> writes:
Show 5 quoted lines
> With "gitk --first-parent", I get a graph that only follows the first
> parent of every merge---perfect if you always merge topic branches
> into the main branch. However, the diff shown is still the normal
> merge diff, and not the diff between the new tree and the first
> parent's tree---is it possible to make it do that instead?

While not automatic, you can right click on the parent and select Diff this->selected.

Andreas.
-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."
Karl Wiberg· Oct 31, 2013, 10:10 UTC · re: Andreas Schwab · lore

Re: Show patch in gitk --first-parent ?

On Wed, Oct 30, 2013 at 6:55 PM, Andreas Schwab <schwab@linux-m68k.org> wrote:
> While not automatic, you can right click on the parent and select
> Diff this->selected.

And there's also the option to "mark" a commit, and diff this with marked. Thanks, that's just what I needed (although as you say, it isn't automatic).

-- 
Karl Wiberg, kha@treskal.com
   subrabbit.wordpress.com
   www.treskal.com/kalle

← back to recent threads