1 |
#!/usr/bin/env tclsh |
2 |
package require sha256 |
3 |
if { $argc < 4 } { |
4 |
puts "Usage: $argv0 svn cvs cache svn_revision" |
5 |
exit 1 |
6 |
} |
7 |
set svn "[lindex $argv 0]" |
8 |
set cvs "[lindex $argv 1]" |
9 |
set cache "[lindex $argv 2]" |
10 |
set rev "[lindex $argv 3]" |
11 |
set old "[pwd]" |
12 |
set log [exec svn log --incremental "$svn" -r "$rev" | tail -n1] |
13 |
|
14 |
set added "" |
15 |
set removed "" |
16 |
set added_dir "" |
17 |
|
18 |
exec -ignorestderr svn up "$svn" -r "$rev" |
19 |
exec -ignorestderr cvs up -d "$cvs" |
20 |
|
21 |
proc rescan {path prefix} { |
22 |
global svn cvs cache old added added_dir |
23 |
foreach name [glob -tails -nocomplain -directory "$path" *] { |
24 |
if { [file type "$path/$name"] == "directory" } { |
25 |
if { ! [file exists "$cvs/$prefix/$name"] } { |
26 |
file mkdir "$cvs/$prefix/$name" |
27 |
file mkdir "$cache/$prefix/$name" |
28 |
cd "$cvs" |
29 |
lappend added_dir "[string range "$prefix/$name" 1 [string length "$prefix/$name"]]" |
30 |
cd "$old" |
31 |
} |
32 |
rescan "$path/$name" "$prefix/$name" |
33 |
} else { |
34 |
set new 0 |
35 |
if { ! [file exists "$cvs/$prefix/$name"] } { |
36 |
set new 1 |
37 |
} |
38 |
if { $new } { |
39 |
puts "New file: `$prefix/$name'" |
40 |
file copy -force "$path/$name" "$cvs/$prefix/$name" |
41 |
file copy -force "$path/$name" "$cache/$prefix/$name" |
42 |
cd "$cvs" |
43 |
lappend added "[string range "$prefix/$name" 1 [string length "$prefix/$name"]]" |
44 |
cd "$old" |
45 |
} else { |
46 |
set hash1 [::sha2::sha256 -hex -filename "$path/$name"] |
47 |
set hash2 [::sha2::sha256 -hex -filename "$cache/$prefix/$name"] |
48 |
if { $hash1 != $hash2 } { |
49 |
puts "Modified: `$prefix/$name'" |
50 |
file copy -force "$path/$name" "$cvs/$prefix/$name" |
51 |
file copy -force "$path/$name" "$cache/$prefix/$name" |
52 |
} else { |
53 |
puts "Not modified: `$prefix/$name'" |
54 |
} |
55 |
} |
56 |
} |
57 |
} |
58 |
} |
59 |
|
60 |
proc remove_left {path prefix} { |
61 |
global svn cvs cache old removed |
62 |
foreach name [glob -tails -nocomplain -directory "$path" *] { |
63 |
if { [file type "$path/$name"] == "directory" } { |
64 |
if { "$name" != "CVS" } { |
65 |
remove_left "$path/$name" "$prefix/$name" |
66 |
} |
67 |
} else { |
68 |
if { [file exists "$cvs/$prefix/$name"] && ![file exists "$svn/$prefix/$name"] } { |
69 |
cd "$cvs" |
70 |
file delete "[string range "$prefix/$name" 1 [string length "$prefix/$name"]]" |
71 |
lappend removed "[string range "$prefix/$name" 1 [string length "$prefix/$name"]]" |
72 |
cd "$old" |
73 |
file delete "$cache/$prefix/$name" |
74 |
|
75 |
} |
76 |
} |
77 |
} |
78 |
} |
79 |
|
80 |
rescan "$svn" "" |
81 |
remove_left "$cvs" "" |
82 |
|
83 |
cd "$cvs" |
84 |
if { "$added_dir" != "" } { |
85 |
eval exec -ignorestderr cvs add \"[join $added_dir "\" \""]\" >/dev/stdout 2>@1 |
86 |
} |
87 |
if { "$added" != "" } { |
88 |
eval exec -ignorestderr cvs add \"[join $added "\" \""]\" >/dev/stdout 2>@1 |
89 |
} |
90 |
if { "$removed" != "" } { |
91 |
eval exec -ignorestderr cvs rm \"[join $removed "\" \""]\" >/dev/stdout 2>@1 |
92 |
} |
93 |
exec -ignorestderr cvs ci -m "$log" |
94 |
cd "$old" |
95 |
|
96 |
if { [regexp -- {\[release ([^\]]+)\]} "$log" -> ver] } { |
97 |
cd "$cvs" |
98 |
exec -ignorestderr cvs tag "v[regsub -all -- {\.} "$ver" {_}]" |
99 |
cd "$old" |
100 |
} |
101 |
|
102 |
puts "This commit was: $log" |