All of lore.kernel.org
 help / color / mirror / Atom feed
From: Linus Torvalds <torvalds@linux-foundation.org>
To: Junio C Hamano <gitster@pobox.com>
Cc: Git Mailing List <git@vger.kernel.org>
Subject: Re: git pull
Date: Sun, 19 Nov 2017 20:04:07 -1000	[thread overview]
Message-ID: <CA+55aFxoNsnKvwAX+bub+amL3s3Znvi-fpRTENP31mrgdZZHRw@mail.gmail.com> (raw)
In-Reply-To: <xmqqr2stldcm.fsf@gitster.mtv.corp.google.com>

On Sun, Nov 19, 2017 at 7:37 PM, Junio C Hamano <gitster@pobox.com> wrote:
>> ...
>> Which is simple. Just create a .git/hooks/prepare-commit-msg file that contains
>>
>>   #!/bin/sh
>>   sed -i 's|ssh://gitolite.kernel.org/|git://git.kernel.org/|g' "$1"
>>
>> and make it executable, and git will do that commit message editing for you.
>
> This should work with any recent versions of Git (1.7.4.2 and
> upwards), but it still is a workaround.  Should we mark it as a
> feature request in the Git land to record the URL you typed as-is in
> the builtin/fetch.c::store_updated_refs() function, instead of the
> one that was rewritten by the insteadOf mechanism?

The main problem with the prepare-commit-msg thing is actually that is
such a nasty hack, and it can change other things than just the remote
name. Maybe "gitolite" might be mentioned in the shortlog of the
merge, and then the sed script comes and edits that part too.

It is really not a huge issue simply because those things don't really
happen in real life, but it's the main thing about that
prepare-commit-msg hook that makes me go "eww, what an ugly hack".

But it's an ugly hack that just happens to work pretty well in practice.

And yes, I looked at alternatives. In fact, I  looked at a couple of
other approaches:

 - the one you mention, namely to remember the original url, and use
that instead

 - the one I'd actually prefer, which is to generalize the whole
"insteadOf" to work in more situations.

Why would I prefer that second one? It turns out that the "original"
isn't actually necessarily what I'd want either. Several people send
me pointers to "https://git.kernel.org/" and I prefer rewriting them
to git:// just to be consistent. And now that people have started
doing the "insteadOf", their pull requests end up containing that
"git@gitolite" version of the URL, so again, I'd actually like to
rewrite the url _anyway_ in the commit message.

For example, for the kernel, the git.kernel.org address is very
common, but it also has a very common path prefix, so almost all pull
messages for the kernel have that

   "git://git.kernel.org/pub/scm/linux/kernel/git/"

part in common, and I have occasioally felt that it's not adding a lot
of value particularly as it shows up in shortlogs and gitk. I could
change my own rules for the first line (instead of the "Merge tag xyz
from git://..." maybe I should just have my human-legible version),
but I have also considered just rewriting the url to something that
shortens that very common thing.

So maybe

   Merge tag 'sound-4.10-rc4' of
git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound

could be instead

   Merge tag 'sound-4.10-rc4' of git://kernel.org/../tiwai/sound

which would keep the _important_ part, and shorten the boilerplate
part away. But that kind of "insteadOf" would only be for the message,
since the end result isn't actually a "real" URL at all, it's
literally a rewritten shorthand.

Again, I can do all of this with the sed script. But again, it's kind
of wrong to do it on the whole message, when it's really only the url
that it should affect.

So it would potentially be nice to just have a generic "rewrite the
url" model, where you can do it for remote fetches, but you could also
do it for just the commit message, or you could do it for doing pushes
(we do have that "pushinsteadof" already - exactly because you might
want to pull and push from different versions, with the push having to
use ssh).

But, as you say:

> It would probably need an update to "struct remote" to have new
> fields, to teach remote.c::alias_all_urls() not to overwrite the
> url[] (and pushurl[] merely for symmetry) fields, to add a field to
> "struct transport" and teach transport.c::transport_get() to record
> the original URL in it so that builtin/fetch.c::fetch_refs() can
> give it to store_updated_refs() instead of the rewritten one.

Yes, the existing "insteadOf" is actually hidden surprisingly deep in
the remote code, and it's very non-obvious. That works ok for the pull
and push case, but really not for just the message rewriting case
(which doesn't happen as part of the pull, but as part of the "git
merge" that then takes the FETCH_HEAD or MERGE_HEAD that contains the
url, and parses that).

Anyway, it's not a big deal. The sed script works. It's a bit hacky,
but it does the job.

I might have wished for a different model, but it's almost certainly
not worth the effort unless somebody really gets fired up about this
and decides they really want to do it.

            Linus

  reply	other threads:[~2017-11-20  6:04 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-13 23:11 git pull Tobin C. Harding
2017-11-14 11:05 ` Greg Kroah-Hartman
2017-11-14 11:05   ` Greg Kroah-Hartman
2017-11-14 12:00   ` Ulf Hansson
2017-11-14 12:00     ` Ulf Hansson
2017-11-14 12:09     ` Greg Kroah-Hartman
2017-11-14 12:09       ` Greg Kroah-Hartman
2017-11-14 18:04   ` Linus Torvalds
2017-11-14 18:04     ` Linus Torvalds
2017-11-14 21:33   ` Tobin C. Harding
2017-11-14 21:33     ` Tobin C. Harding
2017-11-14 21:46     ` Linus Torvalds
2017-11-14 21:46       ` Linus Torvalds
2017-11-15 10:51       ` Michael Ellerman
2017-11-15 10:51         ` Michael Ellerman
2017-11-16 20:36       ` Linus Torvalds
2017-11-16 20:36         ` Linus Torvalds
2017-11-20  5:37         ` Junio C Hamano
2017-11-20  6:04           ` Linus Torvalds [this message]
2017-11-14 21:42   ` Tobin C. Harding
2017-11-14 21:42     ` Tobin C. Harding
  -- strict thread matches above, loose matches on Subject: below --
2012-04-12 14:47 GIT pull cvalusek
2012-04-12 15:03 ` Matthieu Moy
2012-04-12 15:07   ` Michael Witten
2012-04-12 16:58 ` Johannes Sixt
2012-04-12 17:29 ` cvalusek
2010-05-17 21:51 git pull matteo brutti
2010-05-18 16:31 ` Nicolas Sebrecht
2010-05-19 11:03 ` hasen j
2010-01-19  8:01 robin
2010-01-19  8:09 ` robin
2010-01-19 18:37   ` Paul Wilson
2010-01-23  7:22     ` Khem Raj
2010-01-19 20:13   ` Bjørn Forsman

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=CA+55aFxoNsnKvwAX+bub+amL3s3Znvi-fpRTENP31mrgdZZHRw@mail.gmail.com \
    --to=torvalds@linux-foundation.org \
    --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.