Re: [PATCH 47/83] builtin/apply: move applying patches into apply_all_patches()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, Apr 24, 2016 at 6:33 AM, Christian Couder
<christian.couder@xxxxxxxxx> wrote:
> Signed-off-by: Christian Couder <chriscool@xxxxxxxxxxxxx>

Up to this patch, have a
Reviewed-by: Stefan Beller <sbeller@xxxxxxxxxx>
in case you want to split the series in here (as indicated in the
cover letter, this was the last
patch rerolled, the next patches are new and may need more discussion).

I had some nits, but they cleared up in later patches.

Thanks,
Stefan

> ---
>  builtin/apply.c | 128 ++++++++++++++++++++++++++++++--------------------------
>  1 file changed, 69 insertions(+), 59 deletions(-)
>
> diff --git a/builtin/apply.c b/builtin/apply.c
> index 94bf120..787426f 100644
> --- a/builtin/apply.c
> +++ b/builtin/apply.c
> @@ -4720,13 +4720,79 @@ static void check_apply_state(struct apply_state *state, int force_apply)
>                 state->unsafe_paths = 0;
>  }
>
> -int cmd_apply(int argc, const char **argv, const char *prefix_)
> +static int apply_all_patches(struct apply_state *state,
> +                            int argc,
> +                            const char **argv,
> +                            int options)
>  {
>         int i;
>         int errs = 0;
> +       int read_stdin = 1;
> +
> +       for (i = 0; i < argc; i++) {
> +               const char *arg = argv[i];
> +               int fd;
> +
> +               if (!strcmp(arg, "-")) {
> +                       errs |= apply_patch(state, 0, "<stdin>", options);
> +                       read_stdin = 0;
> +                       continue;
> +               } else if (0 < state->prefix_length)
> +                       arg = prefix_filename(state->prefix,
> +                                             state->prefix_length,
> +                                             arg);
> +
> +               fd = open(arg, O_RDONLY);
> +               if (fd < 0)
> +                       die_errno(_("can't open patch '%s'"), arg);
> +               read_stdin = 0;
> +               set_default_whitespace_mode(state);
> +               errs |= apply_patch(state, fd, arg, options);
> +               close(fd);
> +       }
> +       set_default_whitespace_mode(state);
> +       if (read_stdin)
> +               errs |= apply_patch(state, 0, "<stdin>", options);
> +
> +       if (state->whitespace_error) {
> +               if (state->squelch_whitespace_errors &&
> +                   state->squelch_whitespace_errors < state->whitespace_error) {
> +                       int squelched =
> +                               state->whitespace_error - state->squelch_whitespace_errors;
> +                       warning(Q_("squelched %d whitespace error",
> +                                  "squelched %d whitespace errors",
> +                                  squelched),
> +                               squelched);
> +               }
> +               if (state->ws_error_action == die_on_ws_error)
> +                       die(Q_("%d line adds whitespace errors.",
> +                              "%d lines add whitespace errors.",
> +                              state->whitespace_error),
> +                           state->whitespace_error);
> +               if (state->applied_after_fixing_ws && state->apply)
> +                       warning("%d line%s applied after"
> +                               " fixing whitespace errors.",
> +                               state->applied_after_fixing_ws,
> +                               state->applied_after_fixing_ws == 1 ? "" : "s");
> +               else if (state->whitespace_error)
> +                       warning(Q_("%d line adds whitespace errors.",
> +                                  "%d lines add whitespace errors.",
> +                                  state->whitespace_error),
> +                               state->whitespace_error);
> +       }
> +
> +       if (state->update_index) {
> +               if (write_locked_index(&the_index, &lock_file, COMMIT_LOCK))
> +                       die(_("Unable to write new index file"));
> +       }
> +
> +       return !!errs;
> +}
> +
> +int cmd_apply(int argc, const char **argv, const char *prefix_)
> +{
>         int force_apply = 0;
>         int options = 0;
> -       int read_stdin = 1;
>         struct apply_state state;
>
>         struct option builtin_apply_options[] = {
> @@ -4805,61 +4871,5 @@ int cmd_apply(int argc, const char **argv, const char *prefix_)
>
>         check_apply_state(&state, force_apply);
>
> -       for (i = 0; i < argc; i++) {
> -               const char *arg = argv[i];
> -               int fd;
> -
> -               if (!strcmp(arg, "-")) {
> -                       errs |= apply_patch(&state, 0, "<stdin>", options);
> -                       read_stdin = 0;
> -                       continue;
> -               } else if (0 < state.prefix_length)
> -                       arg = prefix_filename(state.prefix,
> -                                             state.prefix_length,
> -                                             arg);
> -
> -               fd = open(arg, O_RDONLY);
> -               if (fd < 0)
> -                       die_errno(_("can't open patch '%s'"), arg);
> -               read_stdin = 0;
> -               set_default_whitespace_mode(&state);
> -               errs |= apply_patch(&state, fd, arg, options);
> -               close(fd);
> -       }
> -       set_default_whitespace_mode(&state);
> -       if (read_stdin)
> -               errs |= apply_patch(&state, 0, "<stdin>", options);
> -       if (state.whitespace_error) {
> -               if (state.squelch_whitespace_errors &&
> -                   state.squelch_whitespace_errors < state.whitespace_error) {
> -                       int squelched =
> -                               state.whitespace_error - state.squelch_whitespace_errors;
> -                       warning(Q_("squelched %d whitespace error",
> -                                  "squelched %d whitespace errors",
> -                                  squelched),
> -                               squelched);
> -               }
> -               if (state.ws_error_action == die_on_ws_error)
> -                       die(Q_("%d line adds whitespace errors.",
> -                              "%d lines add whitespace errors.",
> -                              state.whitespace_error),
> -                           state.whitespace_error);
> -               if (state.applied_after_fixing_ws && state.apply)
> -                       warning("%d line%s applied after"
> -                               " fixing whitespace errors.",
> -                               state.applied_after_fixing_ws,
> -                               state.applied_after_fixing_ws == 1 ? "" : "s");
> -               else if (state.whitespace_error)
> -                       warning(Q_("%d line adds whitespace errors.",
> -                                  "%d lines add whitespace errors.",
> -                                  state.whitespace_error),
> -                               state.whitespace_error);
> -       }
> -
> -       if (state.update_index) {
> -               if (write_locked_index(&the_index, &lock_file, COMMIT_LOCK))
> -                       die(_("Unable to write new index file"));
> -       }
> -
> -       return !!errs;
> +       return apply_all_patches(&state, argc, argv, options);
>  }
> --
> 2.8.1.300.g5fed0c0
>
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]