RepoRevision.pm (f8d20be8) | RepoRevision.pm (27a447d8) |
---|---|
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 unchanged lines hidden (view full) --- 18# under the License. 19# 20#************************************************************** 21 22 23 24package RepoRevision; 25 | 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 unchanged lines hidden (view full) --- 18# under the License. 19# 20#************************************************************** 21 22 23 24package RepoRevision; 25 |
26#old SVN code unchanged 27sub DetectRevisionIdFromSVN ($) | 26sub DetectRevisionIdFromFile ($) |
28{ 29 my $path = shift; | 27{ 28 my $path = shift; |
29 my $id = undef; |
|
30 | 30 |
31 open( my $fh, '<', $path ) || return undef; 32 $id = <$fh>; 33 close $fh; 34 return $id; 35} 36 37sub DetectRevisionIdFromGit ($) 38{ 39 my $path = shift; |
|
31 my $id = undef; 32 | 40 my $id = undef; 41 |
42 $id = `git log -1 --pretty=format:%h --abbrev=10`; 43 return $id; 44} 45 46sub DetectRevisionIdFromSVN ($) 47{ 48 my $path = shift; 49 my $id = undef; 50 |
|
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. | 51 open my $proc, "cd $path && svn info 2>\&1 |"; 52 while (<$proc>) 53 { 54 if (/svn: E155007:/ || /svn: '.' is not a working copy/) 55 { 56 # Not in an SVN repository. |
39 $id = DetectRevisionIdFromGit($path); 40 last; | 57 return undef; |
41 } 42 else 43 { 44 if (/Last Changed Rev:\s+([0-9]+)/) 45 { 46 $id = $1; 47 last; 48 } 49 } 50 } 51 close $proc; | 58 } 59 else 60 { 61 if (/Last Changed Rev:\s+([0-9]+)/) 62 { 63 $id = $1; 64 last; 65 } 66 } 67 } 68 close $proc; |
52 | |
53 return $id; 54} 55 56 57sub DetectRevisionId ($) 58{ 59 my $path = shift; | 69 return $id; 70} 71 72 73sub DetectRevisionId ($) 74{ 75 my $path = shift; |
60 | |
61 my $id = undef; | 76 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) | 77 78 my $NotGit = `cd $path && git rev-parse --git-dir > /dev/null 2>&1`; 79 if (!$NotGit || -d ".git" || -d "$path/.git") |
65 { | 80 { |
66 $id = DetectRevisionIdFromSVN ($path); | 81 $id = DetectRevisionIdFromGit ($path); |
67 } 68 else 69 { | 82 } 83 else 84 { |
70 #returns directly the hash of the current checkout. 71 $id = `git log -1 --pretty=format:%h --abbrev=10`; | 85 $id = DetectRevisionIdFromSVN ($path); |
72 } 73 | 86 } 87 |
88 if (!$id) 89 { 90 #NOTE: Magic cookie file 'reporevision.lst' created by aoo_srcrelease 91 $id = DetectRevisionIdFromFile ("$ENV{'SOLARENV'}/inc/reporevision.lst"); 92 if (!$id) { $id = "unknown-rev" }; 93 } |
|
74 return $id; 75} 76 771; | 94 return $id; 95} 96 971; |