Patchwork [4,of,4] histedit: store full node hash in rules

login
register
mail settings
Submitter Mateusz Kwapich
Date Feb. 2, 2015, 11:55 p.m.
Message ID <0c8cf9835334d76f52e7.1422921322@dev1429.prn1.facebook.com>
Download mbox | patch
Permalink /patch/7609/
State Superseded
Headers show

Comments

Mateusz Kwapich - Feb. 2, 2015, 11:55 p.m.
# HG changeset patch
# User Mateusz Kwapich <mitrandir@fb.com>
# Date 1422314287 28800
#      Mon Jan 26 15:18:07 2015 -0800
# Node ID 0c8cf9835334d76f52e7cebf9d70b5b0df646871
# Parent  a8dc5a3f4f4c2d7195a1ccf1712ef70e2080dc0e
histedit: store full node hash in rules

Previously histedit only stored the short version of the rule nodes in the
state. This meant that later we couldn't resolve a rule node to its full
form if the commit had been deleted from the repo.

Let's store the full form from the beginning.
Mateusz Kwapich - Feb. 2, 2015, 11:58 p.m.
Sorry, the patches went out in reversed order - please read them from 4 to 
1.




On 2/2/15, 3:55 PM, "Mateusz Kwapich" <mitrandir@fb.com> wrote:

># HG changeset patch

># User Mateusz Kwapich <mitrandir@fb.com>

># Date 1422314287 28800

>#      Mon Jan 26 15:18:07 2015 -0800

># Node ID 0c8cf9835334d76f52e7cebf9d70b5b0df646871

># Parent  a8dc5a3f4f4c2d7195a1ccf1712ef70e2080dc0e

>histedit: store full node hash in rules

>

>Previously histedit only stored the short version of the rule nodes in the

>state. This meant that later we couldn't resolve a rule node to its full

>form if the commit had been deleted from the repo.

>

>Let's store the full form from the beginning.

>

>diff --git a/hgext/histedit.py b/hgext/histedit.py

>--- a/hgext/histedit.py

>+++ b/hgext/histedit.py

>@@ -349,7 +349,7 @@

>     repo, ctx = state.repo, state.parentctx

>     oldctx = repo[ha]

>     if oldctx.parents()[0] == ctx:

>-        ui.debug('node %s unchanged\n' % ha)

>+        ui.debug('node %s unchanged\n' % ha[:12])

>         return oldctx, []

>     hg.update(repo, ctx.node())

>     stats = applychanges(ui, repo, oldctx, opts)

>@@ -361,7 +361,7 @@

>     n = commit(text=oldctx.description(), user=oldctx.user(),

>                date=oldctx.date(), extra=oldctx.extra())

>     if n is None:

>-        ui.warn(_('%s: empty changeset\n') % node.hex(ha))

>+        ui.warn(_('%s: empty changeset\n') % ha[:12])

>         return ctx, []

>     new = repo[n]

>     return new, [(oldctx.node(), (n,))]

>@@ -389,10 +389,10 @@

>     if stats and stats[3] > 0:

>         raise error.InterventionRequired(

>             _('Fix up the change and run hg histedit --continue'))

>-    n = repo.commit(text='fold-temp-revision %s' % ha, 

>user=oldctx.user(),

>+    n = repo.commit(text='fold-temp-revision %s' % ha[:12], 

>user=oldctx.user(),

>                     date=oldctx.date(), extra=oldctx.extra())

>     if n is None:

>-        ui.warn(_('%s: empty changeset') % node.hex(ha))

>+        ui.warn(_('%s: empty changeset') % ha[:12])

>         return ctx, []

>     return finishfold(ui, repo, ctx, oldctx, n, opts, [])

> 

>@@ -666,7 +666,7 @@

>     while state.rules:

>         state.write()

>         action, ha = state.rules.pop(0)

>-        ui.debug('histedit: processing %s %s\n' % (action, ha))

>+        ui.debug('histedit: processing %s %s\n' % (action, ha[:12]))

>         actfunc = actiontable[action]

>         state.parentctx, replacement_ = actfunc(ui, state, ha, opts)

>         state.replacements.extend(replacement_)

>@@ -736,7 +736,7 @@

>     if s.modified or s.added or s.removed or s.deleted:

>         # prepare the message for the commit to comes

>         if action in ('f', 'fold', 'r', 'roll'):

>-            message = 'fold-temp-revision %s' % currentnode

>+            message = 'fold-temp-revision %s' % currentnode[:12]

>         else:

>             message = ctx.description()

>         editopt = action in ('e', 'edit', 'm', 'mess')

>@@ -822,7 +822,7 @@

>     or a rule on a changeset outside of the user-given range.

>     """

>     parsed = []

>-    expected = set(str(c) for c in ctxs)

>+    expected = set(c.hex() for c in ctxs)

>     seen = set()

>     for r in rules:

>         if ' ' not in r:

>@@ -830,22 +830,24 @@

>         action, rest = r.split(' ', 1)

>         ha = rest.strip().split(' ', 1)[0]

>         try:

>-            ha = str(repo[ha])  # ensure its a short hash

>+            ha = repo[ha].hex()

>         except error.RepoError:

>-            raise util.Abort(_('unknown changeset %s listed') % ha)

>+            raise util.Abort(_('unknown changeset %s listed') % ha[:12])

>         if ha not in expected:

>             raise util.Abort(

>                 _('may not use changesets other than the ones listed'))

>         if ha in seen:

>-            raise util.Abort(_('duplicated command for changeset %s') % 

>ha)

>+            raise util.Abort(_('duplicated command for changeset %s') %

>+                    ha[:12])

>         seen.add(ha)

>         if action not in actiontable:

>             raise util.Abort(_('unknown action "%s"') % action)

>         parsed.append([action, ha])

>     missing = sorted(expected - seen)  # sort to stabilize output

>     if missing:

>-        raise util.Abort(_('missing rules for changeset %s') % 

>missing[0],

>-                         hint=_('do you want to use the drop action?'))

>+        raise util.Abort(_('missing rules for changeset %s') %

>+                missing[0][:12],

>+                hint=_('do you want to use the drop action?'))

>     return parsed

> 

> def processreplacement(state):

>diff --git a/tests/test-histedit-drop.t b/tests/test-histedit-drop.t

>--- a/tests/test-histedit-drop.t

>+++ b/tests/test-histedit-drop.t

>@@ -96,7 +96,6 @@

> Check histedit_source

> 

>   $ hg log --debug --rev f518305ce889

>-  invalid branchheads cache (visible): tip differs

>   changeset:   4:f518305ce889c07cb5bd05522176d75590ef3324

>   tag:         tip

>   phase:       draft

>_______________________________________________

>Mercurial-devel mailing list

>Mercurial-devel@selenic.com

>http://selenic.com/mailman/listinfo/mercurial-devel
Pierre-Yves David - Feb. 3, 2015, 11 a.m.
On 02/02/2015 11:58 PM, Mateusz Kwapich wrote:
> Sorry, the patches went out in reversed order - please read them from 4 to
> 1.

Looks like patchwork could get a fix about this.

Out fo curiosity? how di dyou achieved this?
Pierre-Yves David - Feb. 3, 2015, 11:22 a.m.
On 02/02/2015 11:55 PM, Mateusz Kwapich wrote:
> # HG changeset patch
> # User Mateusz Kwapich <mitrandir@fb.com>
> # Date 1422314287 28800
> #      Mon Jan 26 15:18:07 2015 -0800
> # Node ID 0c8cf9835334d76f52e7cebf9d70b5b0df646871
> # Parent  a8dc5a3f4f4c2d7195a1ccf1712ef70e2080dc0e
> histedit: store full node hash in rules

That one first patch is pushed to the clowncopter, thanks.

Patch

diff --git a/hgext/histedit.py b/hgext/histedit.py
--- a/hgext/histedit.py
+++ b/hgext/histedit.py
@@ -349,7 +349,7 @@ 
     repo, ctx = state.repo, state.parentctx
     oldctx = repo[ha]
     if oldctx.parents()[0] == ctx:
-        ui.debug('node %s unchanged\n' % ha)
+        ui.debug('node %s unchanged\n' % ha[:12])
         return oldctx, []
     hg.update(repo, ctx.node())
     stats = applychanges(ui, repo, oldctx, opts)
@@ -361,7 +361,7 @@ 
     n = commit(text=oldctx.description(), user=oldctx.user(),
                date=oldctx.date(), extra=oldctx.extra())
     if n is None:
-        ui.warn(_('%s: empty changeset\n') % node.hex(ha))
+        ui.warn(_('%s: empty changeset\n') % ha[:12])
         return ctx, []
     new = repo[n]
     return new, [(oldctx.node(), (n,))]
@@ -389,10 +389,10 @@ 
     if stats and stats[3] > 0:
         raise error.InterventionRequired(
             _('Fix up the change and run hg histedit --continue'))
-    n = repo.commit(text='fold-temp-revision %s' % ha, user=oldctx.user(),
+    n = repo.commit(text='fold-temp-revision %s' % ha[:12], user=oldctx.user(),
                     date=oldctx.date(), extra=oldctx.extra())
     if n is None:
-        ui.warn(_('%s: empty changeset') % node.hex(ha))
+        ui.warn(_('%s: empty changeset') % ha[:12])
         return ctx, []
     return finishfold(ui, repo, ctx, oldctx, n, opts, [])
 
@@ -666,7 +666,7 @@ 
     while state.rules:
         state.write()
         action, ha = state.rules.pop(0)
-        ui.debug('histedit: processing %s %s\n' % (action, ha))
+        ui.debug('histedit: processing %s %s\n' % (action, ha[:12]))
         actfunc = actiontable[action]
         state.parentctx, replacement_ = actfunc(ui, state, ha, opts)
         state.replacements.extend(replacement_)
@@ -736,7 +736,7 @@ 
     if s.modified or s.added or s.removed or s.deleted:
         # prepare the message for the commit to comes
         if action in ('f', 'fold', 'r', 'roll'):
-            message = 'fold-temp-revision %s' % currentnode
+            message = 'fold-temp-revision %s' % currentnode[:12]
         else:
             message = ctx.description()
         editopt = action in ('e', 'edit', 'm', 'mess')
@@ -822,7 +822,7 @@ 
     or a rule on a changeset outside of the user-given range.
     """
     parsed = []
-    expected = set(str(c) for c in ctxs)
+    expected = set(c.hex() for c in ctxs)
     seen = set()
     for r in rules:
         if ' ' not in r:
@@ -830,22 +830,24 @@ 
         action, rest = r.split(' ', 1)
         ha = rest.strip().split(' ', 1)[0]
         try:
-            ha = str(repo[ha])  # ensure its a short hash
+            ha = repo[ha].hex()
         except error.RepoError:
-            raise util.Abort(_('unknown changeset %s listed') % ha)
+            raise util.Abort(_('unknown changeset %s listed') % ha[:12])
         if ha not in expected:
             raise util.Abort(
                 _('may not use changesets other than the ones listed'))
         if ha in seen:
-            raise util.Abort(_('duplicated command for changeset %s') % ha)
+            raise util.Abort(_('duplicated command for changeset %s') %
+                    ha[:12])
         seen.add(ha)
         if action not in actiontable:
             raise util.Abort(_('unknown action "%s"') % action)
         parsed.append([action, ha])
     missing = sorted(expected - seen)  # sort to stabilize output
     if missing:
-        raise util.Abort(_('missing rules for changeset %s') % missing[0],
-                         hint=_('do you want to use the drop action?'))
+        raise util.Abort(_('missing rules for changeset %s') %
+                missing[0][:12],
+                hint=_('do you want to use the drop action?'))
     return parsed
 
 def processreplacement(state):
diff --git a/tests/test-histedit-drop.t b/tests/test-histedit-drop.t
--- a/tests/test-histedit-drop.t
+++ b/tests/test-histedit-drop.t
@@ -96,7 +96,6 @@ 
 Check histedit_source
 
   $ hg log --debug --rev f518305ce889
-  invalid branchheads cache (visible): tip differs
   changeset:   4:f518305ce889c07cb5bd05522176d75590ef3324
   tag:         tip
   phase:       draft