How to add better copy detection to gitk?

Viewed 134

In command line Git, the show, diff and log commands have got an option to --find-copies-harder.

Is there a way I can tell (or patch) gitk to use this, too? I need this from time to time, and my projects are small enough such that I don't care about the reduced performance.

(I don't want to craft the history to force copy detection any more.)

I noticed that the --find-copies-harder appears within the gitk code, but I don't understand why. So I have tried the command line gitk --all --find-copies-harder, but it didn't work: In a commit with a new file copied from another versioned file, gitk still did not display the fact that this file was copied.

Update: Editing the view by entering --find-copies-harder into the field Additional arguments to git log: also has no effect: A copied (and slightly modified) file is still not shown as copied, while in the command line git show --find-copies-harder it is.

2 Answers

The necessary change is:

diff --git a/gitk-git/gitk b/gitk-git/gitk
index 23d9dd1fe0..a98a115080 100755
--- a/gitk-git/gitk
+++ b/gitk-git/gitk
@@ -7909,7 +7909,7 @@ proc diffcmd {ids flags} {
         if {$log_showroot} {
             lappend flags --root
         }
-        set cmd [concat | git diff-tree -r $flags $ids]
+        set cmd [concat | git diff-tree --find-copies-harder -r $flags $ids]
     }
     return $cmd
 }

With this, gitk displays the copy in the second commit of the following test repository

git init
echo "a file" > a
git add a
git commit -m "a file"
cp a b
git add b
git commit -m "a copy"

as desired:

-------------------------------------- b --------------------------------------
similarity index 100%
copy from a
copy to b

But note that there might be unintended side effects, since the modified procedure 'diffcmd' is called in several places. I did not systematically test all these code paths.

(I have also sent a generalized version of this patch to the Git mailing list.)

That does not seem supported without patching somehow the gitk source code itself.

For example, there was in the Git mailing list a similar request in Feb. 2020

As of commit c1a63459ed73 ("gitk: Preserve window dimensions on exit when not using ttk themes", 2019-12-15, Git v2.29.0-rc0), gitk seems to lack two features that I consider "killer" ones, for reviewing patches (including my own patches, of course):

  • support for the "--function-context" ("-W") option,
  • support for the "-O<orderfile>" (aka "diff.orderFile") setting.

These flags are in fact mentioned in the gitk source code, going back to historical commit ee66e089c1d4 ("gitk: Make updates go faster", 2008-05-09, Git v1.5.6-rc0).

The options are stashed in vdflags($n), and then summarily ignored.
A comment says, "These request or affect diff output, which we don't want", and I don't understand why; I would very much like them, please :)

Could someone please write gitk patches for honoring "diff.orderFile" and "--function-context"?

Related