Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2015-03

How do you guys extract an SVN revision number from a Git commit ref?

8 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

vfclists .

I am using this code to obtain the SVN revision of a git commit hash. The example below is for the latest commit hence the git log -n 1.

git log -n 1 | head -n 7 | tail -n 1 | cut -d "@" -f 2 | cut -d " " -f 1

It checks for the seventh line, searches for the '@' in trunk at NNNNN and extracts it from there.
The problem is the position the line with the trunk at NNNNN string varies. Is there some way to work it calculate it?

My awk, grep and sed skills are not so hot.

Frank Church ======================= http://devblog.brahmancreations.com -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20150324/411ee617/attachment.html>

Reply by email

Graeme Geldenhuys
to vfclists .
vfclists . wrote
git log -n 1 | head -n 7 | tail -n 1 | cut -d "@" -f 2 | cut -d " " -f 1

Try:

git svn find-rev $(git log --max-count 1 --pretty=format:%H)

Alternatively you could do something like this:

git log -n 1 -z | grep "* "

Tweak the regex to use lookbehind which could then trim the "trunk@" prefix. I don't know the regex syntax for grep. The following regex does the trick in my editor of choice, but not in the command above for some reason.

(?<=trunk@)[0-9]+

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/

Reply by email

vfclists .
to Graeme Geldenhuys
Graeme Geldenhuys wrote 27 lines
On 2015-03-24 21:10, vfclists . wrote: > > git log -n 1 | head -n 7 | tail -n 1 | cut -d "@" -f 2 | cut -d " " -f 1 Try: git svn find-rev $(git log --max-count 1 --pretty=format:%H) Alternatively you could do something like this: git log -n 1 -z | grep "* " Tweak the regex to use lookbehind which could then trim the "trunk@" prefix. I don't know the regex syntax for grep. The following regex does the trick in my editor of choice, but not in the command above for some reason. (?<=trunk@)[0-9]+ Regards, - Graeme -

This is what I have settled on in the mean time.

LAZ_SVN_REVISION=`git log | grep -A 10 $LAZ_GIT_REVISION | grep git-svn-id | cut -d "@" -f 2 | cut -d " " -f 1`

It searches the commit log for the 10 lines after the git commit ref , looks for the line saying git-svn-id and gets the part after the '@' at sign. It needs more refinement though.

Frank Church ======================= http://devblog.brahmancreations.com -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20150326/ce1f1fa1/attachment.html>

Reply by email

Graeme Geldenhuys
to vfclists .
vfclists . wrote
This is what I have settled on in the mean time. LAZ_SVN_REVISION=`git log | grep -A 10 $LAZ_GIT_REVISION | grep git-svn-id | cut -d "@" -f 2 | cut -d " " -f 1`

Didn't the following work for you? It extracts exactly what you want and will work on any commit, no matter how long the commit message, and only uses built-in git functionality.

git svn find-rev $(git log --max-count 1 --pretty=format:%H)

The "find-rev" needs a SHA1 value, which is what the second part of the command (in brackets) does. So if the above command doesn't work in your script as one command, simply split it into two.

SHA1 = `git log --max-count 1 --pretty=format:%H`
REVISION = `git svn find-rev $SHA1`

Or something like that.

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/

Reply by email

vfclists .
to Graeme Geldenhuys
Graeme Geldenhuys wrote 16 lines
On 2015-03-26 05:47, vfclists . wrote: > This is what I have settled on in the mean time. > > LAZ_SVN_REVISION=`git log | grep -A 10 $LAZ_GIT_REVISION | grep > git-svn-id | cut -d "@" -f 2 | cut -d " " -f 1` Didn't the following work for you? It extracts exactly what you want and will work on any commit, no matter how long the commit message, and only uses built-in git functionality. git svn find-rev $(git log --max-count 1 --pretty=format:%H) The "find-rev" needs a SHA1 value, which is what the second part of the command (in brackets) does. So if the above command doesn't work in your script as one command, simply split it into two.

'git svn find-rev' works for finding the Git commit refs from subversion refs only if the subversion refs are of the form rNNNNN, and I thought going the other way, ie finding subversion refs from git refs wouldn't work as Lazarus uses NNNNN rather than expected NNNNN.

I guess that is probably taken care of during the mirroring process.

Frank Church ======================= http://devblog.brahmancreations.com -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20150326/8e119953/attachment.html>

Reply by email

JuuS
to vfclists .: I am using this code to obtain the SVN revision of a git commit hash. The example below…
vfclists . wrote 12 lines
I am using this code to obtain the SVN revision of a git commit hash. The example below is for the latest commit hence the git log -n 1. git log -n 1 | head -n 7 | tail -n 1 | cut -d "@" -f 2 | cut -d " " -f 1 It checks for the seventh line, searches for the '@' in trunk at NNNNN and extracts it from there. The problem is the position the line with the trunk at NNNNN string varies. Is there some way to work it calculate it? My awk, grep and sed skills are not so hot.

I don't know if you live in the Linux world but if so there is a software available in the Software Center called Kiki.

It's used to build and test Regular Expressions, and is a learning area with a pretty good syntax explanations to try out and get used to.

HTH.

Show quoted text 14 lines
-- Frank Church ======================= http://devblog.brahmancreations.com -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email

Graeme Geldenhuys
to vfclists .: On 26 March 2015 at 09:46, Graeme Geldenhuys 'git svn find-rev' works for finding the Git…
vfclists . wrote
'git svn find-rev' works for finding the Git commit refs from subversion refs only if the subversion refs are of the form rNNNNN, and I thought going the other way

Sorry, I probably haven't had enough coffee yet, but I don't fully understand. I thought you wanted the latest svn revision number by using a git mirror (of a subversion repo). That is exactly what the command does that I posted.

For example. Here is the last commit I have in my lazarus repo (cloned from the git mirror on Github).
===============================
$ git log -1
commit d7e9b24c9bb114264663cc45d7148a4ade3f2b24
Author: dmitry <dmitry at 4005530d-fff6-0310-9dd1-cebe43e6787f> Date: Thu Mar 26 00:48:36 2015 +0000

printer4lazarus: carbon - replace OSX 10.5 (driver specific) code with OSX 10.0 compatible code for getting printerinters DPI

git-svn-id: http://svn.freepascal.org/svn/lazarus/trunk at 48507 4005530d-fff6-0310-9dd1-cebe43e6787f
===============================

As far as I understood, you are interested in finding the SVN revision of that commit - which is r48507 (by looking at the git-svn-id line.

===============================
$ git svn find-rev $(git log --max-count 1 --pretty=format:%H) 48507
===============================

As you can see, the command returns exactly that revision for you.

The first time you run the 'git svn find-rev' git will do some layout migration (svn info) for you. Maybe it is also because I'm using the very latest Git. But after the first run, it will always only return the svn revision number.

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/

Reply by email

vfclists .
to Graeme Geldenhuys
Graeme Geldenhuys wrote 44 lines
On 2015-03-26 10:42, vfclists . wrote: > 'git svn find-rev' works for finding the Git commit refs from subversion > refs only if the subversion refs are of the form rNNNNN, and I thought > going the other way Sorry, I probably haven't had enough coffee yet, but I don't fully understand. I thought you wanted the latest svn revision number by using a git mirror (of a subversion repo). That is exactly what the command does that I posted. For example. Here is the last commit I have in my lazarus repo (cloned from the git mirror on Github). =============================== $ git log -1 commit d7e9b24c9bb114264663cc45d7148a4ade3f2b24 Author: dmitry <dmitry at 4005530d-fff6-0310-9dd1-cebe43e6787f> Date: Thu Mar 26 00:48:36 2015 +0000 printer4lazarus: carbon - replace OSX 10.5 (driver specific) code with OSX 10.0 compatible code for getting printerinters DPI git-svn-id: http://svn.freepascal.org/svn/lazarus/trunk at 48507 4005530d-fff6-0310-9dd1-cebe43e6787f =============================== As far as I understood, you are interested in finding the SVN revision of that commit - which is r48507 (by looking at the git-svn-id line. =============================== $ git svn find-rev $(git log --max-count 1 --pretty=format:%H) 48507 =============================== As you can see, the command returns exactly that revision for you. The first time you run the 'git svn find-rev' git will do some layout migration (svn info) for you. Maybe it is also because I'm using the very latest Git. But after the first run, it will always only return the svn revision number.

Your original answer was correct. I needed something for any commit not just the latest, but the example I used was for just the latest commit, and I confused myself as a result.

Frank Church ======================= http://devblog.brahmancreations.com -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20150326/2963ad6e/attachment.html>

Reply by email