git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH/RFC] WIP: log: allow "-" as a short-hand for "previous branch"

From
Matthieu Moy <matthieu.moy@grenoble-inp.fr>
Date
Feb 8, 2017, 14:40 UTC
Message-ID
<vpqh944eof7.fsf@anie.imag.fr>
In-Reply-To
<20170207191450.GA5569@ubuntu-512mb-blr1-01.localdomain>
Siddharth Kannan <kannan.siddharth12@gmail.com> writes:
> Making a change in sha1_name.c will touch a lot of commands
> (setup_revisions is called from everywhere in the codebase), so, I am
> still trying to figure out how to do this such that the rest of the
> codepath remains unchanged.

Changing sha1_name.c is the way to go *if* we want all commands to support this. Just like other ways to name a revision...

> I hope that you do not mind this side-effect, but rather, you intended
> for this to happen, right? More commands will start supporting this
> shorthand, suddenly.  (such as format-patch, whatchanged, diff to name
> a very few).

... but: the initial implementation of this '-' shorthand was special-casing a single command (IIRC, "git checkout") for which the shorthand was useful.

In a previous discussion, I made an analogy with "cd -" (which is the source of inspiration of this shorthand AFAIK): "-" did not magically become "the last visited directory" for all Unix commands, just for "cd". And in this case, I'm happy with it. For example, I never need "mkdir -", and I'm happy I can't "rm -fr -" by mistake.

So, it's debatable whether it's a good thing to have all commands support "-". For example, forcing users to explicitly type "git branch -d @{1}" and not providing them with a shortcut might be a good thing.

I don't have strong opinion on this: I tend to favor consistency and supporting "-" everywhere goes in this direction, but I think the downsides should be considered too. A large part of the exercice here is to write a good commit message!

Another issue with this is: - is also a common way to say "use stdin instead of a file", so before enabling - for "previous branch", we need to make sure it does not introduce any ambiguity. Git does not seem to use "- for stdin" much (most commands able to read from stdin have an explicit --stdin option for that), a quick grep in the docs shows only "git blame --contents -" which is OK because a revision wouldn't make sense here anyway.

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/
Previous: Siddharth KannanNext: Siddharth Kannan
Message 8 of 11 in “WIP: log: allow "-" as a short-hand for "previous branch"”
  1. WIP: log: allow "-" as a short-hand for "previous branch"Siddharth Kannan, Feb 5, 2017
  2. Pranit BauvaFeb 5, 2017
  3. Junio C HamanoFeb 6, 2017
  4. Siddharth KannanFeb 6, 2017
  5. Siddharth KannanFeb 6, 2017
  6. Junio C HamanoFeb 6, 2017
  7. Siddharth KannanFeb 7, 2017
  8. Matthieu MoyFeb 8, 2017
  9. Siddharth KannanFeb 8, 2017
  10. Matthieu MoyFeb 9, 2017
  11. Siddharth KannanFeb 9, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.