changeset 942:7eb8cbcca7c4

Modify commands.walk to yield a 4-tuple. The new element of the tuple indicates whether a name is an exact match for one passed in on the command line.
author Bryan O'Sullivan <bos@serpentine.com>
date Thu, 18 Aug 2005 13:58:32 -0800
parents 1300271ba8de
children e8e5db72ed51
files mercurial/commands.py tests/test-walk.out
diffstat 2 files changed, 87 insertions(+), 85 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/commands.py	Wed Aug 17 18:52:27 2005 -0800
+++ b/mercurial/commands.py	Thu Aug 18 13:58:32 2005 -0800
@@ -42,9 +42,10 @@
 def makewalk(repo, pats, opts, head = ''):
     cwd = repo.getcwd()
     files, matchfn = matchpats(repo, cwd, pats, opts, head)
+    exact = dict(zip(files, files))
     def walk():
         for src, fn in repo.walk(files = files, match = matchfn):
-            yield src, fn, util.pathto(cwd, fn)
+            yield src, fn, util.pathto(cwd, fn), fn in exact
     return files, matchfn, walk()
 
 def walk(repo, pats, opts, head = ''):
@@ -375,9 +376,8 @@
 def add(ui, repo, *pats, **opts):
     '''add the specified files on the next commit'''
     names = []
-    q = dict(zip(pats, pats))
-    for src, abs, rel in walk(repo, pats, opts):
-        if rel in q or abs in q:
+    for src, abs, rel, exact in walk(repo, pats, opts):
+        if exact:
             names.append(abs)
         elif repo.dirstate.state(abs) == '?':
             ui.status('adding %s\n' % rel)
@@ -386,15 +386,14 @@
 
 def addremove(ui, repo, *pats, **opts):
     """add all new files, delete all missing files"""
-    q = dict(zip(pats, pats))
     add, remove = [], []
-    for src, abs, rel in walk(repo, pats, opts):
+    for src, abs, rel, exact in walk(repo, pats, opts):
         if src == 'f' and repo.dirstate.state(abs) == '?':
             add.append(abs)
-            if rel not in q: ui.status('adding ', rel, '\n')
+            if not exact: ui.status('adding ', rel, '\n')
         if repo.dirstate.state(abs) != 'r' and not os.path.exists(rel):
             remove.append(abs)
-            if rel not in q: ui.status('removing ', rel, '\n')
+            if not exact: ui.status('removing ', rel, '\n')
     repo.add(add)
     repo.remove(remove)
 
@@ -432,7 +431,7 @@
         node = repo.dirstate.parents()[0]
     change = repo.changelog.read(node)
     mmap = repo.manifest.read(change[0])
-    for src, abs, rel in walk(repo, pats, opts):
+    for src, abs, rel, exact in walk(repo, pats, opts):
         if abs not in mmap:
             ui.warn("warning: %s is not in the repository!\n" % rel)
             continue
@@ -629,8 +628,12 @@
 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
+    fmt = '%%s  %%-%ds  %%-%ds  %%s' % (
+        max([len(abs) for (src, abs, rel, exact) in items]),
+        max([len(rel) for (src, abs, rel, exact) in items]))
+    exactly = {True: 'exact', False: ''}
+    for src, abs, rel, exact in items:
+        print fmt % (src, abs, rel, exactly[exact])
 
 def diff(ui, repo, *pats, **opts):
     """diff working directory (or selected files)"""
@@ -645,7 +648,7 @@
     match = util.always
     if pats:
         roots, match, results = makewalk(repo, pats, opts)
-        for src, abs, rel in results:
+        for src, abs, rel, exact in results:
             files.append(abs)
     dodiff(sys.stdout, ui, repo, files, *revs, **{'match': match})
 
@@ -687,12 +690,11 @@
 
 def forget(ui, repo, *pats, **opts):
     """don't add the specified files on the next commit"""
-    q = dict(zip(pats, pats))
     forget = []
-    for src, abs, rel in walk(repo, pats, opts):
+    for src, abs, rel, exact in walk(repo, pats, opts):
         if repo.dirstate.state(abs) == 'a':
             forget.append(abs)
-            if rel not in q: ui.status('forgetting ', rel, '\n')
+            if not exact: ui.status('forgetting ', rel, '\n')
     repo.forget(forget)
 
 def heads(ui, repo, **opts):
@@ -809,7 +811,7 @@
     end = '\n'
     if opts['print0']: end = '\0'
 
-    for src, abs, rel in walk(repo, pats, opts, '(?:.*/|)'):
+    for src, abs, rel, exact in walk(repo, pats, opts, '(?:.*/|)'):
         if repo.dirstate.state(abs) == '?': continue
         if opts['fullpath']:
             ui.write(os.path.join(repo.root, abs), end)
--- a/tests/test-walk.out	Wed Aug 17 18:52:27 2005 -0800
+++ b/tests/test-walk.out	Thu Aug 18 13:58:32 2005 -0800
@@ -12,76 +12,76 @@
 adding mammals/Procyonidae/cacomistle
 adding mammals/Procyonidae/coatimundi
 adding mammals/Procyonidae/raccoon
-f  fennel                          fennel
-f  fenugreek                       fenugreek
-f  fiddlehead                      fiddlehead
-f  glob:glob                       glob:glob
-f  beans/black                     beans/black
-f  beans/borlotti                  beans/borlotti
-f  beans/kidney                    beans/kidney
-f  beans/navy                      beans/navy
-f  beans/pinto                     beans/pinto
-f  beans/turtle                    beans/turtle
-f  mammals/skunk                   mammals/skunk
-f  mammals/Procyonidae/cacomistle  mammals/Procyonidae/cacomistle
-f  mammals/Procyonidae/coatimundi  mammals/Procyonidae/coatimundi
-f  mammals/Procyonidae/raccoon     mammals/Procyonidae/raccoon
-f  mammals/skunk                   skunk
-f  mammals/Procyonidae/cacomistle  Procyonidae/cacomistle
-f  mammals/Procyonidae/coatimundi  Procyonidae/coatimundi
-f  mammals/Procyonidae/raccoon     Procyonidae/raccoon
-f  mammals/Procyonidae/cacomistle  Procyonidae/cacomistle
-f  mammals/Procyonidae/coatimundi  Procyonidae/coatimundi
-f  mammals/Procyonidae/raccoon     Procyonidae/raccoon
-f  mammals/Procyonidae/cacomistle  cacomistle
-f  mammals/Procyonidae/coatimundi  coatimundi
-f  mammals/Procyonidae/raccoon     raccoon
-f  mammals/skunk                   ../skunk
-f  mammals/Procyonidae/cacomistle  cacomistle
-f  mammals/Procyonidae/coatimundi  coatimundi
-f  mammals/Procyonidae/raccoon     raccoon
-f  beans/black     ../beans/black
-f  beans/borlotti  ../beans/borlotti
-f  beans/kidney    ../beans/kidney
-f  beans/navy      ../beans/navy
-f  beans/pinto     ../beans/pinto
-f  beans/turtle    ../beans/turtle
-f  mammals/skunk                   skunk
-f  mammals/Procyonidae/cacomistle  Procyonidae/cacomistle
-f  mammals/Procyonidae/coatimundi  Procyonidae/coatimundi
-f  mammals/Procyonidae/raccoon     Procyonidae/raccoon
-f  beans/black     beans/black
-f  beans/borlotti  beans/borlotti
-f  beans/kidney    beans/kidney
-f  beans/navy      beans/navy
-f  beans/pinto     beans/pinto
-f  beans/turtle    beans/turtle
-f  beans/black     beans/black
-f  beans/borlotti  beans/borlotti
-f  mammals/skunk  mammals/skunk
-f  mammals/skunk                   mammals/skunk
-f  mammals/Procyonidae/cacomistle  mammals/Procyonidae/cacomistle
-f  mammals/Procyonidae/coatimundi  mammals/Procyonidae/coatimundi
-f  mammals/Procyonidae/raccoon     mammals/Procyonidae/raccoon
+f  fennel                          fennel                          
+f  fenugreek                       fenugreek                       
+f  fiddlehead                      fiddlehead                      
+f  glob:glob                       glob:glob                       
+f  beans/black                     beans/black                     
+f  beans/borlotti                  beans/borlotti                  
+f  beans/kidney                    beans/kidney                    
+f  beans/navy                      beans/navy                      
+f  beans/pinto                     beans/pinto                     
+f  beans/turtle                    beans/turtle                    
+f  mammals/skunk                   mammals/skunk                   
+f  mammals/Procyonidae/cacomistle  mammals/Procyonidae/cacomistle  
+f  mammals/Procyonidae/coatimundi  mammals/Procyonidae/coatimundi  
+f  mammals/Procyonidae/raccoon     mammals/Procyonidae/raccoon     
+f  mammals/skunk                   skunk                   
+f  mammals/Procyonidae/cacomistle  Procyonidae/cacomistle  
+f  mammals/Procyonidae/coatimundi  Procyonidae/coatimundi  
+f  mammals/Procyonidae/raccoon     Procyonidae/raccoon     
+f  mammals/Procyonidae/cacomistle  Procyonidae/cacomistle  
+f  mammals/Procyonidae/coatimundi  Procyonidae/coatimundi  
+f  mammals/Procyonidae/raccoon     Procyonidae/raccoon     
+f  mammals/Procyonidae/cacomistle  cacomistle  
+f  mammals/Procyonidae/coatimundi  coatimundi  
+f  mammals/Procyonidae/raccoon     raccoon     
+f  mammals/skunk                   ../skunk    
+f  mammals/Procyonidae/cacomistle  cacomistle  
+f  mammals/Procyonidae/coatimundi  coatimundi  
+f  mammals/Procyonidae/raccoon     raccoon     
+f  beans/black     ../beans/black     
+f  beans/borlotti  ../beans/borlotti  
+f  beans/kidney    ../beans/kidney    
+f  beans/navy      ../beans/navy      
+f  beans/pinto     ../beans/pinto     
+f  beans/turtle    ../beans/turtle    
+f  mammals/skunk                   skunk                   
+f  mammals/Procyonidae/cacomistle  Procyonidae/cacomistle  
+f  mammals/Procyonidae/coatimundi  Procyonidae/coatimundi  
+f  mammals/Procyonidae/raccoon     Procyonidae/raccoon     
+f  beans/black     beans/black     
+f  beans/borlotti  beans/borlotti  
+f  beans/kidney    beans/kidney    
+f  beans/navy      beans/navy      
+f  beans/pinto     beans/pinto     
+f  beans/turtle    beans/turtle    
+f  beans/black     beans/black     
+f  beans/borlotti  beans/borlotti  
+f  mammals/skunk  mammals/skunk  
+f  mammals/skunk                   mammals/skunk                   
+f  mammals/Procyonidae/cacomistle  mammals/Procyonidae/cacomistle  
+f  mammals/Procyonidae/coatimundi  mammals/Procyonidae/coatimundi  
+f  mammals/Procyonidae/raccoon     mammals/Procyonidae/raccoon     
 abort: .. not under repository root
 abort: beans/../.. not under repository root
-f  fennel      fennel
-f  fenugreek   fenugreek
-f  fiddlehead  fiddlehead
-f  glob:glob   glob:glob
-f  fenugreek      fenugreek
-f  glob:glob      glob:glob
-f  beans/black    beans/black
-f  mammals/skunk  mammals/skunk
-f  beans/black  beans/black
-f  beans/black     beans/black
-f  beans/borlotti  beans/borlotti
-f  beans/kidney    beans/kidney
-f  beans/navy      beans/navy
-f  beans/pinto     beans/pinto
-f  beans/turtle    beans/turtle
+f  fennel      fennel      
+f  fenugreek   fenugreek   
+f  fiddlehead  fiddlehead  
+f  glob:glob   glob:glob   
+f  fenugreek      fenugreek      
+f  glob:glob      glob:glob      
+f  beans/black    beans/black    
+f  mammals/skunk  mammals/skunk  
+f  beans/black  beans/black  
+f  beans/black     beans/black     
+f  beans/borlotti  beans/borlotti  
+f  beans/kidney    beans/kidney    
+f  beans/navy      beans/navy      
+f  beans/pinto     beans/pinto     
+f  beans/turtle    beans/turtle    
 NOEXIST: No such file or directory
 fifo: unsupported file type (type is fifo)
-m  fenugreek  fenugreek
-m  fenugreek  fenugreek
-f  new  new
+m  fenugreek  fenugreek  exact
+m  fenugreek  fenugreek  exact
+f  new  new  exact