# HG changeset patch # User Patrick Mezard # Date 1254666060 -7200 # Node ID f5441510cbb05b8b0f067da6caa606d4d77655de # Parent 4b2c5c4ffeffdc9d577adfcb8bec0e9409dd10dc Regroup all ConfigParser dependent code before refactoring diff -r 4b2c5c4ffeff -r f5441510cbb0 forest.py --- a/forest.py Thu Sep 24 13:50:07 2009 +0200 +++ b/forest.py Sun Oct 04 16:21:00 2009 +0200 @@ -105,11 +105,21 @@ """Mercurial <= 0.9.3 doesn't have this feature.""" return url, (revs or None) - # For backwards compatibility, find the HTTP protocol. if not hasattr(hgweb, 'protocol'): hgweb.protocol = hgweb.hgweb_mod.hgweb +ConfigError = ConfigParser.Error + +class SnapshotError(ConfigParser.NoSectionError): + pass + +def readconfig(path): + cfg = ConfigParser.RawConfigParser() + if not cfg.read([path]): + return None + return cfg + def cmd_options(ui, cmd, remove=None, table=commands.table): aliases, spec = findcmd(ui, cmd, table) res = list(spec[1]) @@ -413,10 +423,7 @@ This data structure describes the Forest contained within the current repository. It contains a list of Trees that describe each sub-repository. - """ - - class SnapshotError(ConfigParser.NoSectionError): - pass + """ class Tree(object): """Describe a local sub-repository within a forest.""" @@ -678,8 +685,8 @@ """ if not toppath: toppath = "." - cfg = ConfigParser.RawConfigParser() - if not cfg.read([snapfile]): + cfg = readconfig(snapfile) + if not cfg: raise util.Abort("%s: %s" % (snapfile, os.strerror(errno.ENOENT))) seen_root = False sections = {} @@ -715,8 +722,8 @@ revs=[rev], paths=paths) if not seen_root: - raise Forest.SnapshotError("Could not find 'root = .' in '%s'" % - snapfile) + raise SnapshotError("Could not find 'root = .' in '%s'" % + snapfile) self.trees = sections.values() self.trees.sort(key=(lambda tree: tree.root)) @@ -1322,16 +1329,12 @@ snapfile = None if revision: - cp = ConfigParser.RawConfigParser() try: - if cp.read([revision]): + if readconfig(revision): # Compatibility with old 'hg fupdate SNAPFILE' syntax snapfile = revision - except Exception, err: - if isinstance(err, ConfigParser.Error): - ui.warn(_("warning: %s\n") % err) - else: - raise err + except ConfigError, err: + ui.warn(_("warning: %s\n") % err) if snapfile is None: snapfile = opts['snapfile'] opts['rev'] = revision