[PATCH 1 of 1] inotify: when dirstate is dirty, force local state (fix issue1719)

Simon Heimberg simohe at besonet.ch
Fri Aug 14 16:02:00 CDT 2009


# HG changeset patch
# User Simon Heimberg <simohe at besonet.ch>
# Date 1250283696 -7200
# Node ID e7a6398edf6e6ba9b780ef89271f154f976bbe2e
# Parent  506c6cb9df42e5e096eb8647682cb6c4a0d8ff8e
inotify: when dirstate is dirty, force local state (fix issue1719)

The inotify server always returns the dirstate from disc. When the dirstate
is modified but not yet written to disc, this is the wrong state. The client
fixes the inconsistent states.

diff -r 506c6cb9df42 -r e7a6398edf6e hgext/inotify/__init__.py
--- a/hgext/inotify/__init__.py	Fre Aug 07 16:56:35 2009 +0200
+++ b/hgext/inotify/__init__.py	Fre Aug 14 23:01:36 2009 +0200
@@ -10,8 +10,9 @@
 
 # todo: socket permissions
 
+import bisect
 from mercurial.i18n import _
-from mercurial import cmdutil, util
+from mercurial import cmdutil, util, match as _match
 import server
 from weakref import proxy
 from client import client, QueryFailed
@@ -92,6 +93,45 @@
                                 if f not in a:
                                     ui.warn('*** inotify: %s -%s\n' % (c, f))
                         result = r2
+                    if self._dirty:
+                        # dirstate in memory is modified
+                        #
+                        # Test for all files if the state on disc is consistent
+                        # with the state in memory. If it is not use the one
+                        # from the memory.
+
+                        exact = match.matchfn == match.exact
+                        if files and exact:
+                            unseen = set(files)
+                        elif clean:
+                            # add all files from dirstate for potential fixing
+                            unseen = set(self)
+                        else:
+                            # do not check clean files
+                            unseen = set(f for f in self if self[f] != 'n')
+
+                        fix = set()
+                        matchingstates = 'n nm a r nma ? ? n'.split()
+                        for files, matching in zip(result, matchingstates):
+                            for f in files[:]:
+                                unseen.discard(f)
+                                if self[f] not in matching:
+                                    # inconsistent state
+                                    fix.add(f)
+                                    files.remove(f)
+                        if not exact and (files or match.anypats()):
+                            # only keep matching files
+                            unseen = set(f for f in seen if match(f))
+                        fix.update(unseen)
+                        if fix: # fix states
+                            fmatch = _match.exact(match._root, match._cwd, fix)
+                            # query dirstate in memory for inconsistent files
+                            fresult = super(inotifydirstate, self).status(
+                                fmatch, ignored, clean, unknown)
+                            for st, fst in zip(result, fresult):
+                                for f in fst:
+                                    # insert filename sorted in result
+                                    bisect.insort(st, f)
                     return result
             return super(inotifydirstate, self).status(
                 match, ignored, clean, unknown)
diff -r 506c6cb9df42 -r e7a6398edf6e tests/test-inotify-mq
--- /dev/null	Don Jan 01 00:00:00 1970 +0000
+++ b/tests/test-inotify-mq	Fre Aug 14 23:01:36 2009 +0200
@@ -0,0 +1,29 @@
+#!/bin/sh
+
+"$TESTDIR/hghave" inotify || exit 80
+
+# qpush changeset which adds or deletes a file succedes (issue1719)
+
+echo [extensions] >> $HGRCPATH
+echo inotify= >>  $HGRCPATH
+echo mq= >>  $HGRCPATH
+
+hg init a
+cd a
+
+hg qnew adda
+echo 11 > a
+hg add a
+hg qref
+hg qpo
+hg qpu
+hg st
+
+hg qnew rma
+hg rm a
+hg qref
+hg qpo
+hg qpu
+hg st
+
+hg qpo -a
diff -r 506c6cb9df42 -r e7a6398edf6e tests/test-inotify-mq.out
--- /dev/null	Don Jan 01 00:00:00 1970 +0000
+++ b/tests/test-inotify-mq.out	Fre Aug 14 23:01:36 2009 +0200
@@ -0,0 +1,11 @@
+popping adda
+patch queue now empty
+applying adda
+now at: adda
+popping rma
+now at: adda
+applying rma
+now at: rma
+popping rma
+popping adda
+patch queue now empty


More information about the Mercurial-devel mailing list