Patchwork [11,of,13] obsolete: allow multiple predecessors in createmarkers

login
register
mail settings
Submitter Boris Feld
Date Sept. 27, 2018, 5:08 p.m.
Message ID <84585c803b4156717b39.1538068123@localhost.localdomain>
Download mbox | patch
Permalink /patch/35151/
State Accepted
Headers show

Comments

Boris Feld - Sept. 27, 2018, 5:08 p.m.
# HG changeset patch
# User Boris Feld <boris.feld@octobus.net>
# Date 1537620033 -7200
#      Sat Sep 22 14:40:33 2018 +0200
# Node ID 84585c803b4156717b397e3753fc59e9dc3785d8
# Parent  b3bd71652d1258de723a667a6f1210a27b86b019
# EXP-Topic trackfold
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 84585c803b41
obsolete: allow multiple predecessors in createmarkers

The logic for this change is similar to the change to `cleanupnodes` that we
did earlier. Now that the rebase code is trying to record a fold, we need to
actually record it in the markers. The first step is to have the markers
creation API able to receive such fold data.

To keep things sane, we restrict fold to on successors.
Yuya Nishihara - Sept. 30, 2018, 12:49 p.m.
On Thu, 27 Sep 2018 19:08:43 +0200, Boris Feld wrote:
> # HG changeset patch
> # User Boris Feld <boris.feld@octobus.net>
> # Date 1537620033 -7200
> #      Sat Sep 22 14:40:33 2018 +0200
> # Node ID 84585c803b4156717b397e3753fc59e9dc3785d8
> # Parent  b3bd71652d1258de723a667a6f1210a27b86b019
> # EXP-Topic trackfold
> # Available At https://bitbucket.org/octobus/mercurial-devel/
> #              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 84585c803b41
> obsolete: allow multiple predecessors in createmarkers

> +            if 1 < len(predecessors) and len(rel[1]) != 1:

Really minor nit: I'm not a fan of Yoda conditions. Is it common in Python
folks?
Boris Feld - Oct. 3, 2018, 1:34 p.m.
On 30/09/2018 14:49, Yuya Nishihara wrote:
> On Thu, 27 Sep 2018 19:08:43 +0200, Boris Feld wrote:
>> # HG changeset patch
>> # User Boris Feld <boris.feld@octobus.net>
>> # Date 1537620033 -7200
>> #      Sat Sep 22 14:40:33 2018 +0200
>> # Node ID 84585c803b4156717b397e3753fc59e9dc3785d8
>> # Parent  b3bd71652d1258de723a667a6f1210a27b86b019
>> # EXP-Topic trackfold
>> # Available At https://bitbucket.org/octobus/mercurial-devel/
>> #              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 84585c803b41
>> obsolete: allow multiple predecessors in createmarkers
>> +            if 1 < len(predecessors) and len(rel[1]) != 1:
> Really minor nit: I'm not a fan of Yoda conditions. Is it common in Python
> folks?
It's just an automatic habit of keeping "<" in ascending order with 
smaller on the left and higher on the right. Neither Pep8 nor static 
analysis tools have fought that habit so far.
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
via Mercurial-devel - Oct. 3, 2018, 2:01 p.m.
On Wed, Oct 3, 2018, 06:36 Boris FELD <boris.feld@octobus.net> wrote:

> On 30/09/2018 14:49, Yuya Nishihara wrote:
> > On Thu, 27 Sep 2018 19:08:43 +0200, Boris Feld wrote:
> >> # HG changeset patch
> >> # User Boris Feld <boris.feld@octobus.net>
> >> # Date 1537620033 -7200
> >> #      Sat Sep 22 14:40:33 2018 +0200
> >> # Node ID 84585c803b4156717b397e3753fc59e9dc3785d8
> >> # Parent  b3bd71652d1258de723a667a6f1210a27b86b019
> >> # EXP-Topic trackfold
> >> # Available At https://bitbucket.org/octobus/mercurial-devel/
> >> #              hg pull https://bitbucket.org/octobus/mercurial-devel/
> -r 84585c803b41
> >> obsolete: allow multiple predecessors in createmarkers
> >> +            if 1 < len(predecessors) and len(rel[1]) != 1:
> > Really minor nit: I'm not a fan of Yoda conditions. Is it common in
> Python
> > folks?
> It's just an automatic habit of keeping "<" in ascending order with
> smaller on the left and higher on the right. Neither Pep8 nor static
> analysis tools have fought that habit so far.
>

I'm also not a fan. I might send a patch to remove it :)

> _______________________________________________
> > Mercurial-devel mailing list
> > Mercurial-devel@mercurial-scm.org
> > https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
>

Patch

diff --git a/mercurial/obsolete.py b/mercurial/obsolete.py
--- a/mercurial/obsolete.py
+++ b/mercurial/obsolete.py
@@ -959,7 +959,7 @@  def createmarkers(repo, relations, flag=
                   operation=None):
     """Add obsolete markers between changesets in a repo
 
-    <relations> must be an iterable of (<old>, (<new>, ...)[,{metadata}])
+    <relations> must be an iterable of ((<old>,...), (<new>, ...)[,{metadata}])
     tuple. `old` and `news` are changectx. metadata is an optional dictionary
     containing metadata for this marker only. It is merged with the global
     metadata specified through the `metadata` argument of this function.
@@ -993,8 +993,14 @@  def createmarkers(repo, relations, flag=
     with repo.transaction('add-obsolescence-marker') as tr:
         markerargs = []
         for rel in relations:
-            prec = rel[0]
-            if True:
+            predecessors = rel[0]
+            if not isinstance(predecessors, tuple):
+                # preserve compat with old API until all caller are migrated
+                predecessors = (predecessors,)
+            if 1 < len(predecessors) and len(rel[1]) != 1:
+                msg = 'Fold markers can only have 1 successors, not %d'
+                raise error.ProgrammingError(msg % len(rel[1]))
+            for prec in predecessors:
                 sucs = rel[1]
                 localmetadata = metadata.copy()
                 if 2 < len(rel):