From: Jeff King Date: Mon, 3 Oct 2016 20:34:48 +0000 (-0400) Subject: link_alt_odb_entry: refactor string handling X-Git-Tag: v2.14.2~11^2~2 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/4ea82473aa310de7543141f96c2e6b23ef9fcd4c?hp=4ea82473aa310de7543141f96c2e6b23ef9fcd4c 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 Signed-off-by: Junio C Hamano ---