1eb479a10SJim Jagielski#************************************************************** 2eb479a10SJim Jagielski# 3eb479a10SJim Jagielski# Licensed to the Apache Software Foundation (ASF) under one 4eb479a10SJim Jagielski# or more contributor license agreements. See the NOTICE file 5eb479a10SJim Jagielski# distributed with this work for additional information 6eb479a10SJim Jagielski# regarding copyright ownership. The ASF licenses this file 7eb479a10SJim Jagielski# to you under the Apache License, Version 2.0 (the 8eb479a10SJim Jagielski# "License"); you may not use this file except in compliance 9eb479a10SJim Jagielski# with the License. You may obtain a copy of the License at 10eb479a10SJim Jagielski# 11eb479a10SJim Jagielski# http://www.apache.org/licenses/LICENSE-2.0 12eb479a10SJim Jagielski# 13eb479a10SJim Jagielski# Unless required by applicable law or agreed to in writing, 14eb479a10SJim Jagielski# software distributed under the License is distributed on an 15eb479a10SJim Jagielski# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16eb479a10SJim Jagielski# KIND, either express or implied. See the License for the 17eb479a10SJim Jagielski# specific language governing permissions and limitations 18eb479a10SJim Jagielski# under the License. 19eb479a10SJim Jagielski# 20eb479a10SJim Jagielski#************************************************************** 21eb479a10SJim Jagielski 22eb479a10SJim Jagielski 23eb479a10SJim Jagielski 24eb479a10SJim Jagielskipackage RepoRevision; 25eb479a10SJim Jagielski 260c6d6194SJim Jagielskisub DetectRevisionIdFromFile ($) 270c6d6194SJim Jagielski{ 280c6d6194SJim Jagielski my $path = shift; 290c6d6194SJim Jagielski my $id = undef; 300c6d6194SJim Jagielski 310c6d6194SJim Jagielski open( my $fh, '<', $path ) || return undef; 320c6d6194SJim Jagielski $id = <$fh>; 330c6d6194SJim Jagielski close $fh; 340c6d6194SJim Jagielski return $id; 350c6d6194SJim Jagielski} 360c6d6194SJim Jagielski 370c6d6194SJim Jagielskisub DetectRevisionIdFromGit ($) 380c6d6194SJim Jagielski{ 390c6d6194SJim Jagielski my $path = shift; 400c6d6194SJim Jagielski my $id = undef; 410c6d6194SJim Jagielski 420c6d6194SJim Jagielski $id = `git log -1 --pretty=format:%h --abbrev=10`; 430c6d6194SJim Jagielski return $id; 440c6d6194SJim Jagielski} 450c6d6194SJim Jagielski 46eb479a10SJim Jagielskisub DetectRevisionIdFromSVN ($) 47eb479a10SJim Jagielski{ 48eb479a10SJim Jagielski my $path = shift; 49eb479a10SJim Jagielski my $id = undef; 50eb479a10SJim Jagielski 51eb479a10SJim Jagielski open my $proc, "cd $path && svn info 2>\&1 |"; 52eb479a10SJim Jagielski while (<$proc>) 53eb479a10SJim Jagielski { 54eb479a10SJim Jagielski if (/svn: E155007:/ || /svn: '.' is not a working copy/) 55eb479a10SJim Jagielski { 56eb479a10SJim Jagielski # Not in an SVN repository. 570c6d6194SJim Jagielski return undef; 58eb479a10SJim Jagielski } 59eb479a10SJim Jagielski else 60eb479a10SJim Jagielski { 61eb479a10SJim Jagielski if (/Last Changed Rev:\s+([0-9]+)/) 62eb479a10SJim Jagielski { 63eb479a10SJim Jagielski $id = $1; 64eb479a10SJim Jagielski last; 65eb479a10SJim Jagielski } 66eb479a10SJim Jagielski } 67eb479a10SJim Jagielski } 68eb479a10SJim Jagielski close $proc; 69eb479a10SJim Jagielski return $id; 70eb479a10SJim Jagielski} 71eb479a10SJim Jagielski 72eb479a10SJim Jagielski 73eb479a10SJim Jagielskisub DetectRevisionId ($) 74eb479a10SJim Jagielski{ 75eb479a10SJim Jagielski my $path = shift; 76eb479a10SJim Jagielski my $id = undef; 770c6d6194SJim Jagielski 78*67baec14SJim Jagielski #NOTE: Magic cookie file 'reporevision.lst' created by aoo_srcrelease 79*67baec14SJim Jagielski $id = DetectRevisionIdFromFile ("$ENV{'SOLARENV'}/inc/reporevision.lst"); 80*67baec14SJim Jagielski if ($id) { return $id }; 81*67baec14SJim Jagielski 820c6d6194SJim Jagielski my $NotGit = `cd $path && git rev-parse --git-dir > /dev/null 2>&1`; 830c6d6194SJim Jagielski if (!$NotGit || -d ".git" || -d "$path/.git") 84eb479a10SJim Jagielski { 850c6d6194SJim Jagielski $id = DetectRevisionIdFromGit ($path); 86eb479a10SJim Jagielski } 87eb479a10SJim Jagielski else 88eb479a10SJim Jagielski { 890c6d6194SJim Jagielski $id = DetectRevisionIdFromSVN ($path); 90eb479a10SJim Jagielski } 91eb479a10SJim Jagielski 920c6d6194SJim Jagielski if (!$id) { $id = "unknown-rev" }; 93eb479a10SJim Jagielski return $id; 94eb479a10SJim Jagielski} 95eb479a10SJim Jagielski 96eb479a10SJim Jagielski1; 97