开发者

mercurial log format with file-statuses

I was wondering, how do I return files added/modified/deleted for a commit in such a format:

<modifier> file
<modifier> path/to/a/file
<modifier> path/to/another/file

In git I do this: "git show --pretty="format:" --name-status commitish" and get:

D       file
A       path/to/a/file
M       path/to/another/file

For mercurial I can't figure out how to do it with templates. I have a style file:

changeset = "{file_mo开发者_运维知识库ds}{file_adds}{file_dels}"
file_add  = "A {file_add}\n"
file_mod  = "M {file_mod}\n"
file_del  = "D {file_del}\n"

and with this style and command "hg log -r commitish --style ~/.hgstyle" I get almost what I want:

M path/to/another/file
A path/to/a/file
D file

There is still one issue with mercurial - files are not sorted in good order.

How do I get the same result as on git command (with modifiers and sorted correctly) on mercurial?


Try this:

hg stat --change THE_REV_YOU_WANT


There is no direct way using the templating engine, but you could try:

hg log --style ~/.hgstyle -r <rev> | sort -k2

This will sort the output of the log command on the second column of data (i.e. the file names).


Maybe I didn't understood correctly, but if you want deletion first, then addition and finally modifications, symply change the first line of your style file :

changeset = "{file_dels}{file_adds}{file_mods}"

You can also add a tabulation (\t) instead of a space if you want to be closer to the Git look :

file_add  = "A\t{file_add}\n"


Add this to your .hgrc file

[alias]
prettylog = log -r : --template "{rev} | {date|shortdate} | {desc|strip|firstline}\n{file_dels % '  - {file}\n'}{file_adds % '  + {file}\n'}{file_mods % '  ~ {file}\n'}\n"

It'll print a neatly formatted output like this (2 is the rev number):

2 | 2014-03-21 | my new log format
  - js/remove_me.js
  + js/add_me.js
  ~ doc/modified_me.txt
  ~ www/index.html
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜