changeset 882:bc9ca4d51d23

Merge IPv6 fix.
author Bryan O'Sullivan <bos@serpentine.com>
date Wed, 10 Aug 2005 12:36:34 -0800
parents c2e77581bc84 (diff) 16ce690c411d (current diff)
children 63ca8a68d59e
files .hgignore CONTRIBUTORS TODO doc/hg.1.txt mercurial/commands.py mercurial/hg.py mercurial/hgweb.py mercurial/revlog.py mercurial/util.py templates/map tests/test-help tests/test-help.out
diffstat 3 files changed, 54 insertions(+), 39 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/commands.py	Wed Aug 10 12:35:25 2005 -0800
+++ b/mercurial/commands.py	Wed Aug 10 12:36:34 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,
@@ -427,7 +424,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]]
@@ -541,7 +538,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']
@@ -583,7 +580,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"""
@@ -621,6 +618,7 @@
 
 def debugwalk(ui, repo, *pats, **opts):
     items = list(walk(repo, pats, opts))
+    if not items: return
     fmt = '%%s  %%-%ds  %%s' % max([len(abs) for (src, abs, rel) in items])
     for i in items: print fmt % i
 
@@ -631,7 +629,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)
@@ -665,7 +663,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)
@@ -762,7 +760,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)
@@ -772,7 +770,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):
@@ -1078,7 +1076,7 @@
     '''
 
     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)]
 
@@ -1471,8 +1469,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:
@@ -1500,7 +1496,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:
--- a/mercurial/hg.py	Wed Aug 10 12:35:25 2005 -0800
+++ b/mercurial/hg.py	Wed Aug 10 12:36:34 2005 -0800
@@ -300,6 +300,11 @@
     def wjoin(self, f):
         return os.path.join(self.root, f)
 
+    def getcwd(self):
+        cwd = os.getcwd()
+        if cwd == self.root: return ''
+        return cwd[len(self.root) + 1:]
+
     def ignore(self, f):
         if not self.ignorefunc:
             bigpat = []
@@ -687,9 +692,7 @@
         return filelog(self.opener, f)
 
     def getcwd(self):
-        cwd = os.getcwd()
-        if cwd == self.root: return ''
-        return cwd[len(self.root) + 1:]
+        return self.dirstate.getcwd()
 
     def wfile(self, f, mode='r'):
         return self.wopener(f, mode)
--- a/mercurial/util.py	Wed Aug 10 12:35:25 2005 -0800
+++ b/mercurial/util.py	Wed Aug 10 12:36:34 2005 -0800
@@ -16,7 +16,8 @@
             seen[f] = 1
             yield f
 
-class CommandError(Exception): pass
+class Abort(Exception):
+    """Raised if a command needs to print an error and exit."""
 
 def always(fn): return True
 def never(fn): return False
@@ -68,7 +69,20 @@
 
 _globchars = {'[': 1, '{': 1, '*': 1, '?': 1}
 
-def matcher(cwd, names, inc, exc, head = ''):
+def canonpath(repo, cwd, myname):
+    rootsep = repo.root + os.sep
+    name = myname
+    if not name.startswith(os.sep):
+        name = os.path.join(repo.root, cwd, name)
+    name = os.path.normpath(name)
+    if name.startswith(rootsep):
+        return name[len(rootsep):]
+    elif name == repo.root:
+        return ''
+    else:
+        raise Abort('%s not under repository root' % myname)
+    
+def matcher(repo, cwd, names, inc, exc, head = ''):
     def patkind(name):
         for prefix in 're:', 'glob:', 'path:':
             if name.startswith(prefix): return name.split(':', 1)
@@ -76,8 +90,6 @@
             if c in _globchars: return 'glob', name
         return 'relpath', name
 
-    cwdsep = cwd + os.sep
-
     def regex(name, tail):
         '''convert a pattern into a regular expression'''
         kind, name = patkind(name)
@@ -85,15 +97,8 @@
             return name
         elif kind == 'path':
             return '^' + re.escape(name) + '$'
-        if cwd: name = os.path.join(cwdsep, name)
-        name = os.path.normpath(name)
-        if name == '.': name = '**'
         return head + globre(name, '', tail)
 
-    def under(fn):
-        """check if fn is under our cwd"""
-        return not cwd or fn.startswith(cwdsep)
-
     def matchfn(pats, tail):
         """build a matching function from a set of patterns"""
         if pats:
@@ -108,11 +113,22 @@
             root.append(p)
         return os.sep.join(root)
 
-    patkinds = map(patkind, names)
-    pats = [name for (kind, name) in patkinds if kind != 'relpath']
-    files = [name for (kind, name) in patkinds if kind == 'relpath']
-    roots = filter(None, map(globprefix, pats)) + files
-    if cwd: roots = [cwdsep + r for r in roots]
+    pats = []
+    files = []
+    roots = []
+    for kind, name in map(patkind, names):
+        if kind in ('glob', 'relpath'):
+            name = canonpath(repo, cwd, name)
+            if name == '':
+                kind, name = 'glob', '**'
+        if kind in ('glob', 're'):
+            pats.append(name)
+        if kind == 'glob':
+            root = globprefix(name)
+            if root: roots.append(root)
+        elif kind == 'relpath':
+            files.append(name)
+            roots.append(name)
         
     patmatch = matchfn(pats, '$') or always
     filematch = matchfn(files, '(?:/|$)') or always
@@ -133,7 +149,7 @@
                             explain_exit(rc)[0])
         if errprefix:
             errmsg = "%s: %s" % (errprefix, errmsg)
-        raise CommandError(errmsg)
+        raise Abort(errmsg)
 
 def rename(src, dst):
     try: