开发者

Mercurial: which addremove --similarity default is recommended?

For Hg's addremove command, I'm looking for a reasonable --similarity defaul开发者_如何学编程t.

Which value works well for all kinds of files?

Which value works well for which programming language?


There is no one good value. If there was, it would already be the default. Language and filetypes are largely irrelevant. What matters is the size of the file relative to the size of the changes you're making.

If you are simply moving files around without edits, 100 is the best answer. Mercurial probably won't make any mistakes guessing what adds and removes were actually renames.

If you are making small edits to large files while moving them around, then 90 might work well. Mercurial probably won't be fooled unless you've got some very similar files.

If you're making large changes to small files, you might need to go down to 50 to guess your rename. But the odds of Mercurial mistaking two different but similar files is now quite large.

(For comparison, Git uses a 50% heuristic by default for diffs and merges, but since it doesn't actually record renames in history, there's less permanent downside of guessing wrong.)


You can find out a suitable value for a specific situation by running Mercurial with the option --dry-run. Mercurial won't perform any action but show what it would do. You also see the similarity of each file, so you can adjust your value before performing the real action.

Example:

hg addremove --similarity 50 --dry-run
...
recording removal of ../contact_form/views.py as rename to contact_form/views.py (98% similar)


Note that the bug 3430 and the release note 2012-06-01 mention for addremove:

addremove: document default similarity behavior -s100

So, while not the "best value", -s100 (identical, simple moves without edits) is officially the default one.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜