Let’s Build a Version Control System
shatterealm.netlify.app
shatterealm.netlify.app
> If you actually use this thing, you are accepting the faults, the bugs, and the potential to be personally infected by the Black Plague, without regard for your own safety, and acknowledge that you are an absolute fool.
I wish I had finished it.
That sounds terrible. Terrible and beautiful.
- The original answer https://stackoverflow.com/a/40498130/5775993
- I rewrite it to a class in Typescript https://gist.github.com/hieunc229/ca6aeb507de42a933bafe31e0a...
I was somewhat alarmed for a second there, but at least on bash (version 5.1.4) "set -e" definitely does work inside functions. It doesn't work in pipes though - you'll also need "set -o pipefail" for that.
Busybox also seems to include awk. Would that have been a slightly less terrible choice of implementation language, or even worse?
Two parts to that - I don't know awk well enough. I would need to re-implement diff/patch in awk, or make heavy use of sh anyway.
> I was somewhat alarmed for a second there, but at least on bash (version 5.1.4) "set -e" definitely does work inside functions.
The number of _exceptions_ to set -e is actually quite a number:
> If not interactive, exit immediately if any untested command fails. The exit status of a command is considered to be explicitly tested if the command is used to control an if, elif, while, or until; or if the command is the left hand operand of an ''&&'' or ''||'' operator.
set -o pipefail only catches some of those, especially the while and ifs that will continue to standout to blow your foot off... But even more import to note: sh is not bash.
We're talking about POSIX shell. In Busybox's case, it is based on ash. Which doesn't actually have pipefail to begin with.
+$ cat x
#!/bin/sh
set -eu
foo() {
echo 1
false
echo 2
}
foo
+$ ./x
1
+$ cat x
#!/bin/sh
set -eu
foo() {
echo 1
false
echo 2
}
foo ||:
+$ ./x
1
2