[PATCH 4 of 4 RFC] largefiles: add lflocate and lfmatch commands to check list about largefiles

FUJIWARA Katsunori foozy at lares.dti.ne.jp
Sun Nov 13 09:47:03 CST 2011


# HG changeset patch
# User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
# Date 1321198346 -32400
# Branch stable
# Node ID 09adb751779a86d491c49ba90ff107ebd745035a
# Parent  15127ffc0db4682da9f7dd222bf3acebbc787cc7
largefiles: add lflocate and lfmatch commands to check list about largefiles

lflocate command shows list of files treated as largefile.

lfmatch command shows list of files which should be treated as
largefile in current minsize/patterns configuration for largefiles.

combination of these commands helps you to check whether your large
(small) files are expectedly treated as largefile (non-largefile)
without checking inside of "standin" or any other internal.

and other RFC points for this patch are:

  - is --rev option usefull for lfmatch ?

diff -r 15127ffc0db4 -r 09adb751779a hgext/largefiles/lfcommands.py
--- a/hgext/largefiles/lfcommands.py	Mon Nov 14 00:26:31 2011 +0900
+++ b/hgext/largefiles/lfcommands.py	Mon Nov 14 00:32:26 2011 +0900
@@ -13,6 +13,7 @@
 
 from mercurial import util, match as match_, hg, node, context, error
 from mercurial import scmutil, cmdutil
+from mercurial import commands
 from mercurial.i18n import _
 
 import lfutil
@@ -190,6 +191,84 @@
 
     return failed and 1 or 0
 
+def lflocate(ui, repo, *patterns, **opts):
+    '''locate largefiles matching specific patterns
+
+    Print largefiles under Mercurial control in the working directory whose
+    names match the given patterns.
+
+    Please see hg:`help locate` for detail behavior about this command.
+    '''
+    end = opts.get('print0') and '\0' or '\n'
+    rev = scmutil.revsingle(repo, opts.get('rev'), None).node()
+
+    ret = 1
+    matchfn = scmutil.match(repo[rev], patterns, opts, default='relglob')
+    lfmatchfn = lfutil.composestandinmatcher(repo, matchfn)
+    lfmatchfn.bad = lambda x, y: False
+    for abs in repo[rev].walk(lfmatchfn):
+        if not rev and abs not in repo.dirstate:
+            continue
+        lfpath = lfutil.splitstandin(abs)
+        if opts.get('fullpath'):
+            ui.write(repo.wjoin(lfpath), end)
+        else:
+            ui.write(((patterns and lfmatchfn.rel(lfpath)) or lfpath), end)
+        ret = 0
+
+    return ret
+
+def lfmatch(ui, repo, *patterns, **opts):
+    '''list up files matched with current conditions, but not treated as large
+
+    This command will show files which matche with one of size or pattern
+    condition, if neither --size nor --pattern is specified.
+
+    Please see hg:`locate` for detail about pattern specification.
+    '''
+    end = opts.get('print0') and '\0' or '\n'
+
+    s = opts['size']
+    p = opts['pattern']
+    if (not s) and (not p): # check both conditions
+        s = True
+        p = True
+
+    ret = 1
+    matchfn = scmutil.match(repo[None], patterns, opts, default='relglob')
+    matchfn.bad = lambda x, y: False
+
+    lfrc = lfutil.parseconf(ui, repo, lfutil.lfrcfile)
+
+    lfsize = lfrc.getminsize(lfutil.islfilesrepo(repo),
+                             opts.pop('lfsize', None))
+    matchsize = ((s and lfsize)
+                 and (lambda x: os.lstat(repo.wjoin(x)).st_size >= lfsize)
+                 or (lambda x: False))
+    lfmatcher = None
+    lfpats = lfrc.getpatterns(os.path.exists(repo.wjoin(lfutil.shortname)))
+    matchpattern = ((p)
+                    and (lfpats and match_.match(repo.root, '', list(lfpats)))
+                    or (lambda x: False))
+
+    for abs in repo[None].walk(matchfn):
+        ui.debug('lflistmised: %s\n' % (abs))
+
+        if abs not in repo.dirstate: # ignore 'unknown'
+            continue
+        if lfutil.isstandin(abs): # ignore 'already largefiles'
+            continue
+        if not matchsize(abs) and not matchpattern(abs):
+            continue
+
+        path = (opts.get('fullpath')
+                and repo.wjoin(abs)
+                or (patterns and matchfn.rel(abs) or abs))
+        ui.write('%s%s' % (path, end))
+        ret = 0
+
+    return ret
+
 def _addchangeset(ui, rsrc, rdst, ctx, revmap):
  # Convert src parents to dst parents
     parents = []
@@ -575,4 +654,27 @@
                   _('allow caching for all revisions'))
                  ],
                 _('hg lfcache [FILE ...]')),
+    'lflocate': (lflocate,
+                 [('r', 'rev', '',
+                   _('search the repository as it is in REV'), _('REV')),
+                  ('0', 'print0', None,
+                   _('end filenames with NUL, for use with xargs')),
+                  ('f', 'fullpath', None,
+                   _('print complete paths from the filesystem root')),
+                  ] + commands.walkopts,
+                 _('hg lflocate [OPTION]... [PATTERN]...')),
+    'lfmatch': (lfmatch,
+                [('s', 'size', None,
+                  _('list files matched with size condition')),
+                 ('p', 'pattern', None,
+                  _('list files matched with pattern condition')),
+                 ('0', 'print0', None,
+                  _('end filenames with NUL, for use with xargs')),
+                 ('f', 'fullpath', None,
+                  _('print complete paths from the filesystem root')),
+                 ('', 'lfsize', '',
+                  _('minimum size (MB) of largefile')),
+                 ] + commands.walkopts,
+                _('hg lflistmissed [OPTION]... [PATTERN]...')
+                ),
     }


More information about the Mercurial-devel mailing list