简体   繁体   English

如何在mercurial中提取下一个k变换集

[英]How to pull the next k changesets in mercurial

Suppose I want to pull the next k changesets from a remote repository, where k is greater than or equal to 1. Is there some syntax that will allow be to do so? 假设我想从远程存储库中提取下一个k变更集,其中k大于或等于1.是否有一些语法允许这样做? A command that falls back to plain pull if the changesets available are less than or equal to k would be nice. 如果可用的变更集小于或等于k,则返回到普通pull命令将是不错的。

Of course, in this case. 当然,在这种情况下。 the term "next" references the local revision numbers of the repository, which the remote repository does not expose publicly. 术语“next”引用存储库的本地修​​订号,远程存储库不公开显示。

I realise I can look up a suitable hash if the repository is available to browse via a web interface, but is there a way to do this without any specific information about the remote repository? 我知道如果存储库可以通过Web界面浏览,我可以查找合适的哈希,但有没有办法在没有任何关于远程存储库的特定信息的情况下执行此操作?

If you use hg incoming as a source for changeset hashes, then it's possible to extract N-th hash with awk (in my case, GNU-flavored), for example. 如果你使用hg incoming作为变更集哈希的源,那么可以用awk (在我的例子中,GNU-flavored)提取第N个哈希值。 Feeding the obtained hash to the hg pull then will pull that changeset and all its ancestors. 将获得的哈希提供给hg pull然后将拉出该变更集及其所有祖先。 You can further refine the list of changesets with options to hg incoming , such as --branch. 您可以使用hg incoming选项进一步优化变更集列表,例如--branch。

Here's the example: 这是一个例子:

hg pull -r $(hg in -q -T'{node}\n' | \
    gawk '\
        BEGIN {chunk=10} \
        NR == chunk {printf $0} \
        END {if (chunk > NR) printf $0}')

will pull at most the next incoming 10 changesets. 将最多拉出下一个传入的10个变更集。 You can control the number via chunk variable in awk script. 您可以在awk脚本中通过chunk变量控制数字。

Since, as you understand, the revision numbers locally and remotely don't necessarily correspond, you'll not know exactly which revisions you're getting, but you can assume the total quantity will be the same, so you can probably take your current revision number plus k, and just use that number. 因为,正如您所理解的那样,本地和远程的修订号不一定对应,您不会确切地知道您正在获得哪些修订,但您可以假设总数量相同,因此您可以考虑当前修订号加上k,只需使用该号码即可。 Something like this: 像这样的东西:

hg pull -r $(( $(hd id -n -r tip) + 50)) || hg pull

Each time you run that it will try to pull 50 more than it has, and if that fails just pull what's left. 每次你运行它会尝试拉50多,如果失败只是拉左边的东西。 Here's a sample: 这是一个示例:

ry4an@four:~/projects$ hg clone -r 1 unblog unblog-clone
adding changesets
adding manifests
adding file changes
added 2 changesets with 9 changes to 9 files
updating to branch default
9 files updated, 0 files merged, 0 files removed, 0 files unresolved
ry4an@four:~/projects$ cd unblog-clone/
ry4an@four:~/projects/unblog-clone$ hg pull -r $(( $(hg id -n -r tip) + 50)) || hg pull
pulling from /home/ry4an/projects/unblog
searching for changes
adding changesets
adding manifests
adding file changes
added 50 changesets with 505 changes to 227 files
(run 'hg update' to get a working copy)
ry4an@four:~/projects/unblog-clone$ hg pull -r $(( $(hg id -n -r tip) + 50)) || hg pull
pulling from /home/ry4an/projects/unblog
searching for changes
adding changesets
adding manifests
adding file changes
added 50 changesets with 90 changes to 54 files
(run 'hg update' to get a working copy)
ry4an@four:~/projects/unblog-clone$ hg pull -r $(( $(hg id -n -r tip) + 50)) || hg pull
pulling from /home/ry4an/projects/unblog
abort: unknown revision '151'!
pulling from /home/ry4an/projects/unblog
searching for changes
adding changesets
adding manifests
adding file changes
added 1 changesets with 1 changes to 1 files
(run 'hg update' to get a working copy)
ry4an@four:~/projects/unblog-clone$ 

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

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