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.
Assuming that
calc,addandmultiplycan all use the same version ofpair, I would declareadd,multiplyandpairas submodule ofcalc.And I would remove
pairfromaddandmultiply: those two can look forpairoutside their repository (../pairinstead of./pair).That way:
calcpairremainscalcis in charge of getting the right versions ofpair,addandmultiply