* [PATCH] push: use skip_prefix() instead of starts_with()
@ 2019-11-26 15:18 René Scharfe
2019-11-26 15:57 ` Jeff King
0 siblings, 1 reply; 2+ messages in thread
From: René Scharfe @ 2019-11-26 15:18 UTC (permalink / raw)
To: Git Mailing List; +Cc: Junio C Hamano
Get rid of a magic number by using skip_prefix().
Signed-off-by: René Scharfe <l.s.r@web.de>
---
builtin/push.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/builtin/push.c b/builtin/push.c
index 843f5b22a2..6dbf0f0bb7 100644
--- a/builtin/push.c
+++ b/builtin/push.c
@@ -64,6 +64,7 @@ static struct string_list push_options_config = STRING_LIST_INIT_DUP;
static const char *map_refspec(const char *ref,
struct remote *remote, struct ref *local_refs)
{
+ const char *branch_name;
struct ref *matched = NULL;
/* Does "ref" uniquely name our ref? */
@@ -84,8 +85,8 @@ static const char *map_refspec(const char *ref,
}
if (push_default == PUSH_DEFAULT_UPSTREAM &&
- starts_with(matched->name, "refs/heads/")) {
- struct branch *branch = branch_get(matched->name + 11);
+ skip_prefix(matched->name, "refs/heads/", &branch_name)) {
+ struct branch *branch = branch_get(branch_name);
if (branch->merge_nr == 1 && branch->merge[0]->src) {
struct strbuf buf = STRBUF_INIT;
strbuf_addf(&buf, "%s:%s",
--
2.24.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] push: use skip_prefix() instead of starts_with()
2019-11-26 15:18 [PATCH] push: use skip_prefix() instead of starts_with() René Scharfe
@ 2019-11-26 15:57 ` Jeff King
0 siblings, 0 replies; 2+ messages in thread
From: Jeff King @ 2019-11-26 15:57 UTC (permalink / raw)
To: René Scharfe; +Cc: Git Mailing List, Junio C Hamano
On Tue, Nov 26, 2019 at 04:18:28PM +0100, René Scharfe wrote:
> diff --git a/builtin/push.c b/builtin/push.c
> index 843f5b22a2..6dbf0f0bb7 100644
> --- a/builtin/push.c
> +++ b/builtin/push.c
> @@ -64,6 +64,7 @@ static struct string_list push_options_config = STRING_LIST_INIT_DUP;
> static const char *map_refspec(const char *ref,
> struct remote *remote, struct ref *local_refs)
> {
> + const char *branch_name;
> struct ref *matched = NULL;
>
> /* Does "ref" uniquely name our ref? */
> @@ -84,8 +85,8 @@ static const char *map_refspec(const char *ref,
> }
>
> if (push_default == PUSH_DEFAULT_UPSTREAM &&
> - starts_with(matched->name, "refs/heads/")) {
> - struct branch *branch = branch_get(matched->name + 11);
> + skip_prefix(matched->name, "refs/heads/", &branch_name)) {
> + struct branch *branch = branch_get(branch_name);
Yep, obviously correct because you introduce a new variable instead of
mutating an existing one. Looks good.
-Peff
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-11-26 15:57 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-26 15:18 [PATCH] push: use skip_prefix() instead of starts_with() René Scharfe
2019-11-26 15:57 ` 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).