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:
16
wt-status.c
16
wt-status.c
@ -854,7 +854,7 @@ static void wt_status_print_tracking(struct wt_status *s)
|
||||
int i;
|
||||
|
||||
assert(s->branch && !s->is_initial);
|
||||
if (prefixcmp(s->branch, "refs/heads/"))
|
||||
if (!starts_with(s->branch, "refs/heads/"))
|
||||
return;
|
||||
branch = branch_get(s->branch + 11);
|
||||
if (!format_tracking_info(branch, &sb))
|
||||
@ -1113,9 +1113,9 @@ static char *read_and_strip_branch(const char *path)
|
||||
strbuf_setlen(&sb, sb.len - 1);
|
||||
if (!sb.len)
|
||||
goto got_nothing;
|
||||
if (!prefixcmp(sb.buf, "refs/heads/"))
|
||||
if (starts_with(sb.buf, "refs/heads/"))
|
||||
strbuf_remove(&sb,0, strlen("refs/heads/"));
|
||||
else if (!prefixcmp(sb.buf, "refs/"))
|
||||
else if (starts_with(sb.buf, "refs/"))
|
||||
;
|
||||
else if (!get_sha1_hex(sb.buf, sha1)) {
|
||||
const char *abbrev;
|
||||
@ -1145,7 +1145,7 @@ static int grab_1st_switch(unsigned char *osha1, unsigned char *nsha1,
|
||||
struct grab_1st_switch_cbdata *cb = cb_data;
|
||||
const char *target = NULL, *end;
|
||||
|
||||
if (prefixcmp(message, "checkout: moving from "))
|
||||
if (!starts_with(message, "checkout: moving from "))
|
||||
return 0;
|
||||
message += strlen("checkout: moving from ");
|
||||
target = strstr(message, " to ");
|
||||
@ -1180,9 +1180,9 @@ static void wt_status_get_detached_from(struct wt_status_state *state)
|
||||
((commit = lookup_commit_reference_gently(sha1, 1)) != NULL &&
|
||||
!hashcmp(cb.nsha1, commit->object.sha1)))) {
|
||||
int ofs;
|
||||
if (!prefixcmp(ref, "refs/tags/"))
|
||||
if (starts_with(ref, "refs/tags/"))
|
||||
ofs = strlen("refs/tags/");
|
||||
else if (!prefixcmp(ref, "refs/remotes/"))
|
||||
else if (starts_with(ref, "refs/remotes/"))
|
||||
ofs = strlen("refs/remotes/");
|
||||
else
|
||||
ofs = 0;
|
||||
@ -1271,7 +1271,7 @@ void wt_status_print(struct wt_status *s)
|
||||
if (s->branch) {
|
||||
const char *on_what = _("On branch ");
|
||||
const char *branch_name = s->branch;
|
||||
if (!prefixcmp(branch_name, "refs/heads/"))
|
||||
if (starts_with(branch_name, "refs/heads/"))
|
||||
branch_name += 11;
|
||||
else if (!strcmp(branch_name, "HEAD")) {
|
||||
branch_status_color = color(WT_STATUS_NOBRANCH, s);
|
||||
@ -1472,7 +1472,7 @@ static void wt_shortstatus_print_tracking(struct wt_status *s)
|
||||
return;
|
||||
branch_name = s->branch;
|
||||
|
||||
if (!prefixcmp(branch_name, "refs/heads/"))
|
||||
if (starts_with(branch_name, "refs/heads/"))
|
||||
branch_name += 11;
|
||||
else if (!strcmp(branch_name, "HEAD")) {
|
||||
branch_name = _("HEAD (no branch)");
|
||||
|
Reference in New Issue
Block a user