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 247e51ea90SJim Jagielskipackage RepoRevision; 258bd5297cSJürgen Schmidt 26*a7eb43eeSJim Jagielskisub DetectRevisionIdFromFile ($) 278bd5297cSJürgen Schmidt{ 28997ab3cdSmseidel my $path = shift; 29*a7eb43eeSJim Jagielski my $id = undef; 30*a7eb43eeSJim Jagielski 31*a7eb43eeSJim Jagielski open( my $fh, '<', $path ) || return undef; 32*a7eb43eeSJim Jagielski $id = <$fh>; 33*a7eb43eeSJim Jagielski close $fh; 34*a7eb43eeSJim Jagielski return $id; 35*a7eb43eeSJim Jagielski} 36*a7eb43eeSJim Jagielski 37*a7eb43eeSJim Jagielskisub DetectRevisionIdFromGit ($) 38*a7eb43eeSJim Jagielski{ 39*a7eb43eeSJim Jagielski my $path = shift; 40*a7eb43eeSJim Jagielski my $id = undef; 41*a7eb43eeSJim Jagielski 42*a7eb43eeSJim Jagielski $id = `git log -1 --pretty=format:%h --abbrev=10`; 43*a7eb43eeSJim Jagielski return $id; 44*a7eb43eeSJim Jagielski} 45997ab3cdSmseidel 46*a7eb43eeSJim Jagielskisub DetectRevisionIdFromSVN ($) 47*a7eb43eeSJim Jagielski{ 48*a7eb43eeSJim Jagielski my $path = shift; 49997ab3cdSmseidel my $id = undef; 508bd5297cSJürgen Schmidt 51997ab3cdSmseidel open my $proc, "cd $path && svn info 2>\&1 |"; 52997ab3cdSmseidel while (<$proc>) 53997ab3cdSmseidel { 54997ab3cdSmseidel if (/svn: E155007:/ || /svn: '.' is not a working copy/) 55997ab3cdSmseidel { 56997ab3cdSmseidel # Not in an SVN repository. 57*a7eb43eeSJim Jagielski return undef; 58997ab3cdSmseidel } 59997ab3cdSmseidel else 60997ab3cdSmseidel { 61997ab3cdSmseidel if (/Last Changed Rev:\s+([0-9]+)/) 62997ab3cdSmseidel { 63997ab3cdSmseidel $id = $1; 64997ab3cdSmseidel last; 65997ab3cdSmseidel } 66997ab3cdSmseidel } 67997ab3cdSmseidel } 68997ab3cdSmseidel close $proc; 69997ab3cdSmseidel return $id; 708bd5297cSJürgen Schmidt} 718bd5297cSJürgen Schmidt 723edb530aSPeter Kovacs 733edb530aSPeter Kovacssub DetectRevisionId ($) 743edb530aSPeter Kovacs{ 75997ab3cdSmseidel my $path = shift; 76997ab3cdSmseidel my $id = undef; 77*a7eb43eeSJim Jagielski 78*a7eb43eeSJim Jagielski my $NotGit = `cd $path && git rev-parse --git-dir > /dev/null 2>&1`; 79*a7eb43eeSJim Jagielski if (!$NotGit || -d ".git" || -d "$path/.git") 80997ab3cdSmseidel { 81*a7eb43eeSJim Jagielski $id = DetectRevisionIdFromGit ($path); 82997ab3cdSmseidel } 83997ab3cdSmseidel else 84997ab3cdSmseidel { 85*a7eb43eeSJim Jagielski $id = DetectRevisionIdFromSVN ($path); 86997ab3cdSmseidel } 873edb530aSPeter Kovacs 88*a7eb43eeSJim Jagielski if (!$id) 89*a7eb43eeSJim Jagielski { 90*a7eb43eeSJim Jagielski #NOTE: Magic cookie file 'reporevision.lst' created by aoo_srcrelease 91*a7eb43eeSJim Jagielski $id = DetectRevisionIdFromFile ("$ENV{'SOLARENV'}/inc/reporevision.lst"); 92*a7eb43eeSJim Jagielski if (!$id) { $id = "unknown-rev" }; 93*a7eb43eeSJim Jagielski } 94997ab3cdSmseidel return $id; 953edb530aSPeter Kovacs} 963edb530aSPeter Kovacs 978bd5297cSJürgen Schmidt1; 98