[PATCH 1 of 4 RFC] largefiles: introduce ".hglfrc" to share/track configurations between repos
FUJIWARA Katsunori
foozy at lares.dti.ne.jp
Sun Nov 13 09:47:00 CST 2011
# HG changeset patch
# User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
# Date 1321196937 -32400
# Branch stable
# Node ID 5c1279816b1b11f38c3786f6b7d3ead8f9b7dfdd
# Parent f8a0c79254965fd34eb9cbe82387115c5d7d7a59
largefiles: introduce ".hglfrc" to share/track configurations between repos
this patch introduces ".hglfrc" file in root of working directory to
share/track configurations for largefiles extension between repos,
like ".hgeol" of eol extension.
example of ".hglfrc":
================================
[thresholds]
minsize = 5
[patterns]
jpg_image_file = **.jpg
ms_word_file = **.doc
================================
".hglfrc" configuration will overrides ones described in largefiles
section of hgrc files.
and other RFC points for this patch are:
- "[largefiles]" section handling policy
in original implementation, "largefiles.minsize" is ignored if
there is no commited revision which handles largefiles, even
though "largefiles.pattens" is recognized only if there are any
files which are added as large but not yet commited.
this seems to be very ambiguous for users, does not ?
and this patch treats configuration in ".hglfrc" as effective,
even though there is no commited revision whch handles largefiles.
this combination of "[largefiles]" section and ".hglfrc" file
seems to be very ambiguous for uses, does not ?
- name of configuration file: ".hglargefiles" ?
diff -r f8a0c7925496 -r 5c1279816b1b hgext/largefiles/lfcommands.py
--- a/hgext/largefiles/lfcommands.py Thu Nov 10 17:06:12 2011 -0600
+++ b/hgext/largefiles/lfcommands.py Mon Nov 14 00:08:57 2011 +0900
@@ -42,7 +42,11 @@
tolfile = False
else:
tolfile = True
- size = lfutil.getminsize(ui, True, opts.get('size'), default=None)
+ lfrc = lfutil.parseconf(ui, None, opts['hglfrc'])
+ size = lfrc.getminsize(True, opts.get('size'), default=None)
+ if lfsize is None:
+ msg = _('minimum size for largefiles must be specified')
+ raise util.Abort(msg)
if not hg.islocal(src):
raise util.Abort(_('%s is not a local Mercurial repo') % src)
@@ -71,13 +75,8 @@
lfiles = set()
normalfiles = set()
if not pats:
- pats = ui.config(lfutil.longname, 'patterns', default=())
- if pats:
- pats = pats.split(' ')
- if pats:
- matcher = match_.match(rsrc.root, '', list(pats))
- else:
- matcher = None
+ pats = lfrc.getpatterns(True)
+ matcher = pats and match_.match(rsrc.root, '', pats)
lfiletohash = {}
for ctx in ctxs:
@@ -470,6 +469,9 @@
_('minimum size (MB) for files to be converted '
'as largefiles'),
'SIZE'),
+ ('', 'hglfrc', '',
+ _('specify .hglfrc style configuration file'),
+ 'FILE'),
('', 'to-normal', False,
_('convert from a largefiles repo to a normal repo')),
],
diff -r f8a0c7925496 -r 5c1279816b1b hgext/largefiles/lfutil.py
--- a/hgext/largefiles/lfutil.py Thu Nov 10 17:06:12 2011 -0600
+++ b/hgext/largefiles/lfutil.py Mon Nov 14 00:08:57 2011 +0900
@@ -16,11 +16,13 @@
import tempfile
from mercurial import dirstate, httpconnection, match as match_, util, scmutil
+from mercurial import config, error
from mercurial.i18n import _
shortname = '.hglf'
longname = 'largefiles'
+lfrcfile = '.hglfrc'
# -- Portability wrappers ----------------------------------------------
@@ -59,19 +61,59 @@
# -- Private worker functions ------------------------------------------
-def getminsize(ui, assumelfiles, opt, default=10):
- lfsize = opt
- if not lfsize and assumelfiles:
- lfsize = ui.config(longname, 'minsize', default=default)
- if lfsize:
- try:
- lfsize = float(lfsize)
- except ValueError:
- raise util.Abort(_('largefiles: size must be number (not %s)\n')
- % lfsize)
- if lfsize is None:
- raise util.Abort(_('minimum size for largefiles must be specified'))
- return lfsize
+def parseconf(ui, repo, filename):
+ class lfconfig(config.config):
+ def __init__(self):
+ config.config.__init__(self)
+
+ def getminsize(self, assumelfiles, opt, default=10):
+ lfsize = (opt or
+ self.get('thresholds', 'minsize',
+ (assumelfiles and
+ (ui.config(longname, 'minsize',
+ default=default)))))
+ try:
+ return lfsize and float(lfsize)
+ except ValueError:
+ msg = _('largefiles: size must be number (not %s)\n')
+ raise util.Abort(msg % lfsize)
+
+ def getpatterns(self, assumelfiles):
+ patterns = (assumelfiles and
+ ui.configlist(longname, 'patterns', default=[]))
+ if 'patterns' in self.sections():
+ patterns = [v for k, v in self.items('patterns')] # override
+ return patterns and patterns
+
+ if not filename: return lfconfig() # empty
+
+ # below implementation refers "hgext.eol.parseeol()"
+ if repo:
+ sources = [
+ # read in from None: use content in working directory
+ lambda : repo.wfile(filename).read(),
+ # read in from tip:
+ lambda : repo['tip'][filename].data(),
+ ]
+ else:
+ sources = [
+ # read in from specified file
+ lambda : open(filename).read(),
+ ]
+ try:
+ for source in sources:
+ try:
+ data = source()
+ lfcfg = lfconfig()
+ lfcfg.parse(filename, data)
+ return lfcfg
+ except (IOError, LookupError):
+ pass
+ except error.ParseError, inst:
+ ui.warn(_("warning: ignoring %s file due to parse error at %s: %s\n") %
+ (filename, inst.args[1], inst.args[0]))
+
+ return lfconfig() # empty
def link(src, dest):
try:
diff -r f8a0c7925496 -r 5c1279816b1b hgext/largefiles/overrides.py
--- a/hgext/largefiles/overrides.py Thu Nov 10 17:06:12 2011 -0600
+++ b/hgext/largefiles/overrides.py Mon Nov 14 00:08:57 2011 +0900
@@ -59,14 +59,12 @@
# version of add.
def override_add(orig, ui, repo, *pats, **opts):
large = opts.pop('large', None)
- lfsize = lfutil.getminsize(
- ui, lfutil.islfilesrepo(repo), opts.pop('lfsize', None))
- lfmatcher = None
- if os.path.exists(repo.wjoin(lfutil.shortname)):
- lfpats = ui.configlist(lfutil.longname, 'patterns', default=[])
- if lfpats:
- lfmatcher = match_.match(repo.root, '', list(lfpats))
+ lfrc = lfutil.parseconf(ui, repo, lfutil.lfrcfile)
+ lfsize = lfrc.getminsize(lfutil.islfilesrepo(repo),
+ opts.pop('lfsize', None))
+ lfpats = lfrc.getpatterns(os.path.exists(repo.wjoin(lfutil.shortname)))
+ lfmatcher = lfpats and match_.match(repo.root, '', lfpats)
lfnames = []
m = scmutil.match(repo[None], pats, opts)
More information about the Mercurial-devel
mailing list