简体   繁体   中英

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? A command that falls back to plain pull if the changesets available are less than or equal to k would be nice.

Of course, in this case. the term "next" references the local revision numbers of the repository, which the remote repository does not expose publicly.

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?

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. Feeding the obtained hash to the hg pull then will pull that changeset and all its ancestors. You can further refine the list of changesets with options to hg incoming , such as --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. You can control the number via chunk variable in awk script.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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