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 8, 2014, 7:13 p.m.
Message ID <9989ab0eaa2e43979a3b.1404846836@sparta.ap01.lucent.com>
Download mbox | patch
Permalink /patch/5134/
State Superseded
Headers show

Comments

Prabhu GS - July 8, 2014, 7:13 p.m.
# HG changeset patch
# User Prabhu Gnana Sundar <pprabhugs@gmail.com>
# Date 1404846809 -19800
#      Wed Jul 09 00:43:29 2014 +0530
# Node ID 9989ab0eaa2e43979a3b3bbeb0518fa0735d9d22
# 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.
Matt Mackall - July 12, 2014, 4:10 p.m.
On Wed, 2014-07-09 at 00:43 +0530, Prabhu Gnana Sundar wrote:
> # HG changeset patch
> # User Prabhu Gnana Sundar <pprabhugs@gmail.com>
> # Date 1404846809 -19800
> #      Wed Jul 09 00:43:29 2014 +0530
> # Node ID 9989ab0eaa2e43979a3b3bbeb0518fa0735d9d22
> # 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 9989ab0eaa2e mercurial/revset.py
> --- a/mercurial/revset.py	Fri Jun 27 15:20:50 2014 -0700
> +++ b/mercurial/revset.py	Wed Jul 09 00:43:29 2014 +0530
> @@ -294,7 +294,9 @@
>      return xl + yl
>  
>  def notset(repo, subset, x):
> -    return subset - getset(repo, subset, x)
> +    merged_rev_set = set(getset(repo, subset, x))
> +    subset_list = list(subset)
> +    return filter(lambda x: x not in merged_rev_set, subset_list)

This looks like it undoes all the lazy evaluation logic we added in 3.0.
That isn't there just to make the code confusing.

Two style notes:
- modern Python style uses list comprehensions rather than filter and
lambda
- the Mercurial codebase doesn't use names_with_underscores
Matt Mackall - July 13, 2014, 9:03 p.m.
On Wed, 2014-07-09 at 00:43 +0530, Prabhu Gnana Sundar wrote:
> # HG changeset patch
> # User Prabhu Gnana Sundar <pprabhugs@gmail.com>
> # Date 1404846809 -19800
> #      Wed Jul 09 00:43:29 2014 +0530
> # Node ID 9989ab0eaa2e43979a3b3bbeb0518fa0735d9d22
> # 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 9989ab0eaa2e mercurial/revset.py
> --- a/mercurial/revset.py	Fri Jun 27 15:20:50 2014 -0700
> +++ b/mercurial/revset.py	Wed Jul 09 00:43:29 2014 +0530
> @@ -294,7 +294,9 @@
>      return xl + yl
>  
>  def notset(repo, subset, x):
> -    return subset - getset(repo, subset, x)
> +    merged_rev_set = set(getset(repo, subset, x))
> +    subset_list = list(subset)
> +    return filter(lambda x: x not in merged_rev_set, subset_list)

This looks like it undoes all the lazy evaluation logic we added in 3.0.
That isn't there just to make the code confusing.

Two style notes:
- modern Python style uses list comprehensions rather than filter and
lambda
- the Mercurial codebase doesn't use names_with_underscores

Patch

diff -r 212955411633 -r 9989ab0eaa2e mercurial/revset.py
--- a/mercurial/revset.py	Fri Jun 27 15:20:50 2014 -0700
+++ b/mercurial/revset.py	Wed Jul 09 00:43:29 2014 +0530
@@ -294,7 +294,9 @@ 
     return xl + yl
 
 def notset(repo, subset, x):
-    return subset - getset(repo, subset, x)
+    merged_rev_set = set(getset(repo, subset, x))
+    subset_list = list(subset)
+    return filter(lambda x: x not in merged_rev_set, subset_list)
 
 def listset(repo, subset, a, b):
     raise error.ParseError(_("can't use a list in this context"))
diff -r 212955411633 -r 9989ab0eaa2e tests/test-log.t
--- a/tests/test-log.t	Fri Jun 27 15:20:50 2014 -0700
+++ b/tests/test-log.t	Wed Jul 09 00:43:29 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