mercurial log format with file-statuses

允我心安 提交于 2019-12-23 12:49:20

问题


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_mods}{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?


回答1:


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




回答2:


Try this:

hg stat --change THE_REV_YOU_WANT



回答3:


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"



回答4:


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


来源:https://stackoverflow.com/questions/5977525/mercurial-log-format-with-file-statuses

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