git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jakub Narebski <jnareb@gmail.com>
To: "Kana Natsuno" <kana@whileimautomaton.net>
Cc: git@vger.kernel.org
Subject: Re: Two problems on alias of git
Date: Tue, 5 May 2009 17:42:49 +0200	[thread overview]
Message-ID: <200905051742.51163.jnareb@gmail.com> (raw)
In-Reply-To: <op.utgptirm6f2obg@i220-99-253-139.s27.a098.ap.plala.or.jp>

On Tue, 5 May 2009, Kana Natsuno wrote:
> On Tue, 05 May 2009 23:03:49 +0900, Jakub Narebski <jnareb@gmail.com> wrote:

> > I don't know if it is a bug or a feature, but git-config supports
> > quoted strings (required if you want to have value which has trailing
> > or leading whitespace, or which contains '#' which is beginning of
> > comment character).  Inside quoted string you need to escape '"':

Errr... what I meant here is that I don't know whether stripping
quotes inside value which is not quoted (does not begin and end in '"')
is intended or unintended consequence of git-config behaviour.

> >
> >    [string]
> >         quotes = "quoted \" string ' with # character"
> >
> > expands as intended.  Perhaps stripping of double quotes
> > inside string are artifact of that feature.  Try escaping or
> > double escaping quotes: \" or \\\".
> 
> Thank you for the information.  I've read the source code of git
> and I confirmed that this stripping is caused by parse_value() in
> config.c.
> 
> 
> And as I changed the old definition
> 
>         lr = !$SHELL -c 'n=10; 1="${1:-$n}"; ...' __dummy__
> 
> by enclosing all text in double quotes and substituting '"' with
> '\"' as follows,
> 
> 	lr = "!$SHELL -c 'n=10; 1=\"${1:-$n}\"; ...' __dummy__"
> 
> it works well now.
> 
> 	$ git config --get alias.lr
> 	!$SHELL -c 'n=10; 1="${1:-$n}"; if ! [ "${1##[0-9]*}" ...

By the way, you can use continuation-of-line character (end line
with '\') and/or can embed newlines using C escape sequence, i.e. "\n".

So your code can look like this (although I am not sure it is worth it):

  [alias]
        lr = "!$SHELL -c '                               \n\
                n=10;                                    \n\
                1=\"${1:-$n}\";                          \n\
                if ! [ \"${1##[0-9]*}\" = \"\" ]; then   \n\
                  t=\"$1\";                              \n\
                  1=\"${2:-$n}\";                        \n\
                  2=\"$t\";                              \n\
                fi;                                      \n\
                git --no-pager l1 --reverse -\"$1\" \"${2:-HEAD}\" \n\
              ' __dummy__"

BTW. you need to quote value because it contains comment character '#'
in 4th line of script.

-- 
Jakub Narebski
Poland

  reply	other threads:[~2009-05-05 15:43 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-05-05 12:42 Two problems on alias of git Kana Natsuno
2009-05-05 14:03 ` Jakub Narebski
2009-05-05 15:11   ` Kana Natsuno
2009-05-05 15:42     ` Jakub Narebski [this message]
2009-05-05 16:25       ` Kana Natsuno
2009-05-05 17:01         ` Jakub Narebski
2009-05-08  9:06 ` Jeff King

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=200905051742.51163.jnareb@gmail.com \
    --to=jnareb@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=kana@whileimautomaton.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
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;
as well as URLs for NNTP newsgroup(s).