Patchwork dispatch: fix so that if the -M flag does not change the order of records in hg log (issue4289)

login
register
mail settings
Submitter Prabhu GS
Date July 14, 2014, 4:12 p.m.
Message ID <ee3d37ca8c80bff0d3c5.1405354342@sparta.ap01.lucent.com>
Download mbox | patch
Permalink /patch/5161/
State Changes Requested
Headers show

Comments

Prabhu GS - July 14, 2014, 4:12 p.m.
# HG changeset patch
# User Prabhu Gnana Sundar <pprabhugs@gmail.com>
# Date 1405330767 -19800
#      Mon Jul 14 15:09:27 2014 +0530
# Node ID ee3d37ca8c80bff0d3c57cc0110c79971b7c448e
# Parent  212955411633acbe7ace88f22565ce17d85ec8c5
dispatch: fix so that if the -M flag does not change the order of records in hg log (issue4289)

From hg 3.0.1, if the -M flag and an explicit revision range is given to hg log,
like "hg log -M -q -r 10:9", the revision order gets reversed, which is unexpected.

Example:

Observed:
$ hg log -M -q -r 10:9
9:087ee80fc7bd
10:ac2633661a37

Expected:
$ hg log -M -q -r 10:9
10:ac2633661a37
9:087ee80fc7bd

This patch fixes the above issue by just removing the merged rev while filetering
the revision range and not re-ordering the revisions.
Also, added a test case to test the same.
Prabhu GS - July 14, 2014, 4:16 p.m.
Hi Matt,

I have fixed the style and used list comprehensions in the above patch. But
about the logic, I could not think of another approach. Any pointers would
help me fix it in a better way.



Cheers,
Prabhu


On Mon, Jul 14, 2014 at 9:42 PM, Prabhu Gnana Sundar <pprabhugs@gmail.com>
wrote:

> # HG changeset patch
> # User Prabhu Gnana Sundar <pprabhugs@gmail.com>
> # Date 1405330767 -19800
> #      Mon Jul 14 15:09:27 2014 +0530
> # Node ID ee3d37ca8c80bff0d3c57cc0110c79971b7c448e
> # Parent  212955411633acbe7ace88f22565ce17d85ec8c5
> dispatch: fix so that if the -M flag does not change the order of records
> in hg log (issue4289)
>
> From hg 3.0.1, if the -M flag and an explicit revision range is given to
> hg log,
> like "hg log -M -q -r 10:9", the revision order gets reversed, which is
> unexpected.
>
> Example:
>
> Observed:
> $ hg log -M -q -r 10:9
> 9:087ee80fc7bd
> 10:ac2633661a37
>
> Expected:
> $ hg log -M -q -r 10:9
> 10:ac2633661a37
> 9:087ee80fc7bd
>
> This patch fixes the above issue by just removing the merged rev while
> filetering
> the revision range and not re-ordering the revisions.
> Also, added a test case to test the same.
>
> diff -r 212955411633 -r ee3d37ca8c80 mercurial/revset.py
> --- a/mercurial/revset.py       Fri Jun 27 15:20:50 2014 -0700
> +++ b/mercurial/revset.py       Mon Jul 14 15:09:27 2014 +0530
> @@ -294,7 +294,9 @@
>      return xl + yl
>
>  def notset(repo, subset, x):
> -    return subset - getset(repo, subset, x)
> +    mergedrevset = set(getset(repo, subset, x))
> +    subsetlist = list(subset)
> +    return [x for x in subsetlist if x not in mergedrevset]
>
>  def listset(repo, subset, a, b):
>      raise error.ParseError(_("can't use a list in this context"))
> diff -r 212955411633 -r ee3d37ca8c80 tests/test-log.t
> --- a/tests/test-log.t  Fri Jun 27 15:20:50 2014 -0700
> +++ b/tests/test-log.t  Mon Jul 14 15:09:27 2014 +0530
> @@ -1375,3 +1375,43 @@
>
>
>    $ cd ..
> +
> +issue4289: if -M flag and an explicit revision range is given to hg log,
> the order
> +should not be reversed.
> +
> +Create a new repo
> +  $ hg init issue4289
> +  $ cd issue4289
> +Initial commit to the repo
> +  $ echo "hello" > a.txt
> +  $ hg add
> +  adding a.txt
> +  $ hg ci -m "initial commit"
> +
> +Make another commit to the repo
> +  $ echo "world" >> a.txt
> +  $ hg ci -m "Another commit"
> +
> +Create another head
> +  $ hg up -r 0
> +  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
> +  $ echo "hello world" > b.txt
> +  $ hg add
> +  adding b.txt
> +  $ hg ci -m "added a new file"
> +  created new head
> +
> +Merge the two heads
> +  $ hg merge
> +  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
> +  (branch merge, don't forget to commit)
> +  $ hg ci -m "merged"
> +
> +Run log command
> +  $ hg log -M -q -r 3:1
> +  2:b0b1beee06eb
> +  1:4e6686af661c
> +
> +  $ hg log -M -q -r 1:3
> +  1:4e6686af661c
> +  2:b0b1beee06eb
>

Patch

diff -r 212955411633 -r ee3d37ca8c80 mercurial/revset.py
--- a/mercurial/revset.py	Fri Jun 27 15:20:50 2014 -0700
+++ b/mercurial/revset.py	Mon Jul 14 15:09:27 2014 +0530
@@ -294,7 +294,9 @@ 
     return xl + yl
 
 def notset(repo, subset, x):
-    return subset - getset(repo, subset, x)
+    mergedrevset = set(getset(repo, subset, x))
+    subsetlist = list(subset)
+    return [x for x in subsetlist if x not in mergedrevset]
 
 def listset(repo, subset, a, b):
     raise error.ParseError(_("can't use a list in this context"))
diff -r 212955411633 -r ee3d37ca8c80 tests/test-log.t
--- a/tests/test-log.t	Fri Jun 27 15:20:50 2014 -0700
+++ b/tests/test-log.t	Mon Jul 14 15:09:27 2014 +0530
@@ -1375,3 +1375,43 @@ 
   
 
   $ cd ..
+
+issue4289: if -M flag and an explicit revision range is given to hg log, the order
+should not be reversed.
+
+Create a new repo
+  $ hg init issue4289
+  $ cd issue4289
+Initial commit to the repo
+  $ echo "hello" > a.txt
+  $ hg add
+  adding a.txt
+  $ hg ci -m "initial commit"
+
+Make another commit to the repo
+  $ echo "world" >> a.txt
+  $ hg ci -m "Another commit"
+
+Create another head
+  $ hg up -r 0
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ echo "hello world" > b.txt
+  $ hg add
+  adding b.txt
+  $ hg ci -m "added a new file"
+  created new head
+
+Merge the two heads
+  $ hg merge
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  (branch merge, don't forget to commit)
+  $ hg ci -m "merged"
+
+Run log command
+  $ hg log -M -q -r 3:1
+  2:b0b1beee06eb
+  1:4e6686af661c
+
+  $ hg log -M -q -r 1:3
+  1:4e6686af661c
+  2:b0b1beee06eb