fsl wrapper

Check-in [07960a4b2d]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Experimental check for forks by Jeff Gong
Timelines: family | ancestors | forks-check
Files: files | file ages | folders
SHA1:07960a4b2d15555f17acdff651d03861af22006f
User & Date: mrwellan 2012-05-01 02:37:13
Context
2012-05-01
02:37
Experimental check for forks by Jeff Gong Closed-Leaf check-in: 07960a4b2d user: mrwellan tags: forks-check
2012-04-26
05:01
Check for conflicts on commit, ask for confirmation check-in: b5aaaaf46b user: matt tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to scripts/fsl.

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
..
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
...
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164















165
166
167
168
169
170
171
172
173
...
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
...
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
...
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
...
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
...
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
...
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
...
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420

421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
...
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
...
474
475
476
477
478
479
480

481
482
483
484
485
486
487
...
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574

575
export FOSSILEXE=fossil

#======================================================================
# H O O K S
#======================================================================

# a bash frustration, empty functions are not allowed! 
function hook_pre_repo_get       () { donotdoanything=0; }
function hook_post_repo_get      () { donotdoanything=0; }    
function hook_pre_repo_create    () { donotdoanything=0; }
function hook_post_repo_create   () { donotdoanything=0; }

if [ -e $configdir/.fslcustom ]; then
    source $configdir/.fslcustom
fi

#=====================================================================
# M I S C   F U N C T I O N S 
#======================================================================
function fsl_help () {
    echo "The fsl convienence wrapper. "
    echo "Copyright (C) 2012 Matthew Welland, License GPL 2.0"
    echo "Usage: fsl repo cmd args"
    echo "Or:    fsl <fossil commands>"
    echo ""
    echo "where repo cmd is one of"
    echo "  ls"
................................................................................
    echo "Note: timeline and leaves output is de-wrapped"
    echo ""
    echo "More at: http://chiselapp.com/user/kiatoa/repository/fsl"
    echo ""
}

# Given an area name return the path
function fsl_get_path_area () {
    repo_area=$1
    $SQLITE3 ~/.fsl "SELECT path FROM fsl_repos WHERE area='$repo_area';"
}

# Return a roughly random 8 character string
function fsl_random_string () {
    str0="$$`date`"
    str1=$( echo "$str0" | md5sum | md5sum )
    echo "${str1:2:8}"
}

#======================================================================
# A R E A   R E G I S T R A T I O N   D B   F U N C T I O N S
#======================================================================

# Initial creation of the ~/.fsl db
function fsl_dbinit () {
    configfile=$configdir/.fslconfig
    if [ ! -e ~/.fsl ]; then
        $SQLITE3 ~/.fsl <<EOF
CREATE TABLE fsl_repos (area TEXT PRIMARY KEY,path TEXT);
EOF
       # source a config file (could be used to setup some repo areas)
       # put commands such as:
................................................................................
       if [ $configfile -nt ~/.fsl ]; then
          source $configfile
       fi
    fi
}

# Register an area in the .fsl db
function fsl_add_area () {
    repo_area=$1
    repo_path=$2
    if [ "x$repo_path" = "x" ] || [ "x$repo_path" = "x/" ];then
	echo "ERROR: You must specify both area name and repo path with addarea"
	exit 1
    fi
    $SQLITE3 ~/.fsl <<EOF
INSERT OR REPLACE INTO fsl_repos (area,path) VALUES('$repo_area','$repo_path');
EOF
}

# Remove an area from the .fsl db
function fsl_remove_area () {
    repo_area=$1
    $SQLITE3 ~/.fsl <<EOF
DELETE FROM fsl_repos WHERE area='$repo_area';
EOF
}

# Human readable listing of areas
function fsl_list_areas () {
    $SQLITE3 ~/.fsl <<EOF
.width 10 65
.mode column
.head on
SELECT area,path FROM fsl_repos ORDER by area;
EOF
}

# Get all repo paths in natural order
function fsl_get_area_paths () {
    $SQLITE3 ~/.fsl <<EOF
SELECT path FROM fsl_repos;
EOF
}

# Given an area name return the path
function fsl_get_area_from_path () {
    repo_path=$1
    $SQLITE3 ~/.fsl <<EOF
SELECT area FROM fsl_repos WHERE path='$repo_path';
EOF
}
















# List all the repos stored in a given area
function fsl_list_repos_in_area () {
    repo_area=$1
    apath=`fsl_get_path_area $repo_area`
    if  [ -e $apath ];then
	cd $apath
	for f in *.fossil;do
	    project=`basename $f $REPOSEXT`
	    # add a -l switch to list the descriptions
................................................................................
    else
	echo $apath not found for repo $repo_area
    fi
}

# Do a human readable listing of the areas (if no area name provided)
# or list the repos if the area name is provided
function fsl_ls () {
    repo_area=$1
    if [ ! -e ~/.fsl ];then
	fsl_dbinit
    fi
    case "x$repo_area" in ("x") 
	fsl_list_areas
	exit
................................................................................
}

#======================================================================
# R E P O   C O M M A N D S 
#======================================================================

# Given a repo name find the first repo by that name by searching the areas
function fsl_find_repo() {
    repo_name=$1
    repo_area=NOSUCHREPOEVERFOUND
    for p in `fsl_get_area_paths`; do
	if [ -e $p/$repo_name.fossil ];then
	    repo_path=$p
	    repo_area=`fsl_get_area_from_path $repo_path`
	    break
................................................................................
    done
    echo "$repo_area"
}

# Given a repo area and name get a repo. If called with only one parameter
# it treats that parameter as a repo name and searches for it in all the areas
# and if found gets that repo
function fsl_repo_get () {
    repo_area=$1
    repo_name=$2
    
    # if repo_name is not defined then repo_area is taken as name and
    # the first matching repo is found by looking in each area in order
    if [ "x$repo_name" = "x" ];then
	echo "WARNING: no area provided, searching for first repo by name \"$repo_area\""
................................................................................
    	mkdir -p $repo_name/.fossil
	password=`fsl_random_string`
	# add self to central fossil if not already there
	if ! $FOSSILEXE user list -R $fossil | grep ^$USER;then
	    $FOSSILEXE user new $USER $USER $password -R $fossil
	fi
	localfossil=$repo_name/.fossil/$repo_name.fossil
	$FOSSILEXE clone $fossil $localfossil || exit $?
	# add self to local fossil if not already there
	if ! $FOSSILEXE user list -R $localfossil | grep ^$USER;then
	    $FOSSILEXE user new $USER $USER $password -R $localfossil || exit $?
	fi
	# work around the default user bug
	curr_default_user=`$SQLITE3 $localfossil "select login from user limit 1;"`
	if [ "$curr_default_user" != "$USER" ];then
	    my_user_uid=`$SQLITE3 $localfossil "select uid from user where login='$USER';"`
	    echo "Swap userid $my_user_uid with 1"
	    $SQLITE3 $localfossil <<EOF
UPDATE user SET login='tmp_user_name' WHERE uid=$my_user_uid;
UPDATE user SET login='$USER' WHERE uid=1;
UPDATE user SET login='$curr_default_user' WHERE uid=$my_user_uid;
EOF
	fi
	(cd $repo_name;$FOSSILEXE open .fossil/$repo_name.fossil) || exit $?
    else
        echo "ERROR: $fossil not found"
	exit 1
    fi
    # unset -x
}

# Create a new repo by repo_name in area specified repo_area
function fsl_repo_create () {
    repo_area=$1
    repo_name=$2

    path=`fsl_get_path_area $repo_area`
    fossil="$path/$repo_name.fossil"

    if [ -e $fossil ];then
	echo "ERROR: $repo_name in $repo_area already exists"
	exit
    fi

    $FOSSILEXE init $fossil || exit $?
    # assume groups are used for access control
    chmod ug+rw $fossil
    $FOSSILEXE set allow-symlinks 1 -R $fossil

    # BUG: convert this to a case and check for unrecognised switches
    if [ "x$3" = "x-template" ];then
	template=$4
................................................................................
	    echo "ERROR: You must specify the template using area/fossil_name format."
	    exit 1
	fi
    fi
}

# Import an existing repo into an area
function fsl_repo_import () {
    repo_area=$1
    repo_name=$2
    src_repo=$3
    
    path=`fsl_get_path_area $repo_area`
    fossil="$path/$repo_name.fossil"

................................................................................
#======================================================================
# M O V E   F I X E S
#======================================================================

fsl_force=0

#======================================================================
# F I L E   T O   D I R   O R   F I L E   T O   F I L E 
#======================================================================
# src must be a file and dest must be a directory or a filename in a
# directory that already exists
#======================================================================
function fsl_file_to_any_move () {
    src_path=$1
    dest_path=$2
    if [ ! -e $src_path ];then
	echo "ERROR: source path \"$src_path\" does not exist"
    else
        cmd="$FOSSILEXE mv $src_path $dest_path"
	echo $cmd
................................................................................
	    echo $cmd
	    $cmd
	fi
    fi
}

#======================================================================
# D I R   T O   E X I S T A N T   D I R   M O V E
#======================================================================
function fsl_dir_to_dir () {
    src_path=$1
    dest_path=$2
    files=`cd ${src_path};find . -type f|sed 's#^\./##';find . -type l|sed 's#^\./##'`
    # echo "files: $files"
    for f in $files;do
	cmd="$FOSSILEXE mv $src_path/$f $dest_path/$f"
	echo $cmd
	$cmd || exit $?
	if [ "$fsl_force" != "0" ];then
	    targ_dir=`dirname $dest_path/$f`
	    mkdir -p $targ_dir
	    cmd="mv $src_path/$f $dest_path/$f"
	    echo $cmd
	    $cmd || exit $?
	fi
    done
}

function fsl_mv () {
    all_paths=($@)
    targ_path_num=`expr ${#all_paths[*]} - 1`
    last_path_num=`expr $targ_path_num - 1`
    targ_path=${all_paths[$targ_path_num]}
    echo "targ_path_num: $targ_path_num, last_path_num: $last_path_num, targ_path: $targ_path"
    for i in $(seq 0 1 $last_path_num);do
	src_path=${all_paths[$i]}
	echo "Processing source path $src_path to target $targ_path"
	if [ -d "$src_path" ];then
	    fsl_dir_to_dir $src_path $targ_path
	else
	    fsl_file_to_any_move $src_path $targ_path
	fi
    done
}

#======================================================================
#  M I S C   T W E A K S 
#======================================================================

# From fossil email list by Kriangkrai Soatthiyanont nb// was "U\1\2"
function fsl_conflicts () {
    export CONFLICT_FLAG_FILE=`mktemp`
    $FOSSILEXE "$@" | sed -r 's/^EDITED(\s+)(.*)/grep -q "< BEGIN MERGE CONFLICT:" "\2" \&\& rm -f $CONFLICT_FLAG_FILE \&\& echo "CONFLICT   \2" || echo "\0"/e'; 
}

#======================================================================
# T H E   M A I N   H A N D L E R   A N D   P R O C E S S I N G 

#======================================================================

# repo commands
case "x$1" in ("xrepo")
    fsl_dbinit
    case "x$2" in 
	xhelp)
	fsl_help
	exit
	;;
	
        # repo get
	xget)
	hook_pre_repo_get "$@"
	fsl_repo_get $3 $4
	hook_post_repo_get "$@"
	exit
	;;

	xaddarea)
	fsl_add_area $3 $4
	exit
	;;
................................................................................
	fsl_dbinit
	exit
	;;

	xls|xlist)
	shift
	shift
	fsl_ls "$@"
	exit
	;;

	xcreate)
	hook_pre_repo_create
	fsl_repo_create $3 $4 $5 $6
	hook_post_repo_create
................................................................................
	*)
	fsl_help
	exit
    esac
    ;;

    "xmv")

    if [ "x$2" = "x-f" ];then
	# echo "Force mode"
	fsl_force=1
	shift
	shift
        # change this to exec when happy!
        # fsl mv -f f1 [f2 f3...] targ
................................................................................
	# echo $@  -> echo $@
        # use $# variable to print out
        # number of arguments passed to the bash script
	# echo Number of arguments passed: $#  -> echo Number of arguments passed: $#
	exit
    else
        # echo No force
	shift
	fsl_mv "$@"
	exit
    fi
    ;;

    "xtimeline")
    shift
    $FOSSILEXE timeline "$@" | sed -e :a -e '$!N;s/\n         / /;ta' -e 'P;D'
    exit
    ;;

    # leaves output needs to be niceified, no need for a function
    "xleaves")
    shift
    $FOSSILEXE leaves "$@" | sed -e :a -e '$!N;s/\n         / /;ta' -e 'P;D'
    exit
    ;;

    xchanges | xstatus)
    fsl_conflicts "$@"
    rm -f $CONFLICT_FLAG_FILE
    exit
    ;;

    xci | xcommit)
    fsl_conflicts changes "$@"
    if [ ! -e $CONFLICT_FLAG_FILE ]; then
	rm -f $CONFLICT_FLAG_FILE
	read -p "ERROR: Conflicts detected. Type \"yes\" to continue: " -e ANSWER
	if [ $ANSWER = "yes" ]; then
	    $FOSSILEXE "$@"
	else
	    exit 1
	fi
    else
	$FOSSILEXE "$@"
    fi
    exit
    ;;

    "xtag")
    case "x$2" in
	xadd | xcancel)
	$FOSSILEXE "$@"
	$FOSSILEXE sync
	exit
	;;
	
	*)
	$FOSSILEXE "$@"
	exit
	;;
    esac
    ;;

    # add mention of repo to help
    xhelp)
    if [ $# -gt 1 ]; then
       case "x$2" in 
          xrepo)
          fsl_help
          exit
          ;;
          
          *)
          $FOSSILEXE "$@"
	  ;;

       esac
    else
       $FOSSILEXE help | sed -e 's/sync/sync        repo/'
    fi
    exit
    ;;

esac	


exec $FOSSILEXE "$@"







|
|
|
|








|







 







|





|










|







 







|












|







|









|






|






>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

|







 







|







 







|







 







|







 







|


|












|








|











|







 







|







 







|
<



|







 







|

|


|
<


|
|




|
|




|




|


|












<
<
<
<
|
<

<
>













|

|







 







|







 







>







 







<







|






|



<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<










|











>

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
..
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
...
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
...
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
...
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
...
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
...
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
...
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
...
356
357
358
359
360
361
362
363

364
365
366
367
368
369
370
371
372
373
374
...
378
379
380
381
382
383
384
385
386
387
388
389
390

391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425




426

427

428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
...
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
...
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
...
499
500
501
502
503
504
505

506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523





































524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
export FOSSILEXE=fossil

#======================================================================
# H O O K S
#======================================================================

# a bash frustration, empty functions are not allowed! 
function hook_pre_repo_get       { donotdoanything=0; }
function hook_post_repo_get      { donotdoanything=0; }    
function hook_pre_repo_create    { donotdoanything=0; }
function hook_post_repo_create   { donotdoanything=0; }

if [ -e $configdir/.fslcustom ]; then
    source $configdir/.fslcustom
fi

#=====================================================================
# M I S C   F U N C T I O N S 
#======================================================================
function fsl_help {
    echo "The fsl convienence wrapper. "
    echo "Copyright (C) 2012 Matthew Welland, License GPL 2.0"
    echo "Usage: fsl repo cmd args"
    echo "Or:    fsl <fossil commands>"
    echo ""
    echo "where repo cmd is one of"
    echo "  ls"
................................................................................
    echo "Note: timeline and leaves output is de-wrapped"
    echo ""
    echo "More at: http://chiselapp.com/user/kiatoa/repository/fsl"
    echo ""
}

# Given an area name return the path
function fsl_get_path_area {
    repo_area=$1
    $SQLITE3 ~/.fsl "SELECT path FROM fsl_repos WHERE area='$repo_area';"
}

# Return a roughly random 8 character string
function fsl_random_string {
    str0="$$`date`"
    str1=$( echo "$str0" | md5sum | md5sum )
    echo "${str1:2:8}"
}

#======================================================================
# A R E A   R E G I S T R A T I O N   D B   F U N C T I O N S
#======================================================================

# Initial creation of the ~/.fsl db
function fsl_dbinit {
    configfile=$configdir/.fslconfig
    if [ ! -e ~/.fsl ]; then
        $SQLITE3 ~/.fsl <<EOF
CREATE TABLE fsl_repos (area TEXT PRIMARY KEY,path TEXT);
EOF
       # source a config file (could be used to setup some repo areas)
       # put commands such as:
................................................................................
       if [ $configfile -nt ~/.fsl ]; then
          source $configfile
       fi
    fi
}

# Register an area in the .fsl db
function fsl_add_area {
    repo_area=$1
    repo_path=$2
    if [ "x$repo_path" = "x" ] || [ "x$repo_path" = "x/" ];then
	echo "ERROR: You must specify both area name and repo path with addarea"
	exit 1
    fi
    $SQLITE3 ~/.fsl <<EOF
INSERT OR REPLACE INTO fsl_repos (area,path) VALUES('$repo_area','$repo_path');
EOF
}

# Remove an area from the .fsl db
function fsl_remove_area {
    repo_area=$1
    $SQLITE3 ~/.fsl <<EOF
DELETE FROM fsl_repos WHERE area='$repo_area';
EOF
}

# Human readable listing of areas
function fsl_list_areas {
    $SQLITE3 ~/.fsl <<EOF
.width 10 65
.mode column
.head on
SELECT area,path FROM fsl_repos ORDER by area;
EOF
}

# Get all repo paths in natural order
function fsl_get_area_paths {
    $SQLITE3 ~/.fsl <<EOF
SELECT path FROM fsl_repos;
EOF
}

# Given an area name return the path
function fsl_get_area_from_path {
    repo_path=$1
    $SQLITE3 ~/.fsl <<EOF
SELECT area FROM fsl_repos WHERE path='$repo_path';
EOF
}

# check for forks
function fsl_fork_find {
    $FOSSILEXE sql <<EOF
.width 10 65
.mode column
.head on
SELECT count(tagxref.value), tagxref.value FROM leaf, tagxref WHERE leaf.rid=tagxref.rid and tagxref.value != '' group by tagxref.value having count(tagxref.value) > 1 ;
EOF
    if [ $? -eq 0 ]; then
        echo
        echo "WARNING!!! forks were detected."
        echo
    fi
}

# List all the repos stored in a given area
function fsl_list_repos_in_area {
    repo_area=$1
    apath=`fsl_get_path_area $repo_area`
    if  [ -e $apath ];then
	cd $apath
	for f in *.fossil;do
	    project=`basename $f $REPOSEXT`
	    # add a -l switch to list the descriptions
................................................................................
    else
	echo $apath not found for repo $repo_area
    fi
}

# Do a human readable listing of the areas (if no area name provided)
# or list the repos if the area name is provided
function fsl_ls {
    repo_area=$1
    if [ ! -e ~/.fsl ];then
	fsl_dbinit
    fi
    case "x$repo_area" in ("x") 
	fsl_list_areas
	exit
................................................................................
}

#======================================================================
# R E P O   C O M M A N D S 
#======================================================================

# Given a repo name find the first repo by that name by searching the areas
function fsl_find_repo {
    repo_name=$1
    repo_area=NOSUCHREPOEVERFOUND
    for p in `fsl_get_area_paths`; do
	if [ -e $p/$repo_name.fossil ];then
	    repo_path=$p
	    repo_area=`fsl_get_area_from_path $repo_path`
	    break
................................................................................
    done
    echo "$repo_area"
}

# Given a repo area and name get a repo. If called with only one parameter
# it treats that parameter as a repo name and searches for it in all the areas
# and if found gets that repo
function fsl_repo_get {
    repo_area=$1
    repo_name=$2
    
    # if repo_name is not defined then repo_area is taken as name and
    # the first matching repo is found by looking in each area in order
    if [ "x$repo_name" = "x" ];then
	echo "WARNING: no area provided, searching for first repo by name \"$repo_area\""
................................................................................
    	mkdir -p $repo_name/.fossil
	password=`fsl_random_string`
	# add self to central fossil if not already there
	if ! $FOSSILEXE user list -R $fossil | grep ^$USER;then
	    $FOSSILEXE user new $USER $USER $password -R $fossil
	fi
	localfossil=$repo_name/.fossil/$repo_name.fossil
	$FOSSILEXE clone $fossil $localfossil
	# add self to local fossil if not already there
	if ! $FOSSILEXE user list -R $localfossil | grep ^$USER;then
	    $FOSSILEXE user new $USER $USER $password -R $localfossil
	fi
	# work around the default user bug
	curr_default_user=`$SQLITE3 $localfossil "select login from user limit 1;"`
	if [ "$curr_default_user" != "$USER" ];then
	    my_user_uid=`$SQLITE3 $localfossil "select uid from user where login='$USER';"`
	    echo "Swap userid $my_user_uid with 1"
	    $SQLITE3 $localfossil <<EOF
UPDATE user SET login='tmp_user_name' WHERE uid=$my_user_uid;
UPDATE user SET login='$USER' WHERE uid=1;
UPDATE user SET login='$curr_default_user' WHERE uid=$my_user_uid;
EOF
	fi
	(cd $repo_name;$FOSSILEXE open .fossil/$repo_name.fossil)
    else
        echo "ERROR: $fossil not found"
	exit 1
    fi
    # unset -x
}

# Create a new repo by repo_name in area specified repo_area
function fsl_repo_create {
    repo_area=$1
    repo_name=$2

    path=`fsl_get_path_area $repo_area`
    fossil="$path/$repo_name.fossil"

    if [ -e $fossil ];then
	echo "ERROR: $repo_name in $repo_area already exists"
	exit
    fi

    $FOSSILEXE init $fossil
    # assume groups are used for access control
    chmod ug+rw $fossil
    $FOSSILEXE set allow-symlinks 1 -R $fossil

    # BUG: convert this to a case and check for unrecognised switches
    if [ "x$3" = "x-template" ];then
	template=$4
................................................................................
	    echo "ERROR: You must specify the template using area/fossil_name format."
	    exit 1
	fi
    fi
}

# Import an existing repo into an area
function fsl_repo_import {
    repo_area=$1
    repo_name=$2
    src_repo=$3
    
    path=`fsl_get_path_area $repo_area`
    fossil="$path/$repo_name.fossil"

................................................................................
#======================================================================
# M O V E   F I X E S
#======================================================================

fsl_force=0

#======================================================================
# file to dir or file to file

# src must be a file and dest must be a directory or a filename in a
# directory that already exists
#======================================================================
function fsl_file_to_any_move {
    src_path=$1
    dest_path=$2
    if [ ! -e $src_path ];then
	echo "ERROR: source path \"$src_path\" does not exist"
    else
        cmd="$FOSSILEXE mv $src_path $dest_path"
	echo $cmd
................................................................................
	    echo $cmd
	    $cmd
	fi
    fi
}

#======================================================================
# dir to existant dir move
#======================================================================
function fsl_dir_to_dir {
    src_path=$1
    dest_path=$2
    files=`cd ${src_path};find . -type f -type l`

    for f in $files;do
	cmd="$FOSSILEXE mv $src_path/$f $dest_path/$f"
	# echo $cmd
	$cmd
	if [ "$fsl_force" != "0" ];then
	    targ_dir=`dirname $dest_path/$f`
	    mkdir -p $targ_dir
	    cmd="mv $src_path/$f $dest_path/$f"
	    # echo $cmd
	    $cmd
	fi
    done
}

function fsl_mv {
    all_paths=($@)
    targ_path_num=`expr ${#all_paths[*]} - 1`
    last_path_num=`expr $targ_path_num - 1`
    targ_path=${all_paths[$targ_path_num]}
    # echo "targ_path_num: $targ_path_num, last_path_num: $last_path_num, targ_path: $targ_path"
    for i in $(seq 0 1 $last_path_num);do
	src_path=${all_paths[$i]}
	# echo "Processing source path $src_path to target $targ_path"
	if [ -d "$src_path" ];then
	    fsl_dir_to_dir $src_path $targ_path
	else
	    fsl_file_to_any_move $src_path $targ_path
	fi
    done
}

#======================================================================
#  M I S C   T W E A K S 
#======================================================================







#======================================================================

# The main handler and processing
#======================================================================

# repo commands
case "x$1" in ("xrepo")
    fsl_dbinit
    case "x$2" in 
	xhelp)
	fsl_help
	exit
	;;
	
        # repo get
	xget)
	hook_pre_repo_get $*
	fsl_repo_get $3 $4
	hook_post_repo_get $*
	exit
	;;

	xaddarea)
	fsl_add_area $3 $4
	exit
	;;
................................................................................
	fsl_dbinit
	exit
	;;

	xls|xlist)
	shift
	shift
	fsl_ls $*
	exit
	;;

	xcreate)
	hook_pre_repo_create
	fsl_repo_create $3 $4 $5 $6
	hook_post_repo_create
................................................................................
	*)
	fsl_help
	exit
    esac
    ;;

    "xmv")
    # echo '$2'=$2
    if [ "x$2" = "x-f" ];then
	# echo "Force mode"
	fsl_force=1
	shift
	shift
        # change this to exec when happy!
        # fsl mv -f f1 [f2 f3...] targ
................................................................................
	# echo $@  -> echo $@
        # use $# variable to print out
        # number of arguments passed to the bash script
	# echo Number of arguments passed: $#  -> echo Number of arguments passed: $#
	exit
    else
        # echo No force

	fsl_mv "$@"
	exit
    fi
    ;;

    "xtimeline")
    shift
    $FOSSILEXE timeline $* | sed -e :a -e '$!N;s/\n         / /;ta' -e 'P;D'
    exit
    ;;

    # leaves output needs to be niceified, no need for a function
    "xleaves")
    shift
    $FOSSILEXE leaves $* | sed -e :a -e '$!N;s/\n         / /;ta' -e 'P;D'
    exit
    ;;






































    # add mention of repo to help
    xhelp)
    if [ $# -gt 1 ]; then
       case "x$2" in 
          xrepo)
          fsl_help
          exit
          ;;
          
          *)
          $FOSSILEXE $*
	  ;;

       esac
    else
       $FOSSILEXE help | sed -e 's/sync/sync        repo/'
    fi
    exit
    ;;

esac	

fsl_fork_find
exec $FOSSILEXE "$@"