Merge walk changes with Matt's tip.
authorBryan O'Sullivan <bos@serpentine.com>
Sat, 13 Aug 2005 15:26:32 -0800
changeset 895 77b52b864249
parent 890 391de0bcc722 (current diff)
parent 894 62ec665759f2 (diff)
child 896 01215ad04283
Merge walk changes with Matt's tip.
.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
tests/test-merge-revert.out
tests/test-merge-revert2
tests/test-merge-revert2.out
tests/test-walk
tests/test-walk.out
--- a/doc/hg.1.txt	Fri Aug 12 16:12:09 2005 -0800
+++ b/doc/hg.1.txt	Sat Aug 13 15:26:32 2005 -0800
@@ -509,7 +509,7 @@
     If BEGIN is greater than END, revisions are treated in reverse
     order.
 
-    A range acts as an open interval.  This means that a range of 3:5
+    A range acts as a closed interval.  This means that a range of 3:5
     gives 3, 4 and 5.  Similarly, a range of 4:2 gives 4, 3, and 2.
 
 ENVIRONMENT VARIABLES
--- a/mercurial/commands.py	Fri Aug 12 16:12:09 2005 -0800
+++ b/mercurial/commands.py	Sat Aug 13 15:26:32 2005 -0800
@@ -463,6 +463,8 @@
         ui.warn("abort: destination '%s' already exists\n" % dest)
         return 1
 
+    dest = os.path.realpath(dest)
+
     class Dircleanup:
         def __init__(self, dir_):
             self.rmtree = shutil.rmtree
--- a/mercurial/hg.py	Fri Aug 12 16:12:09 2005 -0800
+++ b/mercurial/hg.py	Sat Aug 13 15:26:32 2005 -0800
@@ -397,7 +397,7 @@
     def copied(self, file):
         return self.copies.get(file, None)
 
-    def update(self, files, state):
+    def update(self, files, state, **kw):
         ''' current states:
         n  normal
         m  needs merging
@@ -412,7 +412,9 @@
                 self.map[f] = ('r', 0, 0, 0)
             else:
                 s = os.stat(os.path.join(self.root, f))
-                self.map[f] = (state, s.st_mode, s.st_size, s.st_mtime)
+                st_size = kw.get('st_size', s.st_size)
+                st_mtime = kw.get('st_mtime', s.st_mtime)
+                self.map[f] = (state, s.st_mode, st_size, st_mtime)
 
     def forget(self, files):
         if not files: return
@@ -502,6 +504,7 @@
                     for dir, subdirs, fl in os.walk(f):
                         d = dir[len(self.root) + 1:]
                         nd = util.normpath(d)
+                        if nd == '.': nd = ''
                         if seen(nd):
                             subdirs[:] = []
                             continue
@@ -543,36 +546,44 @@
             if match(fn):
                 yield src, fn
 
-    def changes(self, files = None, match = util.always):
+    def changes(self, files=None, match=util.always):
         self.read()
         if not files:
             dc = self.map.copy()
         else:
             dc = self.filterfiles(files)
-        lookup, changed, added, unknown = [], [], [], []
+        lookup, modified, added, unknown = [], [], [], []
+        removed, deleted = [], []
 
         for src, fn in self.walk(files, match, dc=dc):
-            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)
+                unknown.append(fn)
 
-        return (lookup, changed, added, filter(match, dc.keys()), unknown)
+        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):
@@ -1623,10 +1634,20 @@
             m, o, flag = merge[f]
             self.merge3(f, m, o)
             util.set_exec(self.wjoin(f), flag)
-            if moddirstate and mode == 'm':
-                # only update dirstate on branch merge, otherwise we
-                # could mark files with changes as unchanged
-                self.dirstate.update([f], mode)
+            if moddirstate:
+                if mode == 'm':
+                    # only update dirstate on branch merge, otherwise we
+                    # could mark files with changes as unchanged
+                    self.dirstate.update([f], mode)
+                elif p2 == nullid:
+                    # update dirstate from parent1's manifest
+                    m1n = self.changelog.read(p1)[0]
+                    m1 = self.manifest.read(m1n)
+                    f_len = len(self.file(f).read(m1[f]))
+                    self.dirstate.update([f], mode, st_size=f_len, st_mtime=0)
+                else:
+                    self.ui.warn("Second parent without branch merge!?\n"
+                                 "Dirstate for file %s may be wrong.\n" % f)
 
         remove.sort()
         for f in remove:
--- a/tests/test-merge-revert.out	Fri Aug 12 16:12:09 2005 -0800
+++ b/tests/test-merge-revert.out	Sat Aug 13 15:26:32 2005 -0800
@@ -26,7 +26,6 @@
 + hg update
 merging file1
 + hg diff
-FIXME: This is a known bug:
 + hg status
 + hg id
 3aa14bbc23d9 tip
--- a/tests/test-merge-revert2	Fri Aug 12 16:12:09 2005 -0800
+++ b/tests/test-merge-revert2	Sat Aug 13 15:26:32 2005 -0800
@@ -4,6 +4,7 @@
 cd t
 hg init
 echo "added file1" > file1
+echo "another line of text" >> file1
 echo "added file2" > file2
 hg add file1 file2
 hg commit -m "added file1 and file2" -d "0 0" -u user
--- a/tests/test-merge-revert2.out	Fri Aug 12 16:12:09 2005 -0800
+++ b/tests/test-merge-revert2.out	Sat Aug 13 15:26:32 2005 -0800
@@ -3,36 +3,37 @@
 + hg commit -m added file1 and file2 -d 0 0 -u user
 + hg commit -m changed file1 -d 0 0 -u user
 + hg -q log
-1:3aa14bbc23d90e3f8b5b639b4a43d76509bae76c
-0:8633637036c18f021d771208e16ae3508ab81d28
+1:f4d7a8c73d231bc078e2a5e791325e55e8a4c252
+0:232e179b3f294d467cfa66e1439bc5b0d44e4a93
 + hg id
-3aa14bbc23d9 tip
+f4d7a8c73d23 tip
 + hg update -C 0
 + hg id
-8633637036c1
+232e179b3f29
 + hg id
-8633637036c1+
+232e179b3f29+
 + hg revert
 + hg diff
 + hg status
 + hg id
-8633637036c1
+232e179b3f29
 + hg update
 + hg diff
 + hg status
 + hg id
-3aa14bbc23d9 tip
+f4d7a8c73d23 tip
 + hg update -C 0
 + hg update
 merge: warning: conflicts during merge
 merging file1
 merging file1 failed!
 + hg diff
-diff -r 3aa14bbc23d9 file1
+diff -r f4d7a8c73d23 file1
 --- a/file1
 +++ b/file1
-@@ -1,2 +1,6 @@
+@@ -1,3 +1,7 @@
  added file1
+ another line of text
 +<<<<<<<
 +changed file1 different
 +=======
@@ -41,20 +42,19 @@
 + hg status
 M file1
 + hg id
-3aa14bbc23d9+ tip
+f4d7a8c73d23+ tip
 + hg revert
 + hg diff
-FIXME: This is a known bug:
 + hg status
 + hg id
-3aa14bbc23d9 tip
+f4d7a8c73d23 tip
 + hg revert -r tip
 + hg diff
 + hg status
 + hg id
-3aa14bbc23d9 tip
+f4d7a8c73d23 tip
 + hg update -C
 + hg diff
 + hg status
 + hg id
-3aa14bbc23d9 tip
+f4d7a8c73d23 tip
--- a/tests/test-walk	Fri Aug 12 16:12:09 2005 -0800
+++ b/tests/test-walk	Sat Aug 13 15:26:32 2005 -0800
@@ -35,8 +35,10 @@
 hg debugwalk path:mammals
 hg debugwalk ..
 hg debugwalk beans/../..
-hg debugwalk `pwd`/beans
-hg debugwalk `pwd`/..
+# Don't know how to test absolute paths without always getting a false
+# error.
+#hg debugwalk `pwd`/beans
+#hg debugwalk `pwd`/..
 hg debugwalk glob:\*
 hg debugwalk 're:.*[kb]$'
 hg debugwalk path:beans/black
--- a/tests/test-walk.out	Fri Aug 12 16:12:09 2005 -0800
+++ b/tests/test-walk.out	Sat Aug 13 15:26:32 2005 -0800
@@ -81,15 +81,6 @@
 abort: .. not under repository root
 + hg debugwalk beans/../..
 abort: beans/../.. not under repository root
-+ hg debugwalk /tmp/hgtests.15784.14760.4713.20670/test-walk/t/beans
-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
-+ hg debugwalk /tmp/hgtests.15784.14760.4713.20670/test-walk/t/..
-abort: /tmp/hgtests.15784.14760.4713.20670/test-walk/t/.. not under repository root
 + hg debugwalk glob:*
 f  fennel      fennel
 f  fenugreek   fenugreek