* [PATCH] fmt-merge-msg: use skip_prefix() instead of starts_with()
@ 2019-11-26 14:22 René Scharfe
2019-11-26 16:10 ` Jeff King
0 siblings, 1 reply; 2+ messages in thread
From: René Scharfe @ 2019-11-26 14:22 UTC (permalink / raw)
To: Git Mailing List; +Cc: Junio C Hamano
Get rid of two magic numbers by using skip_prefix().
Signed-off-by: René Scharfe <l.s.r@web.de>
---
builtin/fmt-merge-msg.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/builtin/fmt-merge-msg.c b/builtin/fmt-merge-msg.c
index a4615587fd..736f666f64 100644
--- a/builtin/fmt-merge-msg.c
+++ b/builtin/fmt-merge-msg.c
@@ -106,7 +106,7 @@ static int handle_line(char *line, struct merge_parents *merge_parents)
int i, len = strlen(line);
struct origin_data *origin_data;
char *src;
- const char *origin;
+ const char *origin, *tag_name;
struct src_data *src_data;
struct string_list_item *item;
int pulling_head = 0;
@@ -162,14 +162,13 @@ static int handle_line(char *line, struct merge_parents *merge_parents)
if (pulling_head) {
origin = src;
src_data->head_status |= 1;
- } else if (starts_with(line, "branch ")) {
+ } else if (skip_prefix(line, "branch ", &origin)) {
origin_data->is_local_branch = 1;
- origin = line + 7;
string_list_append(&src_data->branch, origin);
src_data->head_status |= 2;
- } else if (starts_with(line, "tag ")) {
+ } else if (skip_prefix(line, "tag ", &tag_name)) {
origin = line;
- string_list_append(&src_data->tag, origin + 4);
+ string_list_append(&src_data->tag, tag_name);
src_data->head_status |= 2;
} else if (skip_prefix(line, "remote-tracking branch ", &origin)) {
string_list_append(&src_data->r_branch, origin);
--
2.24.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] fmt-merge-msg: use skip_prefix() instead of starts_with()
2019-11-26 14:22 [PATCH] fmt-merge-msg: use skip_prefix() instead of starts_with() René Scharfe
@ 2019-11-26 16:10 ` Jeff King
0 siblings, 0 replies; 2+ messages in thread
From: Jeff King @ 2019-11-26 16:10 UTC (permalink / raw)
To: René Scharfe; +Cc: Git Mailing List, Junio C Hamano
On Tue, Nov 26, 2019 at 03:22:56PM +0100, René Scharfe wrote:
> diff --git a/builtin/fmt-merge-msg.c b/builtin/fmt-merge-msg.c
> index a4615587fd..736f666f64 100644
> --- a/builtin/fmt-merge-msg.c
> +++ b/builtin/fmt-merge-msg.c
> @@ -106,7 +106,7 @@ static int handle_line(char *line, struct merge_parents *merge_parents)
> int i, len = strlen(line);
> struct origin_data *origin_data;
> char *src;
> - const char *origin;
> + const char *origin, *tag_name;
> struct src_data *src_data;
> struct string_list_item *item;
> int pulling_head = 0;
> @@ -162,14 +162,13 @@ static int handle_line(char *line, struct merge_parents *merge_parents)
> if (pulling_head) {
> origin = src;
> src_data->head_status |= 1;
> - } else if (starts_with(line, "branch ")) {
> + } else if (skip_prefix(line, "branch ", &origin)) {
> origin_data->is_local_branch = 1;
> - origin = line + 7;
> string_list_append(&src_data->branch, origin);
> src_data->head_status |= 2;
> - } else if (starts_with(line, "tag ")) {
> + } else if (skip_prefix(line, "tag ", &tag_name)) {
> origin = line;
> - string_list_append(&src_data->tag, origin + 4);
> + string_list_append(&src_data->tag, tag_name);
> src_data->head_status |= 2;
Looks good, as we're already mutating "origin" in the first one, and
"tag_name" is a new variable in the second one.
-Peff
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-11-26 16:10 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-26 14:22 [PATCH] fmt-merge-msg: use skip_prefix() instead of starts_with() René Scharfe
2019-11-26 16:10 ` Jeff King
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 NNTP newsgroup(s).