Patchwork [07,of,10] largefiles: introduce pulled() revset expression for use in --lfrev

login
register
mail settings
Submitter Mads Kiilerich
Date April 15, 2013, 7:24 p.m.
Message ID <c3c9416e8953509d5836.1366053840@mk-desktop>
Download mbox | patch
Permalink /patch/1324/
State Accepted
Commit 1176832fc757c331acb7c8c10b7228b39af135c8
Headers show

Comments

Mads Kiilerich - April 15, 2013, 7:24 p.m.
# HG changeset patch
# User Mads Kiilerich <madski@unity3d.com>
# Date 1365983944 -7200
#      Mon Apr 15 01:59:04 2013 +0200
# Node ID c3c9416e8953509d5836bf2d58f0b7ed3456ba97
# Parent  0b69489d3bcfc387dbac95d818bf0e3a011f8d6d
largefiles: introduce pulled() revset expression for use in --lfrev

This provides a general way to do what already can be done with
--all-largefiles and --cache-largefiles.

Patch

diff --git a/hgext/largefiles/__init__.py b/hgext/largefiles/__init__.py
--- a/hgext/largefiles/__init__.py
+++ b/hgext/largefiles/__init__.py
@@ -52,10 +52,14 @@ 
 If you want to pull largefiles you don't need for update yet, then
 you can use pull with the `--lfrev` option or the :hg:`lfpull` command.
 
+If you know you are pulling from a non-default location and want do
+download all the largefiles that corresponds to the new changesets at
+the same time, then you can pull with `--lfrev "pulled()"`.
+
 If you just want to ensure that you will have the largefiles needed to
 merge or rebase with new heads that you are pulling, then you can pull
-with `--lfrev "head(0:)"` flag to pre-emptively download any largefiles
-that are in the heads after pulling. You can also pull with the
+with `--lfrev "head(pulled())"` flag to pre-emptively download any largefiles
+that are new in the heads you are pulling. You can also pull with the
 `--cache-largefiles` flag to pre-emptively download any largefiles
 that are new in the heads you are pulling.
 
diff --git a/hgext/largefiles/overrides.py b/hgext/largefiles/overrides.py
--- a/hgext/largefiles/overrides.py
+++ b/hgext/largefiles/overrides.py
@@ -756,13 +756,43 @@ 
     lfrevs = opts.get('lfrev', [])
     if lfrevs and revspostpull > revsprepull:
         numcached = 0
-        for rev in scmutil.revrange(repo, lfrevs):
-            ui.note(_('pulling largefiles for revision %s\n') % rev)
-            (cached, missing) = lfcommands.cachelfiles(ui, repo, rev)
-            numcached += len(cached)
+        repo.firstpulled = revsprepull # for pulled() revset expression
+        try:
+            for rev in scmutil.revrange(repo, lfrevs):
+                ui.note(_('pulling largefiles for revision %s\n') % rev)
+                (cached, missing) = lfcommands.cachelfiles(ui, repo, rev)
+                numcached += len(cached)
+        finally:
+            del repo.firstpulled
         ui.status(_("%d largefiles cached\n") % numcached)
     return result
 
+def pulledrevsetsymbol(repo, subset, x):
+    """``pulled()``
+    Changesets that just has been pulled.
+
+    Only available with largefiles from pull --lfrev expressions.
+
+    .. container:: verbose
+
+      Some examples:
+
+      - pull largefiles for all new changesets::
+
+          hg pull -lfrev "pulled()"
+
+      - pull largefiles for all new branch heads::
+
+          hg pull -lfrev "head(pulled()) and not closed()"
+
+    """
+
+    try:
+        firstpulled = repo.firstpulled
+    except AttributeError:
+        raise util.Abort(_("pulled() only available in --lfrev"))
+    return [r for r in subset if r >= firstpulled]
+
 def overrideclone(orig, ui, source, dest=None, **opts):
     d = dest
     if d is None:
diff --git a/hgext/largefiles/uisetup.py b/hgext/largefiles/uisetup.py
--- a/hgext/largefiles/uisetup.py
+++ b/hgext/largefiles/uisetup.py
@@ -9,7 +9,7 @@ 
 '''setup for largefiles extension: uisetup'''
 
 from mercurial import archival, cmdutil, commands, extensions, filemerge, hg, \
-    httppeer, localrepo, merge, scmutil, sshpeer, wireproto
+    httppeer, localrepo, merge, scmutil, sshpeer, wireproto, revset
 from mercurial.i18n import _
 from mercurial.hgweb import hgweb_mod, webcommands
 from mercurial.subrepo import hgsubrepo
@@ -85,6 +85,8 @@ 
                ('', 'lfrev', [],
                 _('download largefiles for these revisions'), _('REV'))]
     entry[1].extend(pullopt)
+    revset.symbols['pulled'] = overrides.pulledrevsetsymbol
+
     entry = extensions.wrapcommand(commands.table, 'clone',
                                    overrides.overrideclone)
     cloneopt = [('', 'all-largefiles', None,
diff --git a/tests/test-largefiles.t b/tests/test-largefiles.t
--- a/tests/test-largefiles.t
+++ b/tests/test-largefiles.t
@@ -889,7 +889,7 @@ 
 
   $ hg rollback
   repository tip rolled back to revision 1 (undo pull)
-  $ hg pull -v --lfrev 'heads(0:)'
+  $ hg pull -v --lfrev 'heads(pulled())+min(pulled())'
   pulling from $TESTTMP/a (glob)
   searching for changes
   all local heads known remotely
@@ -904,6 +904,8 @@ 
   found 971fb41e78fea4f8e0ba5244784239371cb00591 in store
   found 0d6d75887db61b2c7e6c74b5dd8fc6ad50c0cc30 in store
   found bb3151689acb10f0c3125c560d5e63df914bc1af in store
+  pulling largefiles for revision 2
+  found eb7338044dc27f9bc59b8dd5a246b065ead7a9c4 in store
   0 largefiles cached
 
 lfpull