[PATCH] Add -0,--print0 to manifest

Kevin O. Grover kevin at kevingrover.net
Tue Jun 5 15:48:20 CDT 2012


On Tue, Jun 5, 2012 at 12:54 PM, Matt Mackall <mpm at selenic.com> wrote:

> On Mon, 2012-06-04 at 20:28 -0700, Kevin O. Grover wrote:
> > I wondered why 'hg manifest' did not support -0/--print0 for use with
> xargs.
> >
> > I decided to try to add it.  While testing, I noticed that several other
> > commands did have it.  Now, manifest has it also.
>
> This is a fine idea, but it's probably missed its window. The plan now
> is to add generic templating support and generic output formats to all
> commands.
>
> The goal is to be able to do things like:
>
> $ hg status --style json
> $ hg bookmarks --style xml
> $ hg manifest --template "{file}\0"
>
> ..with a generic facility rather than adding a bunch of options to each
> command.
>
> Some of this is already in place:
>
> http://markmail.org/message/5rn22eludr5dcyn4
>
> If you'd like to help in this direction, an obvious first step is to
> tweak manifest to use a ui.formatter for its output.
>
> --
> Mathematics is the supreme nostalgia of our time.
>
>
>
I'll look into the templating changes.

Sorry about the attached vice inline post.

IMO, It would be nice to have these options for completeness: until I
looked into adding -0/--print0 to manifest, I never realized that locate
already had them (and can could do what manifest does, plus more): is there
a reason manifest is not an alias to locate?

Anyway, for completeness, here is the patch, inline:

FYI - the commented out check was because I was not sure if it made sense
to have nulls with the extra output of debub or verbose, but then decided
more was probably better than (artificially) less.

If there's interest, as mentioned in a previous reply, I could unify the
-0/--print0 descriptions.


# HG changeset patch
# User Kevin O. Grover <kevin at kevingrover.net>
# Date 1338866709 25200
# Node ID 0047b77a03d357efb3a7a405555579872247891f
# Parent  d566aa319d5f7c58c69b985b53ff7498f08e53c6
Added -0,-print0 to manifest.

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -4053,7 +4053,8 @@

 @command('manifest',
     [('r', 'rev', '', _('revision to display'), _('REV')),
-     ('', 'all', False, _("list files from all revisions"))],
+     ('', 'all', False, _("list files from all revisions")),
+     ('0', 'print0', None, _("separate output with NULs instead of
newline"))],
     _('[-r REV]'))
 def manifest(ui, repo, node=None, rev=None, **opts):
     """output the current or given revision of the project manifest
@@ -4068,8 +4069,19 @@
     If option --all is specified, the list of all files from all revisions
     is printed. This includes deleted and renamed files.

+    Use -0, --print0 to separate file names with NUL (so you can pipe
+    the results to xargs -0).
+
     Returns 0 on success.
     """
+
+    eol = '\n'
+    if opts.get('print0'):
+        #if ui.debugflag or ui.verbose:
+        #    raise util.Abort(\
+        #       _("can't specify --debug or --verbose with --print0"))
+        eol = '\0'
+
     if opts.get('all'):
         if rev or node:
             raise util.Abort(_("can't specify a revision with --all"))
@@ -4087,7 +4099,7 @@
         finally:
             lock.release()
         for f in sorted(res):
-            ui.write("%s\n" % f)
+            ui.write(f, eol)
         return

     if rev and node:
@@ -4103,7 +4115,7 @@
             ui.write("%40s " % hex(ctx.manifest()[f]))
         if ui.verbose:
             ui.write(decor[ctx.flags(f)])
-        ui.write("%s\n" % f)
+        ui.write(f, eol)

 @command('^merge',
     [('f', 'force', None, _('force a merge with outstanding changes')),
diff --git a/tests/test-debugcomplete.t b/tests/test-debugcomplete.t
--- a/tests/test-debugcomplete.t
+++ b/tests/test-debugcomplete.t
@@ -255,7 +255,7 @@
   import: strip, base, edit, force, no-commit, bypass, exact,
import-branch, message, logfile, date, user, similarity
   incoming: force, newest-first, bundle, rev, bookmarks, branch, patch,
git, limit, no-merges, stat, style, template, ssh, remotecmd, insecure,
subrepos
   locate: rev, print0, fullpath, include, exclude
-  manifest: rev, all
+  manifest: rev, all, print0
   outgoing: force, rev, newest-first, bookmarks, branch, patch, git,
limit, no-merges, stat, style, template, ssh, remotecmd, insecure, subrepos
   parents: rev, style, template
   paths:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://selenic.com/pipermail/mercurial-devel/attachments/20120605/0b0d947e/attachment.html>


More information about the Mercurial-devel mailing list