changeset 18979:1176832fc757

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.
author Mads Kiilerich <madski@unity3d.com>
date Mon, 15 Apr 2013 01:59:04 +0200
parents 8abaadab9abb
children 9717a326d270
files hgext/largefiles/__init__.py hgext/largefiles/overrides.py hgext/largefiles/uisetup.py tests/test-largefiles.t
diffstat 4 files changed, 46 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/largefiles/__init__.py	Mon Apr 15 01:57:16 2013 +0200
+++ b/hgext/largefiles/__init__.py	Mon Apr 15 01:59:04 2013 +0200
@@ -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.
 
--- a/hgext/largefiles/overrides.py	Mon Apr 15 01:57:16 2013 +0200
+++ b/hgext/largefiles/overrides.py	Mon Apr 15 01:59:04 2013 +0200
@@ -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:
--- a/hgext/largefiles/uisetup.py	Mon Apr 15 01:57:16 2013 +0200
+++ b/hgext/largefiles/uisetup.py	Mon Apr 15 01:59:04 2013 +0200
@@ -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,
--- a/tests/test-largefiles.t	Mon Apr 15 01:57:16 2013 +0200
+++ b/tests/test-largefiles.t	Mon Apr 15 01:59:04 2013 +0200
@@ -917,7 +917,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
@@ -932,6 +932,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