[PATCH] commands: add a --plain option to 'hg export'

Steve Losh steve at stevelosh.com
Sat Feb 6 10:11:33 CST 2010


Don't pull this -- I forgot to update the test output.

--
Steve Losh
http://stevelosh.com/



On Feb 6, 2010, at 10:56 AM, Steve Losh wrote:

> # HG changeset patch
> # User Steve Losh <steve at stevelosh.com>
> # Date 1265471481 18000
> # Node ID 48188a3fb4ab45480cbb3c24f767057a6a27c743
> # Parent  f9108768b89285fc262dd1d637e6eda5399df24c
> commands: add a --plain option to 'hg export'
> 
> This allows users to export patches without the "# HG changeset patch" header.
> Instead a simpler header with the author and date is added. The result looks
> like this:
> 
> From: Test User <test at example.com>
> Date: 1265470036 18000
> ... full commit message ...
> 
> ... all diffs ...
> 
> diff --git a/mercurial/commands.py b/mercurial/commands.py
> --- a/mercurial/commands.py
> +++ b/mercurial/commands.py
> @@ -1166,6 +1166,10 @@
>     Use the -g/--git option to generate diffs in the git extended diff
>     format. See 'hg help diffs' for more information.
> 
> +    Use the -p/--plain option to generate plain headers instead of Mercurial's
> +    standard changeset header. The information shown in plain headers is
> +    author and date.
> +
>     With the --switch-parent option, the diff will be against the
>     second parent. It can be useful to review a merge.
>     """
> @@ -1177,9 +1181,10 @@
>         ui.note(_('exporting patches:\n'))
>     else:
>         ui.note(_('exporting patch:\n'))
> +
>     patch.export(repo, revs, template=opts.get('output'),
>                  switch_parent=opts.get('switch_parent'),
> -                 opts=patch.diffopts(ui, opts))
> +                 plain=opts.get('plain'), opts=patch.diffopts(ui, opts))
> 
> def forget(ui, repo, *pats, **opts):
>     """forget the specified files on the next commit
> @@ -3465,6 +3470,7 @@
>     "^export":
>         (export,
>          [('o', 'output', '', _('print output to file with formatted name')),
> +          ('p', 'plain', None, _('print plain headers')),
>           ('', 'switch-parent', None, _('diff against the second parent')),
>           ('r', 'rev', [], _('revisions to export')),
>           ] + diffopts,
> diff --git a/mercurial/patch.py b/mercurial/patch.py
> --- a/mercurial/patch.py
> +++ b/mercurial/patch.py
> @@ -1425,7 +1425,7 @@
>                 yield text
> 
> def export(repo, revs, template='hg-%h.patch', fp=None, switch_parent=False,
> -           opts=None):
> +           plain=None, opts=None):
>     '''export changesets as hg patches.'''
> 
>     total = len(revs)
> @@ -1447,15 +1447,19 @@
>         if fp != sys.stdout and hasattr(fp, 'name'):
>             repo.ui.note("%s\n" % fp.name)
> 
> -        fp.write("# HG changeset patch\n")
> -        fp.write("# User %s\n" % ctx.user())
> -        fp.write("# Date %d %d\n" % ctx.date())
> -        if branch and (branch != 'default'):
> -            fp.write("# Branch %s\n" % branch)
> -        fp.write("# Node ID %s\n" % hex(node))
> -        fp.write("# Parent  %s\n" % hex(prev))
> -        if len(parents) > 1:
> -            fp.write("# Parent  %s\n" % hex(parents[1]))
> +        if plain:
> +            fp.write("From: %s\n" % ctx.user())
> +            fp.write("Date: %d %d\n" % ctx.date())
> +        else:
> +            fp.write("# HG changeset patch\n")
> +            fp.write("# User %s\n" % ctx.user())
> +            fp.write("# Date %d %d\n" % ctx.date())
> +            if branch and (branch != 'default'):
> +                fp.write("# Branch %s\n" % branch)
> +            fp.write("# Node ID %s\n" % hex(node))
> +            fp.write("# Parent  %s\n" % hex(prev))
> +            if len(parents) > 1:
> +                fp.write("# Parent  %s\n" % hex(parents[1]))
>         fp.write(ctx.description().rstrip())
>         fp.write("\n\n")
> 
> diff --git a/tests/test-export b/tests/test-export
> --- a/tests/test-export
> +++ b/tests/test-export
> @@ -21,3 +21,10 @@
> hg export 1 2 3 4 | grep HG | wc -l | sed -e 's/^ *//'
> echo "# exporting revision -2 to a file"
> hg export -- -2
> +
> +echo "# exporting 4 changesets with plain headers to a file"
> +hg export -p -o export_internal_a 1 2 3 4
> +grep HG export_internal_a | wc -l | sed -e 's/^ *//'
> +grep "# User" export_internal_a | wc -l | sed -e 's/^ *//'
> +grep "From:" export_internal_a | wc -l | sed -e 's/^ *//'
> +grep "Date:" export_internal_a | wc -l | sed -e 's/^ *//'
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel



More information about the Mercurial-devel mailing list