* [PATCH] fetch: use skip_prefix() instead of starts_with()
@ 2019-11-26 11:18 René Scharfe
2019-11-26 16:09 ` Jeff King
0 siblings, 1 reply; 2+ messages in thread
From: René Scharfe @ 2019-11-26 11:18 UTC (permalink / raw)
To: Git Mailing List; +Cc: Junio C Hamano
Get rid of magic numbers by letting skip_prefix() set the pointer
"what".
Signed-off-by: René Scharfe <l.s.r@web.de>
---
builtin/fetch.c | 12 +++---------
1 file changed, 3 insertions(+), 9 deletions(-)
diff --git a/builtin/fetch.c b/builtin/fetch.c
index 863c858fde..02e8619618 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -954,18 +954,12 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
kind = "";
what = "";
}
- else if (starts_with(rm->name, "refs/heads/")) {
+ else if (skip_prefix(rm->name, "refs/heads/", &what))
kind = "branch";
- what = rm->name + 11;
- }
- else if (starts_with(rm->name, "refs/tags/")) {
+ else if (skip_prefix(rm->name, "refs/tags/", &what))
kind = "tag";
- what = rm->name + 10;
- }
- else if (starts_with(rm->name, "refs/remotes/")) {
+ else if (skip_prefix(rm->name, "refs/remotes/", &what))
kind = "remote-tracking branch";
- what = rm->name + 13;
- }
else {
kind = "";
what = rm->name;
--
2.24.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] fetch: use skip_prefix() instead of starts_with()
2019-11-26 11:18 [PATCH] fetch: use skip_prefix() instead of starts_with() René Scharfe
@ 2019-11-26 16:09 ` Jeff King
0 siblings, 0 replies; 2+ messages in thread
From: Jeff King @ 2019-11-26 16:09 UTC (permalink / raw)
To: René Scharfe; +Cc: Git Mailing List, Junio C Hamano
On Tue, Nov 26, 2019 at 12:18:26PM +0100, René Scharfe wrote:
> diff --git a/builtin/fetch.c b/builtin/fetch.c
> index 863c858fde..02e8619618 100644
> --- a/builtin/fetch.c
> +++ b/builtin/fetch.c
> @@ -954,18 +954,12 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
> kind = "";
> what = "";
> }
> - else if (starts_with(rm->name, "refs/heads/")) {
> + else if (skip_prefix(rm->name, "refs/heads/", &what))
> kind = "branch";
> - what = rm->name + 11;
> - }
> - else if (starts_with(rm->name, "refs/tags/")) {
> + else if (skip_prefix(rm->name, "refs/tags/", &what))
> kind = "tag";
> - what = rm->name + 10;
> - }
> - else if (starts_with(rm->name, "refs/remotes/")) {
> + else if (skip_prefix(rm->name, "refs/remotes/", &what))
> kind = "remote-tracking branch";
> - what = rm->name + 13;
> - }
> else {
Yep, this one looks obviously correct. We were already mutating "what",
so this just does it inside skip_prefix(). Much nicer.
-Peff
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-11-26 16:09 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-26 11:18 [PATCH] fetch: use skip_prefix() instead of starts_with() René Scharfe
2019-11-26 16:09 ` Jeff King
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).