fsl wrapper

Check-in [d7717768f9]
Login

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

Overview
Comment:Setting up for new fslutil
Timelines: family | ancestors | trunk
Files: files | file ages | folders
SHA1:d7717768f988ee79ccd9f3825ffc5bafb600a8a6
User & Date: mrwellan 2013-03-30 23:41:14
Context
2013-03-30
23:41
Setting up for new fslutil Leaf check-in: d7717768f9 user: mrwellan tags: trunk
2013-03-29
06:32
Added new files for utils check-in: 33f9807c72 user: matt tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to TODO.



1

2




Exit code preservation and handling
>
>

>

1
2
3
4
5
TODO
====

Support areas via ssh
Exit code preservation and handling

Changes to scripts/.fslconfig.

1







fsl repo addarea misc ~/fossils








>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
fsl repo addarea misc ~/fossils

# set default of allow-symlinks as a global setting
if fossil set | grep allow-symlinks | grep 1 > /dev/null; then
   echo allow-symlinks already set
else
   fossil set allow-symlinks 1 -global
fi

Added scripts/.fslcustom.template.









>
>
>
>
1
2
3
4
unset LD_LIBRARY_PATH

# 

Changes to scripts/fsl.

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
..
86
87
88
89
90
91
92

































93
94
95
96
97
98
99
...
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
...
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
...
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
...
262
263
264
265
266
267
268











269
270
271
272
273
274
275
...
423
424
425
426
427
428
429















430
431
432
433



434
435
436
437
438
439
440

# set -e
# set -u
# set -x

configdir=`dirname $0`
export REPOSEXT=.fossil
# unset LD_LIBRARY_PATH # put this in $configdir/.fslcustom

# res=$(echo $sql_cmd | sqlite -init "" example.db)

# Bias toward using /usr/bin/sqlite3
export SQLITE3EXE=`which sqlite3`
if [ -e $SQLITE3EXE ]; then
    export SQLITE3="$SQLITE3EXE -init ''"
else
    export SQLITE3="$SQLITE3EXE -init ''"
fi

# Set a envvar to use for accessing the fossil binary
# use this to override if necessary but in the usage and
# help fossil reports the full path and it is a little ugly
export FOSSILEXE=fossil







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

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

# 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 () {
................................................................................
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
................................................................................
	    project=`basename $f $REPOSEXT`
	    # add a -l switch to list the descriptions
	    # description=`sqlite3 $f "select value from config where name='project-description';"`
	    # echo $f |cut -f1 -d.
	    # echo "$project	$description"
	    echo $project
	done
    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 () {
................................................................................
    [ -n $repo_area ] && fsl_list_repos_in_area $repo_area
}

#======================================================================
# 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
	fi
    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\""
	repo_name=$repo_area
	repo_area=`fsl_find_repo $repo_name`
	if [ "x$repo_area" = "x" ];then
	    echo "ERROR: No such repo found in any area \"$repo_name\""
	    exit 1
	fi
	echo "NOTE: using repo $repo_name found in $repo_area"
    fi
    path=`fsl_get_path_area $repo_area`
    fossil="$path/$repo_name.fossil"
    # set -x
    if [ -e $fossil ];then 
	if [ -e $repo_name ];then
	    echo "ERROR: $repo_name directory or file already exists"
................................................................................
	    $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
}

................................................................................
    forks=`echo "SELECT tagxref.value FROM leaf, tagxref WHERE leaf.rid=tagxref.rid and tagxref.value != '' and srcid != 0 group by tagxref.value having count(tagxref.value) > 1;"|$FOSSILEXE sql`
    if [ "x$forks" != "x" ]; then
        echo
        echo "WARNING!!! Fork detected on $forks, use \"fsl leaves\" and \"fsl merge\" to find and correct."
        echo
    fi
}
















#======================================================================
# 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 
    # repo
    xrep*)
    fsl_dbinit
    case "x$2" in 







<
<
<













>
>
>
>
>
>







 







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







 







|







 







|







 







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









|
|
|
<
<
<
|
<
<







 







>
>
>
>
>
>
>
>
>
>
>







 







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




>
>
>







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
..
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
...
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
...
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
...
233
234
235
236
237
238
239














240
241
242
243
244
245
246
247
248
249
250
251



252


253
254
255
256
257
258
259
...
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
...
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486

# set -e
# set -u
# set -x

configdir=`dirname $0`
export REPOSEXT=.fossil




# Bias toward using /usr/bin/sqlite3
export SQLITE3EXE=`which sqlite3`
if [ -e $SQLITE3EXE ]; then
    export SQLITE3="$SQLITE3EXE -init ''"
else
    export SQLITE3="$SQLITE3EXE -init ''"
fi

# Set a envvar to use for accessing the fossil binary
# use this to override if necessary but in the usage and
# help fossil reports the full path and it is a little ugly
export FOSSILEXE=fossil

# ACCESS_METHOD defaults to local for filesystem direct access and
# ssh for access via ssh (url constructed from calculate_url function
# taking area and fossilname as params
#
export ACCESS_METHOD=local

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

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

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

# Return an ssh or html compatible URL given area and fossil
# calculate_url /path/area/name.fossil ssh_host =>
#    ssh://$REMOTEHOST///path/area/name.fossil?
# 
function fsl_calculate_url () {
    full_foss_name=$1
    ssh_host=$2
    remote_fossil=$3
    # ssh://localhost:22///areapath/fossilname.fossil?fossil=/path/to/exe/fossil
    repo_area=`fsl_get_path_area $repo_area`
    if [ $ACCESS_METHOD == ssh ]; then
	echo "ssh://$ssh_host///$full_foss_name?fossil=$remote_fossil"
    else
	echo $full_foss_name
    fi
}

# 
# touch the flag file to trigger sync to official
#
function fsl_touch_flag () {
   repo_path=$1
   repo_name=$2
   if [ "x$SSH_CACHE_FLAG" != "x" ];then
      flag_dir="$SSH_CACHE_FLAG$repo_path"
      # Attempt to create the flag dir if it doesn't exist
      if ! [ -e $flag_dir ];then
         mkdir -p $flag_dir
      fi
      touch "$flag_dir/$repo_name.flag"
   fi
}

#======================================================================
# 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 () {
................................................................................
DELETE FROM fsl_repos WHERE area='$repo_area';
EOF
}

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

# Get all repo paths in natural order
................................................................................
	    project=`basename $f $REPOSEXT`
	    # add a -l switch to list the descriptions
	    # description=`sqlite3 $f "select value from config where name='project-description';"`
	    # echo $f |cut -f1 -d.
	    # echo "$project	$description"
	    echo $project
	done
    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 () {
................................................................................
    [ -n $repo_area ] && fsl_list_repos_in_area $repo_area
}

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















# 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_area" == "x" ] || [ "x$repo_name" == "x" ];then
	echo "ERROR: repo area and name must be provided"
        echo



	exit 1


    fi
    path=`fsl_get_path_area $repo_area`
    fossil="$path/$repo_name.fossil"
    # set -x
    if [ -e $fossil ];then 
	if [ -e $repo_name ];then
	    echo "ERROR: $repo_name directory or file already exists"
................................................................................
	    $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 $?
	# If we have defined SSH_CACHE_HOST and SSH_CACHE_BASE then we can 
	# sync to the cache
        if [ "x$SSH_CACHE_HOST" != "x" ];then # we have a cache
	   if [ "x$SSH_CACHE_BASE" == "x" ];then
	      echo "ERROR: SSH_CACHE_BASE must be set in your .fslcustom file"
           else
	      # ssh://localhost:22///tmp/var.tmp/foundry_fossil_cache/fdk/testing.fossil'
              (cd $repo_name;$FOSSILEXE sync "ssh://$SSH_CACHE_HOST//$SSH_CACHE_BASE/$repo_area/$repo_name.fossil")
              fsl_touch_flag $path $repo_name
           fi
        fi
    else
        echo "ERROR: $fossil not found"
	exit 1
    fi
    # unset -x
}

................................................................................
    forks=`echo "SELECT tagxref.value FROM leaf, tagxref WHERE leaf.rid=tagxref.rid and tagxref.value != '' and srcid != 0 group by tagxref.value having count(tagxref.value) > 1;"|$FOSSILEXE sql`
    if [ "x$forks" != "x" ]; then
        echo
        echo "WARNING!!! Fork detected on $forks, use \"fsl leaves\" and \"fsl merge\" to find and correct."
        echo
    fi
}

function fsl_url_check {
    fsl_check_out_status=`$FOSSILEXE status 2>&1 | grep "not within an open checkout"`
    if [ "x$fsl_check_out_status" != "x" ]; then
      return
    fi
    fsl_url=`$FOSSILEXE remote-url | grep 'FIXME_CHANGE_TO_A_VARIABLE`
    if [ "x$fsl_url" == "x" ]; then
        echo
        echo "WARNING WARNING WARNING!!! "
        echo " you may not be in a fossil repo area or fossil remote-url is not set to current known repository path"
        echo " use \"fsl remote-url $proj_tools_area\" and / or call support for help to correct."
        echo
    fi
}

#======================================================================
# 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 
#======================================================================

# fsl_url_check
fsl_dbinit

# repo commands
case "x$1" in 
    # repo
    xrep*)
    fsl_dbinit
    case "x$2" in 

Changes to src/Makefile.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

TARG = 
PREFIX = .

include makefile.mk

# Take out envgui.scm for now
SRCFILES = db.scm  envsetup.scm  fossil.scm  fslmgr.scm  gowork.scm  setup$(TARG).scm
OFILES = $(SRCFILES:%.scm=%.o)

%.o : %.scm
	csc -c $<

fsl$(TARG) : $(OFILES) 
	csc $(OFILES) -o fsl$(TARG)




|


|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

TARG = 
PREFIX = .

# include makefile.mk

# Take out envgui.scm for now
SRCFILES = db.scm fossil.scm  fslmgr.scm
OFILES = $(SRCFILES:%.scm=%.o)

%.o : %.scm
	csc -c $<

fsl$(TARG) : $(OFILES) 
	csc $(OFILES) -o fsl$(TARG)