Eskil

Diff
Login

Differences From Artifact [ce76436a94]:

To Artifact [79a0da569f]:


1
2
3
4

5
6
7
8
9
10

11
12
13
14
15
16
17
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
#  Copyright (c) 2014-2016, Peter Spjuth
#
#  License for vcsvfs package: Same as for Tcl
#----------------------------------------------------------------------

package require vfs
package provide vcsvfs 0.2
package provide vcsvfs 0.3

namespace eval vcsvfs {
    variable DataRefChan
    variable mpoints {}
    namespace eval fossil {}
    namespace eval svn {}
    namespace eval git {}
748
749
750
751
752
753
754
755
756
757








758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773


774
775



776
777
778
779
780
781
782
748
749
750
751
752
753
754



755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780


781
782
783
784
785
786
787
788
789
790







-
-
-
+
+
+
+
+
+
+
+
















+
+
-
-
+
+
+







            # Read-only, always error
        }
    }
    vfs::filesystem posixerror $::vfs::posix(EACCES)
    return -code error $::vfs::posix(EACCES)
}

# Transfer a VcsVfs mount point to another Thread.
# TclVfs mounts are thread local.
# If no mount point is given, tranfer all current mount points
# Transfer VcsVfs mount point(s) to another Thread.
# TclVfs (which VcsVfs is based on) mounts are thread local
#
# threadId:   Thread id as created by Thread package
# mountpoint: Mount point to transfer.
#             If no mount point is given, tranfer all current mount points
#
# Returns: None
proc vcsvfs::transfer {threadId {mountpoint {}}} {
    variable mpoints
    thread::send -async $threadId "package require vcsvfs"
    if {$mountpoint eq ""} {
        set data $mpoints
    } else {
        set data [dict create $mountpoint [dict get $mpoints $mountpoint]]
    }
    # Data might be large. Is that a problem? Is there a more efficient way?
    thread::send -async $threadId [list vcsvfs::Receive $data]
}

# Create mount(s) from received data
proc vcsvfs::Receive {data} {
    variable mpoints
    foreach mountpoint [dict keys $data] {
        # Avoid duplicates
        if {![dict exists $mpoints $mountpoint]} {
        dict set mpoints $mountpoint [dict get $data $mountpoint]
        vfs::filesystem mount $mountpoint [list vcsvfs::Vfs]
            dict set mpoints $mountpoint [dict get $data $mountpoint]
            vfs::filesystem mount $mountpoint [list vcsvfs::Vfs]
        }
    }
}

##################################################################
# Test structure
##################################################################
if 0 {