简体   繁体   English

指定修订集时,如何使用Hg日志限制N个最新条目?

[英]How to limit to N newest entries with Hg Log when specifying a Revset?

This question is not a duplicate of hg log - How to get the last 5 log entries? 这个问题不是hg日志的重复-如何获取最后5个日志条目? - it is easy to apply a limit. -容易应用限制。 The problem is that the log output, when limited , does not appear to always be ordered descending by log date - the behavior changes with the addition of a revset. 问题在于,当日志输出为limited时 ,它似乎并不总是按日志日期的降序排列-行为随着revset的增加而改变。

For example, the simple log work "as expected" and it is displays the newest five log entries. 例如,简单的日志工作“按预期”,它显示最新的五个日志条目。

hg log -l5

However, when using a revset the result is the oldest nodes first (as observed without -l ); 但是,当使用revset时,结果首先是最早的节点(如不使用-l观察到的那样); hence the following shows the oldest five entries which is not desired. 因此,以下显示了不需要的五个条目。

hg log -r "user('Me')" -l5

How can can hg log , with a revset, be instructed to order by the log date descending ("as expected") so that the limit has a predictable 1 and meaningful effect? 如何通过日志日期降序 (“按预期”)指示带有修订版的hg log进行排序,以便限制具有可预测的1和有意义的作用?


$ hg --version
Mercurial Distributed SCM (version 3.6.1)

1 I don't consider throwing random reverse calls in a rev set predictable, but if that is the "best" way.. 1我不考虑以可预测的转速抛出随机reverse调用,但是如果那是“最佳”方式。

There are a couple of options you have. 您有几种选择。

First, you can use reverse() in conjunction with your existing revset, eg: 首先,您可以将reverse()与现有的revset结合使用,例如:

hg log -r 'reverse(user("me"))' -l 5

As a shorthand, you can also use -f or --follow , which – when used in conjunction with -r – will wrap the revision in reverse(...) . 作为简写,您也可以使用-f--follow ,当与-r结合使用时,会将修订版本包装在reverse(...) Example: 例:

hg log -f -r 'user("me")' -l 5

Or you can encode the limit in the changeset, eg: 或者,您可以在变更集中对限制进行编码,例如:

hg log -r 'last(user("me"), 5)'

Note that revset aliases can be useful to avoid having to type out revsets over and over. 请注意,revset别名对于避免不得不一遍又一遍地输入revset很有用。 So, you can put something like this in your .hgrc : 因此,您可以在.hgrc放入以下内容:

[revsetalias]
lastby($1) = last(user($1), 5)

And then do: 然后执行:

hg log -r 'lastby("me")`

Important addendum answer: do not use reverse blindly for this task. 重要提示编的答案: 使用reverse盲目这项任务。 While it will work in many cases, the better/reliable generic solution is to use sort , as in: 尽管在许多情况下都可以使用,但更好/更可靠的通用解决方案是使用sort ,如下所示:

hg log -r 'sort(user("me"), "-date")' -l 5

This is because reverse does not guarantee the source set order is well-ordered - as such it may still result in final output that does not meet the requested criteria of 'newest'. 这是因为reverse 不能保证源设置顺序是有序的 -这样,它仍然可能导致最终输出符合所请求的“最新”标准。

The use of sort above guarantees the behavior as it sorts by the date, descending, and then selects the top 5 per hg log's limit option. 上面使用sort可以保证其行为,因为它按日期,降序进行排序,然后选择每hg日志的limit选项的前5个。

(Otherwise, see Reimer's answer.) (否则,请参阅Reimer的答案。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM