Eskil

Check-in [2fe5c1905a]
Login

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

Overview
Comment:Use fossil ls -r if available.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 2fe5c1905aaea31eff06bad504778abb711fe432
User & Date: peter 2015-03-13 22:43:35.152
Context
2015-03-15
21:16
Extended Mercurial support to commit, revert, log and directory diff. check-in: 89f6168b65 user: peter tags: trunk
2015-03-13
22:43
Use fossil ls -r if available. check-in: 2fe5c1905a user: peter tags: trunk
22:42
Handle errors when mounting a vfs check-in: 9ea8f69db2 user: peter tags: trunk
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/vcsvfs.tcl.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#----------------------------------------------------------------------
#  Virtual File System for Version Control Systems
#
#  Copyright (c) 2014, Peter Spjuth
#
#  License for vcsvfs package: Same as for Tcl
#----------------------------------------------------------------------

package require vfs
package provide vcsvfs 0.1

namespace eval vcsvfs {
    variable DataRefChan
    variable mpoints {}
    namespace eval fossil {}
    namespace eval svn {}
    namespace eval git {}



|





|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#----------------------------------------------------------------------
#  Virtual File System for Version Control Systems
#
#  Copyright (c) 2014-2015, Peter Spjuth
#
#  License for vcsvfs package: Same as for Tcl
#----------------------------------------------------------------------

package require vfs
package provide vcsvfs 0.2

namespace eval vcsvfs {
    variable DataRefChan
    variable mpoints {}
    namespace eval fossil {}
    namespace eval svn {}
    namespace eval git {}
38
39
40
41
42
43
44
45


46
47
48
49
50
51
52
    regexp -line {local-root:\s*(\S.*)} $info -> root
    set root [file normalize $root]
    cd $root

    # Getting files via manifest artifact
    # This is a quick and robust way to get the file tree and each file's sha
    # Other info is trickier and is handled below
    set artifact [exec fossil artifact $rev]


    set commitTime 0
    set cTime now
    set finfo {}
    set todo [split $artifact \n]
    while {[llength $todo] > 0} {
        set line [lindex $todo 0]
        set todo [lrange $todo 1 end]







|
>
>







38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
    regexp -line {local-root:\s*(\S.*)} $info -> root
    set root [file normalize $root]
    cd $root

    # Getting files via manifest artifact
    # This is a quick and robust way to get the file tree and each file's sha
    # Other info is trickier and is handled below
    if {[catch {exec fossil artifact $rev} artifact]} {
        return -code error "No such fossil revision: $rev"
    }
    set commitTime 0
    set cTime now
    set finfo {}
    set todo [split $artifact \n]
    while {[llength $todo] > 0} {
        set line [lindex $todo 0]
        set todo [lrange $todo 1 end]
84
85
86
87
88
89
90













91
92
93
94
95
96
97
98
99
100
101
102
                dict set finfo $parentStr isfile 0
                dict set finfo $parentStr isdir 1
                dict set finfo $parentStr type directory
                set parentStr [file join $parentStr $dirPath]
            }
        }
    }














    # Getting files via http fileage to aquire file times
    # Since dates are parsed from the age string they are rather imprecise
    # Use a while around it to be able to break free easily (faking goto)
    while 1 {
        set html [exec fossil http << "GET /fileage?name=$rev"]
        if {![regexp {Files in.*} $html html]} {
            # Not the expected format of response, skip
            break
        }
        if {![regexp {\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}} $html cTime2]} {
            # Not the expected format of response, skip







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




|







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
                dict set finfo $parentStr isfile 0
                dict set finfo $parentStr isdir 1
                dict set finfo $parentStr type directory
                set parentStr [file join $parentStr $dirPath]
            }
        }
    }
    # Try to use "fossil ls -r, available in newer versions"
    set doneCollecting 0
    if {![catch {exec fossil ls -r $rev -v} lsdata]} {
        set lsdata [string trim $lsdata \n]
        foreach line [split $lsdata \n] {
            # Expected format in a line:
            # 2012-08-21 20:38:19  4563  tests/rev.test
            regexp {(\S+ \S+)\s+(\d+)\s+(.+)} $line -> fDate fSize fName
            dict set finfo $fName mtimestr $fDate
            dict set finfo $fName size $fSize
        }
        set doneCollecting 1
    }

    # Getting files via http fileage to aquire file times
    # Since dates are parsed from the age string they are rather imprecise
    # Use a while around it to be able to break free easily (faking goto)
    while {!$doneCollecting} {
        set html [exec fossil http << "GET /fileage?name=$rev"]
        if {![regexp {Files in.*} $html html]} {
            # Not the expected format of response, skip
            break
        }
        if {![regexp {\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}} $html cTime2]} {
            # Not the expected format of response, skip
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

    # As another step, get current file stamps from fossil ls.
    # Since ls show current checkout they might not be valid for the rev
    # being looked at. However if they are still present and older than the
    # ones from fileage they are likely correct.
    # Also, fileage and ls uses different criteria for which commit defines
    # the age (across merges), so things basically will be a best effort guess.

    set allfiles [exec fossil ls --age .]
    foreach line [split $allfiles \n] {
        # Expected format in a line:
        # 2012-08-21 20:38:19  tests/rev.test
        regexp {(\S+ \S+)\s+(.+)} $line -> fDate fName
        set mTime [clock scan $fDate -gmt 1]
        if {[dict exists $finfo $fName mtime]} {
            set x [dict get $finfo $fName mtime]
            set e [dict get $finfo $fName errX]
            if {$mTime < $x} {
                dict set finfo $fName mtime $mTime
            } elseif {abs($mTime - $x) < 3600} {
                #puts "$fName   age $x   ls $mTime  diff [expr {$mTime - $x}]  err $e"

            }
        }
    }

    cd $oldpwd

    # Generate a mount point.







>
|
|
|
|
|
|
|
|
|
|
|
|
|
>







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

    # As another step, get current file stamps from fossil ls.
    # Since ls show current checkout they might not be valid for the rev
    # being looked at. However if they are still present and older than the
    # ones from fileage they are likely correct.
    # Also, fileage and ls uses different criteria for which commit defines
    # the age (across merges), so things basically will be a best effort guess.
    if {!$doneCollecting} {
        set allfiles [exec fossil ls --age .]
        foreach line [split $allfiles \n] {
            # Expected format in a line:
            # 2012-08-21 20:38:19  tests/rev.test
            regexp {(\S+ \S+)\s+(.+)} $line -> fDate fName
            set mTime [clock scan $fDate -gmt 1]
            if {[dict exists $finfo $fName mtime]} {
                set x [dict get $finfo $fName mtime]
                set e [dict get $finfo $fName errX]
                if {$mTime < $x} {
                    dict set finfo $fName mtime $mTime
                } elseif {abs($mTime - $x) < 3600} {
                    #puts "$fName   age $x   ls $mTime  diff [expr {$mTime - $x}]  err $e"
                }
            }
        }
    }

    cd $oldpwd

    # Generate a mount point.