summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: f4c6f2d)
raw | patch | inline | side by side (parent: f4c6f2d)
author | Junio C Hamano <junkio@cox.net> | |
Wed, 26 Apr 2006 08:20:50 +0000 (01:20 -0700) | ||
committer | Junio C Hamano <junkio@cox.net> | |
Tue, 2 May 2006 05:29:16 +0000 (22:29 -0700) |
The "bind" commit can express an aggregation of multiple
projects into a single commit.
In such an organization, there would be one project, root of
whose tree object is at the same level of the root of the
aggregated projects, and other projects have their toplevel in
separate subdirectories. Let's call that root level project the
"primary project", and call other ones just "subprojects".
You would first read-tree the primary project, and then graft
the subprojects under their appropriate location using read-tree
--prefix=<subdir>/ repeatedly.
To write out a tree object from such an index for a subproject,
write-tree --prefix=<subdir>/ is used.
Signed-off-by: Junio C Hamano <junkio@cox.net>
projects into a single commit.
In such an organization, there would be one project, root of
whose tree object is at the same level of the root of the
aggregated projects, and other projects have their toplevel in
separate subdirectories. Let's call that root level project the
"primary project", and call other ones just "subprojects".
You would first read-tree the primary project, and then graft
the subprojects under their appropriate location using read-tree
--prefix=<subdir>/ repeatedly.
To write out a tree object from such an index for a subproject,
write-tree --prefix=<subdir>/ is used.
Signed-off-by: Junio C Hamano <junkio@cox.net>
index 77e12cb949201445ab33992f9ff155f647ce167c..c85fa89c30e25ed026d2e95a2b537798f878e50f 100644 (file)
SYNOPSIS
--------
-'git-write-tree' [--missing-ok]
+'git-write-tree' [--missing-ok] [--prefix=<prefix>/]
DESCRIPTION
-----------
directory exist in the object database. This option disables this
check.
+--prefix=<prefix>/::
+ Writes a tree object that represents a subdirectory
+ `<prefix>`. This can be used to write the tree object
+ for a subproject that is in the named subdirectory.
+
+
Author
------
Written by Linus Torvalds <torvalds@osdl.org>
diff --git a/cache-tree.c b/cache-tree.c
index e452238ba7db47c08bd732dd425cb3be4c8bd73d..dae4399c1e038f4282eb456309b43ec760117bf7 100644 (file)
--- a/cache-tree.c
+++ b/cache-tree.c
return NULL; /* not the whole tree */
return read_one(&buffer, &size);
}
+
+struct cache_tree *cache_tree_find(struct cache_tree *it, const char *path)
+{
+ while (*path) {
+ const char *slash;
+ struct cache_tree_sub *sub;
+
+ slash = strchr(path, '/');
+ if (!slash)
+ slash = path + strlen(path);
+ /* between path and slash is the name of the
+ * subtree to look for.
+ */
+ sub = find_subtree(it, path, slash - path, 0);
+ if (!sub)
+ return NULL;
+ it = sub->cache_tree;
+ if (slash)
+ while (*slash && *slash == '/')
+ slash++;
+ if (!slash || !*slash)
+ return it; /* prefix ended with slashes */
+ path = slash;
+ }
+ return it;
+}
diff --git a/cache-tree.h b/cache-tree.h
index 72c64801f5e16d1e5d03dab505a388138dfcd8ab..119407e3a10562166fc61e009613842b213dfcfc 100644 (file)
--- a/cache-tree.h
+++ b/cache-tree.h
int cache_tree_fully_valid(struct cache_tree *);
int cache_tree_update(struct cache_tree *, struct cache_entry **, int, int, int);
+struct cache_tree *cache_tree_find(struct cache_tree *, const char *);
+
#endif
diff --git a/t/t0000-basic.sh b/t/t0000-basic.sh
index cf33989b5687e171bcef159f74af9a37973c1285..2c9bbb59b03d97ea668ab3010eaca95eb36f64e8 100755 (executable)
--- a/t/t0000-basic.sh
+++ b/t/t0000-basic.sh
'git-ls-tree -r output for a known tree.' \
'diff current expected'
+test_expect_success \
+ 'writing partial tree out with git-write-tree --prefix.' \
+ 'ptree=$(git-write-tree --prefix=path3)'
+test_expect_success \
+ 'validate object ID for a known tree.' \
+ 'test "$ptree" = 21ae8269cacbe57ae09138dcc3a2887f904d02b3'
+
+test_expect_success \
+ 'writing partial tree out with git-write-tree --prefix.' \
+ 'ptree=$(git-write-tree --prefix=path3/subp3)'
+test_expect_success \
+ 'validate object ID for a known tree.' \
+ 'test "$ptree" = 3c5e5399f3a333eddecce7a9b9465b63f65f51e2'
+
################################################################
rm .git/index
test_expect_success \
diff --git a/write-tree.c b/write-tree.c
index 7a4f691d8ab8f6f560685ec6fe71cf2d82e8a018..895e7a359d108312918c27d98c7b529f2e25e300 100644 (file)
--- a/write-tree.c
+++ b/write-tree.c
#include "cache-tree.h"
static int missing_ok = 0;
+static char *prefix = NULL;
-static const char write_tree_usage[] = "git-write-tree [--missing-ok]";
+static const char write_tree_usage[] =
+"git-write-tree [--missing-ok] [--prefix=<prefix>/]";
static struct cache_file cache_file;
newfd = hold_index_file_for_update(&cache_file, get_index_file());
entries = read_cache();
- if (argc == 2) {
- if (!strcmp(argv[1], "--missing-ok"))
+
+ while (1 < argc) {
+ char *arg = argv[1];
+ if (!strcmp(arg, "--missing-ok"))
missing_ok = 1;
+ else if (!strncmp(arg, "--prefix=", 9))
+ prefix = arg + 9;
else
die(write_tree_usage);
+ argc--; argv++;
}
-
+
if (argc > 2)
die("too many options");
* performance penalty and not a big deal.
*/
}
- printf("%s\n", sha1_to_hex(active_cache_tree->sha1));
+ if (prefix) {
+ struct cache_tree *subtree =
+ cache_tree_find(active_cache_tree, prefix);
+ printf("%s\n", sha1_to_hex(subtree->sha1));
+ }
+ else
+ printf("%s\n", sha1_to_hex(active_cache_tree->sha1));
return 0;
}