This file is indexed.

/usr/share/tcltk/vfs1.3/template/versionvfs.tcl is in tcl-vfs 1.3-20080503-4.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
 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
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
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
189
190
191
192
193
194
195
196
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
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
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
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
444
445
446
447
448
449
450
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
487
488
489
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
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
if 0 {
########################

versionvfs.tcl --

Written by Stephen Huntley (stephen.huntley@alum.mit.edu)
License: Tcl license
Version 1.5.2

A versioning virtual filesystem.  Requires the template vfs in templatevfs.tcl.

Similar to historical versioning filesystems, each edited version of a file is saved separately;
each version file is tagged with a timestamp, and optional project tags.
A deleted file is represented by a new zero-length file with timestamp and a tag reading "deleted".
By default only the latest version is visible.  If the latest version is marked deleted, it is invisible.

Directories are versioned and tagged in the same way as files.

Older versions can be retrieved by setting the -project and -time values appropriately.


Usage: mount ?-keep <number> -project <list of tags> -time <timestamp or "clock scan" suitable phrase>? <existing directory> <virtual directory>

Options:

-keep
maximum number of previous versions of a file to keep per project.

-project
a list of one or more version-identifying tags.  Any file created or edited in the virtual file space
will be given these tags.  File versions with a tag matching the ones given here will be visible in 
preference to other, possibly later versions without the tag.

If a file version has project tags but none of them is included in this project tag list, it will be 
invisible; the file itself will then be invisible unless a file version exists without any 
project tags, in which case it will be treated as the default.

In cases where several file versions each have multiple tags that match in the project
list, the version with the greatest number of matches will be visible.

Deleted files are marked with the tag "deleted".  If this value is in the project
name list, then deleted files will become visible again.

Newly-created and deleted directories are tagged and shown/hidden in the same way as files.

-time
A timestamp in the form returned by [clock seconds], or a string understandable by [clock scan].
Versions of files as they existed at the given time will be visible, rather than the
default latest version.  Version choices based on project tags will still be made, but
versions later than the timestamp will be ignored in the decision process.


The values of each option can be changed dynamically after mount by using the "file attributes" 
command on the mount virtual directory. Each option is editable as an attribute; 
i.e., "file attributes C:/version -project {version2 release}".  Display of visible files will 
change dynamically based on decisions with new attribute values.

In addition, new attributes are defined which can be queried for individual files:  

The command "file attributes $file -version_filename" will show the exact filename of the 
currently visible version of the given file as it is stored in the vfs, complete with 
timestamp and project tags if any.

The command "file attributes $file -versions" will return a list containing information on
all stored versions of the given file.  Each element of the list is itself a three-element 
list: 1) the unique millisecond-level timestamp of the version, 2) a human-readable date string
showing the time represented by the timestamp (can be used a a value for the -time attribute), 
and 3) a list of the project tags attached to the version, if any.

The versioning vfs inherits the -cache and -volume options of the template vfs.

########################
}

package require vfs::template 1.5

package require fileutil::globfind

namespace eval ::vfs::template::version {

# read template procedures into current namespace. Do not edit:
foreach templateProc [namespace eval ::vfs::template {info procs}] {
	set infoArgs [info args ::vfs::template::$templateProc]
	set infoBody [info body ::vfs::template::$templateProc]
	proc $templateProc $infoArgs $infoBody
}

# edit following procedures:
proc close_ {channelID} {
	upvar path path root root relative relative

# get hash of file as it existed before edit:
	array set fileStats $::vfs::template::version::filestats($channelID)
	unset ::vfs::template::version::filestats($channelID)

# if new hash shows file is unchanged, return immediately:
	fconfigure $channelID -translation binary
	set hash [Hash $channelID]
	if [string equal -nocase $hash $fileStats(hash)] {return}

# create new unique filename for new version:
	set fileName [VFileNameEncode [file join $path $relative]]\;[VCreateTag $root]
	catch {array set oldAttributes [file attributes $fileStats(filename)]}

# delete file version created by open_ if it's a new file:
	if [string equal $fileStats(hash) {}] {
		file delete -- $fileStats(filename)
	}

# save new version:
	set f [open $fileName w]
	fconfigure $f -translation binary
	seek $channelID 0
	fcopy $channelID $f
	close $f

# ensure attributes are the same for new version:
	foreach {attr value} [file attributes $fileName] {
		if ![info exists oldAttributes($attr)] {continue}
		if {$oldAttributes($attr) != $value} {catch {file attributes $fileName $attr $oldAttributes($attr)}}
	}

	return
}
proc file_atime {file time} {	
	upvar path path root root relative relative
# check if current version is latest, if not disallow edit:
	set latest [lindex [lindex [lsort [VersionsAll $path $relative]] end] 0]
	set acquired [lindex [split [set fileName [VAcquireFile $path $root $relative]] \;] 1]
	if ![string first .&dir [file tail $fileName]] {::vfs::filesystem posixerror $::vfs::posix(ENOENT)}
	if {($acquired != {}) && ($latest != $acquired)} {::vfs::filesystem posixerror $::vfs::posix(EPERM)}

	file atime $fileName $time
}
proc file_mtime {file time} {
	upvar path path root root relative relative
# check if current version is latest, if not disallow edit:
	set latest [lindex [lindex [lsort [VersionsAll $path $relative]] end] 0]
	set acquired [lindex [split [set fileName [VAcquireFile $path $root $relative]] \;] 1]
	if ![string first .&dir [file tail $fileName]] {::vfs::filesystem posixerror $::vfs::posix(ENOENT)}
	if {($acquired != {}) && ($latest != $acquired)} {::vfs::filesystem posixerror $::vfs::posix(EPERM)}

	file mtime $fileName $time
}
proc file_attributes {file {attribute {}} args} {
	upvar path path root root relative relative
	set latest [lindex [lindex [lsort [set allVersions [VersionsAll $path $relative]]] end] 0]
	set acquired [lindex [split [set fileName [VAcquireFile $path $root $relative]] \;] 1]
	if ![string first .&dir [file tail $fileName]] {::vfs::filesystem posixerror $::vfs::posix(ENOENT)}
# process vfs-specific attributes:
	if {($relative == {}) && ([string map {-keep 1 -project 1 -time 1} $attribute] == 1)} {
		set attribute [string range $attribute 1 end]
		if {$args == {}} {
			if ![info exists ::vfs::template::version::${attribute}($root)] {return}
			eval return \$::vfs::template::version::${attribute}(\$root)
		}
		set ::vfs::template::version::${attribute}($root) [lindex $args 0]
		if {[lindex $args 0] == {}} {unset ::vfs::template::version::${attribute}($root)}
		return
	}
	# process read-only vfs-specific attributes:
	if {$attribute == "-versions"} {
		if {$args == {}} {return $allVersions}
		error "cannot set attribute \"-versions\" for file \"[file tail $relative]\": attribute is readonly"
	}
	if {$attribute == "-version_filename"} {
		if {$args == {}} {return [file tail $fileName]}
		error "cannot set attribute \"-version_filename\" for file \"[file tail $relative]\": attribute is readonly"
	}
# check if current version is latest, if not disallow edit:
	if {($args != {}) && ($acquired != {}) && ($latest != $acquired)} {::vfs::filesystem posixerror $::vfs::posix(EPERM)}
	set returnValue [eval file attributes \$fileName $attribute $args]
# collect values for vfs-specific attributes:
	if {$attribute == {}} {
		append returnValue " [list -versions $allVersions]"
		if {$file != $fileName} {append returnValue " [list -version_filename [file tail $fileName]]"}
		if {$relative != {}} {return $returnValue}
		foreach atr "keep project time" {
			set $atr "-$atr {}"
			if [info exists ::vfs::template::version::${atr}($root)] {eval set $atr \[list "-$atr" \$::vfs::template::version::${atr}(\$root)\]}
		}
		append returnValue " $keep $project $time"
	}
	return $returnValue
}

proc file_delete {file} {
	upvar path path root root relative relative
	set dir 0

# make sure subfiles of directory are deleted:
	if [file isdirectory $file] {
		set subfiles [globfind $file]
		set subfiles [lsort -decreasing $subfiles]
		set deleted {}
		foreach sf $subfiles {
			if [file isdirectory $sf] {continue}
			globdelete $sf
		}
		set dir 1
		return
	}
	set fileName [VAcquireFile $path $root $relative]

# allow straight deletion of new zero-length file:
	if {!$dir && ([llength [VersionsAll $path $relative]] == 1) && ![file size $fileName]} {
		file delete -force -- $fileName
		return
	}

# for all others, create new file with "deleted" tag
	set file [VFileNameEncode $file]
	set fileName $file\;[VCreateTag $root]
	if $dir {set fileName [file join $file .&dir[file tail $file]]\;[VCreateTag $root]}
	set fileName [split $fileName \;]
	set fileName [linsert $fileName 2 "deleted"]
	set fileName [join $fileName \;]
	close [open $fileName w]
	if $dir {catch {file attributes $fileName -hidden 1}}
}
proc file_executable {file} {
	upvar path path root root relative relative
	set fileName [VAcquireFile $path $root $relative]
	if ![string first .&dir [file tail $fileName]] {return 0}
	file executable $fileName
}
proc file_exists {file} {
	upvar path path root root relative relative
	set fileName [VAcquireFile $path $root $relative]
	if ![string first .&dir [file tail $fileName]] {return 0}
	if [file isdirectory $fileName] {return 1}
	expr ![string equal [file join $path $relative] $fileName]
}
proc file_mkdir {file} {
	upvar root root
	file mkdir $file

# create a file to store timestamps and tags for directory:
	set fileName [VFileNameEncode $file]
	set fileName [file join $fileName .&dir[file tail $fileName]]\;[VCreateTag $root]
	close [open $fileName w]
	catch {file attributes $fileName -hidden 1}
	return
}
proc file_readable {file} {
	upvar path path root root relative relative
	set fileName [VAcquireFile $path $root $relative]
	if ![string first .&dir [file tail $fileName]] {return 0}
	file readable $fileName
}
proc file_stat {file array} {
	upvar path path root root relative relative $array fs
	set fileName [VAcquireFile $path $root $relative]
	if ![string first .&dir [file tail $fileName]] {error "no such file or directory"}
	file stat $fileName fs
	if {$fs(type) == "directory"} {
		return
	}
	if {$fileName == [file join $path $relative]} {error "no such file or directory"}
	return
}
proc file_writable {file} {
	upvar path path root root relative relative
	set fileName [VAcquireFile $path $root $relative]
	if ![string first .&dir [file tail $fileName]] {return 0}
	file writable $fileName
}
proc glob_ {directory dir nocomplain tails types typeString dashes pattern} {
	upvar path path root root relative relative
	set globList [glob -directory $dir -nocomplain -types $typeString *]
	set newGlobList {}
	set acquireAttempts {}
	foreach gL $globList {
		if [file isdirectory $gL] {
			set acquiredFile [VAcquireFile $path $root [file join $relative [file tail $gL]]]
			if ![string equal $acquiredFile $gL] {continue}
		} else {
			if ![string first .&dir [file tail $gL]] {continue}
			set gL [VFileNameDecode $gL]
			if {[lsearch $acquireAttempts $gL] > -1} {continue}
			lappend acquireAttempts $gL
			set acquiredFile [VAcquireFile $path $root [file join $relative [file tail $gL]]]
			if [string equal $acquiredFile $gL] {continue}
		}
		if [string match $pattern [file tail $gL]] {lappend newGlobList [file tail $gL]}
	}
	return $newGlobList
}
proc open_ {file mode} {
	upvar path path root root relative relative 
	set fileName [VAcquireFile $path $root $relative]
	if {$mode == "r"} {return [open $fileName r]}
	set hash {}

# Use memchans so if file contents don't change we are free to delete file rather than commit to
# creating new version which is identical to last.
# If file is new, create new tag for it and return memchan:
	if {$fileName == [file join $path $relative]} {
		set fileName [VFileNameEncode [file join $path $relative]]\;[VCreateTag $root]
		close [open $fileName $mode]
		set channelID [memchan]
		set ::vfs::template::version::filestats($channelID) "filename [list $fileName] hash [list $hash]"
		return $channelID
	}

# otherwise, get hash of existing file and store it where close callback can grab it,
# then return memchan:
	set f [open $fileName r]
	fconfigure $f -translation binary
	set hash [Hash $f]
	close $f
	set filed [memchan]
	if {[string index $mode 0] == "a"} {
		set f [open $fileName r]
		fconfigure $f -translation binary
		fconfigure $filed -translation binary
		fcopy $f $filed
		close $f
		seek $filed 0
	}
	set fileStats(hash) $hash
	set fileStats(filename) $fileName
	set ::vfs::template::version::filestats($filed) [array get fileStats]
	return $filed
}


proc MountProcedure {args} {
	upvar volume volume

# take real and virtual directories from command line args.
	set to [lindex $args end]
	if [string equal $volume {}] {set to [::file normalize $to]}
	set path [::file normalize [lindex $args end-1]]

# make sure mount location exists:
	::file mkdir $path

# add custom handling for new vfs args here.

	namespace import -force ::fileutil::globfind::globfind

	set argsLength [llength $args]
	for {set i 0} {$i < $argsLength} {incr i} {
		switch -- [lindex $args $i] {
			-keep {
				set keep [lindex $args [incr i]]
				if ![string is digit -strict $keep] {continue}
				set ::vfs::template::version::keep($to) $keep
			}
			-project {
				set project [lindex $args [incr i]]
				set ::vfs::template::version::project($to) $project
			}
			-time {
				set time [lindex $args [incr i]]
				SetTime $time
				set ::vfs::template::version::time($to) $time
			}
		}
	}

	if [catch {glob -directory $path -type {f hidden} .&dir*}] {
		set root $to
		file_mkdir $path
	}


# return two-item list consisting of real and virtual locations.
	lappend pathto $path
	lappend pathto $to
	return $pathto
}


proc UnmountProcedure {path to} {
# add custom unmount handling of new vfs elements here.
	if [info exists ::vfs::template::version::keep($to)] {unset ::vfs::template::version::keep($to)}
	if [info exists ::vfs::template::version::project($to)] {unset ::vfs::template::version::project($to)}
	if [info exists ::vfs::template::version::time($to)] {unset ::vfs::template::version::time($to)}
	return
}

# utility proc called by file_delete for recursive deletion of dir contents:
proc globdelete {file} {
	upvar root root deleted deleted
	set file [file join [file dirname $file] [lindex [split [file tail $file] \;] 0]]
	if {[lsearch $deleted $file] > -1} {return}
	lappend deleted $file
	set fileName $file\;[VCreateTag $root]
	set fileName [split $fileName \;] 
	set fileName [linsert $fileName 2 "deleted"]
	set fileName [join $fileName \;]
	close [open $fileName w]
	if ![string first {.&} [file tail $fileName]] {catch {file attributes $fileName -hidden 1}}
}

# Can replace this proc with one that uses different hash function if preferred.
proc Hash {channel} {
	seek $channel 0
	if [catch {package present md5 2}] {package forget md5 ; package require md5 2}
	::md5::md5 -hex -- [read $channel]
}

# figure out if time is a string, milliseconds or seconds count, return seconds count
proc SetTime {time} {
	if ![string is digit -strict $time] {catch {set time [clock scan $time]}}
	if ![string is digit -strict $time] {error "invalid time value."}
	set time "[string range $time 0 [expr [string length [clock seconds]] - 1]]000"
}

# decide which version is preferred considering time and project settings:
proc VAcquireFile {path root relative {actualpath {}}} {
	set fileName [VFileNameEncode [file join $path $relative]]
	if [file isdirectory [file join $path $relative]] {
		set fileName [file join $fileName .&dir[file tail $fileName]]
		set relative [file join $relative .&dir[file tail $relative]]
	}

# grab all versions:
	set versions [glob -path $fileName -nocomplain -types f "\;*"]
	if [catch {::vfs::filesystem info $path}] {append versions " [glob -path $fileName -nocomplain -types "f hidden" "\;*"]"}

	set versions [string trim $versions]
	if {$versions == {}} {return [file join $path $relative]}

	set checkProject 0
	if [info exists ::vfs::template::version::project($root)] {
		set projects [string map {; &s} [string map {& &a} $::vfs::template::version::project($root)]]
		set checkProject 1
	}

# find versions that have current project tags to see if keep setting requires deleting any:
	foreach ver $versions {
		set ver $root/[file tail $ver]
		lappend versionFiles $ver
		if !$checkProject {continue}
		foreach project $projects {
			if {[lsearch [lrange [split $ver \;] 1 end] $project] > -1} {lappend projectFiles $ver}
		}
	}
	unset versions

# delete older versions if keep setting requires it:
	if ![catch {if {[llength $projectFiles] <= $::vfs::template::version::keep($root)} {error}}] {
		set keep $::vfs::template::version::keep($root)
		set projectFiles [lsort -decreasing -dictionary $projectFiles]
		set fileNumber [llength $projectFiles]
		for {set i [incr fileNumber -1]} {$i >= 0} {incr i -1} {
			if {[llength $projectFiles] <= $keep} {break}
			set delFile [file join [file dirname [file join $path $relative]] [file tail [lindex $projectFiles $i]]]
			if ![catch {file delete -- $delFile}] {set projectFiles [lreplace $projectFiles $i $i]}
		}
	}

# find version that's best match with time and project settings:
	set fileName [file tail [lindex [lsort -command VersionSort $versionFiles] 0]]

# if file version has "deleted" tag, return with no version info, indicating file doesn't exist:
	if !$checkProject {
		if {[lindex [split $fileName \;] 2] == "deleted"} {return [file join $path $relative]}
	}

# if project attribute is set, and version has project tags, ensure version belongs to one of the set projects,
# otherwise it will be invisible:
	if $checkProject {
		if {([lindex [split $fileName \;] 2] == "deleted") && ([lsearch $projects "deleted"] == -1)} {return [file join $path $relative]}
		set projectMember 0
		set tags [lrange [split $fileName \;] 1 end]
		if {[lindex $tags 1] == "deleted"} {set tags [lreplace $tags 1 1]}
		foreach project $projects {
				if {[lsearch $tags $project] > -1} {set projectMember 1}
		}
		set projectLength [llength $tags]
		if {($projectLength > 1) && !$projectMember} {return [file join $path $relative]}
	}

# if time tag value is before creation date of chosen version, make file invisible:
	if {[info exists ::vfs::template::version::time($root)] && ([lindex [split $fileName \;] 1] > "$::vfs::template::version::time($root)000")} {
		return [file join $path $relative]
	}

	if ![string first .&dir [file tail $relative]] {
		set fileName [file join $path [file dirname $relative]]
		return [file normalize $fileName]
	}
	return [file join [file dirname [file join $path $relative]] $fileName]
}

# create new version tag with millisecond-scale timestamp and curernt project tags:
proc VCreateTag {root} {
	set tag [clock seconds][string range [clock clicks -milliseconds] end-2 end]
	if [info exists ::vfs::template::version::project($root)] {
		set projects [string map {; &s} [string map {& &a} $::vfs::template::version::project($root)]]
		set projectTag [join $projects \;]
		set tag [join "$tag $projectTag" \;]
	}
	return $tag
}

# return info on all versions of a file:
proc VersionsAll {path relative} {
	set fileName [VFileNameEncode [file join $path $relative]]
	if [file isdirectory [file join $path $relative]] {
		set fileName [file join $fileName .&dir[file tail $fileName]]
		set relative [file join $relative .&dir[file tail $relative]]
	}
	set versions [glob -path $fileName -nocomplain -types f "\;*"]
	if [catch {::vfs::filesystem info $path}] {append versions " [glob -path $fileName -nocomplain -types "f hidden" "\;*"]"}

	set versions [string trim $versions]

	set newVersions {}
	foreach ver $versions {
		set ver [lrange [split $ver \;] 1 end]
		set ver [file tail [VFileNameDecode $ver]]
		set tag [lindex $ver 0]
		set time [string range $tag 0 end-3]
		set time [clock format $time -format "%Y%m%dT%H:%M:%S"]
		lappend newVersions "$tag $time [list [lrange $ver 1 end]]"
	}
	return $newVersions
}

# specialized command for lsort, decide which of two versions is preferred given 
# project and time settings:
proc VersionSort {element1 element2} {
	set root [file dirname $element1]
	set element1 [file tail $element1]
	set element2 [file tail $element2]
	if [string equal $element1 $element2] {return 0}
	set sorted [lsort -dictionary -decreasing "$element1 $element2"]

# decision 1: choose latest timestamp:
	if {[lindex $sorted 0] == $element1} {set returnValue -1}
	if {[lindex $sorted 0] == $element2} {set returnValue 1}

	set time1 [lindex [split $element1 \;] 1]
	set time2 [lindex [split $element2 \;] 1]
	set time $time1
	if {$time2 > $time1} {set time $time2}

# decision 2: if time setting exists, choose latest timestamp less than time setting:
	if [info exists ::vfs::template::version::time($root)] {
		set returnValue -1
		set time $::vfs::template::version::time($root)
		if {!([string is digit -strict $time] && ([string length $time] == [string length $time1]))} {
			set time [SetTime $::vfs::template::version::time($root)]
		}

		if {$time1 > $time} {set time1 [expr $time2 - 1]}
		if {($time2 <= $time) && ($time2 > $time1)} {set returnValue 1}
	}

# decision 3: choose version with greatest number of project tag matches with project setting:
	if [info exists ::vfs::template::version::project($root)] {
		set projects [string map {; &s} [string map {& &a} $::vfs::template::version::project($root)]]
		set project1 0
		set project2 0
		foreach project [lsort -unique $projects] {
			set sumproject1 [lsearch [lrange [split $element1 \;] 1 end] $project]
			set sumproject2 [lsearch [lrange [split $element2 \;] 1 end] $project]
			incr sumproject1 ; incr sumproject2
			if $sumproject1 {incr project1}
			if $sumproject2 {incr project2}
		}
		if {$project1 > $project2} {set project1 1 ; set project2 0}
		if {$project1 < $project2} {set project1 0 ; set project2 1}

		# don't count "deleted" as a project tag for purpose of choosing default:
		set tagEnd1 [lindex [split $element1 \;] 2]
		if {$tagEnd1 == "deleted"} {set tagEnd1 [lindex [split $element1 \;] 3]}
		set tagEnd2 [lindex [split $element2 \;] 2]
		if {$tagEnd2 == "deleted"} {set tagEnd2 [lindex [split $element2 \;] 3]}
	
		# set version with no project tags as default choice:
		if {($tagEnd1 == {}) && !($tagEnd2 == {})} {set returnValue -1}
		if {!($tagEnd1 == {}) && ($tagEnd2 == {})} {set returnValue 1}

		# if a project tag match exists, replace default choice with it:
		if {$project2 && !$project1 && ($time2 <= $time)} {set returnValue 1}
		if {$project1 && !$project2 && ($time1 <= $time)} {set returnValue -1}
	}
	return $returnValue
}

# ampersand and semicolon are privileged chars in tagging, 
# encode and decode filenames containing them:
proc VFileNameEncode {filename} {
	set filename [file dirname $filename]/[string map {& &a} [file tail $filename]]
	set filename [file dirname $filename]/[string map {; &s} [file tail $filename]]
}

proc VFileNameDecode {filename} {
	set filename [file dirname $filename]/[lindex [split [file tail $filename] \;] 0]
	set filename [file dirname $filename]/[string map {&s ;} [file tail $filename]]
	set filename [file dirname $filename]/[string map {&a &} [file tail $filename]]
}

}
# end namespace ::vfs::template::version