xref: /trunk/main/solenv/bin/modules/RepoRevision.pm (revision 9b02d673)
1#**************************************************************
2#
3#  Licensed to the Apache Software Foundation (ASF) under one
4#  or more contributor license agreements.  See the NOTICE file
5#  distributed with this work for additional information
6#  regarding copyright ownership.  The ASF licenses this file
7#  to you under the Apache License, Version 2.0 (the
8#  "License"); you may not use this file except in compliance
9#  with the License.  You may obtain a copy of the License at
10#
11#    http://www.apache.org/licenses/LICENSE-2.0
12#
13#  Unless required by applicable law or agreed to in writing,
14#  software distributed under the License is distributed on an
15#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16#  KIND, either express or implied.  See the License for the
17#  specific language governing permissions and limitations
18#  under the License.
19#
20#**************************************************************
21
22
23
24package SvnRevision;
25
26#old SVN code unchanged
27sub DetectRevisionIdFromSVN ($)
28{
29	my $path = shift;
30
31	my $id = undef;
32
33	open my $proc, "cd $path && svn info 2>\&1 |";
34	while (<$proc>)
35	{
36		if (/svn: E155007:/ || /svn: '.' is not a working copy/)
37		{
38			# Not in an SVN repository.
39			$id = DetectRevisionIdFromGit($path);
40			last;
41		}
42		else
43		{
44			if (/Last Changed Rev:\s+([0-9]+)/)
45			{
46				$id = $1;
47				last;
48			}
49		}
50	}
51	close $proc;
52
53	return $id;
54}
55
56
57sub DetectRevisionId ($)
58{
59	my $path = shift;
60
61	my $id = undef;
62	#test if path points to a git repository. if true return is 0 else positive number.
63	my $isNotGit= `[ -d .git ] || git rev-parse --git-dir > /dev/null 2>&1`;
64	if ($isNotGit)
65	{
66		$id = DetectRevisionIdFromSVN ($path);
67	}
68	else
69	{
70		#returns directly the hash of the current checkout.
71		$id = `git log -1 --pretty=format:%h --abbrev=10`;
72	}
73
74	return $id;
75}
76
771;
78