[PATCH 1 of 4] largefiles: factor out lfutil.getminsize()

Greg Ward greg at gerg.ca
Tue Oct 11 20:11:59 CDT 2011


# HG changeset patch
# User Greg Ward <greg at gerg.ca>
# Date 1318381861 14400
# Node ID 5fadd3117fe23f600ae22f258e6417ccf4d0dbb0
# Parent  c81dce8a7bb642248b787c3139409d94dbe998ab
largefiles: factor out lfutil.getminsize()

diff --git a/hgext/largefiles/lfcommands.py b/hgext/largefiles/lfcommands.py
--- a/hgext/largefiles/lfcommands.py
+++ b/hgext/largefiles/lfcommands.py
@@ -33,17 +33,7 @@
         tolfile = False
     else:
         tolfile = True
-        size = opts['size']
-        if not size:
-            size = ui.config(lfutil.longname, 'size', default=None)
-            try:
-                size = int(size)
-            except ValueError:
-                raise util.Abort(_('largefiles.size must be integer, was %s\n')
-                                 % size)
-            except TypeError:
-                raise util.Abort(_('size must be specified'))
-
+        size = lfutil.getminsize(ui, True, opts.get('size'), default=None)
     try:
         rsrc = hg.repository(ui, src)
         if not rsrc.local():
diff --git a/hgext/largefiles/lfutil.py b/hgext/largefiles/lfutil.py
--- a/hgext/largefiles/lfutil.py
+++ b/hgext/largefiles/lfutil.py
@@ -101,6 +101,20 @@
 
 # -- Private worker functions ------------------------------------------
 
+def getminsize(ui, assumelfiles, opt, default=10):
+    lfsize = opt
+    if not lfsize and assumelfiles:
+        lfsize = ui.config(longname, 'size', default=default)
+    if lfsize:
+        try:
+            lfsize = int(lfsize)
+        except ValueError:
+            raise util.Abort(_('largefiles: size must be an integer, was %s\n')
+                             % lfsize)
+    if lfsize is None:
+        raise util.Abort(_('minimum size for largefiles must be specified'))
+    return lfsize
+
 def link(src, dest):
     try:
         util.oslink(src, dest)
diff --git a/hgext/largefiles/overrides.py b/hgext/largefiles/overrides.py
--- a/hgext/largefiles/overrides.py
+++ b/hgext/largefiles/overrides.py
@@ -79,16 +79,8 @@
 # version of add.
 def override_add(orig, ui, repo, *pats, **opts):
     large = opts.pop('large', None)
-
-    lfsize = opts.pop('lfsize', None)
-    if not lfsize and lfutil.islfilesrepo(repo):
-        lfsize = ui.config(lfutil.longname, 'size', default='10')
-    if lfsize:
-        try:
-            lfsize = int(lfsize)
-        except ValueError:
-            raise util.Abort(_('largefiles: size must be an integer, was %s\n')
-                             % lfsize)
+    lfsize = lfutil.getminsize(
+        ui, islfilesrepo(repo), opts.pop('lfsize', None))
 
     lfmatcher = None
     if os.path.exists(repo.wjoin(lfutil.shortname)):


More information about the Mercurial-devel mailing list