Tricking Darcs, or How to Make a Common Branch
Imagine you have a repository. At time t0 someone copies the code from the repository, starts another repository from there, and commences development. You also continue development. At time t you want to pull in the changes the other guy has made.
One approach could be you simply merge other guys code into yours with one big commit calculated from time t0. Now suppose you want to keep other guy’s history from t0 on, or even worse, you want to pull only some changes and you want to push some of your changes to other guy.
This is a true story. It all started with CVS. A webapp was developed, cloned and branched. Now there are 4 of them, mostly the same, but subtly different, and each with it’s own CVS repo. Each one at some point in time is identical to another, but the history behind those points in time are different, thanks to copy and commit cloning.
So after converting the CVS to Darcs, I came up with a way of tricking darcs into treating time t0 in each repository as the same t0, thus enabling cross-pollination, and here I describe that method.
First you find t0, and tag liberally. By liberally I mean twice. I’ll explain why later. Of course you put the same two tags on both repos, both at the same point in time. Then you do a darcs opt --checkpoint on each so you can do a partial get on them.
Now you have to decide which repo you’re going to keep, and which one you are bringing in. You probably want to keep the one with past history, and bring in the one that did copy and commit cloning. Do a darcs get --partial on each repo, keeping track of which is what. I like to use a for the destination, and b for the bad repo.
Edit: The below paragraph is a bit confusing. Keep in mind that to make b think it’s a, you just replace @b@’s guts with those of a, but this only works for the partial at time t0. So we make a snapshot for reference, and then pull in @b@’s downstream stuff (because we can’t do this after b thinks it’s a).
Now go into b/_darcs and we’ll play around with these guts to make it think it’s a, but we want it to have it’s future patches first. So we take a snapshot before pulling the other stuff. I just made a temp directory and did cp -r inv* patches temp, these are the three things in the _darcs directory we care about. Here’s where the liberal tagging comes in, the partial at the later tag only depends on the first tag, so that makes your inventory and patches much simpler. Now you’re ready to pull in all the subsequent patches from the cloned branch.
Once that’s done, you go back into b/_darcs, this time you take anything in temp/patches and temp/inventories and remove the corresponding files from patches and inventories. Then you replace those files with the files from a/_darcs/{inventories,patches}. These two steps I accomplish like so:
ls temp/inventories | while read i; do rm inventories/$i; done
ls temp/patches | while read i; do rm patches/$i; done
for f in inventories patches; do cp ../../a/_darcs/$f/* $f; done
One last step remains. Now you edit inventory and replace that very first patch number, the one that’s a tag, with the one that’s in the inventory file from a. Now b effectively has the exact same past history as a, and has all it’s future patches, and now you can share between your repo and other guy’s repo freely.
One might think this is an uncommon situation, but I can’t help but think it’s more common than I think… Hopefully this guide will save others the headache of trying to wrap their minds around the darcs inner guts, as well as save me some headache should I ever encounter this again (which I’m pretty sure I will, in only a few weeks!).
Post a comment
Website and email are optional. Email will be displayeduser at example dot com.