Changeset - r15633:41f638112d0f
[Not reviewed]
master
0 2 0
rubidium - 14 years ago 2010-08-02 16:38:26
rubidium@openttd.org
(svn r20308) -Change: don't only look at only the src directory for the revision, but at the parent of the src directory.
2 files changed with 17 insertions and 18 deletions:
0 comments (0 inline, 0 general)
findversion.sh
Show inline comments
 
@@ -57,67 +57,66 @@ version of "awk" is used. If nothing is 
 
EOF
 
exit 1;
 
fi
 

	
 
# Allow awk to be provided by the caller.
 
if [ -z "$AWK" ]; then
 
	AWK=awk
 
fi
 

	
 
# Find out some dirs
 
cd `dirname "$0"`
 
ROOT_DIR=`pwd`
 
SRC_DIR=src
 

	
 
# Determine if we are using a modified version
 
# Assume the dir is not modified
 
MODIFIED="0"
 
if [ -d "$ROOT_DIR/.svn" ]; then
 
	# We are an svn checkout
 
	if [ -n "`svnversion \"$SRC_DIR\" | grep 'M'`" ]; then
 
	if [ -n "`svnversion | grep 'M'`" ]; then
 
		MODIFIED="2"
 
	fi
 
	# Find the revision like: rXXXXM-branch
 
	BRANCH=`LC_ALL=C svn info "$SRC_DIR" | "$AWK" '/^URL:.*branches/ { split($2, a, "/"); for(i in a) if (a[i]=="branches") { print a[i+1]; break } }'`
 
	TAG=`LC_ALL=C svn info "$SRC_DIR" | "$AWK" '/^URL:.*tags/ { split($2, a, "/"); for(i in a) if (a[i]=="tags") { print a[i+1]; break } }'`
 
	REV_NR=`LC_ALL=C svn info "$SRC_DIR" | "$AWK" '/^Last Changed Rev:/ { print $4 }'`
 
	BRANCH=`LC_ALL=C svn info | "$AWK" '/^URL:.*branches/ { split($2, a, "/"); for(i in a) if (a[i]=="branches") { print a[i+1]; break } }'`
 
	TAG=`LC_ALL=C svn info | "$AWK" '/^URL:.*tags/ { split($2, a, "/"); for(i in a) if (a[i]=="tags") { print a[i+1]; break } }'`
 
	REV_NR=`LC_ALL=C svn info | "$AWK" '/^Last Changed Rev:/ { print $4 }'`
 
	if [ -n "$TAG" ]; then
 
		REV=$TAG
 
	else
 
		REV="r$REV_NR"
 
	fi
 
elif [ -d "$ROOT_DIR/.git" ]; then
 
	# We are a git checkout
 
	# Refresh the index to make sure file stat info is in sync, then look for modifications
 
	git update-index --refresh >/dev/null
 
	if [ -n "`git diff-index HEAD \"$SRC_DIR\"`" ]; then
 
	if [ -n "`git diff-index HEAD`" ]; then
 
		MODIFIED="2"
 
	fi
 
	HASH=`LC_ALL=C git rev-parse --verify HEAD 2>/dev/null`
 
	REV="g`echo $HASH | cut -c1-8`"
 
	BRANCH=`git symbolic-ref -q HEAD 2>/dev/null | sed 's@.*/@@;s@^master$@@'`
 
	REV_NR=`LC_ALL=C git log --pretty=format:%s --grep="^(svn r[0-9]*)" -1 -- "$SRC_DIR" | sed "s@.*(svn r\([0-9]*\)).*@\1@"`
 
	REV_NR=`LC_ALL=C git log --pretty=format:%s --grep="^(svn r[0-9]*)" -1 | sed "s@.*(svn r\([0-9]*\)).*@\1@"`
 
	if [ -z "$REV_NR" ]; then
 
		# No rev? Maybe it is a custom git-svn clone
 
		REV_NR=`LC_ALL=C git log --pretty=format:%b --grep="git-svn-id:.*@[0-9]*" -1 -- "$SRC_DIR" | sed "s@.*\@\([0-9]*\).*@\1@"`
 
		REV_NR=`LC_ALL=C git log --pretty=format:%b --grep="git-svn-id:.*@[0-9]*" -1 | sed "s@.*\@\([0-9]*\).*@\1@"`
 
	fi
 
elif [ -d "$ROOT_DIR/.hg" ]; then
 
	# We are a hg checkout
 
	if [ -n "`hg status \"$SRC_DIR\" | grep -v '^?'`" ]; then
 
	if [ -n "`hg status | grep -v '^?'`" ]; then
 
		MODIFIED="2"
 
	fi
 
	HASH=`LC_ALL=C hg id -i | cut -c1-12`
 
	REV="h`echo $HASH | cut -c1-8`"
 
	BRANCH=`hg branch | sed 's@^default$@@'`
 
	REV_NR=`LC_ALL=C hg log -r $HASH:0 -k "svn" -l 1 --template "{desc}\n" "$SRC_DIR" | grep "^(svn r[0-9]*)" | head -n 1 | sed "s@.*(svn r\([0-9]*\)).*@\1@"`
 
	REV_NR=`LC_ALL=C hg log -r $HASH:0 -k "svn" -l 1 --template "{desc}\n" | grep "^(svn r[0-9]*)" | head -n 1 | sed "s@.*(svn r\([0-9]*\)).*@\1@"`
 
else
 
	# We don't know
 
	MODIFIED="1"
 
	BRANCH=""
 
	REV=""
 
	REV_NR=""
 
fi
 

	
 
if [ "$MODIFIED" -eq "2" ]; then
 
	REV="${REV}M"
 
fi
 

	
projects/determineversion.vbs
Show inline comments
 
@@ -96,57 +96,57 @@ Function DetermineSVNVersion()
 
	Dim sTortoise
 
	' First, try with 32-bit architecture
 
	sTortoise = ReadRegistryKey("HKLM", "SOFTWARE\TortoiseSVN", "Directory", 32)
 
	If sTortoise = "" Or IsNull(sTortoise) Then
 
		' No 32-bit version of TortoiseSVN installed, try 64-bit version (doesn't hurt on 32-bit machines, it returns nothing or is ignored)
 
		sTortoise = ReadRegistryKey("HKLM", "SOFTWARE\TortoiseSVN", "Directory", 64)
 
	End If
 

	
 
	' If TortoiseSVN is installed, try to get the revision number
 
	If sTortoise <> "" Then
 
		Dim SubWCRev
 
		Set SubWCRev = WScript.CreateObject("SubWCRev.object")
 
		SubWCRev.GetWCInfo FSO.GetAbsolutePathName("../src"), 0, 0
 
		SubWCRev.GetWCInfo FSO.GetAbsolutePathName("../"), 0, 0
 
		revision = SubWCRev.Revision
 
		version = "r" & revision
 
		modified = 0
 
		if SubWCRev.HasModifications then modified = 2
 
		url = SubWCRev.Url
 
	End If
 

	
 
	' Looks like there is no TortoiseSVN installed either. Then we don't know it.
 
	If revision = 0 Then
 
		' Reset error and version
 
		Err.Clear
 
		version = "norev000"
 
		modified = 0
 

	
 
		' Set the environment to english
 
		WshShell.Environment("PROCESS")("LANG") = "en"
 

	
 
		' Do we have subversion installed? Check immediatelly whether we've got a modified WC.
 
		Set oExec = WshShell.Exec("svnversion ../src")
 
		Set oExec = WshShell.Exec("svnversion ../")
 
		If Err.Number = 0 Then
 
			' Wait till the application is finished ...
 
			Do While oExec.Status = 0
 
			Loop
 

	
 
			line = OExec.StdOut.ReadLine()
 
			If line <> "exported" Then
 
				If InStr(line, "M") Then
 
					modified = 2
 
				End If
 

	
 
				' And use svn info to get the correct revision and branch information.
 
				Set oExec = WshShell.Exec("svn info ../src")
 
				Set oExec = WshShell.Exec("svn info ../")
 
				If Err.Number = 0 Then
 
					Do
 
						line = OExec.StdOut.ReadLine()
 
						If InStr(line, "URL") Then
 
							url = line
 
						End If
 
						If InStr(line, "Last Changed Rev") Then
 
							revision = Mid(line, 19)
 
							version = "r" & revision
 
						End If
 
					Loop While Not OExec.StdOut.atEndOfStream
 
				End If ' Err.Number = 0
 
@@ -170,95 +170,95 @@ Function DetermineSVNVersion()
 

	
 
			If oExec.ExitCode = 0 Then
 
				hash = oExec.StdOut.ReadLine()
 
				version = "g" & Mid(hash, 1, 8)
 
				' Make sure index is in sync with disk
 
				Set oExec = WshShell.Exec("git update-index --refresh")
 
				If Err.Number = 0 Then
 
					' Wait till the application is finished ...
 
					Do While oExec.Status = 0
 
						WScript.Sleep 10
 
					Loop
 
				End If
 
				Set oExec = WshShell.Exec("git diff-index --exit-code --quiet HEAD ../src")
 
				Set oExec = WshShell.Exec("git diff-index --exit-code --quiet HEAD ../")
 
				If Err.Number = 0 Then
 
					' Wait till the application is finished ...
 
					Do While oExec.Status = 0
 
					Loop
 

	
 
					If oExec.ExitCode = 1 Then
 
						modified = 2
 
					End If ' oExec.ExitCode = 1
 

	
 
					Set oExec = WshShell.Exec("git symbolic-ref HEAD")
 
					If Err.Number = 0 Then
 
						line = oExec.StdOut.ReadLine()
 
						line = Mid(line, InStrRev(line, "/") + 1)
 
						If line <> "master" Then
 
							branch = line
 
						End If ' line <> "master"
 
					End If ' Err.Number = 0
 

	
 
					Set oExec = WshShell.Exec("git log --pretty=format:%s --grep=" & Chr(34) & "^(svn r[0-9]*)" & Chr(34) & " -1 ../src")
 
					Set oExec = WshShell.Exec("git log --pretty=format:%s --grep=" & Chr(34) & "^(svn r[0-9]*)" & Chr(34) & " -1 ../")
 
					if Err.Number = 0 Then
 
						revision = Mid(oExec.StdOut.ReadLine(), 7)
 
						revision = Mid(revision, 1, InStr(revision, ")") - 1)
 
					End If ' Err.Number = 0
 
					If revision = "" Then
 
						' No revision? Maybe it is a custom git-svn clone
 
						' Reset error number as WshShell.Exec will not do that on success
 
						Err.Clear
 
						Set oExec = WshShell.Exec("git log --pretty=format:%b --grep=" & Chr(34) & "git-svn-id:.*@[0-9]*" & Chr(34) & " -1 ../src")
 
						Set oExec = WshShell.Exec("git log --pretty=format:%b --grep=" & Chr(34) & "git-svn-id:.*@[0-9]*" & Chr(34) & " -1 ../")
 
						If Err.Number = 0 Then
 
							revision = oExec.StdOut.ReadLine()
 
							revision = Mid(revision, InStr(revision, "@") + 1)
 
							revision = Mid(revision, 1, InStr(revision, " ") - 1)
 
						End If ' Err.Number = 0
 
					End If ' revision = ""
 
				End If ' Err.Number = 0
 
			End If ' oExec.ExitCode = 0
 
		End If ' Err.Number = 0
 

	
 
		If version = "norev000" Then
 
			' git detection failed, reset error and try mercurial (hg)
 
			Err.Clear
 
			Set oExec = WshShell.Exec("hg parents")
 
			If Err.Number = 0 Then
 
				' Wait till the application is finished ...
 
				Do While oExec.Status = 0
 
				Loop
 

	
 
				If oExec.ExitCode = 0 Then
 
					line = OExec.StdOut.ReadLine()
 
					hash = Mid(line, InStrRev(line, ":") + 1)
 
					version = "h" & Mid(hash, 1, 8)
 
					Set oExec = WshShell.Exec("hg status ../src")
 
					Set oExec = WshShell.Exec("hg status ../")
 
					If Err.Number = 0 Then
 
						Do
 
							line = OExec.StdOut.ReadLine()
 
							If Len(line) > 0 And Mid(line, 1, 1) <> "?" Then
 
								modified = 2
 
								Exit Do
 
							End If ' Len(line) > 0 And Mid(line, 1, 1) <> "?"
 
						Loop While Not OExec.StdOut.atEndOfStream
 

	
 
						Set oExec = WshShell.Exec("hg branch")
 
						If Err.Number = 0 Then
 
							line = OExec.StdOut.ReadLine()
 
							If line <> "default" Then
 
								branch = line
 
							End If ' line <> "default"
 
						End If ' Err.Number = 0
 

	
 
						Set oExec = WshShell.Exec("hg log -r " & hash & ":0 -k " & Chr(34) & "svn" & Chr(34) & " -l 1 --template " & Chr(34) & "{desc}\n" & Chr(34) & " ../src")
 
						Set oExec = WshShell.Exec("hg log -r " & hash & ":0 -k " & Chr(34) & "svn" & Chr(34) & " -l 1 --template " & Chr(34) & "{desc}\n" & Chr(34) & " ../")
 
						If Err.Number = 0 Then
 
							revision = Mid(OExec.StdOut.ReadLine(), 7)
 
							revision = Mid(revision, 1, InStr(revision, ")") - 1)
 
						End If ' Err.Number = 0
 
					End If ' Err.Number = 0
 
				End If ' oExec.ExitCode = 0
 
			End If ' Err.Number = 0
 
		End If ' version = "norev000"
 
	End If ' version <> "norev000"
 

	
 
	If modified = 2 Then
 
		version = version & "M"
0 comments (0 inline, 0 general)