[PATCH V2 1/2] diff: add the --output option
Kevin Bullock
kbullock+mercurial at ringworld.org
Tue Jul 9 22:25:14 CDT 2013
On 1 Jul 2013, at 11:25 AM, Ahmed S. Darwish wrote:
> # HG changeset patch
> # User Ahmed S. Darwish <a.darwish at vireton.com>
> # Date 1372695210 -7200
> # Node ID c1aa2fdfc7b7a8fff58b192259dcdf4f74f7ada7
> # Parent 648d1974b3f328947ee6cf2d00c66815a33cd208
> diff: add the --output option
>
> For all shells which cannot save a command standard output correctly,
> this option is now introduced.
Missing tests. More comments below.
> The most common example is Microsoft PowerShell, where the piped
> output gets corrupted if saved using the standard, unix-like, stdout
> rediction, '>' operator. By transforming the piped output to a
> different encoding, PowerShell saves 'hg diff' patch output to a
> format __not understandable__ by GNU patch and 'hg patch' commands.
>
> Windows PowerShell is installed by default on all Windows 7+
> machines (Windows 7, 8, Server 2008, and Server 2012). An easily
> invokable 'hg diff > temp.patch' command should thus be available
> on these systems.
>
> For a similar real-world scenario, please check:
>
> http://www.webcitation.org/6Hiiqf425 - Archived from the original
> post at http://nbevans.wordpress.com/2011/02/22/lightweight-shelving-of-your-work-in-progress-with-mercurial/
>
> diff -r 648d1974b3f3 -r c1aa2fdfc7b7 mercurial/cmdutil.py
> --- a/mercurial/cmdutil.py Sun Jun 30 15:19:39 2013 -0500
> +++ b/mercurial/cmdutil.py Mon Jul 01 18:13:30 2013 +0200
> @@ -7,6 +7,7 @@
>
> from node import hex, nullid, nullrev, short
> from i18n import _
> +from datetime import datetime
> import os, sys, errno, re, tempfile
> import util, scmutil, templater, patch, error, templatekw, revlog, copies
> import match as matchmod
> @@ -123,6 +124,16 @@
> limit = None
> return limit
>
> +def fsfriendly(user):
> + """return committer's username in a short and filesystem-friendly
> + manner. This basically implies removing email info, white spaces,
> + and other problematic characters for common filesystems.
> + reference: MSDN - Naming Files, Paths, and Namespaces.
> + """
> + user = re.sub('\<[^<]*@[^>]*\>', '', user)
> + user = re.sub("[\W]", '', user)
> + return user.lower()
> +
> def makefilename(repo, pat, node, desc=None,
> total=None, seqno=None, revwidth=None, pathname=None):
> node_expander = {
> @@ -134,6 +145,8 @@
> expander = {
> '%': lambda: '%',
> 'b': lambda: os.path.basename(repo.root),
> + 'u': lambda: fsfriendly(repo.ui.username()),
> + 'd': lambda: datetime.now().strftime("%Y_%m_%d-%H_%M_%S")
This change should be in its own patch. We should also (eventually) update the help for `hg export` to mention these expansions.
Oh, and repo.ui.username() is _not_ (necessarily) the committer; I'm not sure that "committer" has any meaning for diff unless it's of a single rev. It _would_, however, have meaning for 'export'. And "date" would have a different meaning for diff vs. export as well.
pacem in terris / мир / शान्ति / سَلاَم / 平和
Kevin R. Bullock
More information about the Mercurial-devel
mailing list