diff mbox series

Some local customization enhancements when using git

Message ID 54834f12-32b1-492f-fb9e-b2c74df23167@arm.com
State New
Headers show
Series Some local customization enhancements when using git | expand

Commit Message

Richard Earnshaw (lists) Jan. 10, 2020, 1:23 p.m. UTC
This patch is intended to help with folks setting up a git work 
environment for use with GCC following the transition to git.  It 
currently does a couple of things.

1) Add an alias 'svn-rev' to git so that you can look up a legacy commit 
by its svn revision number.  This enables you to type
git svn-rev 1234
and git will show the commit log entry relating to SVN r1234.

2) Sets up tracking information for the user's private name area in the 
git repo.  It tries to figure out some sensible answers to the data it 
needs, but allows the user to override the values.  It then creates the 
fetch and push entries that are needed for tracking the extra refs. 
This implements one part of the recommendations that I've proposed in 
svnwrite.html for dealing with private branches.

It should be possible to run the script more than once and for it to 
DTRT.  If you change your answers the configuration should be correctly 
updated.

2020-01-10  Richard Earnshaw  <rearnsha@arm.com>

	* gcc-git-customization: New file.

Comments

Richard Biener Jan. 10, 2020, 1:29 p.m. UTC | #1
On Fri, Jan 10, 2020 at 2:23 PM Richard Earnshaw (lists)
<Richard.Earnshaw@arm.com> wrote:
>
> This patch is intended to help with folks setting up a git work
> environment for use with GCC following the transition to git.  It
> currently does a couple of things.
>
> 1) Add an alias 'svn-rev' to git so that you can look up a legacy commit
> by its svn revision number.  This enables you to type
> git svn-rev 1234
> and git will show the commit log entry relating to SVN r1234.
>
> 2) Sets up tracking information for the user's private name area in the
> git repo.  It tries to figure out some sensible answers to the data it
> needs, but allows the user to override the values.  It then creates the
> fetch and push entries that are needed for tracking the extra refs.
> This implements one part of the recommendations that I've proposed in
> svnwrite.html for dealing with private branches.
>
> It should be possible to run the script more than once and for it to
> DTRT.  If you change your answers the configuration should be correctly
> updated.

I assume the script is invoked from a clone of the new (final) repo.  Does it
need to be cloned in any special way?

Richard.

> 2020-01-10  Richard Earnshaw  <rearnsha@arm.com>
>
>         * gcc-git-customization: New file.
>
Richard Earnshaw (lists) Jan. 10, 2020, 2:01 p.m. UTC | #2
On 10/01/2020 13:29, Richard Biener wrote:
> On Fri, Jan 10, 2020 at 2:23 PM Richard Earnshaw (lists)
> <Richard.Earnshaw@arm.com> wrote:
>>
>> This patch is intended to help with folks setting up a git work
>> environment for use with GCC following the transition to git.  It
>> currently does a couple of things.
>>
>> 1) Add an alias 'svn-rev' to git so that you can look up a legacy commit
>> by its svn revision number.  This enables you to type
>> git svn-rev 1234
>> and git will show the commit log entry relating to SVN r1234.
>>
>> 2) Sets up tracking information for the user's private name area in the
>> git repo.  It tries to figure out some sensible answers to the data it
>> needs, but allows the user to override the values.  It then creates the
>> fetch and push entries that are needed for tracking the extra refs.
>> This implements one part of the recommendations that I've proposed in
>> svnwrite.html for dealing with private branches.
>>
>> It should be possible to run the script more than once and for it to
>> DTRT.  If you change your answers the configuration should be correctly
>> updated.
> 
> I assume the script is invoked from a clone of the new (final) repo.  Does it
> need to be cloned in any special way?
> 
> Richard.
> 
>> 2020-01-10  Richard Earnshaw  <rearnsha@arm.com>
>>
>>          * gcc-git-customization: New file.
>>

You can run the script after doing a clone.  It adds the bits that a 
normal clone would not.  I don't know if there's any way of hooking git 
to run this automatically, but I'm not sure if that would be a good idea 
anyway, since that would break non-interactive cloning.

R.
Richard Earnshaw (lists) Jan. 10, 2020, 2:04 p.m. UTC | #3
On 10/01/2020 14:01, Richard Earnshaw (lists) wrote:
> On 10/01/2020 13:29, Richard Biener wrote:
>> On Fri, Jan 10, 2020 at 2:23 PM Richard Earnshaw (lists)
>> <Richard.Earnshaw@arm.com> wrote:
>>>
>>> This patch is intended to help with folks setting up a git work
>>> environment for use with GCC following the transition to git.  It
>>> currently does a couple of things.
>>>
>>> 1) Add an alias 'svn-rev' to git so that you can look up a legacy commit
>>> by its svn revision number.  This enables you to type
>>> git svn-rev 1234
>>> and git will show the commit log entry relating to SVN r1234.
>>>
>>> 2) Sets up tracking information for the user's private name area in the
>>> git repo.  It tries to figure out some sensible answers to the data it
>>> needs, but allows the user to override the values.  It then creates the
>>> fetch and push entries that are needed for tracking the extra refs.
>>> This implements one part of the recommendations that I've proposed in
>>> svnwrite.html for dealing with private branches.
>>>
>>> It should be possible to run the script more than once and for it to
>>> DTRT.  If you change your answers the configuration should be correctly
>>> updated.
>>
>> I assume the script is invoked from a clone of the new (final) repo.  
>> Does it
>> need to be cloned in any special way?
>>
>> Richard.
>>
>>> 2020-01-10  Richard Earnshaw  <rearnsha@arm.com>
>>>
>>>          * gcc-git-customization: New file.
>>>
> 
> You can run the script after doing a clone.  It adds the bits that a 
> normal clone would not.  I don't know if there's any way of hooking git 
> to run this automatically, but I'm not sure if that would be a good idea 
> anyway, since that would break non-interactive cloning.
> 
> R.

The expected using is:

$ git clone git+svn://{id}@gcc.gnu.org/git/gcc
$ cd gcc
$ contrib/gcc-git-customization
# Now pull the additional refs
$ git fetch

R.
Richard Earnshaw (lists) Jan. 10, 2020, 2:26 p.m. UTC | #4
On 10/01/2020 13:23, Richard Earnshaw (lists) wrote:
> This patch is intended to help with folks setting up a git work 
> environment for use with GCC following the transition to git.  It 
> currently does a couple of things.
> 
> 1) Add an alias 'svn-rev' to git so that you can look up a legacy commit 
> by its svn revision number.  This enables you to type
> git svn-rev 1234
> and git will show the commit log entry relating to SVN r1234.
> 
> 2) Sets up tracking information for the user's private name area in the 
> git repo.  It tries to figure out some sensible answers to the data it 
> needs, but allows the user to override the values.  It then creates the 
> fetch and push entries that are needed for tracking the extra refs. This 
> implements one part of the recommendations that I've proposed in 
> svnwrite.html for dealing with private branches.
> 
> It should be possible to run the script more than once and for it to 
> DTRT.  If you change your answers the configuration should be correctly 
> updated.
> 
> 2020-01-10  Richard Earnshaw  <rearnsha@arm.com>
> 
>      * gcc-git-customization: New file.
> 

Updated to add better support for diff-ing .md files.

R.
Richard Earnshaw (lists) Jan. 13, 2020, 1:44 p.m. UTC | #5
On 10/01/2020 14:26, Richard Earnshaw (lists) wrote:
> On 10/01/2020 13:23, Richard Earnshaw (lists) wrote:
>> This patch is intended to help with folks setting up a git work
>> environment for use with GCC following the transition to git.  It
>> currently does a couple of things.
>>
>> 1) Add an alias 'svn-rev' to git so that you can look up a legacy
>> commit by its svn revision number.  This enables you to type
>> git svn-rev 1234
>> and git will show the commit log entry relating to SVN r1234.
>>
>> 2) Sets up tracking information for the user's private name area in
>> the git repo.  It tries to figure out some sensible answers to the
>> data it needs, but allows the user to override the values.  It then
>> creates the fetch and push entries that are needed for tracking the
>> extra refs. This implements one part of the recommendations that I've
>> proposed in svnwrite.html for dealing with private branches.
>>
>> It should be possible to run the script more than once and for it to
>> DTRT.  If you change your answers the configuration should be
>> correctly updated.
>>
>> 2020-01-10  Richard Earnshaw  <rearnsha@arm.com>
>>
>>      * gcc-git-customization: New file.
>>
> 
> Updated to add better support for diff-ing .md files.
> 
> R.

A couple more tweaks to this file and I've now checked it in.

1) Added the ability to select the prefix for the personal namespace.
This will be cached.  If you change it, then the push operations will be
updated (but any local branches you will have to rename if you want them
to continue working afterwards).
2) Removed the + from the added push spec.

R.
Richard Earnshaw (lists) Jan. 13, 2020, 1:55 p.m. UTC | #6
On 13/01/2020 13:44, Richard Earnshaw (lists) wrote:
> On 10/01/2020 14:26, Richard Earnshaw (lists) wrote:
>> On 10/01/2020 13:23, Richard Earnshaw (lists) wrote:
>>> This patch is intended to help with folks setting up a git work
>>> environment for use with GCC following the transition to git.  It
>>> currently does a couple of things.
>>>
>>> 1) Add an alias 'svn-rev' to git so that you can look up a legacy
>>> commit by its svn revision number.  This enables you to type
>>> git svn-rev 1234
>>> and git will show the commit log entry relating to SVN r1234.
>>>
>>> 2) Sets up tracking information for the user's private name area in
>>> the git repo.  It tries to figure out some sensible answers to the
>>> data it needs, but allows the user to override the values.  It then
>>> creates the fetch and push entries that are needed for tracking the
>>> extra refs. This implements one part of the recommendations that I've
>>> proposed in svnwrite.html for dealing with private branches.
>>>
>>> It should be possible to run the script more than once and for it to
>>> DTRT.  If you change your answers the configuration should be
>>> correctly updated.
>>>
>>> 2020-01-10  Richard Earnshaw  <rearnsha@arm.com>
>>>
>>>      * gcc-git-customization: New file.
>>>
>>
>> Updated to add better support for diff-ing .md files.
>>
>> R.
> 
> A couple more tweaks to this file and I've now checked it in.
> 
> 1) Added the ability to select the prefix for the personal namespace.
> This will be cached.  If you change it, then the push operations will be
> updated (but any local branches you will have to rename if you want them
> to continue working afterwards).
> 2) Removed the + from the added push spec.
> 

And one more tweak I forgot to mention:

3) an optional 'r' can now be used in front of an svn revision number in
'git svn-rev'.

> R.
>
diff mbox series

Patch

diff --git a/contrib/gcc-git-customization b/contrib/gcc-git-customization
new file mode 100755
index 00000000000..7f1a13bdf79
--- /dev/null
+++ b/contrib/gcc-git-customization
@@ -0,0 +1,54 @@ 
+#!/bin/sh
+
+# Script to add some local git customizations suitable for working
+# with the GCC git repository
+
+ask () {
+    question=$1
+    default=$2
+    var=$3
+    echo -n $question "["$default"]? "
+    read answer
+    if [ "x$answer" = "x" ]
+    then
+	eval $var=$default
+    else
+	eval $var=$answer
+    fi
+}
+
+# Add a git command to find the git commit equivalent to legacy SVN revision NNN
+git config alias.svn-rev '!f() { rev=$1; shift; git log --all --grep="From-SVN: r$rev\\b" "${@}"; } ; f'
+
+upstream=`git config --get "gcc-config.upstream"`
+if [ "x$upstream" = "x" ]
+then
+    upstream="origin"
+fi
+ask "Local name for upstream repository" "origin" upstream
+git config "gcc-config.upstream" "$upstream"
+
+remote_id=`git config --get "gcc-config.user"`
+if [ "x$remote_id" = "x" ]
+then
+    # See if the url specifies the remote user name.
+    url=`git config --get "remote.$upstream.url"`
+    if [ "x$url" = "x" ]
+    then
+	# This is a pure guess, but for many people it might be OK.
+	remote_id=`whoami`
+    else
+	remote_id=`echo $url | sed -r "s|^.*ssh://(.+)@gcc.gnu.org.*$|\1|"`
+	if [ x$remote_id = x$url ]
+	then
+	    remote_id=`whoami`
+	fi
+    fi
+fi
+ask "Account name on gcc.gnu.org" $remote_id remote_id
+git config "gcc-config.user" "$remote_id"
+
+echo "Setting up tracking for private namespace $remote_id in remotes/$upstream/me"
+git config --replace-all "remote.${upstream}.fetch" "+refs/users/${remote_id}/heads/*:refs/remotes/${upstream}/me/*" ":refs/remotes/${upstream}/me/"
+git config --replace-all "remote.${upstream}.fetch" "+refs/users/${remote_id}/tags/*:refs/tags/me/*" ":refs/tags/me/"
+git config --replace-all "remote.${upstream}.push" "+refs/heads/me/*:refs/users/${remote_id}/heads/*" "^\+refs/heads/me/"