[PATCH 5 of 5] patch: invoke dirstate.dirtyifambig on changed file for safety

FUJIWARA Katsunori foozy at lares.dti.ne.jp
Wed May 27 12:03:25 CDT 2015


# HG changeset patch
# User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
# Date 1432745859 -32400
#      Thu May 28 01:57:39 2015 +0900
# Node ID 0b360140869e72996260435940cfefb88a1e9cdc
# Parent  6d5d5a1d294d51f4a76cafec192278fd961047bf
patch: invoke dirstate.dirtyifambig on changed file for safety

Patched file may be mis-recognized as clean by dirstate, if mode, size
and timestamp of it on the filesystem aren't changed.

To avoid such ambiguous situation, this patch invokes
`dirstate.dirtyifambig()` on changed file in `workingbackend.setfile()`

This should be executed explicitly, because `fsbackend.setfile()`
doesn't use `localrepository.wwrite()` to write data into the working
directory (probably, to avoid decoding file content).

diff --git a/mercurial/patch.py b/mercurial/patch.py
--- a/mercurial/patch.py
+++ b/mercurial/patch.py
@@ -488,6 +488,8 @@
     def setfile(self, fname, data, mode, copysource):
         self._checkknown(fname)
         super(workingbackend, self).setfile(fname, data, mode, copysource)
+        if data is not None:
+            self.repo.dirstate.unsureifambig(fname, len(data))
         if copysource is not None:
             self.copied.append((copysource, fname))
         self.changed.add(fname)
diff --git a/tests/test-import.t b/tests/test-import.t
--- a/tests/test-import.t
+++ b/tests/test-import.t
@@ -193,6 +193,33 @@
   @@ -1,1 +1,2 @@
    line 1
   +line 2
+
+(test that patched file is recognized as "modified" correctly, even if
+mode, size and timestamp of it on the filesystem aren't changed)
+
+  $ echo 'LINE X' > b/a
+  $ hg --cwd b diff --nodates > $TESTTMP/dirtyambig.patch
+  $ cat $TESTTMP/dirtyambig.patch
+  diff -r 80971e65b431 a
+  --- a/a
+  +++ b/a
+  @@ -1,1 +1,1 @@
+  -line 1
+  +LINE X
+  $ hg --cwd b update -q -C .
+  $ touch -t 200001010000 b/a
+  $ hg --cwd b status -A a
+  C a
+  $ cat b/a
+  line 1
+  $ hg --cwd b import --no-commit $TESTTMP/dirtyambig.patch
+  applying $TESTTMP/dirtyambig.patch
+  $ touch -t 200001010000 b/a
+  $ hg --cwd b status -A a
+  M a
+  $ cat b/a
+  LINE X
+
   $ rm -r b
 
 


More information about the Mercurial-devel mailing list