builtin/apply: make gitdiff_verify_name() return void

As the value returned by gitdiff_verify_name() is put into the same variable that is passed as a parameter to this function, it is simpler to pass the address of the variable and have gitdiff_verify_name() change the variable itself. This also makes it possible to later have this function return -1 instead of die()ing in case of error. Reviewed-by: Stefan Beller <sbeller@google.com> Signed-off-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Christian Couder committed May 11, 2016 at 15:16 UTC 12913a78cedc491f89a34ab0b545831d6006fc98
1 file changed +13 -13
builtin/apply.c
+13 -13
@@ -925,43 +925,43 @@ static int gitdiff_hdrend(const char *line, struct patch *patch)
925 #define DIFF_OLD_NAME 0
926 #define DIFF_NEW_NAME 1
927
928 -static char *gitdiff_verify_name(const char *line, int isnull, char *orig_name, int side)
928 +static void gitdiff_verify_name(const char *line, int isnull, char **name, int side)
929 {
930 - if (!orig_name && !isnull)
931 - return find_name(line, NULL, p_value, TERM_TAB);
930 + if (!*name && !isnull) {
931 + *name = find_name(line, NULL, p_value, TERM_TAB);
932 + return;
933 + }
934
933 - if (orig_name) {
934 - int len = strlen(orig_name);
935 + if (*name) {
936 + int len = strlen(*name);
937 char *another;
938 if (isnull)
939 die(_("git apply: bad git-diff - expected /dev/null, got %s on line %d"),
938 - orig_name, linenr);
940 + *name, linenr);
941 another = find_name(line, NULL, p_value, TERM_TAB);
940 - if (!another || memcmp(another, orig_name, len + 1))
942 + if (!another || memcmp(another, *name, len + 1))
943 die((side == DIFF_NEW_NAME) ?
944 _("git apply: bad git-diff - inconsistent new filename on line %d") :
945 _("git apply: bad git-diff - inconsistent old filename on line %d"), linenr);
946 free(another);
945 - return orig_name;
947 } else {
948 /* expect "/dev/null" */
949 if (memcmp("/dev/null", line, 9) || line[9] != '\n')
950 die(_("git apply: bad git-diff - expected /dev/null on line %d"), linenr);
950 - return NULL;
951 }
952 }
953
954 static int gitdiff_oldname(const char *line, struct patch *patch)
955 {
956 - patch->old_name = gitdiff_verify_name(line, patch->is_new, patch->old_name,
957 - DIFF_OLD_NAME);
956 + gitdiff_verify_name(line, patch->is_new, &patch->old_name,
957 + DIFF_OLD_NAME);
958 return 0;
959 }
960
961 static int gitdiff_newname(const char *line, struct patch *patch)
962 {
963 - patch->new_name = gitdiff_verify_name(line, patch->is_delete, patch->new_name,
964 - DIFF_NEW_NAME);
963 + gitdiff_verify_name(line, patch->is_delete, &patch->new_name,
964 + DIFF_NEW_NAME);
965 return 0;
966 }
967