|
1
|
#!/bin/sh |
|
2
|
# |
|
3
|
# This is a TCL script that tries to sync the changes in a local |
|
4
|
# Fossil checkout to another machine. The changes are gathered into |
|
5
|
# a tarball, then sent via ssh to the remote and unpacked. |
|
6
|
# |
|
7
|
# Usage: |
|
8
|
# |
|
9
|
# co-rsync.tcl REMOTE |
|
10
|
# |
|
11
|
# Where REMOTE is the root of the remote repository into which changes |
|
12
|
# are to be moved. |
|
13
|
# |
|
14
|
# Use Case: |
|
15
|
# |
|
16
|
# Sometimes while in the middle of an edit it is useful to transfer |
|
17
|
# the incomplete changes to another machine for testing. This could |
|
18
|
# be accomplished using scp, but doing it that was is tedious if many |
|
19
|
# files in multiple directories have changed. This command does all |
|
20
|
# the necessary transfer using a single command. |
|
21
|
# |
|
22
|
# A Tcl comment, whose contents don't matter \ |
|
23
|
exec tclsh "$0" "$@" |
|
24
|
|
|
25
|
# Begin by changing directories to the root of the check-out. |
|
26
|
# |
|
27
|
set remote {} |
|
28
|
set dryrun 0 |
|
29
|
proc usage {} { |
|
30
|
puts stderr "Usage: $::argv0 REMOTE" |
|
31
|
puts stderr "Options:" |
|
32
|
puts stderr " --dryrun No-op but print what would have happened" |
|
33
|
exit 1 |
|
34
|
} |
|
35
|
foreach arg $argv { |
|
36
|
if {$arg=="--dryrun" || $arg=="--dry-run"} { |
|
37
|
set dryrun 1 |
|
38
|
continue |
|
39
|
} |
|
40
|
if {$remote!=""} { |
|
41
|
usage |
|
42
|
} |
|
43
|
set remote $arg |
|
44
|
} |
|
45
|
if {$remote==""} usage |
|
46
|
|
|
47
|
set in [open {|fossil status} rb] |
|
48
|
set status [read $in] |
|
49
|
if {[catch {close $in} msg]} { |
|
50
|
puts stderr $msg |
|
51
|
exit 1 |
|
52
|
} |
|
53
|
set root {} |
|
54
|
regexp {local-root: +([^\n]+)} $status all root |
|
55
|
if {$root==""} { |
|
56
|
puts stderr "not in a fossil check-out" |
|
57
|
exit 1 |
|
58
|
} |
|
59
|
cd $root |
|
60
|
set tmpname filelist- |
|
61
|
for {set i 0} {$i<3} {incr i} { |
|
62
|
append tmpname [format %08x [expr {int(rand()*0xffffffff)}]] |
|
63
|
} |
|
64
|
set out [open $tmpname wb] |
|
65
|
puts $out [exec fossil changes --no-classify --no-merge] |
|
66
|
close $out |
|
67
|
set cmd "rsync -v --files-from=$tmpname . $remote" |
|
68
|
puts $cmd |
|
69
|
if {!$dryrun} { |
|
70
|
exec {*}$cmd |
|
71
|
} |
|
72
|
file delete $tmpname |
|
73
|
|