Patchwork [6,of,6] dirstate: make write() aware of pending file

login
register
mail settings
Submitter Katsunori FUJIWARA
Date May 19, 2015, 4:42 p.m.
Message ID <18d35e7df884b3bdd8f6.1432053726@feefifofum>
Download mbox | patch
Permalink /patch/9184/
State Changes Requested
Delegated to: Pierre-Yves David
Headers show

Comments

Katsunori FUJIWARA - May 19, 2015, 4:42 p.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
# Date 1432051569 -32400
#      Wed May 20 01:06:09 2015 +0900
# Node ID 18d35e7df884b3bdd8f6d1351703679f650a83b9
# Parent  06310e0ab134f1bb45bdebd5d87cfcfca4ca2548
dirstate: make write() aware of pending file

When pending file exists, `write()` should:

- rename from `dirstate.pendnig` to `dirstate`, if not dirty
  - the former works well as the latter
    (dirstate hasn't been changed since last `_writepending()`), and
  - renaming is more efficient than writing out again

- remove `dirstate.pending` and write changes into `dirstate`, otherwise

`_fixuppending()` is defined as a function to reuse it in subsequent
patch: pending file should be fixed up also at the end of transaction
regardless of outcome of it.
Augie Fackler - May 19, 2015, 11:36 p.m.
On Wed, May 20, 2015 at 01:42:06AM +0900, FUJIWARA Katsunori wrote:
> # HG changeset patch
> # User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
> # Date 1432051569 -32400
> #      Wed May 20 01:06:09 2015 +0900
> # Node ID 18d35e7df884b3bdd8f6d1351703679f650a83b9
> # Parent  06310e0ab134f1bb45bdebd5d87cfcfca4ca2548
> dirstate: make write() aware of pending file

This series LGTM, but marmoute has some extra state so I'm going to
ask him to reivew it too.

>
> When pending file exists, `write()` should:
>
> - rename from `dirstate.pendnig` to `dirstate`, if not dirty
>   - the former works well as the latter
>     (dirstate hasn't been changed since last `_writepending()`), and
>   - renaming is more efficient than writing out again
>
> - remove `dirstate.pending` and write changes into `dirstate`, otherwise
>
> `_fixuppending()` is defined as a function to reuse it in subsequent
> patch: pending file should be fixed up also at the end of transaction
> regardless of outcome of it.
>
> diff --git a/mercurial/dirstate.py b/mercurial/dirstate.py
> --- a/mercurial/dirstate.py
> +++ b/mercurial/dirstate.py
> @@ -621,6 +621,7 @@
>          self._dirty = True
>
>      def write(self):
> +        self._fixuppending(None)
>          if not self._dirty:
>              return
>          self._writedirstate(self._filename)
> @@ -633,6 +634,21 @@
>                  raise
>          self._diverted = False
>
> +    def _fixuppending(self, tr):
> +        '''Fix up pending file
> +
> +        `tr` may be None, because this is used also out of transaction
> +        scope.
> +        '''
> +        if self._diverted:
> +            if self._dirty:
> +                # '.pending' file should be out of date
> +                self._removepending()
> +            else:
> +                # dirstate hasn't been changed since last _writepending
> +                self._opener.rename(self._pendingfilename, self._filename)
> +                self._diverted = False
> +
>      def _writepending(self, tr):
>          '''Make pending data visible to external processes
>
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel

Patch

diff --git a/mercurial/dirstate.py b/mercurial/dirstate.py
--- a/mercurial/dirstate.py
+++ b/mercurial/dirstate.py
@@ -621,6 +621,7 @@ 
         self._dirty = True
 
     def write(self):
+        self._fixuppending(None)
         if not self._dirty:
             return
         self._writedirstate(self._filename)
@@ -633,6 +634,21 @@ 
                 raise
         self._diverted = False
 
+    def _fixuppending(self, tr):
+        '''Fix up pending file
+
+        `tr` may be None, because this is used also out of transaction
+        scope.
+        '''
+        if self._diverted:
+            if self._dirty:
+                # '.pending' file should be out of date
+                self._removepending()
+            else:
+                # dirstate hasn't been changed since last _writepending
+                self._opener.rename(self._pendingfilename, self._filename)
+                self._diverted = False
+
     def _writepending(self, tr):
         '''Make pending data visible to external processes