git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / mirror / code / Atom feed
From: Siddharth Kannan <kannan.siddharth12@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org, pranit.bauva@gmail.com,
	Matthieu.Moy@imag.fr, peff@peff.net, pclouds@gmail.com,
	sandals@crustytoothpaste.ath.cx
Subject: Re: [PATCH/RFC] WIP: log: allow "-" as a short-hand for "previous branch"
Date: Mon, 6 Feb 2017 02:27:05 +0000	[thread overview]
Message-ID: <20170206022705.GA3323@ubuntu-512mb-blr1-01.localdomain> (raw)
In-Reply-To: <xmqqtw882n08.fsf@gitster.mtv.corp.google.com>

Hey Junio,
On Sun, Feb 05, 2017 at 04:15:03PM -0800, Junio C Hamano wrote:
> Siddharth Kannan <kannan.siddharth12@gmail.com> writes:
> 
> > @@ -158,6 +158,51 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix,
> >
> >  	if (quiet)
> >  		rev->diffopt.output_format |= DIFF_FORMAT_NO_OUTPUT;
> > +
> > +	/*
> > +	 * Check if any argument has a "-" in it, which has been referred to as a
> > +	 * shorthand for @{-1}.  Handles methods that might be used to list commits
> > +	 * as mentioned in git rev-list --help
> > +	 */
> > +
> > +	for(i = 0; i < argc; ++i) {
> > +		if (!strcmp(argv[i], "-")) {
> > +			argv[i] = "@{-1}";
> > +		} else if (!strcmp(argv[i], "^-")) {
> > +			argv[i] = "^@{-1}";
> > +		} else if (strlen(argv[i]) >= 4) {
> > +
> > +	...
> > +		}
> > +	}
> > +
> >  	argc = setup_revisions(argc, argv, rev, opt);
> 
> "Turn '-' to '@{-1}' before we do the real parsing" can never be a
> reasonable strategy to implement the desired "'-' means the tip of
> the previous branch" correctly.  To understand why, you only need to
> imagine what happens to this command:
> 
>     $ git log --grep '^-'
> 
> Turning it into "git log --grep '^@{-1}'" obviously is not what the
> end-users want, so that is an immediate bug in the version of Git
> with this patch applied.
> 
> Even if this were not a patch for the "log" command but for some
> other command, a change with the above approach is very much
> unwelcome, even if that other command does not currently have any
> option that takes arbitrary string the user may want to specify
> (like "find commit with a line that matches this pattern" option
> called "--grep" the "log" command has).  That is because it will
> make it impossible to enhance the command by adding such an option
> in the future.  So it is also adding the problems to future
> developers (and users) of Git.

Understood!
> 
> A correct solution needs to know if the argument is at the position
> where a revision (or revision range) is expected and then give the
> tip of the previous branch when it sees "-" (and other combinations
> this patch tries to cover).  In other words, the parser always knows
> what it is parsing, and if and only if it is parsing a rev, react to
> "-" and think "ah, the user wants me to use the tip of the previous
> branch".

Ah, okay. I will do another one of the suggestions as my micro project
but continue to look into this part of the code and try to find the
right place to write the code to implement the present patch.

> 
> But the code that knows that it expects to see a revision already
> exists, and it is the real parser.  In the above snippet,
> setup_revisions() is the one that does the real parsing of argv[].
> The code there knows when it wants to see a rev, and takes argv[i]
> and turns into an object to call add_pending_object().  That codepath
> may not yet know that "-" means the tip of the previous branch, and
> that is where the change needs to go.
> 
> Such a properly-done update does not need to textually replace "-"
> with "@{-1}" in argv[]; the codepath is where it understands what
> any textual representation of a rev the user gave it means, and it
> understands "@{-1}" there.  It would be the matter of updating it to
> also understand what "-" means.
> 
> A correct solution will be a lot more involved, of course, and I
> think it will be larger than a reasonable microproject for people
> new to the codebase.
> 
> I didn't check the microproject ideas page myself; whether it says
> that turning "-" unconditionally to "@{-1}" is a good idea, or it
> hints that supporting "-" as "the tip of the previous branch" in
> more commands is a reasonable byte-sized microproject, I think it is
> misleading and misguided.  Can somebody remove that entry so that we
> won't waste time of new developers (which would lead to discouraging
> them)?  Thanks.

Thanks a lot for writing this detailed reply! I will definitely take
into account all of the points mentioned here in the future patches I
send.

- Siddharth Kannan

  reply	other threads:[~2017-02-06  2:27 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-05 12:57 Siddharth Kannan
2017-02-05 14:55 ` Pranit Bauva
2017-02-06  0:15 ` Junio C Hamano
2017-02-06  2:27   ` Siddharth Kannan [this message]
2017-02-06 18:10   ` Siddharth Kannan
2017-02-06 23:09     ` Junio C Hamano
2017-02-07 19:14       ` Siddharth Kannan
2017-02-08 14:40         ` Matthieu Moy
2017-02-08 17:23           ` Siddharth Kannan
2017-02-09 12:25             ` Matthieu Moy
2017-02-09 18:21               ` Siddharth Kannan

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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=20170206022705.GA3323@ubuntu-512mb-blr1-01.localdomain \
    --to=kannan.siddharth12@gmail.com \
    --cc=Matthieu.Moy@imag.fr \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=pclouds@gmail.com \
    --cc=peff@peff.net \
    --cc=pranit.bauva@gmail.com \
    --cc=sandals@crustytoothpaste.ath.cx \
    /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.
Code repositories for project(s) associated with this inbox:

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).