sha1-name: pass len argument to interpret_branch_name()

This is useful to make sure we don't step outside the boundaries of what we are interpreting at the moment. For example while interpreting foobar@{u}~1, the job of interpret_branch_name() ends right before ~1, but there's no way to figure that out inside the function, unless the len argument is passed. So let's do that. Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Felipe Contreras committed Sep 2, 2013 at 01:34 UTC cf99a761d3903dbaf8265f60da9eaee6a15a6fe6
4 files changed +9 -7
cache.h
+1 -1
@@ -893,7 +893,7 @@ extern char *resolve_refdup(const char *ref, unsigned char *sha1, int reading, i
893
894 extern int dwim_ref(const char *str, int len, unsigned char *sha1, char **ref);
895 extern int dwim_log(const char *str, int len, unsigned char *sha1, char **ref);
896 -extern int interpret_branch_name(const char *str, struct strbuf *);
896 +extern int interpret_branch_name(const char *str, int len, struct strbuf *);
897 extern int get_sha1_mb(const char *str, unsigned char *sha1);
898
899 extern int refname_match(const char *abbrev_name, const char *full_name, const char **rules);
refs.c
+1 -1
@@ -1951,7 +1951,7 @@ static int remove_empty_directories(const char *file)
1951 static char *substitute_branch_name(const char **string, int *len)
1952 {
1953 struct strbuf buf = STRBUF_INIT;
1954 - int ret = interpret_branch_name(*string, &buf);
1954 + int ret = interpret_branch_name(*string, *len, &buf);
1955
1956 if (ret == *len) {
1957 size_t size;
revision.c
+1 -1
@@ -200,7 +200,7 @@ static void add_pending_object_with_mode(struct rev_info *revs,
200 revs->no_walk = 0;
201 if (revs->reflog_info && obj->type == OBJ_COMMIT) {
202 struct strbuf buf = STRBUF_INIT;
203 - int len = interpret_branch_name(name, &buf);
203 + int len = interpret_branch_name(name, 0, &buf);
204 int st;
205
206 if (0 < len && name[len] && buf.len)
sha1_name.c
+6 -4
@@ -1012,7 +1012,7 @@ static int reinterpret(const char *name, int namelen, int len, struct strbuf *bu
1012 int ret;
1013
1014 strbuf_add(buf, name + len, namelen - len);
1015 - ret = interpret_branch_name(buf->buf, &tmp);
1015 + ret = interpret_branch_name(buf->buf, buf->len, &tmp);
1016 /* that data was not interpreted, remove our cruft */
1017 if (ret < 0) {
1018 strbuf_setlen(buf, used);
@@ -1046,14 +1046,16 @@ static int reinterpret(const char *name, int namelen, int len, struct strbuf *bu
1046 * If the input was ok but there are not N branch switches in the
1047 * reflog, it returns 0.
1048 */
1049 -int interpret_branch_name(const char *name, struct strbuf *buf)
1049 +int interpret_branch_name(const char *name, int namelen, struct strbuf *buf)
1050 {
1051 char *cp;
1052 struct branch *upstream;
1053 - int namelen = strlen(name);
1053 int len = interpret_nth_prior_checkout(name, buf);
1054 int tmp_len;
1055
1056 + if (!namelen)
1057 + namelen = strlen(name);
1058 +
1059 if (!len) {
1060 return len; /* syntax Ok, not enough switches */
1061 } else if (len > 0) {
@@ -1100,7 +1102,7 @@ int interpret_branch_name(const char *name, struct strbuf *buf)
1102 int strbuf_branchname(struct strbuf *sb, const char *name)
1103 {
1104 int len = strlen(name);
1103 - int used = interpret_branch_name(name, sb);
1105 + int used = interpret_branch_name(name, len, sb);
1106
1107 if (used == len)
1108 return 0;