[PATCH stable] mq: fix qrefresh case sensitivity (issue3271)

Durham Goode durham at fb.com
Tue Oct 30 17:54:08 CDT 2012


# HG changeset patch
# User Durham Goode <durham at fb.com>
# Date 1351628346 25200
# Branch stable
# Node ID 983d425ca3f84e77ebbd5a9562352a9284f0a656
# Parent  0188ddfa844ed5f9cf2eed46765dcaa7dcad89f6
mq: fix qrefresh case sensitivity (issue3271)

When calling qrefresh with filenames, the filenames were being
treated as case-sensistive on case-insensitive file systems.
So 'qrefresh foo' would not match file 'Foo', and it failed silently.
This fix makes it work correctly on case-insensitive file systems.

Previously the matching function was applied directly to the filenames.
Now we apply the matching function through repo.status, which handles
the case logic for us. A side effect of using repo.status is that
if the qrefresh file doesn't exist, there is output stating it
doesn't exist.

Adds a test to an existing mq refresh case test.

diff --git a/hgext/mq.py b/hgext/mq.py
--- a/hgext/mq.py
+++ b/hgext/mq.py
@@ -1570,18 +1570,28 @@
                     continue
                 else:
                     mm.discard(x)
                 dd.add(x)
 
             m = list(mm)
             r = list(dd)
             a = list(aa)
-            c = [filter(matchfn, l) for l in (m, a, r)]
-            match = scmutil.matchfiles(repo, set(c[0] + c[1] + c[2] + inclsubs))
+
+            # create 'match' that includes the files to be recommited.
+            # apply matchfn via repo.status to ensure correct case handling.
+            cm, ca, cr, cd = repo.status(patchparent, match=matchfn)[:4]
+            allmatches = set(cm + ca + cr + cd)
+            refreshchanges = [x.intersection(allmatches) for x in (mm, aa, dd)]
+
+            files = set(inclsubs)
+            for x in refreshchanges:
+                files.update(x)
+            match = scmutil.matchfiles(repo, files)
+
             bmlist = repo[top].bookmarks()
 
             try:
                 if diffopts.git or diffopts.upgrade:
                     copies = {}
                     for dst in a:
                         src = repo.dirstate.copied(dst)
                         # during qfold, the source file for copies may
@@ -1651,16 +1661,17 @@
             try:
                 # might be nice to attempt to roll back strip after this
 
                 # Ensure we create a new changeset in the same phase than
                 # the old one.
                 n = newcommit(repo, oldphase, message, user, ph.date,
                               match=match, force=True)
                 # only write patch after a successful commit
+                c = [list(x) for x in refreshchanges]
                 if inclsubs:
                     self.putsubstate2changes(substatestate, c)
                 chunks = patchmod.diff(repo, patchparent,
                                        changes=c, opts=diffopts)
                 for chunk in chunks:
                     patchf.write(chunk)
                 patchf.close()
 
diff --git a/tests/test-casefolding.t b/tests/test-casefolding.t
--- a/tests/test-casefolding.t
+++ b/tests/test-casefolding.t
@@ -155,9 +155,20 @@
   $ hg status -A
   A MiXeDcAsE
     mIxEdCaSe
   R mIxEdCaSe
   $ hg qrefresh
   $ hg status -A
   C MiXeDcAsE
 
+  $ hg qpop -a
+  popping refresh-casechange
+  patch queue now empty
+  $ hg qnew refresh-pattern
+  $ hg status
+  $ echo A > A
+  $ hg add
+  adding A
+  $ hg qrefresh a # issue 3271, qrefresh with file handled case wrong
+  $ hg status # empty status means the qrefresh worked
+
   $ cd ..
diff --git a/tests/test-mq-qrefresh.t b/tests/test-mq-qrefresh.t
--- a/tests/test-mq-qrefresh.t
+++ b/tests/test-mq-qrefresh.t
@@ -203,16 +203,17 @@
   +patched
 
 
 qrefresh --short tests:
 
   $ echo 'orphan' > orphanchild
   $ hg add orphanchild
   $ hg qrefresh nonexistentfilename # clear patch
+  nonexistentfilename: No such file or directory
   $ hg qrefresh --short 1/base
   $ hg qrefresh --short 2/base
 
   $ hg qdiff
   diff -r e7af5904b465 1/base
   --- a/1/base
   +++ b/1/base
   @@ -1,1 +1,1 @@


More information about the Mercurial-devel mailing list