Patchwork D2597: graft: add test for reading old format state files with new mechanism

login
register
mail settings
Submitter phabricator
Date March 3, 2018, 7:19 p.m.
Message ID <differential-rev-PHID-DREV-otnfhxyfb56l77ixgze3-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/28803/
State Superseded
Headers show

Comments

phabricator - March 3, 2018, 7:19 p.m.
pulkit created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D2597

AFFECTED FILES
  tests/test-graft.t

CHANGE DETAILS




To: pulkit, #hg-reviewers
Cc: mercurial-devel
phabricator - March 4, 2018, 4:13 p.m.
durin42 added a comment.


  Overall I think I like where this is headed.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D2597

To: pulkit, #hg-reviewers
Cc: durin42, mercurial-devel
phabricator - May 24, 2018, 10:43 p.m.
martinvonz added inline comments.

INLINE COMMENTS

> test-graft.t:1417
> +  created new head
> +  $ hg oldgraft -r 1 -r 2 --config extensions.oldgraft=$TESTTMP/oldgraft.py
> +  merging b

Can this line be replaced by `hg log -r 1 -r 2 -T '{node}\n' > .hg/graftstate` and remove the need for the extension above (and the need to create conflicting changes)?

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D2597

To: pulkit, #hg-reviewers
Cc: martinvonz, durin42, mercurial-devel
phabricator - May 25, 2018, 10:14 a.m.
pulkit added inline comments.

INLINE COMMENTS

> martinvonz wrote in test-graft.t:1417
> Can this line be replaced by `hg log -r 1 -r 2 -T '{node}\n' > .hg/graftstate` and remove the need for the extension above (and the need to create conflicting changes)?

That's a nice idea. I think we can, but the behavior will be bit different since graft will think the working directory now contains changes from `rev 1` and will straight away try to create a commit and later reporting that graft of 1 created no changes to commit. Here is the diff:

  ~/repo/hg-committed/tests$ hg diff
  diff --git a/tests/test-graft.t b/tests/test-graft.t
  --- a/tests/test-graft.t
  +++ b/tests/test-graft.t
  @@ -1414,16 +1414,9 @@ Testing the reading of old format grafts
     $ hg add b
     $ hg ci -m "bar to b"
     created new head
  -  $ hg oldgraft -r 1 -r 2 --config extensions.oldgraft=$TESTTMP/oldgraft.py
  -  merging b
  -  warning: conflicts while merging b! (edit, then use 'hg resolve --mark')
  -  abort: unresolved conflicts
  -  [255]
  +  $ hg log -r 1 -r 2 -T '{node}\n' > .hg/graftstate
   
  -  $ echo foo > b
  -  $ hg resolve -m
  -  (no more unresolved files)
  -  continue: hg graft --continue
     $ hg graft --continue
     grafting 1:80e6d2c47cfe "added b"
  +  note: graft of 1:80e6d2c47cfe created no changes to commit
     grafting 2:8be98ac1a569 "added c"

Since we are just testing reading old state format files, we should be fine with this. What do you think?

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D2597

To: pulkit, #hg-reviewers
Cc: martinvonz, durin42, mercurial-devel
phabricator - May 25, 2018, 1:10 p.m.
martinvonz added inline comments.

INLINE COMMENTS

> pulkit wrote in test-graft.t:1417
> That's a nice idea. I think we can, but the behavior will be bit different since graft will think the working directory now contains changes from `rev 1` and will straight away try to create a commit and later reporting that graft of 1 created no changes to commit. Here is the diff:
> 
>   ~/repo/hg-committed/tests$ hg diff
>   diff --git a/tests/test-graft.t b/tests/test-graft.t
>   --- a/tests/test-graft.t
>   +++ b/tests/test-graft.t
>   @@ -1414,16 +1414,9 @@ Testing the reading of old format grafts
>      $ hg add b
>      $ hg ci -m "bar to b"
>      created new head
>   -  $ hg oldgraft -r 1 -r 2 --config extensions.oldgraft=$TESTTMP/oldgraft.py
>   -  merging b
>   -  warning: conflicts while merging b! (edit, then use 'hg resolve --mark')
>   -  abort: unresolved conflicts
>   -  [255]
>   +  $ hg log -r 1 -r 2 -T '{node}\n' > .hg/graftstate
>    
>   -  $ echo foo > b
>   -  $ hg resolve -m
>   -  (no more unresolved files)
>   -  continue: hg graft --continue
>      $ hg graft --continue
>      grafting 1:80e6d2c47cfe "added b"
>   +  note: graft of 1:80e6d2c47cfe created no changes to commit
>      grafting 2:8be98ac1a569 "added c"
> 
> Since we are just testing reading old state format files, we should be fine with this. What do you think?

An alternative is to use the regular great command to start the process and then replace the .hg/graftstate once it's run into conflicts. That might be better so we have a repo state (include the merge state) that we know is valid to continue from.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D2597

To: pulkit, #hg-reviewers
Cc: martinvonz, durin42, mercurial-devel
phabricator - May 25, 2018, 6:54 p.m.
pulkit added inline comments.

INLINE COMMENTS

> martinvonz wrote in test-graft.t:1417
> An alternative is to use the regular great command to start the process and then replace the .hg/graftstate once it's run into conflicts. That might be better so we have a repo state (include the merge state) that we know is valid to continue from.

That's a very good suggestion. Thanks for that!

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D2597

To: pulkit, #hg-reviewers
Cc: martinvonz, durin42, mercurial-devel

Patch

diff --git a/tests/test-graft.t b/tests/test-graft.t
--- a/tests/test-graft.t
+++ b/tests/test-graft.t
@@ -1373,3 +1373,56 @@ 
   note: graft of 7:d3c3f2b38ecc created no changes to commit
 
   $ cd ..
+
+Testing the reading of old format graftstate file with newer mercurial
+
+  $ cat >> $TESTTMP/oldgraft.py <<EOF
+  > from __future__ import absolute_import
+  > from mercurial import merge, registrar, error
+  > cmdtable = {}
+  > command = registrar.command(cmdtable)
+  > @command('oldgraft', [('r', 'rev', [], 'revisions to graft')], ())
+  > def oldgraft(ui, repo, *args, **opts):
+  >     revs = opts[r'rev']
+  >     for pos, ctx in enumerate(repo.set("%ld", revs)):
+  >         stats = merge.graft(repo, ctx, ctx.p1(), ['local', 'graft'])
+  >         if stats and stats[3] > 0:
+  >             nodelines = [repo[rev].hex() + "\n" for rev in revs[pos:]]
+  >             with repo.wlock(), repo.vfs('graftstate', 'wb') as fp:
+  >                 fp.write(''.join(nodelines))
+  >             raise error.Abort("unresolved conflicts")
+  >         else:
+  >             raise error.Abort("this command is only to write an old state"
+  >                               "file for graft by creating conflicts. Doing graft without"
+  >                               "conflicts should not be done by this")
+  > EOF
+
+  $ hg init oldgraft
+  $ cd oldgraft
+  $ for ch in a b c; do echo foo > $ch; hg add $ch; hg ci -Aqm "added "$ch; done;
+  $ hg log -GT "{rev}:{node|short} {desc}\n"
+  @  2:8be98ac1a569 added c
+  |
+  o  1:80e6d2c47cfe added b
+  |
+  o  0:f7ad41964313 added a
+  
+  $ hg up 0
+  0 files updated, 0 files merged, 2 files removed, 0 files unresolved
+  $ echo bar > b
+  $ hg add b
+  $ hg ci -m "bar to b"
+  created new head
+  $ hg oldgraft -r 1 -r 2 --config extensions.oldgraft=$TESTTMP/oldgraft.py
+  merging b
+  warning: conflicts while merging b! (edit, then use 'hg resolve --mark')
+  abort: unresolved conflicts
+  [255]
+
+  $ echo foo > b
+  $ hg resolve -m
+  (no more unresolved files)
+  continue: hg graft --continue
+  $ hg graft --continue
+  grafting 1:80e6d2c47cfe "added b"
+  grafting 2:8be98ac1a569 "added c"