All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vikrant Varma <vikrant.varma94@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH 1/2] help: add help_unknown_ref
Date: Thu, 02 May 2013 03:56:06 +0530	[thread overview]
Message-ID: <5181967E.9020601@gmail.com> (raw)
In-Reply-To: <7vppxa5z01.fsf@alter.siamese.dyndns.org>

On 02-05-2013 00:05, Junio C Hamano wrote:
> If you step back a bit, you would notice two things.
>
>   (1) Saying 'foo' when the user means 'origin/foo' is hardly the
>       only (or even the most common) kind of mistake that the code
>       you need to add to 'git merge' would encounter and could help
>       the user with.

Yes. I like your suggestion of using levenshtein.c, similar to what's 
been done in help.c:help_unknown_cmd. However, where do you draw the 
line? Do you also suggest 'remotes/origin/foo' for 'remotes/foo'? Also, 
which would you then prioritize for 'foo': 'fob' (this is local) or 
'origin/foo'? In other words, what kind of mistakes are you looking to 
correct -  typos, or forgetful omissions, or both and something more?

>   (2) "merge" is not the single command that user may make this kind
>       of mistake the command could help and use the same helper.
>       "git branch myfoo foo" may want to suggest "origin/foo", for
>       example.  I just typed "git checkout mater", which could have
>       been easily corrected to "git checkout master" with a mechanism
>       like this.
>

Of course, once the suggestion mechanism is in place, it can be used to 
replace unfriendly die()s in every command that takes a ref.

>
> An asterisk sticks to the parameter name, not type
>
> Indent with two HT, not HT followed by a run of SPs.
>
> An overlong line can and should be split
 >
 > Do not add trailing blank lines.
 >

Thanks, will fix this.

> When you consider the point (2) above, it becomes clear why this
> message does not belong to a helper function with a bland and
> generic name "help unknown ref".
>
> This API is misdesigned.  A possible alternative that may be better
> reusable would be to have a helper that is used to come up with a
> list of suggestions and make the caller responsible for emitting the
> error message.
>

Yes, I think a better name is needed, I was trying to follow along the 
lines of help_unknown_cmd.

However, making the caller responsible for printing the suggestions may 
not be the best alternative. Borrowing from the way help_unknown_cmd 
works, in help_unknown_ref we could:
1) check if autocorrect is on, returning the corrected refname to the 
calling function, otherwise
2) print an error message, a list of suggestions, and exit()

I think this makes for a clean and reusable API, and requires changing 
one line of code in every function that currently calls die().

  reply	other threads:[~2013-05-01 22:26 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-01 11:22 [PATCH 0/2] Better advice on merge Vikrant Varma
2013-05-01 11:22 ` [PATCH 1/2] help: add help_unknown_ref Vikrant Varma
2013-05-01 12:23   ` Ramkumar Ramachandra
2013-05-01 14:06     ` Matthieu Moy
2013-05-01 19:55     ` Vikrant Varma
2013-05-01 20:23       ` Johannes Sixt
2013-05-01 20:32       ` Ramkumar Ramachandra
2013-05-01 21:45         ` Vikrant Varma
2013-05-01 22:12           ` Junio C Hamano
2013-05-01 18:35   ` Junio C Hamano
2013-05-01 22:26     ` Vikrant Varma [this message]
2013-05-01 23:07       ` Junio C Hamano
2013-05-01 11:22 ` [PATCH 2/2] merge: use help_unknown_ref instead of die Vikrant Varma
2013-05-01 18:36   ` Junio C Hamano
2013-05-01 18:27 ` [PATCH 0/2] Better advice on merge Jonathan Nieder
2013-05-01 23:06   ` Vikrant Varma

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=5181967E.9020601@gmail.com \
    --to=vikrant.varma94@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.