Differences between revisions 6 and 28 (spanning 22 versions)
Revision 6 as of 2009-07-24 01:18:50
Size: 5063
Editor: JonnyDee
Comment:
Revision 28 as of 2013-08-30 02:21:26
Size: 384
Editor: TeddyBlan
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
= Introduction =

Mercurial as well as other well-known version control systems cannot version directories. A "workaround" for this issue is to use placeholder files which are placed into empty directories. These placeholder files can then be committed into the repository and will make sure that, upon checkout, the directory tree is entirely reconstructed. This solution is also suggested in the [[http://mercurial.selenic.com/wiki/FAQ#FAQ.2BAC8-CommonProblems.I_tried_to_check_in_an_empty_directory_and_it_failed.21|Mercurial FAQ]]. Note however, that using that workaround might not be a good idea. Creating missing directories during a build process should also be considered as an option.

Sometimes a solution where the missing directories are created by some magic is not practicable and people will face the problem of managing such placeholder files. In particular, the problem with using placeholder files is that you need to create them, and delete them, if they are not necessary anymore (because there were added sub-directories or files). With big source trees managing these placeholder files can be cumbersome and error prone.

I had been confronted with such a situation several days ago and it wasn't the first time. This is why I decided to write an open source tool which can manage the creation/deletion of such placeholder files automatically. It creates placeholder files in all empty directories. If later on new files or directories are put into such directories, the placeholder files are not necessary anymore and, thus, are removed automatically.

This tool is licensed under the GPLv3 and runs under Mono (Linux) as well as under Microsoft .NET platform (Windows). It can be downloaded here: [[http://code.google.com/p/markemptydirs/downloads/list]]

= Use Cases =

In the following sections some typical use cases are described and it is shown how the tool can help you getting your work easily done. For clarity, I use directory names with upper case letters and file names with lowercase letters in the following examples.

== Create placeholder files ==

Within a directory `PROJECT` find all "leaf" directories that do not contain any files or sub-directories, and create a placeholder file `.emptydir` within each such "leaf" directory.

For example, let's assume the following source tree:

{{{
[PROJECT]
        |
        *--[DIR1]
        | |
        | *--[DIR1-1]
        |
        *--[DIR2]
        | |
        | *--file1
        |
        *--[DIR3]
}}}

A tree with the corresponding placeholder files will then look like this:

{{{
[PROJECT]
        |
        *--[DIR1]
        | |
        | *--[DIR1-1]
        | |
        | *--.emptydir
        |
        *--[DIR2]
        | |
        | *--file1
        |
        *--[DIR3]
                |
                *--.emptydir
}}}

Using the `MarkEmptyDirs` tool one would simply do:

{{{
$> MarkEmptyDirs PROJECT
}}}

== Update placeholder files ==

Let's assume the `PROJECT` directory has undergone some changes. Directories and/or files have been added and/or deleted. This requires to synchronize the corresponding placeholder files. In particular, some now are not needed anymore and new ones may now be necessary.

For instance, have a look at the following tree:

{{{
[PROJECT]
        |
        *--[DIR1]
        | |
        | *--[DIR1-1]
        | |
        | *--.emptydir
        | |
        | *--newfile.txt
        |
        *--[DIR2]
        |
        *--[DIR3]
                |
                *--.emptydir
}}}

`DIR1-1` now contains a new file `newfile.txt` and a previously created `.emptydir` file. The former now acts as a placholder and, thus, the latter is not needed anymore. `DIR2` now is empty and requires a placeholder file.

Consequently, after updating the placeholder files the tree should look like this:

{{{
[PROJECT]
        |
        *--[DIR1]
        | |
        | *--[DIR1-1]
        | |
        | *--newfile.txt
        |
        *--[DIR2]
        | |
        | *--.emptydir
        |
        *--[DIR3]
                |
                *--.emptydir
}}}

Using the `MarkEmptyDirs` tool for synchronization one would simply do (again):

{{{
$> MarkEmptyDirs PROJECT
}}}

== Delete placeholder files ==

There are situations where one wants a clean tree which does not consist any placeholder files. So all `.emptydir` files should be removed.

This can simply be achieved by using the optional `--clean` option:

{{{
$> MarkEmptyDirs --clean PROJECT
}}}

== List placeholder files ==

In order to list all placeholder files just execute:

{{{
$> MarkEmptyDirs --list PROJECT
}}}

Note that this command is simply a shorthand for:

{{{
$> MarkEmptyDirs --short --dry-run --clean PROJECT
}}}
Lucien is what my spouse loves to call my life and I totally cannot get enough of that name.<<BR>>
The favorite hobby for my kids and as well as me is caving plus I'll be starting another thing along with it. I am currently a currency broker. For a while I've at one time been in Tennessee and I don't plan on changing it. Check out my very website here: http://elevategfreview.com

Lucien is what my spouse loves to call my life and I totally cannot get enough of that name.
The favorite hobby for my kids and as well as me is caving plus I'll be starting another thing along with it. I am currently a currency broker. For a while I've at one time been in Tennessee and I don't plan on changing it. Check out my very website here: http://elevategfreview.com

MarkEmptyDirs (last edited 2013-08-30 07:25:24 by Pierre-YvesDavid)