xref: /aoo42x/main/solenv/bin/modules/RepoRevision.pm (revision 8bd5297c)
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
25sub DetectRevisionIdFromGit ($)
26{
27    my $path = shift;
28
29    my $id = undef;
30
31    open my $proc, "cd $path && git show HEAD 2>\&1|";
32    while (<$proc>)
33    {
34        if (/^fatal: Not a git repository/)
35        {
36            # Not in a GIT repository.
37            last;
38        }
39        elsif (/^\s*git-svn-id:.*?trunk@([0-9]+)\s+/)
40        {
41            $id = $1;
42            last;
43        }
44    }
45    close $proc;
46
47    return $id;
48}
49
50
51
52
53sub DetectRevisionId ($)
54{
55    my $path = shift;
56
57    my $id = undef;
58
59    open my $proc, "cd $path && svn info 2>\&1 |";
60    while (<$proc>)
61    {
62        if (/svn: E155007:/)
63        {
64            # Not in an SVN repository.
65            $id = DetectRevisionIdFromGit($path);
66            last;
67        }
68        else
69        {
70            if (/Last Changed Rev:\s+([0-9]+)/)
71            {
72                $id = $1;
73                last;
74            }
75        }
76    }
77    close $proc;
78
79    return $id;
80}
81
821;
83