public inbox for git@vger.kernel.org 
 help / color / mirror / Atom feed
From: Luke Diamand <luke@diamand•org>
To: larsxschneider@gmail•com, git@vger•kernel.org
Subject: Re: [PATCH v7] git-p4: improve path encoding verbose output
Date: Tue, 15 Sep 2015 08:31:09 +0100	[thread overview]
Message-ID: <55F7C93D.1080309@diamand.org> (raw)
In-Reply-To: <1442250640-93838-2-git-send-email-larsxschneider@gmail.com>

On 14/09/15 18:10, larsxschneider@gmail•com wrote:
> From: Lars Schneider <larsxschneider@gmail•com>
>
> If a path with non-ASCII characters is detected then print always the

s/print always/print/


> encoding and the encoded string in verbose mode.
>
> Signed-off-by: Lars Schneider <larsxschneider@gmail•com>
> ---
>   git-p4.py | 19 +++++++++----------
>   1 file changed, 9 insertions(+), 10 deletions(-)
>
> diff --git a/git-p4.py b/git-p4.py
> index d45cf2b..da25d3f 100755
> --- a/git-p4.py
> +++ b/git-p4.py
> @@ -2220,16 +2220,15 @@ class P4Sync(Command, P4UserMap):
>               text = regexp.sub(r'$\1$', text)
>               contents = [ text ]
>
> -        if gitConfig("git-p4.pathEncoding"):
> -            relPath = relPath.decode(gitConfig("git-p4.pathEncoding")).encode('utf8', 'replace')
> -        elif self.verbose:
> -            try:
> -                relPath.decode('ascii')
> -            except:
> -                print (
> -                    "Path with Non-ASCII characters detected and no path encoding defined. "
> -                    "Please check the encoding: %s" % relPath
> -                )
> +        try:
> +            relPath.decode('ascii')
> +        except:
> +            encoding = 'utf8'
> +            if gitConfig('git-p4.pathEncoding'):
> +                encoding = gitConfig('git-p4.pathEncoding')

It would be better to query this once at startup. Otherwise we're 
potentially forking "git config" twice per file which on a large repo 
could become significant. Make it an instance variable perhaps?

> +                relPath = relPath.decode(encoding).encode('utf8', 'replace')
> +            if self.verbose:
> +                print 'Path with non-ASCII characters detected. Used %s to encode: %s ' % (encoding, relPath)
>
>           self.gitStream.write("M %s inline %s\n" % (git_mode, relPath))
>
>

  parent reply	other threads:[~2015-09-15  7:31 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-14 17:10 [PATCH v7] git-p4: add config git-p4.pathEncoding larsxschneider
2015-09-14 17:10 ` [PATCH v7] git-p4: improve path encoding verbose output larsxschneider
2015-09-14 18:40   ` Junio C Hamano
2015-09-15 15:55     ` Lars Schneider
2015-09-15  7:31   ` Luke Diamand [this message]
2015-09-15  7:36     ` Luke Diamand
2015-09-15 15:59     ` Lars Schneider
2015-09-14 18:25 ` [PATCH v7] git-p4: add config git-p4.pathEncoding Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=55F7C93D.1080309@diamand.org \
    --to=luke@diamand$(echo .)org \
    --cc=git@vger$(echo .)kernel.org \
    --cc=larsxschneider@gmail$(echo .)com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox