D6005: uncommit: added interactive mode and removed _fixdirstate(issue6062)
taapas1128 updated this revision to Diff 14192. taapas1128 retitled this revision from "uncommit: added interactive mode and removed _fixdirstate()(issue6062)" to "uncommit: added interactive mode and removed _fixdirstate(issue6062)". REPOSITORY rHG Mercurial CHANGES SINCE LAST UPDATE https://phab.mercurial-scm.org/D6005?vs=14191&id=14192 REVISION DETAIL https://phab.mercurial-scm.org/D6005 AFFECTED FILES hgext/uncommit.py tests/test-unamend.t tests/test-uncommit-interactive.t tests/test-uncommit.t CHANGE DETAILS diff --git a/tests/test-uncommit.t b/tests/test-uncommit.t --- a/tests/test-uncommit.t +++ b/tests/test-uncommit.t @@ -34,6 +34,7 @@ options ([+] can be repeated): + -i --interactive interactive mode to uncommit --keepallow an empty commit after uncommiting -I --include PATTERN [+] include names matching the given patterns -X --exclude PATTERN [+] exclude names matching the given patterns diff --git a/tests/test-uncommit-interactive.t b/tests/test-uncommit-interactive.t new file mode 100644 --- /dev/null +++ b/tests/test-uncommit-interactive.t @@ -0,0 +1,969 @@ + +|| The test for `hg uncommit --interactive` || + + +Repo Setup + + + $ cat >> $HGRCPATH < [ui] + > interactive = true + > [experimental] + > evolution.createmarkers=True + > evolution.allowunstable=True + > uncommitondirtywdir = true + > [extensions] + > uncommit = + > amend = + > drawdag=$TESTDIR/drawdag.py + > EOF + $ glog() { + > hg log -G --template '{rev}:{node|short}@{branch}({separate("/", obsolete, phase)}) {desc|firstline}\n' "$@" + > } + + $ hg init repo + $ cd repo + + $ touch a + $ cat >> a << EOF + > 1 + > 2 + > 3 + > 4 + > 5 + > EOF + + $ hg add a + $ hg ci -m "The base commit" + +Make sure aborting the interactive selection does no magic +-- + + $ hg status + $ hg uncommit -i< q + > EOF + diff --git a/a b/a + new file mode 100644 + examine changes to 'a'? [Ynesfdaq?] q + + abort: user quit + [255] + $ hg status + +Make a commit with multiple hunks +- + + $ cat > a << EOF + > -2 + > -1 + > 0 + > 1 + > 2 + > 3 + > foo + > bar + > 4 + > 5 + > babar + > EOF + + $ hg diff + diff -r 7733902a8d94 a + --- a/a Thu Jan 01 00:00:00 1970 + + +++ b/a Thu Jan 01 00:00:00 1970 + + @@ -1,5 +1,11 @@ + +-2 + +-1 + +0 + 1 + 2 + 3 + +foo + +bar + 4 + 5 + +babar + + $ hg ci -m "another one" + +Not selecting anything to uncommit +== + + $ hg uncommit -i< y + > n + > n + > n + > EOF + diff --git a/a b/a + 3 hunks, 6 lines changed + examine changes to 'a'? [Ynesfdaq?] y + + @@ -1,3 +1,6 @@ + +-2 + +-1 + +0 + 1 + 2 + 3 + discard change 1/3 to 'a'? [Ynesfdaq?] n + + @@ -1,5 +4,7 @@ + 1 + 2 + 3 + +foo + +bar + 4 + 5 + discard change 2/3 to 'a'? [Ynesfdaq?] n + + @@ -4,2 +9,3 @@ + 4 + 5 + +babar + discard change 3/3 to 'a'? [Ynesfdaq?] n + + abort: nothing selected to uncommit + [255] + $ hg status + +Uncommit a chunk + + + $ hg uncommit -i< y + > y + > n + > n + > EOF + diff --git a/a b/a + 3 hunks, 6 lines changed + examine changes to 'a'? [Ynesfdaq?] y + + @@ -1,3 +1,6 @@ + +-2 + +-1 + +0 + 1 + 2 + 3 + discard change 1/3 to 'a'? [Ynesfdaq?] y + + @@ -1,5 +4,7 @@ + 1 + 2 + 3 + +foo + +bar + 4 + 5 + discard change 2/3 to 'a'? [Ynesfdaq?] n + + @@ -4,2 +9,3 @@ + 4 + 5 + +babar + discard change 3/3 to 'a'? [Ynesfdaq?] n + + + $ hg log -G --hidden + @ changeset: 3:678a59e5ff90 + | tag: tip + | parent: 0:7733902a8d94 + | user:test + | date:Thu Jan 01 00:00:00 1970 + + | summary: another one + | + | x changeset: 2:e9635f4beaf1 + |/ parent: 0:7733902a8d94 + |user:test + |date:Thu Jan 01 00:00:00 1970 + + |obsolete:pruned using uncommit + |summary: temporary commit for uncommiting f70fb463d5bf + | + | x changeset: 1:f70fb463d5bf + |/ user:test + |date:Thu Jan 01 00:00:00 1970 + + |obsolete:rewritten using uncommit as 3:678a59e5ff90 + |summary: another one + | + o changeset: 0:7733902a8d94 + user:test + date:Thu Jan 01 00:00:00 1970 + + summary: The base commit + +The unselected part should be in the diff +- + + $ hg diff + diff -r 678a59e5ff90 a + --- a/a Thu Jan 01 00:00:00 1970 + + +++ b/a Thu Jan 01 00:00:00 1970 + + @@ -1,3 +1,6 @@ + +-2 + +-1 + +0 + 1 + 2 + 3 + +The commit should contain the rest of part +-- + + $ hg exp + # HG chang
D6005: uncommit: added interactive mode and removed _fixdirstate()(issue6062)
martinvonz added a comment. I haven't reviewed much of it, but here are some initial comments INLINE COMMENTS > uncommit.py:101 > > -def _fixdirstate(repo, oldctx, newctx, match=None): > -""" fix the dirstate after switching the working directory from oldctx to > -newctx which can be result of either unamend or uncommit. > +def _uncommitdirstate(repo, oldctx, newctx, match, interactive): > +"""Fix the dirstate after switching the working directory from I don't think we need to rename it from `_fixdirstate()`, especially since it's used for both uncommit and unamend. (Fix commit message too, of course, if you switch back to the old name.) > uncommit.py:114 > +# us in defining the exact behavior > +m, a, r = repo.status(oldctx, ctx, match=match)[:3] > +for f in m: I've been trying to avoid accessing status fields by index because it's not very readable. Can you use the same pattern as below instead (i.e. `s.modifed` etc)? > uncommit.py:399 > +match=None > +interactive=0 > +_uncommitdirstate(repo, curctx, newpredctx, match, interactive) Instead of defining a value here, specify the argument by name when you call the function: `_uncommitdirstate(..., interactive=False)`. But it's probably better to just make `interactive` default to `False` and not pass it here. > uncommit.py:400 > +interactive=0 > +_uncommitdirstate(repo, curctx, newpredctx, match, interactive) > Keep the match optional instead? REPOSITORY rHG Mercurial REVISION DETAIL https://phab.mercurial-scm.org/D6005 To: taapas1128, #hg-reviewers Cc: martinvonz, mercurial-devel ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
D6005: uncommit: added interactive mode and removed _fixdirstate()(issue6062)
taapas1128 created this revision. Herald added a subscriber: mercurial-devel. Herald added a reviewer: hg-reviewers. REPOSITORY rHG Mercurial REVISION DETAIL https://phab.mercurial-scm.org/D6005 AFFECTED FILES hgext/uncommit.py tests/test-unamend.t tests/test-uncommit-interactive.t tests/test-uncommit.t CHANGE DETAILS diff --git a/tests/test-uncommit.t b/tests/test-uncommit.t --- a/tests/test-uncommit.t +++ b/tests/test-uncommit.t @@ -34,6 +34,7 @@ options ([+] can be repeated): + -i --interactive interactive mode to uncommit --keepallow an empty commit after uncommiting -I --include PATTERN [+] include names matching the given patterns -X --exclude PATTERN [+] exclude names matching the given patterns diff --git a/tests/test-uncommit-interactive.t b/tests/test-uncommit-interactive.t new file mode 100644 --- /dev/null +++ b/tests/test-uncommit-interactive.t @@ -0,0 +1,969 @@ + +|| The test for `hg uncommit --interactive` || + + +Repo Setup + + + $ cat >> $HGRCPATH < [ui] + > interactive = true + > [experimental] + > evolution.createmarkers=True + > evolution.allowunstable=True + > uncommitondirtywdir = true + > [extensions] + > uncommit = + > amend = + > drawdag=$TESTDIR/drawdag.py + > EOF + $ glog() { + > hg log -G --template '{rev}:{node|short}@{branch}({separate("/", obsolete, phase)}) {desc|firstline}\n' "$@" + > } + + $ hg init repo + $ cd repo + + $ touch a + $ cat >> a << EOF + > 1 + > 2 + > 3 + > 4 + > 5 + > EOF + + $ hg add a + $ hg ci -m "The base commit" + +Make sure aborting the interactive selection does no magic +-- + + $ hg status + $ hg uncommit -i< q + > EOF + diff --git a/a b/a + new file mode 100644 + examine changes to 'a'? [Ynesfdaq?] q + + abort: user quit + [255] + $ hg status + +Make a commit with multiple hunks +- + + $ cat > a << EOF + > -2 + > -1 + > 0 + > 1 + > 2 + > 3 + > foo + > bar + > 4 + > 5 + > babar + > EOF + + $ hg diff + diff -r 7733902a8d94 a + --- a/a Thu Jan 01 00:00:00 1970 + + +++ b/a Thu Jan 01 00:00:00 1970 + + @@ -1,5 +1,11 @@ + +-2 + +-1 + +0 + 1 + 2 + 3 + +foo + +bar + 4 + 5 + +babar + + $ hg ci -m "another one" + +Not selecting anything to uncommit +== + + $ hg uncommit -i< y + > n + > n + > n + > EOF + diff --git a/a b/a + 3 hunks, 6 lines changed + examine changes to 'a'? [Ynesfdaq?] y + + @@ -1,3 +1,6 @@ + +-2 + +-1 + +0 + 1 + 2 + 3 + discard change 1/3 to 'a'? [Ynesfdaq?] n + + @@ -1,5 +4,7 @@ + 1 + 2 + 3 + +foo + +bar + 4 + 5 + discard change 2/3 to 'a'? [Ynesfdaq?] n + + @@ -4,2 +9,3 @@ + 4 + 5 + +babar + discard change 3/3 to 'a'? [Ynesfdaq?] n + + abort: nothing selected to uncommit + [255] + $ hg status + +Uncommit a chunk + + + $ hg uncommit -i< y + > y + > n + > n + > EOF + diff --git a/a b/a + 3 hunks, 6 lines changed + examine changes to 'a'? [Ynesfdaq?] y + + @@ -1,3 +1,6 @@ + +-2 + +-1 + +0 + 1 + 2 + 3 + discard change 1/3 to 'a'? [Ynesfdaq?] y + + @@ -1,5 +4,7 @@ + 1 + 2 + 3 + +foo + +bar + 4 + 5 + discard change 2/3 to 'a'? [Ynesfdaq?] n + + @@ -4,2 +9,3 @@ + 4 + 5 + +babar + discard change 3/3 to 'a'? [Ynesfdaq?] n + + + $ hg log -G --hidden + @ changeset: 3:678a59e5ff90 + | tag: tip + | parent: 0:7733902a8d94 + | user:test + | date:Thu Jan 01 00:00:00 1970 + + | summary: another one + | + | x changeset: 2:e9635f4beaf1 + |/ parent: 0:7733902a8d94 + |user:test + |date:Thu Jan 01 00:00:00 1970 + + |obsolete:pruned using uncommit + |summary: temporary commit for uncommiting f70fb463d5bf + | + | x changeset: 1:f70fb463d5bf + |/ user:test + |date:Thu Jan 01 00:00:00 1970 + + |obsolete:rewritten using uncommit as 3:678a59e5ff90 + |summary: another one + | + o changeset: 0:7733902a8d94 + user:test + date:Thu Jan 01 00:00:00 1970 + + summary: The base commit + +The unselected part should be in the diff +- + + $ hg diff + diff -r 678a59e5ff90 a + --- a/a Thu Jan 01 00:00:00 1970 + + +++ b/a Thu Jan 01 00:00:00 1970 + + @@ -1,3 +1,6 @@ + +-2 + +-1 + +0 + 1 + 2 + 3 + +The commit should contain the rest of part +-- + + $ hg exp + # HG changeset patch + # User test + # Date 0 0 + # Thu Jan 01 00:00:00 1970 + + # Node ID 678a59e5ff90754d5e94719bd82ad169be773c21 + # Parent 7733902a8d94c789ca81d866bea1893d79442db6 + another one