如何向 gitk 添加更好的复制检测?
How to add better copy detection to gitk?
在命令行 Git 中,show
、diff
和 log
命令有一个选项 --find-copies-harder
。
有什么方法可以告诉(或修补)gitk
也使用它吗?我不时需要这个,而且我的项目足够小,所以我不关心性能下降。
(我不想再craft the history to force copy detection了。)
我注意到 --find-copies-harder
appears within the gitk code,但我不明白为什么。
所以我尝试了命令行 gitk --all --find-copies-harder
,但它没有用:在从另一个版本文件复制的新文件的提交中,gitk 仍然没有显示这个文件被复制的事实。
更新:通过在字段 Additional arguments to git log:
中输入 --find-copies-harder
来编辑视图也没有效果:复制(并稍作修改)的文件仍未显示为已复制,而在命令行中git show --find-copies-harder
是。
如果不以某种方式修补 gitk 源代码本身,这似乎不受支持。
例如,Git 邮件列表中有一个 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
"?
必要的更改是:
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
}
由此,gitk 在以下测试存储库的第二次提交中显示副本
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"
随心所欲:
-------------------------------------- b --------------------------------------
similarity index 100%
copy from a
copy to b
但请注意,可能会有意想不到的副作用,因为修改后的过程 'diffcmd' 在多个地方被调用。我没有系统地测试所有这些代码路径。
(我也有sent a generalized version of this patch to the Git mailing list。)
在命令行 Git 中,show
、diff
和 log
命令有一个选项 --find-copies-harder
。
有什么方法可以告诉(或修补)gitk
也使用它吗?我不时需要这个,而且我的项目足够小,所以我不关心性能下降。
(我不想再craft the history to force copy detection了。)
我注意到 --find-copies-harder
appears within the gitk code,但我不明白为什么。
所以我尝试了命令行 gitk --all --find-copies-harder
,但它没有用:在从另一个版本文件复制的新文件的提交中,gitk 仍然没有显示这个文件被复制的事实。
更新:通过在字段 Additional arguments to git log:
中输入 --find-copies-harder
来编辑视图也没有效果:复制(并稍作修改)的文件仍未显示为已复制,而在命令行中git show --find-copies-harder
是。
如果不以某种方式修补 gitk 源代码本身,这似乎不受支持。
例如,Git 邮件列表中有一个 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
"?
必要的更改是:
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
}
由此,gitk 在以下测试存储库的第二次提交中显示副本
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"
随心所欲:
-------------------------------------- b --------------------------------------
similarity index 100%
copy from a
copy to b
但请注意,可能会有意想不到的副作用,因为修改后的过程 'diffcmd' 在多个地方被调用。我没有系统地测试所有这些代码路径。
(我也有sent a generalized version of this patch to the Git mailing list。)