Patchwork revert: stabilize status message of chunks selected interactively

login
register
mail settings
Submitter Yuya Nishihara
Date Sept. 3, 2018, 2:11 p.m.
Message ID <1cbe19eb496d2dd8d4c8.1535983892@mimosa>
Download mbox | patch
Permalink /patch/34272/
State Accepted
Headers show

Comments

Yuya Nishihara - Sept. 3, 2018, 2:11 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1535983399 -32400
#      Mon Sep 03 23:03:19 2018 +0900
# Node ID 1cbe19eb496d2dd8d4c8cae849a513348fefadf2
# Parent  babad5ebaf0aed3add17b444c0df983570c03fc3
revert: stabilize status message of chunks selected interactively

Unfortunately, patch.filterpatch() doesn't preserve the order of the input
files. We have to sort them manually.
Pulkit Goyal - Sept. 3, 2018, 7:46 p.m.
On Mon, Sep 3, 2018 at 7:42 PM Yuya Nishihara <yuya@tcha.org> wrote:

> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1535983399 -32400
> #      Mon Sep 03 23:03:19 2018 +0900
> # Node ID 1cbe19eb496d2dd8d4c8cae849a513348fefadf2
> # Parent  babad5ebaf0aed3add17b444c0df983570c03fc3
> revert: stabilize status message of chunks selected interactively
>
> Unfortunately, patch.filterpatch() doesn't preserve the order of the input
> files. We have to sort them manually.
>

Queued this patch, many thanks!

Patch

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -3152,15 +3152,12 @@  def _performrevert(repo, parents, ctx, n
             tobackup = set()
         # Apply changes
         fp = stringio()
-        # `fnames` keeps track of filenames for which we have initiated changes,
-        # to make sure that we print status msg only once per file.
-        fnames = set()
+        # chunks are serialized per file, but files aren't sorted
+        for f in sorted(set(c.header.filename() for c in chunks if ishunk(c))):
+            prntstatusmsg('revert', f)
         for c in chunks:
             if ishunk(c):
                 abs = c.header.filename()
-                if abs not in fnames:
-                    fnames.add(abs)
-                    prntstatusmsg('revert', abs)
                 # Create a backup file only if this hunk should be backed up
                 if c.header.filename() in tobackup:
                     target = repo.wjoin(abs)
diff --git a/tests/test-revert-interactive.t b/tests/test-revert-interactive.t
--- a/tests/test-revert-interactive.t
+++ b/tests/test-revert-interactive.t
@@ -112,8 +112,8 @@  10 run the same test than 8 from within 
   2 hunks, 2 lines changed
   examine changes to 'folder2/h'? [Ynesfdaq?] n
   
+  reverting f
   reverting folder1/g
-  reverting f
   $ cat f
   1
   2
@@ -243,8 +243,8 @@  Test --no-backup
   2 hunks, 2 lines changed
   examine changes to 'folder2/h'? [Ynesfdaq?] n
   
+  reverting f
   reverting folder1/g
-  reverting f
   $ cat f
   1
   2