git-instaweb: fix lighttpd configuration on cygwin
[gitweb.git] / builtin-apply.c
index cb988a35269e6c28bffe6e7c3c408c9a6a60049c..f312798af38553e0badeda9732736a62460eae05 100644 (file)
@@ -635,7 +635,7 @@ static int gitdiff_index(const char *line, struct patch *patch)
        memcpy(patch->new_sha1_prefix, line, len);
        patch->new_sha1_prefix[len] = 0;
        if (*ptr == ' ')
-               patch->new_mode = patch->old_mode = strtoul(ptr+1, NULL, 8);
+               patch->old_mode = strtoul(ptr+1, NULL, 8);
        return 0;
 }
 
@@ -1258,8 +1258,9 @@ static char *inflate_it(const void *data, unsigned long size,
        stream.avail_in = size;
        stream.next_out = out = xmalloc(inflated_size);
        stream.avail_out = inflated_size;
-       inflateInit(&stream);
-       st = inflate(&stream, Z_FINISH);
+       git_inflate_init(&stream);
+       st = git_inflate(&stream, Z_FINISH);
+       git_inflate_end(&stream);
        if ((st != Z_STREAM_END) || stream.total_out != inflated_size) {
                free(out);
                return NULL;
@@ -2440,7 +2441,7 @@ static int check_preimage(struct patch *patch, struct cache_entry **ce, struct s
                return error("%s: %s", old_name, strerror(errno));
        }
 
-       if (!cached)
+       if (!cached && !tpatch)
                st_mode = ce_mode_from_stat(*ce, st->st_mode);
 
        if (patch->is_new < 0)
@@ -2452,6 +2453,8 @@ static int check_preimage(struct patch *patch, struct cache_entry **ce, struct s
        if (st_mode != patch->old_mode)
                fprintf(stderr, "warning: %s has type %o, expected %o\n",
                        old_name, st_mode, patch->old_mode);
+       if (!patch->new_mode && !patch->is_delete)
+               patch->new_mode = st_mode;
        return 0;
 
  is_new:
@@ -3140,16 +3143,6 @@ static int git_apply_config(const char *var, const char *value, void *cb)
        return git_default_config(var, value, cb);
 }
 
-static int option_parse_stdin(const struct option *opt,
-                             const char *arg, int unset)
-{
-       int *errs = opt->value;
-
-       *errs |= apply_patch(0, "<stdin>", options);
-       read_stdin = 0;
-       return 0;
-}
-
 static int option_parse_exclude(const struct option *opt,
                                const char *arg, int unset)
 {
@@ -3218,9 +3211,6 @@ int cmd_apply(int argc, const char **argv, const char *unused_prefix)
        const char *whitespace_option = NULL;
 
        struct option builtin_apply_options[] = {
-               { OPTION_CALLBACK, '-', NULL, &errs, NULL,
-                       "read the patch from the standard input",
-                       PARSE_OPT_NOARG, option_parse_stdin },
                { OPTION_CALLBACK, 0, "exclude", NULL, "path",
                        "donĀ“t apply changes matching the given path",
                        0, option_parse_exclude },
@@ -3302,7 +3292,11 @@ int cmd_apply(int argc, const char **argv, const char *unused_prefix)
                const char *arg = argv[i];
                int fd;
 
-               if (0 < prefix_length)
+               if (!strcmp(arg, "-")) {
+                       errs |= apply_patch(0, "<stdin>", options);
+                       read_stdin = 0;
+                       continue;
+               } else if (0 < prefix_length)
                        arg = prefix_filename(prefix, prefix_length, arg);
 
                fd = open(arg, O_RDONLY);