If You Use Unix, Use Version Control

If you’ve used Unix (or Linux. This applies to Linux, and MacOS X, and probably various flavors of Windows as well), you’ve no doubt found yourself editing configuration files with a text editor. This is especially true if you’ve been administering a machine, either professionally or because you got roped into doing it.

And if you’ve been doing it for more than a day or two, you’ve made a mistake, and wished you could undo it, or at least see what things looked like before you started messing with them.

This is something that programmers have been dealing with for a long time, so they’ve developed an impressive array of tools to allow you to keep track of how a file has changed over time. Most of them have too much overhead for someone who doesn’t do this stuff full-time. But I’m going to talk about RCS, which is simple enough that you can just start using it.

Most programmers will tell you that RCS has severe limitations, like only being able to work on one file at a time, rather than a collection of files, that makes it unsuitable for use in all but a few special circumstances. Thankfully, Unix system administration happens to be one of those circumstances!

What’s version control?

Basically, it allows you to track changes to a file, over time. You check a file in, meaning that you want to keep track of its changes. Periodically, you check it in again, which is a bit like bookmarking a particular version so you can come back to it later. And you can check a file out, that is, retrieve it from the history archive. Or you can compare the file as it is now to how it looked one, five, or a hundred versions ago.

Note that RCS doesn’t record any changes unless you tell it to. That means that you should get into the habit of checking in your changes when you’re done messing with a file.

Starting out

Let’s create a file:

# echo "first" > myfile

Now let’s check it in, to tell RCS that we want to track it:

# ci -u myfile
myfile,v <-- myfile
enter description, terminated with single '.' or end of file:
NOTE: This is NOT the log message!
>> This is a test file
>> .
initial revision: 1.1
done

ci stands for “check in”, and is RCS’s tool for checking files in. The -u option says to unlock it after checking in.

Locking is a feature of RCS that helps prevent two people from stepping on each other’s toes by editing a file at the same time. We’ll talk more about this later.

Note that I typed in This is a test file. I could have given a description on multiple lines if I wanted to, but usually you want to keep this short: “DNS config file” or “Login message”, or something similar.

End the description with a single dot on a line by itself.

You’ll notice that you now have a file called myfile,v. That’s the history file for myfile.

Since you probably don’t want ,v files lying around cluttering the place up, know that if there’s a directory called RCS, the RCS utilities will look for ,v history files in that directory. So before we get in too deep, let’s create an RCS directory:

# mkdir RCS

Now delete myfile and start from scratch, above.

Done? Good. By the way, you could also have cheated and just moved the ,v file into the RCS directory. Now you know for next time.

Making a change

All right, so now you want to make a change to your file. This happens in three steps:

  1. Check out the file and lock it.
  2. Make the change(s)
  3. Check in your changes and unlock the file.

Check out the file:

# co -l myfile
RCS/myfile,v --> myfile
revision 1.1 (locked)
done

co is RCS’s check-out utility. In this case, it pulls the latest version out of the history archive, if it’s not there already.

The -l (lower-case ell) flag says to lock the file. This helps to prevent other people from working on the file at the same time as you. It’s still possible for other people to step on your toes, especially if they’re working as root and can overwrite anything, but it makes it a little harder. Just remember that co is almost always followed by -l.

Now let’s change the file. Edit it with your favorite editor and replace the word “first” with the word “second”.

If you want to see what has changed between the last version in history and the current version of the file, use rcsdiff:

# rcsdiff -u myfile
===================================================================
RCS file: RCS/myfile,v
retrieving revision 1.1
diff -u -r1.1 myfile
--- myfile 2016/06/07 20:18:12 1.1
+++ myfile 2016/06/07 20:32:38
@@ -1 +1 @@
-first
+second

The -u option makes it print the difference in “unified-diff” format, which I find more readable than the other possibilities. Read the man page for more options.

In unified-diff format, lines that were deleted are preceded with a minus sign, and lines that were added are preceded by a plus sign. So the above is saying that the line “first” was removed, and “second” was added.

Finally, let’s check in your change:

# ci -u myfile
RCS/myfile,v <-- myfile
new revision: 1.2; previous revision: 1.1
enter log message, terminated with single '.' or end of file:
>> Updated to second version.
>> .
done

Again, we were prompted to list the changes we made to the file (with a dot on a line by itself to mark the end of our text). You’ll want to be concise yet descriptive in this text, because these are notes you’re making for your future self when you want to go back and find out when and why a change was made.

Viewing a file’s history

Use the rlog command to see a file’s history:

# rlog myfile

RCS file: RCS/myfile,v
Working file: myfile
head: 1.2
branch:
locks: strict
access list:
symbolic names:
keyword substitution: kv
total revisions: 2; selected revisions: 2
description:
Test file.
----------------------------
revision 1.2
date: 2016/06/07 20:36:52; author: arensb; state: Exp; lines: +1 -1
Made a change.
----------------------------
revision 1.1
date: 2016/06/07 20:18:12; author: arensb; state: Exp;
Initial revision
=============================================================================

In this case, there are two revisions: 1.1, with the log message “Initial revision”, and 1.2, with the log “Made a change.”.

Undoing a change

You’ve already see rlog, which shows you a file’s history. And you’ve seen one way to use rcsdiff.

You can also use either one or two -rrevision-number arguments, to see the difference between specific revisions:

# rcsdiff -u -r1.1 myfile

will show you the difference between revision 1.1 and what’s in the file right now, and

# rcsdiff -u -r1.1 -r1.2 myfile

will show you the difference between revisions 1.1 and 1.2.

(Yes, RCS will just increment the second number in the revision number, so after a while you’ll be editing revision 1.2486 of the file. Getting to revision 2.0 is an advanced topic that we won’t cover here.)

With the tools you already have, the simplest way to revert an unintended change to a file is simply to see what the file used to look like, and copy-paste that into a new revision.

Once you’re comfortable with that, you can read the manual and read up on things like deleting revisions with rcs -o1.2 myfile.

Checking in someone else’s changes

You will inevitably run into cases where someone changes your file without going through RCS. Either it’ll be a coworker managing the same system who didn’t notice the ,v file lying around, or else you’ll forget to check in your changes after making changes.

Here’s a simple way to see whether someone (possibly you) has made changes without your knowledge:

# co -l myfile
RCS/myfile,v --> myfile
revision 1.2 (locked)
writable myfile exists; remove it? [ny](n):

In this case, either you forgot to check in your changes, or else someone made the file writable with chmod, then (possibly) edited it.

In the former case, see what you did with rcsdiff, check in your changes, then check the file out again to do what you were going to do.

The latter case requires a bit more work, because you don’t want to lose your coworker’s changes, even though they bypassed version control.

  1. Make a copy of the file
  2. Check out the latest version of the file.
  3. Overwrite that file with your coworker’s version.
  4. Check those changes in.
  5. Check the file out and make your changes.
  6. Have a talk with your coworker about the benefits of using version control..

You already know, from the above, how to do all of this. But just to recap:

Move the file aside:

# mv myfile myfile.new

Check out the latest version:

# co -l myfile

Overwrite it with your coworker’s changes:

# mv myfile.new myfile

Check in those changes:

# ci -u myfile
RCS/myfile,v <-- myfile
new revision: 1.3; previous revision: 1.2
enter log message, terminated with single '.' or end of file:
>> Checking in Bob's changes:.
>> Route around Internet damage.
>> .
done

That should be enough to get you started. Play around with this, and I’m sure you’ll find that this is a huge improvement over what you’ve probably been using so far: a not-system of making innumerable copies of files when you remember to, with names like “file.bob”, “file.new”, “file.new2”, “file.newer”, and other names that mean nothing to you a week later.

Reason Rally 2016

I’m down on the Mall for the Reason Rally (I’m an official redshirt). If you see me, day hi!

BillDo Opines on the Reason Rally

Oh, goody! BillDo has written a piece about this Saturday’s Reason Rally on the National Mall (are you coming? If you’re an atheist, agnostic, freethinker, none, or anywhere in that general ballpark, you should totally come). Shall we see what nuggets of wisdom he might share with us from the depths of his pious bowels?

They stand for nothing, believe in nothing, and many are good for nothing.

Feel that Christian love! BillDo usually has his panties in a knot, but here he looks like a jamboree at Victoria’s Secret.

Most of the speakers are nobodies

I suppose that depends how you define “nobody”. It’s true that none of the major party candidates will be speaking, and no sitting presidents or senators. But I count two sitting Representatives (Tulsi Gabbard, D-HI and Rep. Bobby Scott, D-VA), as well as House candidate Jamie raskin (D-MD).

I also count a number of scientists and entertainers, including more Wu Tang Clan members than I realized (then again, I’m an old, and I don’t follow the hippity-hop).

But hark! Bill continues:

an exception being Penn Jillette: He is known for his obscene rants against Mother Teresa.

Actually, no: he’s known for being a stage magician. Pointing out that the Albanian worshiper of suffering may not be all she was cracked up to be is just a sideline.

Has Penn talked about her, since that one episode of Bullshit!? If so, I’m not aware of it. Maybe Bill is still butthurt 11 years after that show aired?

Besides bashing Christians, the speakers will discuss “climate change, LGBT rights, sex education, and social justice issues.” Exactly what the atheist perspective is on these issues is a mystery (if I may use that word).

Wait, seriously? Bill thinks there’s something provocative, edgy, or even clever about using the word “mystery” in a secular context? Does he think atheists don’t read murder mysteries?

What is really striking, however, is that the rally is showcasing how important the atheist vote is, thus suggesting that their group-think community is anything but a home for “freethinkers.”

So he just told us that he doesn’t know what atheists think about climate change, LGBT rights, etc, but he knows we all believe the same thing? Is that anything like saying, “I don’t understand the doctrine of the Trinity, but I believe it to be true”?

The Freedom From Religion Foundation is cashing in on the event by spending hundreds of millions on newspaper ads telling readers how unfair it is that their leader, Dan Barker, was denied a request to deliver an atheist address to Congress.

“[H]undreds of millions”? Please. A glance at the New York Times’s ad rates shows that a full-page color ad in the International section will set you back $107,075. The FFRF ad is running in three newspapers, so call it something close to half a million bucks. A good chunk of change, but still only half a percent of what Bill is claiming.

But anyway, go on:

David Silverman of American Atheists boasts that there are 40-50 million atheists in the U.S. He makes this figure up.

…says the man who just confused “million” and “thousand”.

Of course, it’s not hard to find other atheists criticizing Silverman for his estimate. But you wouldn’t know it because of all the groupthink.

A Mother’s Day Sermon

I ran across “Mother and Grandmother”, a Mother’s Day sermon by one Edwin Whitney Bishop from May 14, 1911, about a hundred years ago, and was curious to see what it might say.

The first surprise came in the first sentence:

A VERY decided attempt is being made in many quarters to have this second Sunday in May set apart as Mother’s Day, or perhaps better as Parent’s Day, as a counterbalance to the very wide spread observance of the second Sunday in June as Children’s Day,

I would have placed the origin of Mother’s Day some time in the 1950s or 1960s, and I certainly didn’t know that it was preceded by  Children’s Day.

After a couple of pages about the importance of raising children properly, like bred roses or horses, he starts railing against people who shouldn’t have kids:

It is perfectly permissible for consumptives, habitual criminals, and feeble minded to marry at will and populate the hospitals and alms houses, and no one shall say them nay. We pass laws to cut down peach trees that have the yellows and we eliminate cattle that have the hoof and mouth disease, but we have thought nothing of having diseased people transmit certain terrible tendencies to the third and fourth generation.

Bishop was clearly an advocate of eugenics. He cites the cost to society of having murderers, beggars, convicts, children born out of wedlock, and people leading “disreputable lives”, something that he sees as being passed down from parent to child, genetically as we would say today. “And yet there are those who insist that the State has no interest in who shall be parents !”, he exclaims.

No doubt there are creationists who would love to claim that this man of God was corrupted by the Great Satan, Darwin. So here you go:

For whether you are a disciple of Spencer and Darwin, or a disciple of Häckel and Weissman as to the way the facts shall be interpreted, the facts themselves are beyond question.

And a bit later,

Endless life is promised by evolution as well as by Christ only to the righteous. It may take millions of years to bring it about, but it is sure to come — the evil self-destructive in its own nature and therefore self-limiting will annihilate itself out, and the good which always has in itself the embryo of eternal life will flower in richest perfection.

And

Henry Drummond in his book, entitled : “The Ascent of Man,” has in it a remarkable chapter, called : “The evolution of a mother.” He shows how motherhood comes to its own only in the human race.

(passages emphasizes in bold to tweak Ken Ham.)

The interesting thing to me about this passage is that in Grand Rapids in 1911, a preacher seemed to consider evolution to be settled science, at least in its broad outlines, and that the only areas on which educated laymen might disagree concerned the particular hypotheses being hashed out.

He does hold a misconception that’s still widespread, though: after talking about reptiles and birds, he says that “[l]ions are higher up in the scale”. Throughout his sermon, he seems to take for granted that there is a Great Chain of Being, with some above (and better than) others: reptiles above insects, birds above reptiles, humans above lions. I wouldn’t be surprised if he considered some humans to be above others on this scale.

Happy Mother’s Day, everyone!

There Are Days When I Hate XML

…and days when I really hate XML.

In this case, I have an XML document like

<?xml version="1.0" ?>
<foo xmlns="http://some.org/foo">
  <thing id="first"/>
  <thing id="second"/>
  <thing id="third"/>
</foo>

and I want to get things out of it with XPath.

But I couldn’t manage to select things exactly, such as the <foo> element at the top. You’d think “/foo” would do it, but it didn’t.

Eventually I found out that the problem is the xmlns=”...” attribute. It looks perfectly normal, saying that if you have <thing> without a prefix (like “<ns:thing>”), then it’s in the “http://some.org/foo” namespace.

However, in XPath, if you specify “ns:thing”, it means “a thing element in whichever namespace the ns prefix corresponds to”. BUT “thing” means “a thing element that’s not in a namespace”.

So how do you specify an element that’s the empty-string namespace, as above? The obvious way would be to select “:thing”, but that doesn’t work. Too simple, I suppose. Maybe that gets confused with CSS pseudo-selectors or something.

No, apparently the thing you need to do is to invent a prefix for the standard elements of the file you’re parsing. That is, add “ns” as another prefix that maps onto “http://some.org/foo” and then select “ns:thing”. There are different ways of doing this, depending which library you’re using to make XPath queries, but still, it seems like a giant pain in the ass.

“Looks like I was wrong for 30 years”

Yesterday, thanks to @Monahan_PJ (via the incomparable @edyong209), I ran across this paper in Science:

No buts about it, the butthole is one of the finest innovations in the past 
540 million years of animal evolution. The first animals that arose seem to have literally had potty mouths: Their modern-day descendants, such as sea sponges, sea anemones, and jellyfish, all lack an anus and must eat and excrete through the same hole. Once an independent exit evolved, however, animals diversified into the majority of species alive today, ranging from earthworms
 to humans.

So go read it, because it’s interesting. In case you didn’t, the tl;dr of it is that there are animals who eat and excrete using different orifices, like we do, and there are those that use the same orifice for ingestion and excretion. These box jellyfish were thought to be in the latter category, but it turns out they’re not (with a twist).

And then, there’s a throwaway line about halfway down:

“Looks like I’ve been wrong for 30 years,” said George Matsumoto, a marine bio
logist at Monterey Bay Aquarium Research Institute in Moss Landing, California, after he saw Browne’s talk.

That’s a remarkable thing to say, and I congratulate Dr. Matsumoto on his honesty.

But it also made me realize that while I’ve heard scientists make this sort of statement (not often enough, but on a regular basis), and sometimes even politicians (see, for instance, Barack Obama’s and Hillary Clinton’s reversals on gay marriage), I don’t remember ever hearing a theologian (or cleric engaging in theology) say this.

Yes, plenty of people have changed their religious affiliation, and the “I was a wretched sinful atheist heathen gay pagan until I found Jesus” story is a genre unto itself. And I’ve heard plenty of stories of people switching denominations because their old church was too repressive, not serious enough about its faith, or whatever. But these are largely matters of opinion.

Find me people changing their mind on small matters of fact. Take a look at Wikipedia’s list of Christian heresies and show me the ones that were resolved through observation and reason, rather than bloodshed.

It just doesn’t happen. In religion, there’s no reality check, no way to see that your beliefs are completely out of line with reality.

Would You Get Off the Plane?

There’s an old joke about an instructor who asks, “if you were on a plane, and found out that the inflight systems were controlled by a beta version of software written by your team, would you get off the plane?” Most of the students pale and say yes. One person says, “No. If it were written by my team, it wouldn’t make it to the runway.”

The implication is that most software is far crappier than people realize, and that programmers are keenly aware of this. But I’d like to present another reason for getting off the plane:

Even if my team writes good code, the fact that it’s still in beta means that it hasn’t been fully tested. That means that there must have been some kind of snafu at the airline and/or the software company for untested software to be put in control of a flight with ordinary passengers. And if management permitted this error, what other problems might there be? Maybe the fuel tanks are only half-full. Maybe the landing gear hasn’t been inspected.

Wheeze A Coda Dog

The Alexa app on my tablet wanted to share with me the exciting (to it) news that Amazon has released a companion device to its Echo, called an Echo Dot, and invited me to ask “Alexa, what’s Echo Dot?” to learn more.

According to said app’s transcript, here’s the conversation we just had:

– Alexa, what’s echo dog?
– Sorry, I couldn’t find the answer to your question.
– Alexa, what’s the Dutch?
– The Netherlands national football team represents the Netherlands in international football.
– Alexa, what’s the code coda?
– Sorry, I couldn’t find the answer to your question.
– Alexa, what’s the code doctor?
– Sorry, I couldn’t find the answer to your question.
– Alexa, what’s the coda?
– Coda is a term used in music primarily to designate a passage that brings a piece to an end.
– Alexa, what’s Echo Dot?
– [Spiel about Echo Dot]
– Alexa, order some Echo Q-Tips.

Paul Ryan Denounces Republican Strategy

You may have heard that establishment Republicans are almost as terrified at the prospect of a Trump presidency as the rest of us. And since they haven’t been able to stop him so far, they’re getting a bit desperate.
So today, Speaker Paul Ryan opened his mouth and said some words:

The Republican party does not prey on people’s prejudices—we appeal to their highest ideals.

Are you fucking kidding me? He would have us believe that he lives in this country, has managed to become Speaker of the House, and yet somehow has never paid attention to electoral politics in the last twenty-some years?

Republicans gave us the Willie Horton ad. They gave us “welfare queens”. They made “9/11” the most commonly-repeated phrase in several conventions.

Republicans were the ones screaming loudest that gay marriage would undermine religious liberty, destroy the family, and probably rain on your Fourth of July barbecue. Ditto gays in the military. And gay scout masters. And now the fearmongering about trans people in bathroom bills is all coming from the right.

Who kept accusing Barack Obama of not being American? Which party gave us “blah people”?

I understand that Ryan doesn’t want Trump to be president. But he’s the culmination of years and years of Republican divisiveness and fearmongering. They, as the saying goes, built that. Preying on people’s prejudices and fears is what Republicans do. Does Ryan really expect anyone to believe otherwise?

I Should Have Known the Pope Wasn’t Going to Change Policy

The news today mentioned that Pope Francis I had okayed contraception for women in Zika-struck areas. Yay, liberal hippie pope! My complaint since the beginning of his tenure is that while he gives good press conference, that’s all he does: he hasn’t changed the church’s policy, and that’s the real problem.

At least so far, the Catholic church has been opposed to both contraception and abortion; Catholic hospitals don’t provide contraceptives when they have a choice, the previous pope famously told Africans that condoms make the AIDS crisis worse. Claims that contraceptives cause abortions. So against that backdrop, saying that contraception ≠ abortion is a step in the right direction, no?

Except, well, maybe not so much: according to AP,

Abortion “is an evil in and of itself, but it is not a religious evil at its root, no? It’s a human evil,” Francis told reporters. “On the other hand, avoiding pregnancy is not an absolute evil. In certain cases, as in this one (Zika), such as the one I mentioned of Blessed Paul VI, it was clear.”

That’s a reference to a document from 1968 in which that okayed contraception for nuns in the Congo who were being raped.

In other words, Francis still isn’t changing policy. He’s just reaffirming Catholic policy from fifty years ago, policy that’s slightly less dogmatic than the way it’s usually portrayed.

U.N. officials have called on Latin American countries to loosen their abortion laws to allow women to terminate pregnancies if they fear the fetus may be at risk for microcephaly, a rare birth defect that causes brain damage and may be linked to the virus.

But Francis told reporters, “Taking one life to save another, that’s what the Mafia does. It’s a crime. It’s an absolute evil.”

So if you’ve found out that your fetus will likely never develop normal brain function; or if you have an ectopic pregnancy; and decide to abort, well, then apparently that makes you just like the Mafia.

[youtube https://www.youtube.com/watch?v=7gqFZjfFGuM&w=420&h=315]