@matheusbsbs / matheus-bagliano / commits / fbca583732
Fork 0

Move parse-options's skip_prefix() to git-compat-util.h

builtin-remote.c and parse-options.c both have a skip_prefix() function, for the same purpose. Move parse-options's one to git-compat-util.h and let builtin-remote use it as well. Signed-off-by: Miklos Vajna <vmiklos@frugalware.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Miklos Vajna committed Jun 27, 2008 at 18:21 UTC fbca58373291afa07c5b30ab562d36ce0f6174e0
3 files changed +32 -19
builtin-remote.c
+26 -13
@@ -29,12 +29,6 @@ static inline int postfixcmp(const char *string, const char *postfix)
29 return strcmp(string + len1 - len2, postfix);
30 }
31
32 -static inline const char *skip_prefix(const char *name, const char *prefix)
33 -{
34 - return !name ? "" :
35 - prefixcmp(name, prefix) ? name : name + strlen(prefix);
36 -}
37 -
32 static int opt_parse_track(const struct option *opt, const char *arg, int not)
33 {
34 struct path_list *list = opt->value;
@@ -182,12 +176,18 @@ static int config_read_branches(const char *key, const char *value, void *cb)
176 info->remote = xstrdup(value);
177 } else {
178 char *space = strchr(value, ' ');
185 - value = skip_prefix(value, "refs/heads/");
179 + const char *ptr = skip_prefix(value, "refs/heads/");
180 + if (ptr)
181 + value = ptr;
182 while (space) {
183 char *merge;
184 merge = xstrndup(value, space - value);
185 path_list_append(merge, &info->merge);
190 - value = skip_prefix(space + 1, "refs/heads/");
186 + ptr = skip_prefix(space + 1, "refs/heads/");
187 + if (ptr)
188 + value = ptr;
189 + else
190 + value = space + 1;
191 space = strchr(value, ' ');
192 }
193 path_list_append(xstrdup(value), &info->merge);
@@ -219,7 +219,12 @@ static int handle_one_branch(const char *refname,
219 refspec.dst = (char *)refname;
220 if (!remote_find_tracking(states->remote, &refspec)) {
221 struct path_list_item *item;
222 - const char *name = skip_prefix(refspec.src, "refs/heads/");
222 + const char *name, *ptr;
223 + ptr = skip_prefix(refspec.src, "refs/heads/");
224 + if (ptr)
225 + name = ptr;
226 + else
227 + name = refspec.src;
228 /* symbolic refs pointing nowhere were handled already */
229 if ((flags & REF_ISSYMREF) ||
230 unsorted_path_list_has_path(&states->tracked,
@@ -248,6 +253,7 @@ static int get_ref_states(const struct ref *ref, struct ref_states *states)
253 struct path_list *target = &states->tracked;
254 unsigned char sha1[20];
255 void *util = NULL;
256 + const char *ptr;
257
258 if (!ref->peer_ref || read_ref(ref->peer_ref->name, sha1))
259 target = &states->new;
@@ -256,8 +262,10 @@ static int get_ref_states(const struct ref *ref, struct ref_states *states)
262 if (hashcmp(sha1, ref->new_sha1))
263 util = &states;
264 }
259 - path_list_append(skip_prefix(ref->name, "refs/heads/"),
260 - target)->util = util;
265 + ptr = skip_prefix(ref->name, "refs/heads/");
266 + if (!ptr)
267 + ptr = ref->name;
268 + path_list_append(ptr, target)->util = util;
269 }
270 free_refs(fetch_map);
271
@@ -522,10 +530,15 @@ static int show(int argc, const char **argv)
530 "es" : "");
531 for (i = 0; i < states.remote->push_refspec_nr; i++) {
532 struct refspec *spec = states.remote->push + i;
533 + const char *p = "", *q = "";
534 + if (spec->src)
535 + p = skip_prefix(spec->src, "refs/heads/");
536 + if (spec->dst)
537 + q = skip_prefix(spec->dst, "refs/heads/");
538 printf(" %s%s%s%s", spec->force ? "+" : "",
526 - skip_prefix(spec->src, "refs/heads/"),
539 + p ? p : spec->src,
540 spec->dst ? ":" : "",
528 - skip_prefix(spec->dst, "refs/heads/"));
541 + q ? q : spec->dst);
542 }
543 printf("\n");
544 }
git-compat-util.h
+6
@@ -127,6 +127,12 @@ extern void set_warn_routine(void (*routine)(const char *warn, va_list params));
127
128 extern int prefixcmp(const char *str, const char *prefix);
129
130 +static inline const char *skip_prefix(const char *str, const char *prefix)
131 +{
132 + size_t len = strlen(prefix);
133 + return strncmp(str, prefix, len) ? NULL : str + len;
134 +}
135 +
136 #ifdef NO_MMAP
137
138 #ifndef PROT_READ
parse-options.c
-6
@@ -22,12 +22,6 @@ static inline const char *get_arg(struct optparse_t *p)
22 return *++p->argv;
23 }
24
25 -static inline const char *skip_prefix(const char *str, const char *prefix)
26 -{
27 - size_t len = strlen(prefix);
28 - return strncmp(str, prefix, len) ? NULL : str + len;
29 -}
30 -
25 static int opterror(const struct option *opt, const char *reason, int flags)
26 {
27 if (flags & OPT_SHORT)