diff mercurial/commands.py @ 870:a82eae840447

Teach walk code about absolute paths. The first consequence of this is that absolute and relative paths now all work in the same way. The second is that paths that lie outside the repository now cause an error to be reported, instead of something arbitrary and expensive being done. Internally, all of the serious work is in the util package. The new canonpath function takes an arbitrary path and either returns a canonical path or raises an error. Because it needs to know where the repository root is, it must be fed a repository or dirstate object, which has given commands.matchpats and friends a new parameter to pass along. The util.matcher function uses this to canonicalise globs and relative path names. Meanwhile, I've moved the Abort exception from commands to util, and killed off the redundant util.CommandError exception.
author Bryan O'Sullivan <bos@serpentine.com>
date Sun, 07 Aug 2005 12:43:11 -0800
parents 6a8a50bcc143
children c2e77581bc84
line wrap: on
line diff
--- a/mercurial/commands.py	Sun Aug 07 11:09:21 2005 -0800
+++ b/mercurial/commands.py	Sun Aug 07 12:43:11 2005 -0800
@@ -14,9 +14,6 @@
 class UnknownCommand(Exception):
     """Exception raised if command is not in the command table."""
 
-class Abort(Exception):
-    """Raised if a command needs to print an error and exit."""
-
 def filterfiles(filters, files):
     l = [x for x in files if x in filters]
 
@@ -39,8 +36,8 @@
                 for x in args]
     return args
 
-def matchpats(cwd, pats = [], opts = {}, head = ''):
-    return util.matcher(cwd, pats or ['.'], opts.get('include'),
+def matchpats(repo, cwd, pats = [], opts = {}, head = ''):
+    return util.matcher(repo, cwd, pats or ['.'], opts.get('include'),
                         opts.get('exclude'), head)
 
 def pathto(n1, n2):
@@ -55,7 +52,7 @@
 
 def makewalk(repo, pats, opts, head = ''):
     cwd = repo.getcwd()
-    files, matchfn = matchpats(cwd, pats, opts, head)
+    files, matchfn = matchpats(repo, cwd, pats, opts, head)
     def walk():
         for src, fn in repo.walk(files = files, match = matchfn):
             yield src, fn, pathto(cwd, fn)
@@ -89,7 +86,7 @@
                 try:
                     num = revlog.rev(revlog.lookup(val))
                 except KeyError:
-                    raise Abort('invalid revision identifier %s', val)
+                    raise util.Abort('invalid revision identifier %s', val)
         return num
     for spec in revs:
         if spec.find(revrangesep) >= 0:
@@ -144,7 +141,7 @@
             i += 1
         return ''.join(newname)
     except KeyError, inst:
-        raise Abort("invalid format spec '%%%s' in output file name",
+        raise util.Abort("invalid format spec '%%%s' in output file name",
                     inst.args[0])
 
 def make_file(repo, r, pat, node=None,
@@ -387,7 +384,7 @@
             return name
 
     if not pats:
-        raise Abort('at least one file name or pattern required')
+        raise util.Abort('at least one file name or pattern required')
 
     bcache = {}
     opmap = [['user', getname], ['number', str], ['changeset', getnode]]
@@ -501,7 +498,7 @@
     if not pats and cwd:
         opts['include'] = [os.path.join(cwd, i) for i in opts['include']]
         opts['exclude'] = [os.path.join(cwd, x) for x in opts['exclude']]
-    fns, match = matchpats((pats and repo.getcwd()) or '', pats, opts)
+    fns, match = matchpats(repo, (pats and repo.getcwd()) or '', pats, opts)
     if pats:
         c, a, d, u = repo.changes(files = fns, match = match)
         files = c + a + [fn for fn in d if repo.dirstate.state(fn) == 'r']
@@ -543,7 +540,7 @@
             ui.warn("%s in manifest1, but listed as state %s" % (f, state))
             errors += 1
     if errors:
-        raise Abort(".hg/dirstate inconsistent with current parent's manifest")
+        raise util.Abort(".hg/dirstate inconsistent with current parent's manifest")
 
 def debugstate(ui, repo):
     """show the contents of the current dirstate"""
@@ -592,7 +589,7 @@
         revs = map(lambda x: repo.lookup(x), opts['rev'])
 
     if len(revs) > 2:
-        raise Abort("too many revisions to diff")
+        raise util.Abort("too many revisions to diff")
 
     files = []
     roots, match, results = makewalk(repo, pats, opts)
@@ -626,7 +623,7 @@
 def export(ui, repo, *changesets, **opts):
     """dump the header and diffs for one or more changesets"""
     if not changesets:
-        raise Abort("export requires at least one changeset")
+        raise util.Abort("export requires at least one changeset")
     seqno = 0
     revs = list(revrange(ui, repo, changesets))
     total = len(revs)
@@ -722,7 +719,7 @@
                     files.append(pf)
         patcherr = f.close()
         if patcherr:
-            raise Abort("patch failed")
+            raise util.Abort("patch failed")
 
         if len(files) > 0:
             addremove(ui, repo, *files)
@@ -732,7 +729,7 @@
     """create a new repository in the current directory"""
 
     if source:
-        raise Abort("no longer supported: use \"hg clone\" instead")
+        raise util.Abort("no longer supported: use \"hg clone\" instead")
     hg.repository(ui, ".", create=1)
 
 def locate(ui, repo, *pats, **opts):
@@ -1037,7 +1034,7 @@
     ? = not tracked'''
 
     cwd = repo.getcwd()
-    files, matchfn = matchpats(cwd, pats, opts)
+    files, matchfn = matchpats(repo, cwd, pats, opts)
     (c, a, d, u) = [[pathto(cwd, x) for x in n]
                     for n in repo.changes(files=files, match=matchfn)]
 
@@ -1420,8 +1417,6 @@
             if options['traceback']:
                 traceback.print_exc()
             raise
-    except util.CommandError, inst:
-        u.warn("abort: %s\n" % inst.args)
     except hg.RepoError, inst:
         u.warn("abort: ", inst, "!\n")
     except SignalInterrupt:
@@ -1449,7 +1444,7 @@
             u.warn("abort: %s: %s\n" % (inst.strerror, inst.filename))
         else:
             u.warn("abort: %s\n" % inst.strerror)
-    except Abort, inst:
+    except util.Abort, inst:
         u.warn('abort: ', inst.args[0] % inst.args[1:], '\n')
         sys.exit(1)
     except TypeError, inst: