summaryrefslogtreecommitdiff
path: root/cache.h
diff options
context:
space:
mode:
authorLibravatar Jeff King <peff@peff.net>2016-10-03 16:34:48 -0400
committerLibravatar Junio C Hamano <gitster@pobox.com>2016-10-10 13:52:36 -0700
commit4ea82473aa310de7543141f96c2e6b23ef9fcd4c (patch)
treea0dc2524271418b69d24bfa015c49d031271c6d5 /cache.h
parentlink_alt_odb_entry: handle normalize_path errors (diff)
downloadtgif-4ea82473aa310de7543141f96c2e6b23ef9fcd4c.tar.xz
link_alt_odb_entry: refactor string handling
The string handling in link_alt_odb_entry() is mostly an artifact of the original version, which took the path as a ptr/len combo, and did not have a NUL-terminated string until we created one in the alternate_object_database struct. But since 5bdf0a8 (sha1_file: normalize alt_odb path before comparing and storing, 2011-09-07), the first thing we do is put the path into a strbuf, which gives us some easy opportunities for cleanup. In particular: - we call strlen(pathbuf.buf), which is silly; we can look at pathbuf.len. - even though we have a strbuf, we don't maintain its "len" field when chomping extra slashes from the end, and instead keep a separate "pfxlen" variable. We can fix this and then drop "pfxlen" entirely. - we don't check whether the path is usable until after we allocate the new struct, making extra cleanup work for ourselves. Since we have a NUL-terminated string, we can bump the "is it usable" checks higher in the function. While we're at it, we can move that logic to its own helper, which makes the flow of link_alt_odb_entry() easier to follow. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'cache.h')
0 files changed, 0 insertions, 0 deletions