6

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.

Robert Pollak
  • 3,751
  • 4
  • 30
  • 54
  • 1
    I'm no gitk expert, but the line you linked to is there to *throw out* the option when gitk is running some internal Git commands. Whether it puts the option back somewhere else, I don't know—but it's probably too late, by that point. – torek Sep 17 '20 at 21:45
  • Hmm. Do you see where these `diffargs` are finally used? I have tried adding `--find-copies-harder` directly to the two invocations of `git log` (lines 415, 563 and 1652), but this did not help. – Robert Pollak Sep 18 '20 at 12:41
  • 1
    I see a `set vdflags($n) $diffargs` at the bottom of `parseviewargs`, but vdflags itself is never used anywhere else. – torek Sep 18 '20 at 18:24

2 Answers2

2

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.)

Robert Pollak
  • 3,751
  • 4
  • 30
  • 54
0

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"?

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Sorry for not accepting this answer and awarding the bounty: As the question title says, I explicitly ask for instructions on how to modify/patch gitk. Your answer does not add anything useful to the already existing question comments. – Robert Pollak Dec 07 '20 at 09:27
  • @RobertPollak No problem. Hopefully, someone will have a more precise answer. Mine is just there to illustrate and confirm this is not supported. – VonC Dec 07 '20 at 09:30