Merge branch 'cc/starts-n-ends-with'
Remove a few duplicate implementations of prefix/suffix comparison functions, and rename them to starts_with and ends_with. * cc/starts-n-ends-with: replace {pre,suf}fixcmp() with {starts,ends}_with() strbuf: introduce starts_with() and ends_with() builtin/remote: remove postfixcmp() and use suffixcmp() instead environment: normalize use of prefixcmp() by removing " != 0"
This commit is contained in:
@ -78,14 +78,6 @@ static const char * const builtin_remote_seturl_usage[] = {
|
||||
|
||||
static int verbose;
|
||||
|
||||
static inline int postfixcmp(const char *string, const char *postfix)
|
||||
{
|
||||
int len1 = strlen(string), len2 = strlen(postfix);
|
||||
if (len1 < len2)
|
||||
return 1;
|
||||
return strcmp(string + len1 - len2, postfix);
|
||||
}
|
||||
|
||||
static int fetch_remote(const char *name)
|
||||
{
|
||||
const char *argv[] = { "fetch", name, NULL, NULL };
|
||||
@ -267,7 +259,7 @@ static const char *abbrev_ref(const char *name, const char *prefix)
|
||||
|
||||
static int config_read_branches(const char *key, const char *value, void *cb)
|
||||
{
|
||||
if (!prefixcmp(key, "branch.")) {
|
||||
if (starts_with(key, "branch.")) {
|
||||
const char *orig_key = key;
|
||||
char *name;
|
||||
struct string_list_item *item;
|
||||
@ -275,13 +267,13 @@ static int config_read_branches(const char *key, const char *value, void *cb)
|
||||
enum { REMOTE, MERGE, REBASE } type;
|
||||
|
||||
key += 7;
|
||||
if (!postfixcmp(key, ".remote")) {
|
||||
if (ends_with(key, ".remote")) {
|
||||
name = xstrndup(key, strlen(key) - 7);
|
||||
type = REMOTE;
|
||||
} else if (!postfixcmp(key, ".merge")) {
|
||||
} else if (ends_with(key, ".merge")) {
|
||||
name = xstrndup(key, strlen(key) - 6);
|
||||
type = MERGE;
|
||||
} else if (!postfixcmp(key, ".rebase")) {
|
||||
} else if (ends_with(key, ".rebase")) {
|
||||
name = xstrndup(key, strlen(key) - 7);
|
||||
type = REBASE;
|
||||
} else
|
||||
@ -537,9 +529,9 @@ static int add_branch_for_removal(const char *refname,
|
||||
}
|
||||
|
||||
/* don't delete non-remote-tracking refs */
|
||||
if (prefixcmp(refname, "refs/remotes/")) {
|
||||
if (!starts_with(refname, "refs/remotes/")) {
|
||||
/* advise user how to delete local branches */
|
||||
if (!prefixcmp(refname, "refs/heads/"))
|
||||
if (starts_with(refname, "refs/heads/"))
|
||||
string_list_append(branches->skipped,
|
||||
abbrev_branch(refname));
|
||||
/* silently skip over other non-remote refs */
|
||||
@ -574,7 +566,7 @@ static int read_remote_branches(const char *refname,
|
||||
const char *symref;
|
||||
|
||||
strbuf_addf(&buf, "refs/remotes/%s/", rename->old);
|
||||
if (!prefixcmp(refname, buf.buf)) {
|
||||
if (starts_with(refname, buf.buf)) {
|
||||
item = string_list_append(rename->remote_branches, xstrdup(refname));
|
||||
symref = resolve_ref_unsafe(refname, orig_sha1, 1, &flag);
|
||||
if (flag & REF_ISSYMREF)
|
||||
|
Reference in New Issue
Block a user