1
|
#!/usr/bin/ruby
|
2
|
|
3
|
DEBUG=false
|
4
|
CVSROOT="/var/cvsroot"
|
5
|
|
6
|
ALIASES=
|
7
|
{
|
8
|
"alias1" => [ "module1" , "module2", "module3" ],
|
9
|
"alias2" => [ "module1" , "module2", "module4" ],
|
10
|
}
|
11
|
|
12
|
class CvsAlias
|
13
|
|
14
|
def initialize(argv)
|
15
|
parse_arg(argv)
|
16
|
parse_path
|
17
|
end
|
18
|
|
19
|
private
|
20
|
def parse_arg(argv)
|
21
|
@args = ""
|
22
|
@cvs_cmd = nil
|
23
|
index = 0
|
24
|
next_is_cmd = false
|
25
|
while index < argv.length - 1
|
26
|
arg = argv[index]
|
27
|
unless @cvs_cmd
|
28
|
if next_is_cmd
|
29
|
@cvs_cmd = arg
|
30
|
else
|
31
|
next_is_cmd = true if arg == CVSROOT
|
32
|
end
|
33
|
end
|
34
|
arg = "'#{arg}'" if arg =~ />/
|
35
|
@args += " #{arg}";
|
36
|
index += 1
|
37
|
end
|
38
|
@path = argv[index]
|
39
|
|
40
|
STDERR.print "cmd: #{@cvs_cmd}\n" if DEBUG
|
41
|
STDERR.print "path: [#{index}] #{@path}\n" if DEBUG
|
42
|
end
|
43
|
|
44
|
def parse_path
|
45
|
if @path =~ %r:/*([^/]+)/(.+):
|
46
|
@alias = $1
|
47
|
@real_paths = [$2]
|
48
|
STDERR.print "HAS SUB: #{$2} for #{@alias}\n" if DEBUG
|
49
|
elsif @path =~ %r:/*([^/]+)/*$:
|
50
|
@is_root_path = true
|
51
|
@alias = $1
|
52
|
@real_paths = ALIASES[@alias]
|
53
|
STDERR.print "REAL PATHs: #{@real_paths} for #{@alias}\n" if DEBUG
|
54
|
else
|
55
|
STDERR.print "MISC: #{@path}\n" if DEBUG
|
56
|
@real_paths = [@path]
|
57
|
end
|
58
|
end
|
59
|
|
60
|
def do_cmd(real_path)
|
61
|
cmd_line = "cvs #{@args} #{real_path}"
|
62
|
STDERR.print "#{cmd_line}\n" if DEBUG
|
63
|
|
64
|
result = `#{cmd_line}`
|
65
|
|
66
|
STDERR.print "original result ==================================" if DEBUG
|
67
|
STDERR.print result if DEBUG
|
68
|
|
69
|
result.gsub! %r=RCS file: #{CVSROOT}=, "RCS file: #{CVSROOT}/#{@alias}"
|
70
|
|
71
|
STDERR.print "modified result ==================================" if DEBUG
|
72
|
STDERR.print result if DEBUG
|
73
|
STDERR.print "==================================================" if DEBUG
|
74
|
print result
|
75
|
end
|
76
|
|
77
|
public
|
78
|
def exec_cmd
|
79
|
if @is_root_path && @cvs_cmd == "rls"
|
80
|
@real_paths.each do |real_path|
|
81
|
print "D/#{real_path}////\n"
|
82
|
end
|
83
|
else
|
84
|
@real_paths.each do |real_path|
|
85
|
do_cmd(real_path)
|
86
|
end
|
87
|
end
|
88
|
end
|
89
|
end
|
90
|
|
91
|
STDERR.print "HOOKED---------\n" if DEBUG
|
92
|
|
93
|
wrap = CvsAlias.new(ARGV)
|
94
|
wrap.exec_cmd
|