Mercurial: Identify file name after rename

浪尽此生 提交于 2019-12-13 16:08:33

问题


Mercurial tracks the contents of a file throughout renames (hg mv $OLD $NEW), so that hg annotate $NEW also shows up the line-wise changes formerly made to $OLD with their original identification. That works fine.

BUT there seems no straightforward way to find out the name of the $OLD file, to which some given line has belonged within the ancestry of $NEW. hg annot $NEW -r$REV only works down to the rename changeset.

Of course the information is somehow accessible, e. g. by crawling through hg log (without --follow) and identifying the renames with some hg log -r$RENAMEREV -g -p (or by clicking through hg serve's web interface). But this “workflow” is not only annoying and error-prone, but [most importantly] it isn't non-interactive/scriptable.

My question: Is there a way to get/construct either

  • some list of the file name history of $NEW (best with respective revision ranges), or
  • the name of the file in which line $LINE was commited (some kind of filename option for hg annot)?

Ideas in either the hg CLI or Python/hglib appreciated.


回答1:


Either include the {file_copies} keyword in your hg log template:

$ hg init demo
$ cd demo
$ touch a
$ hg ci -Am 'file a'
adding a
$ hg mv a b
$ hg ci -Am 'moved to file b'
$ hg log -r . -T"{file_copies}\n"
b (a)

The built-in template status will include file copy info when you set the --copies flag:

$ hg log -r 1 -Tstatus --copies
changeset:   1:b37952faaddc
tag:         tip
user:        Martijn Pieters <mjpieters@fb.com>
date:        Sun Jul 31 16:07:04 2016 +0100
summary:     moved to file b
files:
A b
  a
R a

So file b was taken from a.

See hg help template for more things you can include in log output.



来源:https://stackoverflow.com/questions/38685228/mercurial-identify-file-name-after-rename

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!