Complex repository dependencies in C without waste of disk space

86 views Asked by At

Assume that I have 4 git repositories with C files. The base repository pair, on which the others depend, declares a type.

pair.h:

typedef struct {
    int a;
    int b; 
} PAIR;

Two other repositories add and multiply define operations on this type and both contain pair as a submodule or subtree:

add.c:

int add (PAIR p) {
    return p.a + p.b;
}

multiply.c:

int multiply (PAIR p) {
    return p.a * p.b;
}

The last repository calc, which contains add and multiply as submodules or subtrees, contains a program which uses both operations.

calc.c:

int main (int argc, char *argv[]) {
    PAIR p;
    p.a = atoi(argv[1]);
    p.b = atoi(argv[2]);
    printf("sum = %d\n", add (p));
    printf("product = %d\n", mul (p));
    return 0;
}

The problem is that, if I clone calc recursively, then pair will be contained twice in the directory tree of calc, although it is only needed once. If the real structure gets more complex with several dependency stages, it leads to a huge waste of disk space.

How can this be organized in a disk-space-friendlier way?

It would be fine for me to have only one "current version" of every repository to be able to work with.

1

There are 1 answers

0
VonC On

Assuming that calc, add and multiply can all use the same version of pair, I would declare add, multiply and pair as submodule of calc.

And I would remove pair from add and multiply: those two can look for pair outside their repository (../pair instead of ./pair).

That way:

  • you can do a recursive clone of calc
  • only one version of pair remains
  • calc is in charge of getting the right versions of pair, add and multiply