xref: /aoo42x/main/solenv/bin/modules/RepoRevision.pm (revision 7e51ea90)
18bd5297cSJürgen Schmidt#**************************************************************
2997ab3cdSmseidel#
38bd5297cSJürgen Schmidt#  Licensed to the Apache Software Foundation (ASF) under one
48bd5297cSJürgen Schmidt#  or more contributor license agreements.  See the NOTICE file
58bd5297cSJürgen Schmidt#  distributed with this work for additional information
68bd5297cSJürgen Schmidt#  regarding copyright ownership.  The ASF licenses this file
78bd5297cSJürgen Schmidt#  to you under the Apache License, Version 2.0 (the
88bd5297cSJürgen Schmidt#  "License"); you may not use this file except in compliance
98bd5297cSJürgen Schmidt#  with the License.  You may obtain a copy of the License at
10997ab3cdSmseidel#
118bd5297cSJürgen Schmidt#    http://www.apache.org/licenses/LICENSE-2.0
12997ab3cdSmseidel#
138bd5297cSJürgen Schmidt#  Unless required by applicable law or agreed to in writing,
148bd5297cSJürgen Schmidt#  software distributed under the License is distributed on an
158bd5297cSJürgen Schmidt#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
168bd5297cSJürgen Schmidt#  KIND, either express or implied.  See the License for the
178bd5297cSJürgen Schmidt#  specific language governing permissions and limitations
188bd5297cSJürgen Schmidt#  under the License.
19997ab3cdSmseidel#
208bd5297cSJürgen Schmidt#**************************************************************
218bd5297cSJürgen Schmidt
22997ab3cdSmseidel
23997ab3cdSmseidel
24*7e51ea90SJim Jagielskipackage RepoRevision;
258bd5297cSJürgen Schmidt
263edb530aSPeter Kovacs#old SVN code unchanged
273edb530aSPeter Kovacssub DetectRevisionIdFromSVN ($)
288bd5297cSJürgen Schmidt{
29997ab3cdSmseidel	my $path = shift;
30997ab3cdSmseidel
31997ab3cdSmseidel	my $id = undef;
328bd5297cSJürgen Schmidt
33997ab3cdSmseidel	open my $proc, "cd $path && svn info 2>\&1 |";
34997ab3cdSmseidel	while (<$proc>)
35997ab3cdSmseidel	{
36997ab3cdSmseidel		if (/svn: E155007:/ || /svn: '.' is not a working copy/)
37997ab3cdSmseidel		{
38997ab3cdSmseidel			# Not in an SVN repository.
39997ab3cdSmseidel			$id = DetectRevisionIdFromGit($path);
40997ab3cdSmseidel			last;
41997ab3cdSmseidel		}
42997ab3cdSmseidel		else
43997ab3cdSmseidel		{
44997ab3cdSmseidel			if (/Last Changed Rev:\s+([0-9]+)/)
45997ab3cdSmseidel			{
46997ab3cdSmseidel				$id = $1;
47997ab3cdSmseidel				last;
48997ab3cdSmseidel			}
49997ab3cdSmseidel		}
50997ab3cdSmseidel	}
51997ab3cdSmseidel	close $proc;
528bd5297cSJürgen Schmidt
53997ab3cdSmseidel	return $id;
548bd5297cSJürgen Schmidt}
558bd5297cSJürgen Schmidt
563edb530aSPeter Kovacs
573edb530aSPeter Kovacssub DetectRevisionId ($)
583edb530aSPeter Kovacs{
59997ab3cdSmseidel	my $path = shift;
603edb530aSPeter Kovacs
61997ab3cdSmseidel	my $id = undef;
62997ab3cdSmseidel	#test if path points to a git repository. if true return is 0 else positive number.
63997ab3cdSmseidel	my $isNotGit= `[ -d .git ] || git rev-parse --git-dir > /dev/null 2>&1`;
64997ab3cdSmseidel	if ($isNotGit)
65997ab3cdSmseidel	{
66997ab3cdSmseidel		$id = DetectRevisionIdFromSVN ($path);
67997ab3cdSmseidel	}
68997ab3cdSmseidel	else
69997ab3cdSmseidel	{
70997ab3cdSmseidel		#returns directly the hash of the current checkout.
71997ab3cdSmseidel		$id = `git log -1 --pretty=format:%h --abbrev=10`;
72997ab3cdSmseidel	}
733edb530aSPeter Kovacs
74997ab3cdSmseidel	return $id;
753edb530aSPeter Kovacs}
763edb530aSPeter Kovacs
778bd5297cSJürgen Schmidt1;
78