blob: 280ec0b62d6cb9d809f3c09d4bd0f5cb72277e29 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
#!/bin/bash
# $Id$
#
# Copyright 2005, Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# Written by Aron Griffis <agriffis@gentoo.org>
#
# eviewcvs - generate viewcvs urls for some files
#
if [[ -t 1 ]]; then
blue="[34;01m"
cyan="[36;01m"
green="[32;01m"
red="[31;01m"
off="[0m"
else
unset blue cyan green red off
fi
startdir="$PWD"
url="http://sources.gentoo.org/viewcvs.py"
unset diffs
declare -a hdr orev
chdir() {
cd "$1" || return
# Figure out where we are, hopefully
unset cwd root
if [[ -f CVS/Repository ]]; then
cwd=$(<CVS/Repository)
elif [[ -f .svn/entries ]]; then
cwd=$(grep -om1 'url=.*' .svn/entries)
cwd=${cwd#*/var/svnroot/}
cwd=${cwd%\"*}
fi
}
# Default to all files in directory
[[ -n $* ]] || set -- *
for f in "$@"; do
[[ -f $f ]] || continue
# Determine the directory settings
if [[ $f == */* ]]; then
chdir ${f%/*}
f=${f##*/}
else
chdir ${startdir}
fi
# Default to the directory settings
fwd=$cwd
# Get the header for this file, from which we can extract the root,
# directory and revision
hdr=( $(egrep -m1 -o '\$(Header|Id):[^$]*\$' "$f") )
frev=${hdr[2]}
case ${hdr[*]} in
\$Header:\ /var/cvsroot/*/*\ \$*)
fwd=${hdr[1]} # /var/cvsroot/gentoo-src/keychain/keychain.sh,v
fwd=${fwd#/var/cvsroot/} # gentoo-src/keychain/keychain.sh,v
fwd=${fwd%/*} # gentoo-src/keychain
;;
'')
if [[ -d CVS ]]; then
frev=$(cvs log "$f" 2>/dev/null | awk '/^head:/{print $2}')
elif [[ -d .svn ]]; then
frev=$(svn info "$f" 2>/dev/null | awk '/^Revision:/{print $2}')
fi
;;
esac
[[ -n ${frev} ]] || continue
# Here is the simple URL to view it
echo "${url}/${fwd:+$fwd/}${green}${f}${off}?rev=${frev}&view=markup"
# Also supply a diff URL if possible
if [[ ${frev##*.} -gt 1 ]]; then
orev=( ${frev//./ } ) # convert to array
(( orev[${#orev[@]}-1]-- )) # decrement the last element
orev=${orev[*]} # convert to string
orev=${orev// /.} # revert spaces to dots
diffs="${diffs:+$diffs
}${url}/${fwd:+$fwd/}${blue}${f}${off}?r1=${orev}&r2=${frev}"
fi
done
if [[ -n ${diffs} ]]; then
echo "${diffs}"
fi
# vim:set expandtab sw=4 smarttab:
|