hg remove implicit for whole tree commits?

Thomas Arendsen Hein thomas at intevation.de
Tue Aug 9 05:36:55 CDT 2005


* Thomas Arendsen Hein <thomas at intevation.de> [20050808 11:59]:
> * Robin Farine <robin.farine at terminus.org> [20050808 10:33]:
> > >       if fn in dc:
> > >         c = dc[fn]
> > >         del dc[fn]
> > 
> > Since you now handle !-files explicitely, the 'del dc[fn]' can
> > be either removed or you could verify that dc is empty before
> > returning (and raise a software error exception if not).
> 
> The del probably isn't needed, I'll check.

The del thing is needed because the walk method doesn't yield
directoriy names.

> > > -      else:
> > > -        if match(fn): unknown.append(fn)
> > > +      elif s and match(fn):
> > 
> > Here we have an fn that is not in dc, so doesn't the walk() code
> > already ensure the match(fn) condition?
> 
> I have just used the old code here to not break anything, but I
> looked at this with suspicion, too.

It really is not needed, so I removed it in the new version.

Attached the updated patch, this time also pullable.

Thomas

-- 
Email: thomas at intevation.de
http://intevation.de/~thomas/
-------------- next part --------------
# HG changeset patch
# User Thomas Arendsen Hein <thomas at intevation.de>
# Node ID cbe5c4d016b712283add05545165551f47166c92
# Parent  8ccbac05cf593efcef858dbe23bf0a61e66a791f
dirstate.changes() now distinguishes 'hg remove'd or just deleted files.
Interface is not yet changed.
Non-regular files are considered to be removed or deleted.
Removed the unneeded match(fn) call for adding to the unknown list.

diff -r 8ccbac05cf593efcef858dbe23bf0a61e66a791f -r cbe5c4d016b712283add05545165551f47166c92 mercurial/hg.py
--- a/mercurial/hg.py	Tue Aug  9 10:15:57 2005
+++ b/mercurial/hg.py	Tue Aug  9 10:32:30 2005
@@ -10,7 +10,7 @@
 from revlog import *
 from demandload import *
 demandload(globals(), "re lock urllib urllib2 transaction time socket")
-demandload(globals(), "tempfile httprangereader bdiff urlparse")
+demandload(globals(), "tempfile httprangereader bdiff urlparse stat")
 demandload(globals(), "bisect select")
 
 class filelog(revlog):
@@ -484,33 +484,41 @@
             if match(fn):
                 yield src, fn
 
-    def changes(self, files = None, match = util.always):
+    def changes(self, files=None, match=util.always):
         self.read()
         dc = self.map.copy()
-        lookup, changed, added, unknown = [], [], [], []
+        lookup, modified, added, unknown = [], [], [], []
+        removed, deleted = [], []
 
         for src, fn in self.walk(files, match):
-            try: s = os.stat(os.path.join(self.root, fn))
-            except: continue
-
-            if fn in dc:
-                c = dc[fn]
+            try:
+                s = os.stat(os.path.join(self.root, fn))
+            except OSError:
+                continue
+            if not stat.S_ISREG(s.st_mode):
+                continue
+            c = dc.get(fn)
+            if c:
                 del dc[fn]
-
                 if c[0] == 'm':
-                    changed.append(fn)
+                    modified.append(fn)
                 elif c[0] == 'a':
                     added.append(fn)
                 elif c[0] == 'r':
                     unknown.append(fn)
                 elif c[2] != s.st_size or (c[1] ^ s.st_mode) & 0100:
-                    changed.append(fn)
-                elif c[1] != s.st_mode or c[3] != s.st_mtime:
+                    modified.append(fn)
+                elif c[3] != s.st_mtime:
                     lookup.append(fn)
             else:
-                if match(fn): unknown.append(fn)
-
-        return (lookup, changed, added, filter(match, dc.keys()), unknown)
+                unknown.append(fn)
+
+        for fn, c in [(fn, c) for fn, c in dc.items() if match(fn)]:
+            if c[0] == 'r':
+                removed.append(fn)
+            else:
+                deleted.append(fn)
+        return (lookup, modified, added, removed + deleted, unknown)
 
 # used to avoid circular references so destructors work
 def opener(base):


More information about the Mercurial mailing list