xref: /aosp_15_r20/external/llvm/utils/GetRepositoryPath (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker#!/bin/sh
2*9880d681SAndroid Build Coastguard Worker
3*9880d681SAndroid Build Coastguard Workerusage() {
4*9880d681SAndroid Build Coastguard Worker  echo "usage: $0 <source root>"
5*9880d681SAndroid Build Coastguard Worker  echo "  Prints the source control repository path of the given source"
6*9880d681SAndroid Build Coastguard Worker  echo "  directory, the exact format of the revision string depends on the"
7*9880d681SAndroid Build Coastguard Worker  echo "  source control system. If the source control system isn't known,"
8*9880d681SAndroid Build Coastguard Worker  echo "  the output is empty and the exit code is 1."
9*9880d681SAndroid Build Coastguard Worker  exit 1
10*9880d681SAndroid Build Coastguard Worker}
11*9880d681SAndroid Build Coastguard Worker
12*9880d681SAndroid Build Coastguard Workerif [ $# != 1 ] || [ ! -d $1 ]; then
13*9880d681SAndroid Build Coastguard Worker  usage;
14*9880d681SAndroid Build Coastguard Workerfi
15*9880d681SAndroid Build Coastguard Worker
16*9880d681SAndroid Build Coastguard Workercd $1
17*9880d681SAndroid Build Coastguard Workerif [ -d .svn ]; then
18*9880d681SAndroid Build Coastguard Worker  svn info | grep '^URL:' | cut -d: -f2-
19*9880d681SAndroid Build Coastguard Workerelif [ -f .git/svn/.metadata ]; then
20*9880d681SAndroid Build Coastguard Worker  git svn info | grep 'URL:' | cut -d: -f2-
21*9880d681SAndroid Build Coastguard Workerelif [ -d .git ]; then
22*9880d681SAndroid Build Coastguard Worker  git remote -v | grep 'fetch' | awk '{ print $2 }' | head -n1
23*9880d681SAndroid Build Coastguard Workerelse
24*9880d681SAndroid Build Coastguard Worker  exit 1;
25*9880d681SAndroid Build Coastguard Workerfi
26*9880d681SAndroid Build Coastguard Worker
27*9880d681SAndroid Build Coastguard Workerexit 0
28