Skip to content

Commit 4440690

Browse files
peffgitster
authored andcommitted
builtin/apply.c: use xstrdup_or_null instead of null_strdup
This file had its own identical helper that predates xstrdup_or_null. Let's use the global one to avoid repetition. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d64ea0f commit 4440690

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

builtin/apply.c

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -656,11 +656,6 @@ static size_t diff_timestamp_len(const char *line, size_t len)
656656
return line + len - end;
657657
}
658658

659-
static char *null_strdup(const char *s)
660-
{
661-
return s ? xstrdup(s) : NULL;
662-
}
663-
664659
static char *find_name_common(const char *line, const char *def,
665660
int p_value, const char *end, int terminate)
666661
{
@@ -683,10 +678,10 @@ static char *find_name_common(const char *line, const char *def,
683678
start = line;
684679
}
685680
if (!start)
686-
return squash_slash(null_strdup(def));
681+
return squash_slash(xstrdup_or_null(def));
687682
len = line - start;
688683
if (!len)
689-
return squash_slash(null_strdup(def));
684+
return squash_slash(xstrdup_or_null(def));
690685

691686
/*
692687
* Generally we prefer the shorter name, especially
@@ -908,7 +903,7 @@ static void parse_traditional_patch(const char *first, const char *second, struc
908903
patch->old_name = name;
909904
} else {
910905
patch->old_name = name;
911-
patch->new_name = null_strdup(name);
906+
patch->new_name = xstrdup_or_null(name);
912907
}
913908
}
914909
if (!name)
@@ -997,15 +992,15 @@ static int gitdiff_delete(const char *line, struct patch *patch)
997992
{
998993
patch->is_delete = 1;
999994
free(patch->old_name);
1000-
patch->old_name = null_strdup(patch->def_name);
995+
patch->old_name = xstrdup_or_null(patch->def_name);
1001996
return gitdiff_oldmode(line, patch);
1002997
}
1003998

1004999
static int gitdiff_newfile(const char *line, struct patch *patch)
10051000
{
10061001
patch->is_new = 1;
10071002
free(patch->new_name);
1008-
patch->new_name = null_strdup(patch->def_name);
1003+
patch->new_name = xstrdup_or_null(patch->def_name);
10091004
return gitdiff_newmode(line, patch);
10101005
}
10111006

0 commit comments

Comments
 (0)