[TUHS] Warner's Early Unix Presentation

Larry McVoy lm at mcvoy.com
Sun Feb 9 10:19:30 AEST 2020


> In today's Unix (I use the term loosely) world, the phrase "free of
> decoration" is apostasy.

Yeah, it's annoying.  When I was building my last big system (BitKeeper)
I "solved" the problem by having -s (silent) as an option to pretty much
every command that produced output.

In terms of controlling output, we took the SCCS keywords on steriods,
we evolved it to sort of a little programming language.  I was told
that "bk changes" (think git log sort of) couldn't be taught to produce
JSON output.  Oh, it can't huh.  Below is the input that tells it to do
just that.  It's sort of awk like, control words are $word,  "quoted stuff
is printed, :THING: means print whatever THING is, variables are $0 .. $9
and eval to "" or 0 in numerical context.  The main body script, much like
awk calls it on each line, the script is called on each commit (and it 
optionally recurses into files as well).  I'm pretty proud of it, it
works really, really well.

$ cat `bk bin`/dspec-changes-json
# dspec-v2
# The default dspec used by 'bk changes -json'

$begin {
	"[\n"
}

$if (:CHANGESET: && !:COMPONENT_V:) {
	$if($0 -eq 1) {
		"\},\n"
	}
	"\{\n"
	"  \"key\": \":MD5KEY:\",\n"
	"  \"user\": \":USER:\",\n"
	"  \"host\": \":HOST:\",\n"
	"  \"date\": \":Dy:-:Dm:-:Dd:T:T::TZ:\",\n"
	"  \"serial\": :DS:,\n"
	"  \"comments\": \"" $each(:C:){$json{(:C:)}\\n} "\",\n"
        $if (:TAGS:) {
             "  \"tags\": [ "
             $each(:TAGS:){:JOIN:"\""(:TAGS:)"\""}
             " ],\n"
        }
        "  \"parents\": [ "
            $if(:PARENT:){"\"" :MD5KEY|PARENT: "\""}
            $if(:PARENT: && :MPARENT:){," "}
            $if(:MPARENT:){"\"" :MD5KEY|MPARENT: "\""}
            " ]\n"
	${0=1}		 		# we need to close off the changeset
}

$end {
	$if($0 -eq 1) {
		"\}\n"
	}
	"]\n"
}


More information about the TUHS mailing list