summaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2016-10-03 20:35:51 (GMT)
committerJunio C Hamano <gitster@pobox.com>2016-10-10 20:52:36 (GMT)
commit597f9134ded20f882e2bf6bca8b0e1f03981b98d (patch)
treead7cd7eff31ed1dd109230e4ef99de551f0e908c /builtin
parent29ec6af2b81894d3236f2aec100323138023ef4d (diff)
downloadgit-597f9134ded20f882e2bf6bca8b0e1f03981b98d.zip
git-597f9134ded20f882e2bf6bca8b0e1f03981b98d.tar.gz
git-597f9134ded20f882e2bf6bca8b0e1f03981b98d.tar.bz2
alternates: use a separate scratch space
The alternate_object_database struct uses a single buffer both for storing the path to the alternate, and as a scratch buffer for forming object names. This is efficient (since otherwise we'd end up storing the path twice), but it makes life hard for callers who just want to know the path to the alternate. They have to remember to stop reading after "alt->name - alt->base" bytes, and to subtract one for the trailing '/'. It would be much simpler if they could simply access a NUL-terminated path string. We could encapsulate this in a function which puts a NUL in the scratch buffer and returns the string, but that opens up questions about the lifetime of the result. The first time another caller uses the alternate, the scratch buffer may get other data tacked onto it. Let's instead just store the root path separately from the scratch buffer. There aren't enough alternates being stored for the duplicated data to matter for performance, and this keeps things simple and safe for the callers. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin')
-rw-r--r--builtin/fsck.c10
-rw-r--r--builtin/submodule--helper.c11
2 files changed, 5 insertions, 16 deletions
diff --git a/builtin/fsck.c b/builtin/fsck.c
index 055dfdc..f01b81e 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -644,14 +644,8 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
fsck_object_dir(get_object_directory());
prepare_alt_odb();
- for (alt = alt_odb_list; alt; alt = alt->next) {
- /* directory name, minus trailing slash */
- size_t namelen = alt->name - alt->base - 1;
- struct strbuf name = STRBUF_INIT;
- strbuf_add(&name, alt->base, namelen);
- fsck_object_dir(name.buf);
- strbuf_release(&name);
- }
+ for (alt = alt_odb_list; alt; alt = alt->next)
+ fsck_object_dir(alt->path);
}
if (check_full) {
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index e3fdc0a..fd72c90 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -492,20 +492,16 @@ static int add_possible_reference_from_superproject(
{
struct submodule_alternate_setup *sas = sas_cb;
- /* directory name, minus trailing slash */
- size_t namelen = alt->name - alt->base - 1;
- struct strbuf name = STRBUF_INIT;
- strbuf_add(&name, alt->base, namelen);
-
/*
* If the alternate object store is another repository, try the
* standard layout with .git/modules/<name>/objects
*/
- if (ends_with(name.buf, ".git/objects")) {
+ if (ends_with(alt->path, ".git/objects")) {
char *sm_alternate;
struct strbuf sb = STRBUF_INIT;
struct strbuf err = STRBUF_INIT;
- strbuf_add(&sb, name.buf, name.len - strlen("objects"));
+ strbuf_add(&sb, alt->path, strlen(alt->path) - strlen("objects"));
+
/*
* We need to end the new path with '/' to mark it as a dir,
* otherwise a submodule name containing '/' will be broken
@@ -533,7 +529,6 @@ static int add_possible_reference_from_superproject(
strbuf_release(&sb);
}
- strbuf_release(&name);
return 0;
}