How to pull the next k changes in mercurial

Suppose I want to pull the next k changesets from the remote repository where k is greater than or equal to 1. Is there some syntax that would allow me to do this? A command that falls back to normal pull

if the available changes are less than or equal to k would be nice.

Of course in this case. the term "next" refers to the local version numbers of the repository that the remote repository does not publicly publish.

I understand that I can find a suitable hash if the repository is viewable through the web interface, but is there a way to do this without any specific information about the remote repository?

+3


source to share


2 answers


If you are using hg incoming

changes as a source for hashes, then you can extract the Nth hash using awk

(in my case, with the addition of GNU). By feeding the resulting hash to hg pull

, it will pull this changeset and all of its ancestors. You can further refine the list of hg incoming

changesets with options , such as -branch.

Here's an 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 withstand no more than 10 incoming changesets. You can manipulate the number through the chunk variable in your awk script.

+3


source


Since, as you can imagine, the revision numbers locally and remotely don't necessarily match, you won't know exactly what changes you are getting, but you can assume the total will be the same, so you can probably take your current revision number plus k and just use that number. Something like that:

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

      



Every time you run this it will try to pull out 50 more than it does, and if that fails, just pull out the rest. 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$ 

      

+2


source







All Articles