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 22package SvnRevision; 23 24#old SVN code unchanged 25sub DetectRevisionIdFromSVN ($) 26{ 27 my $path = shift; 28 29 my $id = undef; 30 31 open my $proc, "cd $path && svn info 2>\&1 |"; 32 while (<$proc>) 33 { 34 if (/svn: E155007:/ || /svn: '.' is not a working copy/) 35 { 36 # Not in an SVN repository. 37 $id = DetectRevisionIdFromGit($path); 38 last; 39 } 40 else 41 { 42 if (/Last Changed Rev:\s+([0-9]+)/) 43 { 44 $id = $1; 45 last; 46 } 47 } 48 } 49 close $proc; 50 51 return $id; 52} 53 54 55sub DetectRevisionId ($) 56{ 57 my $path = shift; 58 59 my $id = undef; 60 #test if path points to a git repository. if true return is 0 else positive number. 61 my $isNotGit= `[ -d .git ] || git rev-parse --git-dir > /dev/null 2>&1`; 62 if ($isNotGit) 63 { 64 $id = DetectRevisionIdFromSVN ($path); 65 } 66 else 67 { 68 #returns directly the hash of the current checkout. 69 $id = `git log -1 --pretty=format:%h`; 70 } 71 72 return $id; 73} 74 751; 76