[PATCH 2 of 2] import: read X-Mercurial-Node email header to determine nodeid

Augie Fackler raf at durin42.com
Tue Oct 8 13:18:05 EDT 2019


sure, queued

> On Oct 6, 2019, at 07:14, Denis Laxalde <denis at laxalde.org> wrote:
> 
> # HG changeset patch
> # User Denis Laxalde <denis at laxalde.org>
> # Date 1570359979 -7200
> #      Sun Oct 06 13:06:19 2019 +0200
> # Node ID bbfd3358c4169aef9837dcd6d72648a16acd56aa
> # Parent  d0e3c6accb3c176527c8b85e739cf1d30343d96d
> import: read X-Mercurial-Node email header to determine nodeid
> 
> This would be useful to import and obsolete patches sent using 'hg email
> --plain', using evolve's --obsolete option of 'hg import'.
> 
> If email body contains Mercurial patch header ('# HG changeset patch'
> block), nodeid parsed from X-Mercurial-Node header will still be
> overridden by respective value found in body.
> 
> diff --git a/mercurial/patch.py b/mercurial/patch.py
> index 53cb8a3..db80833 100644
> --- a/mercurial/patch.py
> +++ b/mercurial/patch.py
> @@ -242,6 +242,11 @@ def _extract(ui, fileobj, tmpname, tmpfp
>     # should try to parse msg['Date']
>     parents = []
> 
> +    nodeid = msg[r'X-Mercurial-Node']
> +    if nodeid:
> +        data['nodeid'] = nodeid = mail.headdecode(nodeid)
> +        ui.debug('Node ID: %s\n' % nodeid)
> +
>     if subject:
>         if subject.startswith('[PATCH'):
>             pend = subject.find(']')
> diff --git a/tests/test-import.t b/tests/test-import.t
> index e5c2c35..8122d1b 100644
> --- a/tests/test-import.t
> +++ b/tests/test-import.t
> @@ -237,7 +237,6 @@ import of malformed plain diff should fa
>   [255]
>   $ rm -r b
> 
> -
> hg -R repo import
> put the clone in a subdir - having a directory named "a"
> used to hide a bug.
> @@ -396,6 +395,48 @@ hg export in email, should use patch hea
>   summary:     second change
>   $ rm -r b
> 
> +hg email --plain, should read X-Mercurial-Node header
> +
> +  $ cat >> a/.hg/hgrc << EOF
> +  > [extensions]
> +  > patchbomb =
> +  > [email]
> +  > from = foo
> +  > cc = foo
> +  > to = bar
> +  > EOF
> +  $ hg --cwd a email -m ../tip-plain.mbox --plain --date '1970-1-1 0:1' tip
> +  this patch series consists of 1 patches.
> +  
> +  
> +  sending [PATCH] second change ...
> +
> +  $ hg clone -r0 a b -q
> +  $ hg --cwd b import --debug ../tip-plain.mbox
> +  applying ../tip-plain.mbox
> +  Node ID: 1d4bd90af0e43687763d158dfa83ff2a4b6c0c32
> +  Subject: second change
> +  From: foo
> +  Content-Type: text/plain
> +  found patch at byte 0
> +  message:
> +  second change
> +  patching file a
> +  committing files:
> +  a
> +  committing manifest
> +  committing changelog
> +  created de620f6fe949
> +  updating the branch cache
> +  $ hg --cwd b tip
> +  changeset:   1:de620f6fe949
> +  tag:         tip
> +  user:        foo
> +  date:        Thu Jan 01 00:00:00 1970 +0000
> +  summary:     second change
> +  
> +  $ rm -r b
> +
> 
> subject: duplicate detection, removal of [PATCH]
> The '---' tests the gitsendmail handling without proper mail headers
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel



More information about the Mercurial-devel mailing list