summaryrefslogtreecommitdiff
path: root/transport.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2017-02-08 20:52:54 (GMT)
committerJunio C Hamano <gitster@pobox.com>2017-02-08 23:39:55 (GMT)
commit5e8c968c6465d35c9047ab3ed522cb08d46386f5 (patch)
treeb26c9029831c2d9565c27a2626bc4a3c09030208 /transport.c
parentece657f39939d067265eaf57e519a20019bcf794 (diff)
downloadgit-5e8c968c6465d35c9047ab3ed522cb08d46386f5.zip
git-5e8c968c6465d35c9047ab3ed522cb08d46386f5.tar.gz
git-5e8c968c6465d35c9047ab3ed522cb08d46386f5.tar.bz2
for_each_alternate_ref: use strbuf for path allocation
We have a string with ".../objects" pointing to the alternate object store, and overwrite bits of it to look at other paths in the (potential) git repository holding it. This works because the only path we care about is "refs", which is shorter than "objects". Using a strbuf to hold the path lets us get rid of some magic numbers, and makes it more obvious that the memory operations are safe. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'transport.c')
-rw-r--r--transport.c28
1 files changed, 14 insertions, 14 deletions
diff --git a/transport.c b/transport.c
index 6fba9e9..6b78471 100644
--- a/transport.c
+++ b/transport.c
@@ -1214,34 +1214,34 @@ struct alternate_refs_data {
static int refs_from_alternate_cb(struct alternate_object_database *e,
void *data)
{
- char *other;
- size_t len;
+ struct strbuf path = STRBUF_INIT;
+ size_t base_len;
struct remote *remote;
struct transport *transport;
const struct ref *extra;
struct alternate_refs_data *cb = data;
- other = real_pathdup(e->path);
- if (!other)
- return 0;
- len = strlen(other);
-
- if (len < 8 || memcmp(other + len - 8, "/objects", 8))
+ if (!strbuf_realpath(&path, e->path, 0))
+ goto out;
+ if (!strbuf_strip_suffix(&path, "/objects"))
goto out;
+ base_len = path.len;
+
/* Is this a git repository with refs? */
- memcpy(other + len - 8, "/refs", 6);
- if (!is_directory(other))
+ strbuf_addstr(&path, "/refs");
+ if (!is_directory(path.buf))
goto out;
- other[len - 8] = '\0';
- remote = remote_get(other);
- transport = transport_get(remote, other);
+ strbuf_setlen(&path, base_len);
+
+ remote = remote_get(path.buf);
+ transport = transport_get(remote, path.buf);
for (extra = transport_get_remote_refs(transport);
extra;
extra = extra->next)
cb->fn(extra, cb->data);
transport_disconnect(transport);
out:
- free(other);
+ strbuf_release(&path);
return 0;
}