Make diffdir take a revision argument
authormpm@selenic.com
Thu, 05 May 2005 15:05:50 -0800
changeset 29 4d3a5dcb6972
parent 28 9f64ee817199
child 30 12f598340423
Make diffdir take a revision argument
hg
mercurial/hg.py
--- a/hg	Wed May 04 22:57:51 2005 -0800
+++ b/hg	Thu May 05 15:05:50 2005 -0800
@@ -112,7 +112,7 @@
         repo.commit(files)
 
 elif cmd == "status":
-    (c, a, d) = repo.diffdir(repo.root)
+    (c, a, d) = repo.diffdir(repo.root, repo.current)
     for f in c: print "C", f
     for f in a: print "?", f
     for f in d: print "R", f
@@ -123,7 +123,7 @@
         change = repo.changelog.read(repo.current)
         mmap = repo.manifest.read(change[0])
 
-    (c, a, d) = repo.diffdir(repo.root)
+    (c, a, d) = repo.diffdir(repo.root, repo.current)
 
     if args:
         nc = [ x for x in c if x in args ]
@@ -151,7 +151,7 @@
         sys.stdout.write(mdiff.unidiff(to, tn, f))
 
 elif cmd == "addremove":
-    (c, a, d) = repo.diffdir(repo.root)
+    (c, a, d) = repo.diffdir(repo.root, repo.current)
     repo.add(a)
     repo.remove(d)
     
--- a/mercurial/hg.py	Wed May 04 22:57:51 2005 -0800
+++ b/mercurial/hg.py	Thu May 05 15:05:50 2005 -0800
@@ -408,7 +408,7 @@
 
         tr.close()
 
-    def commit(self, update = None, text = ""):
+    def commit(self, update = None, parent, text = ""):
         tr = self.transaction()
         
         try:
@@ -419,7 +419,7 @@
             remove = []
 
         if update == None:
-            update = self.diffdir(self.root)[0]
+            update = self.diffdir(self.root, parent)[0]
 
         # check in files
         new = {}
@@ -484,16 +484,25 @@
         self.dircache.clear()
         self.dircache.update(l)
 
-    def diffdir(self, path):
-        dc = self.dircache.copy()
+    def diffdir(self, path, changeset):
         changed = []
         mf = {}
         added = []
 
-        if self.current:
-            change = self.changelog.read(self.current)
+        if changeset:
+            change = self.changelog.read(changeset)
             mf = self.manifest.read(change[0])
 
+        if changeset == self.current:
+            dc = self.dircache.copy()
+        else:
+            dc = dict.fromkeys(mf)
+
+        def fcmp(fn):
+            t1 = file(fn).read()
+            t2 = self.file(fn).revision(mf[fn])
+            return cmp(t1, t2)
+
         for dir, subdirs, files in os.walk(self.root):
             d = dir[len(self.root)+1:]
             if ".hg" in subdirs: subdirs.remove(".hg")
@@ -505,12 +514,13 @@
                 if fn in dc:
                     c = dc[fn]
                     del dc[fn]
+                    if not c:
+                        if fcmp(fn):
+                            changed.append(fn)
                     if c[1] != s.st_size:
                         changed.append(fn)
                     elif c[0] != s.st_mode or c[2] != s.st_mtime:
-                        t1 = file(fn).read()
-                        t2 = self.file(fn).revision(mf[fn])
-                        if t1 != t2:
+                        if fcmp(fn):
                             changed.append(fn)
                 else:
                     if self.ignore(fn): continue