Patchwork [6,of,8,evolve-ext,V2] metaedit: rewrite rewritemeta to reuse manifests

login
register
mail settings
Submitter Mateusz Kwapich
Date Dec. 6, 2016, 4:41 p.m.
Message ID <02a29df6827d1dae26b8.1481042475@devvm314.lla2.facebook.com>
Download mbox | patch
Permalink /patch/17836/
State Changes Requested
Headers show

Comments

Mateusz Kwapich - Dec. 6, 2016, 4:41 p.m.
# HG changeset patch
# User Mateusz Kwapich <mitrandir@fb.com>
# Date 1479405307 28800
#      Thu Nov 17 09:55:07 2016 -0800
# Branch stable
# Node ID 02a29df6827d1dae26b885c9c6c9d56be33ecd00
# Parent  651b6258e993f6d45e4ef7b324303201db5639b2
metaedit: rewrite rewritemeta to reuse manifests
Pierre-Yves David - Dec. 20, 2016, 6:55 p.m.
note: evolve is currently backward compatible with an handful of 
previous version. It would be nice if you could detect if 'memlightctx' 
is available, and only use it in this case.

Cheers,

On 12/06/2016 05:41 PM, Mateusz Kwapich wrote:
> # HG changeset patch
> # User Mateusz Kwapich <mitrandir@fb.com>
> # Date 1479405307 28800
> #      Thu Nov 17 09:55:07 2016 -0800
> # Branch stable
> # Node ID 02a29df6827d1dae26b885c9c6c9d56be33ecd00
> # Parent  651b6258e993f6d45e4ef7b324303201db5639b2
> metaedit: rewrite rewritemeta to reuse manifests
>
> diff --git a/hgext/evolve.py b/hgext/evolve.py
> --- a/hgext/evolve.py
> +++ b/hgext/evolve.py
> @@ -908,11 +908,47 @@ def rewrite(repo, old, updates, head, ne
>          lockmod.release(tr, lock, wlock)
>
>  def metarewrite(repo, old, newbases, commitopts):
> -    '''Like rewrite but affects only the changeset metadata.'''
> -    # TODO: reuse the manifest for speed
> -    newid, created = rewrite(repo, old, [old], old, newbases,
> -                             commitopts=commitopts)
> -    return newid, created
> +    """Return (nodeid, created) where nodeid is the identifier of the
> +    changeset generated by the rewrite process, and created is True if
> +    nodeid was actually created. If created is False, nodeid
> +    references a changeset existing before the rewrite call.
> +    """
> +    wlock = lock = tr = None
> +    try:
> +        wlock = repo.wlock()
> +        lock = repo.lock()
> +        tr = repo.transaction('rewrite')
> +        updatebookmarks = _bookmarksupdater(repo, old.node(), tr)
> +
> +        message = cmdutil.logmessage(repo.ui, commitopts)
> +        if not message:
> +            message = old.description()
> +
> +        user = commitopts.get('user') or old.user()
> +        date = commitopts.get('date') or None # old.date()
> +        extra = dict(commitopts.get('extra', old.extra()))
> +        extra['branch'] = old.branch()
> +
> +        new = context.memlightctx(repo,
> +                          old,
> +                          parents=newbases,
> +                          text=message,
> +                          user=user,
> +                          date=date,
> +                          extra=extra)
> +
> +        if commitopts.get('edit'):
> +            new._text = cmdutil.commitforceeditor(repo, new, [])
> +        revcount = len(repo)
> +        newid = repo.commitctx(new)
> +        new = repo[newid]
> +        created = len(repo) != revcount
> +        updatebookmarks(newid)
> +
> +        tr.close()
> +        return newid, created
> +    finally:
> +        lockmod.release(tr, lock, wlock)
>
>  class MergeFailure(error.Abort):
>      pass
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
>

Patch

diff --git a/hgext/evolve.py b/hgext/evolve.py
--- a/hgext/evolve.py
+++ b/hgext/evolve.py
@@ -908,11 +908,47 @@  def rewrite(repo, old, updates, head, ne
         lockmod.release(tr, lock, wlock)
 
 def metarewrite(repo, old, newbases, commitopts):
-    '''Like rewrite but affects only the changeset metadata.'''
-    # TODO: reuse the manifest for speed
-    newid, created = rewrite(repo, old, [old], old, newbases,
-                             commitopts=commitopts)
-    return newid, created
+    """Return (nodeid, created) where nodeid is the identifier of the
+    changeset generated by the rewrite process, and created is True if
+    nodeid was actually created. If created is False, nodeid
+    references a changeset existing before the rewrite call.
+    """
+    wlock = lock = tr = None
+    try:
+        wlock = repo.wlock()
+        lock = repo.lock()
+        tr = repo.transaction('rewrite')
+        updatebookmarks = _bookmarksupdater(repo, old.node(), tr)
+
+        message = cmdutil.logmessage(repo.ui, commitopts)
+        if not message:
+            message = old.description()
+
+        user = commitopts.get('user') or old.user()
+        date = commitopts.get('date') or None # old.date()
+        extra = dict(commitopts.get('extra', old.extra()))
+        extra['branch'] = old.branch()
+
+        new = context.memlightctx(repo,
+                          old,
+                          parents=newbases,
+                          text=message,
+                          user=user,
+                          date=date,
+                          extra=extra)
+
+        if commitopts.get('edit'):
+            new._text = cmdutil.commitforceeditor(repo, new, [])
+        revcount = len(repo)
+        newid = repo.commitctx(new)
+        new = repo[newid]
+        created = len(repo) != revcount
+        updatebookmarks(newid)
+
+        tr.close()
+        return newid, created
+    finally:
+        lockmod.release(tr, lock, wlock)
 
 class MergeFailure(error.Abort):
     pass