Patrick Mézard avatar Patrick Mézard committed f544151

Regroup all ConfigParser dependent code before refactoring

Comments (0)

Files changed (1)

             """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])
     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."""
         """
         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 = {}
                                                     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))
 
 
     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
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.