The Hackerlab at `regexps.com`

## Starting a New Source Tree

up: arch Meets hello-world next: Project Tree Inventories prev: Starting a New Project

After following the examples in earlier chapters, you should have a new archive and new `hello-world` project within that archive.

In this chapter, we'll walk through the steps of preparing a source tree to be part of that project.

### The Intial Source

For the sake of example, let's assume that we have an initial, slightly buggy, implementation of `hello-world` :

            % cd ~/wd

            % ls
            hello-world

            % cd hello-world

            % ls
            hw.c    main.c

            % cat hw.c

            #include <stdio.h>

            void
            hello_world (void)
            {
              (void)printf ("hello warld");
            }

            % cat main.c

            extern void hello_world (void);

            int
            main (int argc, char * argv[])
            {
              hello_world ();
              return 0;
            }

### Initializing a Project Tree

The first step of preparing source is to turn the ordinary source tree into a project tree :

            % cd ~/wd/hello-world

            % larch init-tree hello-world--mainline--0.1

            % ls
            hw.c    main.c  {arch}

Note that we passed `init-tree` the name of the version in the archive that we'll be working on. `init-tree` created a new subdirectory in the root of the tree (`{arch}` ).

The `{arch}` subdirectory indicates that this is the root of a project tree:

            % larch tree-root
            /usr/lord/wd/hello-world

`larch` knows what archive version this tree is for:

            % larch tree-version
            lord@emf.net--2003-example/hello-world--mainline--0.1

Finally, `arch` has created something called a patch log for the version passed to `init-tree` :

            % larch logs
            lord@emf.net--2003-example/hello-world--mainline--0.1

We'll explain what patch logs are for in later chapters.

### Initializing a Tree Does Not Change an Archive

So far, we've only marked the project tree as source: we haven't yet stored anything new in the archive. We'll get there, but before we do that, there's an important topic to cover first: source inventories. We'll cover that in the next chapter.

### What if You Make a Mistake With init-tree?

Suppose that in the example above, we had mis-typed:

            % larch init-tree hello-world--mainlin--0.1

One "brute force" solution is just to delete the `{arch}` subdirectory and start over. Later on, though, that solution is undesirable: the `{arch}` subdirectory may contain some data you don't want to delete. So, we'll take this opportunity to introduce a few more advanced commands.

There are two problems after the bogus call to `init-tree` . The output from both of these commands is not what we want:

            % larch tree-version
            lord@emf.net--2003-example/hello-world--mainlin--0.1

            % larch logs
            lord@emf.net--2003-example/hello-world--mainlin--0.1

We can change the `tree-version` of a tree at any time:

            % larch set-tree-version hello-world--mainline--0.1

            % larch tree-version
            lord@emf.net--2003-example/hello-world--mainline--0.1

Patch logs are a little trickier. We have to delete the log we don't want, and add a log that we do want:

            % larch add-log hello-world--mainline--0.1

            % larch logs
            lord@emf.net--2003-example/hello-world--mainlin--0.1
            lord@emf.net--2003-example/hello-world--mainline--0.1

            % larch remove-log hello-world--mainlin--0.1

            % larch logs
            lord@emf.net--2003-example/hello-world--mainline--0.1

WARNING: `remove-log` is a dangerous command: it will remove a patch log that you might need if you ask it to. You should only use `remove-log` when you are certain, as we were above, that the log being removed is one you do not want.

### How it Works -- Initializing a New Tree

`init-tree` created the `{arch}` subdirectory at the root of the source tree. What's in there?

            % ls {arch}
            ++default-version       hello-world

            % cat {arch}/++default-version
            lord@emf.net--2003-example/hello-world--mainline--0.1

`{arch}/hello-world` is the root of a fairly deep tree. Patch logs are stored within that tree.

Note: You should not, of course, edit the contents of the `{arch}` directory by hand.

arch Meets hello-world: A Tutorial Introduction to The arch Revision Control System
The Hackerlab at `regexps.com`