Tuesday, November 4, 2014

Compare go source files in two file trees in clive

I'm still amazed at how pieces fit together in Clive. This is like a recursive diff in unix, but in Clive, and compares just source files in go as found within two trees:

    ; comp ',~\.go$' '/tmp/x,~\.go$'
    #diff comp.go:208: and /tmp/x/comp.go:207:
    -   x.diff()
    #diff: comp.go:209: and /tmp/x/comp.go:209:
    +  x.diff()

There are several things working together here
  • Commands accept names made of two elements: a path and a predicate (separated by a comma). In the example the predicates match the name against what would be "*.go" in UNIX.
  • Each name is issued to a finder to find a stream of directory entries
  • Directory entries are self-describing, and thus a stream of directory entries is enough to reach the different file servers involved in the name space used for the search.
  • File and directory contents may be retrieved along with the find request; they are streamed through channels, like everybody else.
  • Directories always report and find entries in the same order, i.e. they are always sorted
As a result, the compare command only has to use a library function to make each name become a stream and then compare the two streams.