1 # Copyright (C) 2007 Apple Inc. All rights reserved.
3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions
7 # 1. Redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer.
9 # 2. Redistributions in binary form must reproduce the above copyright
10 # notice, this list of conditions and the following disclaimer in the
11 # documentation and/or other materials provided with the distribution.
12 # 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
13 # its contributors may be used to endorse or promote products derived
14 # from this software without specific prior written permission.
16 # THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
17 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 # DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
20 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 # Module to share code to work with various version control systems.
36 our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
39 @EXPORT = qw(&isGitDirectory &isGit &isSVNDirectory &isSVN &makeFilePathRelative);
54 return system("cd $dir && git rev-parse > /dev/null 2>&1") == 0;
59 return $isGit if defined $isGit;
61 $isGit = isGitDirectory(".");
67 unless (defined $gitBranch) {
68 chomp($gitBranch = `git symbolic-ref -q HEAD`);
69 $gitBranch = "" if exitStatus($?);
70 $gitBranch =~ s#^refs/heads/##;
71 $gitBranch = "" if $gitBranch eq "master";
77 sub isGitBranchBuild()
79 my $branch = gitBranch();
80 chomp(my $override = `git config --bool branch.$branch.webKitBranchBuild`);
81 return 1 if $override eq "true";
82 return 0 if $override eq "false";
84 unless (defined $isGitBranchBuild) {
85 chomp(my $gitBranchBuild = `git config --bool core.webKitBranchBuild`);
86 $isGitBranchBuild = $gitBranchBuild eq "true";
89 return $isGitBranchBuild;
96 return -d File::Spec->catdir($dir, ".svn");
101 return $isSVN if defined $isSVN;
103 $isSVN = isSVNDirectory(".");
108 sub makeFilePathRelative($)
111 return $path unless isGit();
113 unless (defined $gitRoot) {
114 chomp($gitRoot = `git rev-parse --show-cdup`);
116 return $gitRoot . $path;