File: co-rsync.tcl

package info (click to toggle)
fossil 1%3A2.26-2
  • links: PTS
  • area: main
  • in suites: sid, trixie
  • size: 28,572 kB
  • sloc: ansic: 332,171; tcl: 14,144; javascript: 10,171; sh: 6,791; makefile: 4,276; pascal: 1,139; cpp: 1,001; cs: 879; sql: 376; asm: 281; perl: 166; xml: 95
file content (72 lines) | stat: -rwxr-xr-x 1,768 bytes parent folder | download | duplicates (3)
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
#!/bin/sh
#
# This is a TCL script that tries to sync the changes in a local
# Fossil checkout to another machine.  The changes are gathered into
# a tarball, then sent via ssh to the remote and unpacked.
#
# Usage:
#
#     co-rsync.tcl REMOTE
#
# Where REMOTE is the root of the remote repository into which changes
# are to be moved.
#
# Use Case:
#
# Sometimes while in the middle of an edit it is useful to transfer
# the incomplete changes to another machine for testing.  This could
# be accomplished using scp, but doing it that was is tedious if many
# files in multiple directories have changed.  This command does all
# the necessary transfer using a single command.
#
# A Tcl comment, whose contents don't matter \
exec tclsh "$0" "$@"

# Begin by changing directories to the root of the check-out.
#
set remote {}
set dryrun 0
proc usage {} {
  puts stderr "Usage: $::argv0 REMOTE"
  puts stderr "Options:"
  puts stderr "  --dryrun      No-op but print what would have happened"
  exit 1
}
foreach arg $argv {
  if {$arg=="--dryrun" || $arg=="--dry-run"} {
    set dryrun 1
    continue
  }
  if {$remote!=""} {
    usage
  }
  set remote $arg
}
if {$remote==""} usage

set in [open {|fossil status} rb]
set status [read $in]
if {[catch {close $in} msg]} {
  puts stderr $msg
  exit 1
}
set root {}
regexp {local-root: +([^\n]+)} $status all root
if {$root==""} {
  puts stderr "not in a fossil check-out"
  exit 1
}
cd $root
set tmpname filelist-
for {set i 0} {$i<3} {incr i} {
  append tmpname [format %08x [expr {int(rand()*0xffffffff)}]]
}
set out [open $tmpname wb]
puts $out [exec fossil changes --no-classify --no-merge]
close $out
set cmd "rsync -v --files-from=$tmpname . $remote"
puts $cmd
if {!$dryrun} {
  exec {*}$cmd
}
file delete $tmpname