Merge branch 'tk/sigchain-unnecessary-post-tempfile'
authorJunio C Hamano <gitster@pobox.com>
Thu, 29 Oct 2015 20:59:17 +0000 (13:59 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 29 Oct 2015 20:59:18 +0000 (13:59 -0700)
Remove no-longer used #include.

* tk/sigchain-unnecessary-post-tempfile:
shallow: remove unused #include "sigchain.h"
read-cache: remove unused #include "sigchain.h"
diff: remove unused #include "sigchain.h"
credential-cache--daemon: remove unused #include "sigchain.h"

1  2 
diff.c
read-cache.c
shallow.c
diff --combined diff.c
index 835a12e84d65b3fa9d680d55b452f7d748a340b1,75ad32ae79128cff1c8d03d113f7c7c7c2266fff..80eb0c2156a0f3727f8a9598f3e83233224539b0
--- 1/diff.c
--- 2/diff.c
+++ b/diff.c
@@@ -13,8 -13,6 +13,7 @@@
  #include "run-command.h"
  #include "utf8.h"
  #include "userdiff.h"
- #include "sigchain.h"
 +#include "submodule-config.h"
  #include "submodule.h"
  #include "ll-merge.h"
  #include "string-list.h"
@@@ -44,7 -42,7 +43,7 @@@ static long diff_algorithm
  
  static char diff_colors[][COLOR_MAXLEN] = {
        GIT_COLOR_RESET,
 -      GIT_COLOR_NORMAL,       /* PLAIN */
 +      GIT_COLOR_NORMAL,       /* CONTEXT */
        GIT_COLOR_BOLD,         /* METAINFO */
        GIT_COLOR_CYAN,         /* FRAGINFO */
        GIT_COLOR_RED,          /* OLD */
@@@ -56,8 -54,8 +55,8 @@@
  
  static int parse_diff_color_slot(const char *var)
  {
 -      if (!strcasecmp(var, "plain"))
 -              return DIFF_PLAIN;
 +      if (!strcasecmp(var, "context") || !strcasecmp(var, "plain"))
 +              return DIFF_CONTEXT;
        if (!strcasecmp(var, "meta"))
                return DIFF_METAINFO;
        if (!strcasecmp(var, "frag"))
@@@ -322,7 -320,7 +321,7 @@@ static struct diff_tempfile 
         */
        const char *name;
  
 -      char hex[41];
 +      char hex[GIT_SHA1_HEXSZ + 1];
        char mode[10];
  
        /*
@@@ -495,63 -493,30 +494,63 @@@ static int new_blank_line_at_eof(struc
        return ws_blank_line(line, len, ecbdata->ws_rule);
  }
  
 -static void emit_add_line(const char *reset,
 -                        struct emit_callback *ecbdata,
 -                        const char *line, int len)
 +static void emit_line_checked(const char *reset,
 +                            struct emit_callback *ecbdata,
 +                            const char *line, int len,
 +                            enum color_diff color,
 +                            unsigned ws_error_highlight,
 +                            char sign)
  {
 -      const char *ws = diff_get_color(ecbdata->color_diff, DIFF_WHITESPACE);
 -      const char *set = diff_get_color(ecbdata->color_diff, DIFF_FILE_NEW);
 +      const char *set = diff_get_color(ecbdata->color_diff, color);
 +      const char *ws = NULL;
  
 -      if (!*ws)
 -              emit_line_0(ecbdata->opt, set, reset, '+', line, len);
 -      else if (new_blank_line_at_eof(ecbdata, line, len))
 +      if (ecbdata->opt->ws_error_highlight & ws_error_highlight) {
 +              ws = diff_get_color(ecbdata->color_diff, DIFF_WHITESPACE);
 +              if (!*ws)
 +                      ws = NULL;
 +      }
 +
 +      if (!ws)
 +              emit_line_0(ecbdata->opt, set, reset, sign, line, len);
 +      else if (sign == '+' && new_blank_line_at_eof(ecbdata, line, len))
                /* Blank line at EOF - paint '+' as well */
 -              emit_line_0(ecbdata->opt, ws, reset, '+', line, len);
 +              emit_line_0(ecbdata->opt, ws, reset, sign, line, len);
        else {
                /* Emit just the prefix, then the rest. */
 -              emit_line_0(ecbdata->opt, set, reset, '+', "", 0);
 +              emit_line_0(ecbdata->opt, set, reset, sign, "", 0);
                ws_check_emit(line, len, ecbdata->ws_rule,
                              ecbdata->opt->file, set, reset, ws);
        }
  }
  
 +static void emit_add_line(const char *reset,
 +                        struct emit_callback *ecbdata,
 +                        const char *line, int len)
 +{
 +      emit_line_checked(reset, ecbdata, line, len,
 +                        DIFF_FILE_NEW, WSEH_NEW, '+');
 +}
 +
 +static void emit_del_line(const char *reset,
 +                        struct emit_callback *ecbdata,
 +                        const char *line, int len)
 +{
 +      emit_line_checked(reset, ecbdata, line, len,
 +                        DIFF_FILE_OLD, WSEH_OLD, '-');
 +}
 +
 +static void emit_context_line(const char *reset,
 +                            struct emit_callback *ecbdata,
 +                            const char *line, int len)
 +{
 +      emit_line_checked(reset, ecbdata, line, len,
 +                        DIFF_CONTEXT, WSEH_CONTEXT, ' ');
 +}
 +
  static void emit_hunk_header(struct emit_callback *ecbdata,
                             const char *line, int len)
  {
 -      const char *plain = diff_get_color(ecbdata->color_diff, DIFF_PLAIN);
 +      const char *context = diff_get_color(ecbdata->color_diff, DIFF_CONTEXT);
        const char *frag = diff_get_color(ecbdata->color_diff, DIFF_FRAGINFO);
        const char *func = diff_get_color(ecbdata->color_diff, DIFF_FUNCINFO);
        const char *reset = diff_get_color(ecbdata->color_diff, DIFF_RESET);
        if (len < 10 ||
            memcmp(line, atat, 2) ||
            !(ep = memmem(line + 2, len - 2, atat, 2))) {
 -              emit_line(ecbdata->opt, plain, reset, line, len);
 +              emit_line(ecbdata->opt, context, reset, line, len);
                return;
        }
        ep += 2; /* skip over @@ */
                if (*ep != ' ' && *ep != '\t')
                        break;
        if (ep != cp) {
 -              strbuf_addstr(&msgbuf, plain);
 +              strbuf_addstr(&msgbuf, context);
                strbuf_add(&msgbuf, cp, ep - cp);
                strbuf_addstr(&msgbuf, reset);
        }
@@@ -644,6 -609,7 +643,6 @@@ static void emit_rewrite_lines(struct e
  {
        const char *endp = NULL;
        static const char *nneof = " No newline at end of file\n";
 -      const char *old = diff_get_color(ecb->color_diff, DIFF_FILE_OLD);
        const char *reset = diff_get_color(ecb->color_diff, DIFF_RESET);
  
        while (0 < size) {
                len = endp ? (endp - data + 1) : size;
                if (prefix != '+') {
                        ecb->lno_in_preimage++;
 -                      emit_line_0(ecb->opt, old, reset, '-',
 -                                  data, len);
 +                      emit_del_line(reset, ecb, data, len);
                } else {
                        ecb->lno_in_postimage++;
                        emit_add_line(reset, ecb, data, len);
                data += len;
        }
        if (!endp) {
 -              const char *plain = diff_get_color(ecb->color_diff,
 -                                                 DIFF_PLAIN);
 +              const char *context = diff_get_color(ecb->color_diff,
 +                                                   DIFF_CONTEXT);
                putc('\n', ecb->opt->file);
 -              emit_line_0(ecb->opt, plain, reset, '\\',
 +              emit_line_0(ecb->opt, context, reset, '\\',
                            nneof, strlen(nneof));
        }
  }
@@@ -1041,9 -1008,8 +1040,9 @@@ static void diff_words_show(struct diff
        xpp.flags = 0;
        /* as only the hunk header will be parsed, we need a 0-context */
        xecfg.ctxlen = 0;
 -      xdi_diff_outf(&minus, &plus, fn_out_diff_words_aux, diff_words,
 -                    &xpp, &xecfg);
 +      if (xdi_diff_outf(&minus, &plus, fn_out_diff_words_aux, diff_words,
 +                        &xpp, &xecfg))
 +              die("unable to generate word diff");
        free(minus.ptr);
        free(plus.ptr);
        if (diff_words->current_plus != diff_words->plus.text.ptr +
@@@ -1126,7 -1092,7 +1125,7 @@@ static void init_diff_words_data(struc
                struct diff_words_style *st = ecbdata->diff_words->style;
                st->old.color = diff_get_color_opt(o, DIFF_FILE_OLD);
                st->new.color = diff_get_color_opt(o, DIFF_FILE_NEW);
 -              st->ctx.color = diff_get_color_opt(o, DIFF_PLAIN);
 +              st->ctx.color = diff_get_color_opt(o, DIFF_CONTEXT);
        }
  }
  
@@@ -1202,7 -1168,7 +1201,7 @@@ static void fn_out_consume(void *priv, 
  {
        struct emit_callback *ecbdata = priv;
        const char *meta = diff_get_color(ecbdata->color_diff, DIFF_METAINFO);
 -      const char *plain = diff_get_color(ecbdata->color_diff, DIFF_PLAIN);
 +      const char *context = diff_get_color(ecbdata->color_diff, DIFF_CONTEXT);
        const char *reset = diff_get_color(ecbdata->color_diff, DIFF_RESET);
        struct diff_options *o = ecbdata->opt;
        const char *line_prefix = diff_line_prefix(o);
                }
                diff_words_flush(ecbdata);
                if (ecbdata->diff_words->type == DIFF_WORDS_PORCELAIN) {
 -                      emit_line(ecbdata->opt, plain, reset, line, len);
 +                      emit_line(ecbdata->opt, context, reset, line, len);
                        fputs("~\n", ecbdata->opt->file);
                } else {
                        /*
                              line++;
                              len--;
                        }
 -                      emit_line(ecbdata->opt, plain, reset, line, len);
 +                      emit_line(ecbdata->opt, context, reset, line, len);
                }
                return;
        }
  
 -      if (line[0] != '+') {
 -              const char *color =
 -                      diff_get_color(ecbdata->color_diff,
 -                                     line[0] == '-' ? DIFF_FILE_OLD : DIFF_PLAIN);
 -              ecbdata->lno_in_preimage++;
 -              if (line[0] == ' ')
 -                      ecbdata->lno_in_postimage++;
 -              emit_line(ecbdata->opt, color, reset, line, len);
 -      } else {
 +      switch (line[0]) {
 +      case '+':
                ecbdata->lno_in_postimage++;
                emit_add_line(reset, ecbdata, line + 1, len - 1);
 +              break;
 +      case '-':
 +              ecbdata->lno_in_preimage++;
 +              emit_del_line(reset, ecbdata, line + 1, len - 1);
 +              break;
 +      case ' ':
 +              ecbdata->lno_in_postimage++;
 +              ecbdata->lno_in_preimage++;
 +              emit_context_line(reset, ecbdata, line + 1, len - 1);
 +              break;
 +      default:
 +              /* incomplete line at the end */
 +              ecbdata->lno_in_preimage++;
 +              emit_line(ecbdata->opt,
 +                        diff_get_color(ecbdata->color_diff, DIFF_CONTEXT),
 +                        reset, line, len);
 +              break;
        }
  }
  
@@@ -2450,9 -2406,8 +2449,9 @@@ static void builtin_diff(const char *na
                        xecfg.ctxlen = strtoul(v, NULL, 10);
                if (o->word_diff)
                        init_diff_words_data(&ecbdata, o, one, two);
 -              xdi_diff_outf(&mf1, &mf2, fn_out_consume, &ecbdata,
 -                            &xpp, &xecfg);
 +              if (xdi_diff_outf(&mf1, &mf2, fn_out_consume, &ecbdata,
 +                                &xpp, &xecfg))
 +                      die("unable to generate diff for %s", one->path);
                if (o->word_diff)
                        free_diff_words_data(&ecbdata);
                if (textconv_one)
@@@ -2529,9 -2484,8 +2528,9 @@@ static void builtin_diffstat(const cha
                xpp.flags = o->xdl_opts;
                xecfg.ctxlen = o->context;
                xecfg.interhunkctxlen = o->interhunkcontext;
 -              xdi_diff_outf(&mf1, &mf2, diffstat_consume, diffstat,
 -                            &xpp, &xecfg);
 +              if (xdi_diff_outf(&mf1, &mf2, diffstat_consume, diffstat,
 +                                &xpp, &xecfg))
 +                      die("unable to generate diffstat for %s", one->path);
        }
  
        diff_free_filespec_data(one);
@@@ -2577,9 -2531,8 +2576,9 @@@ static void builtin_checkdiff(const cha
                memset(&xecfg, 0, sizeof(xecfg));
                xecfg.ctxlen = 1; /* at least one context line */
                xpp.flags = 0;
 -              xdi_diff_outf(&mf1, &mf2, checkdiff_consume, &data,
 -                            &xpp, &xecfg);
 +              if (xdi_diff_outf(&mf1, &mf2, checkdiff_consume, &data,
 +                                &xpp, &xecfg))
 +                      die("unable to generate checkdiff for %s", one->path);
  
                if (data.ws_rule & WS_BLANK_AT_EOF) {
                        struct emit_callback ecbdata;
@@@ -2882,8 -2835,9 +2881,8 @@@ static void prep_temp_blob(const char *
                die_errno("unable to write temp-file");
        close_tempfile(&temp->tempfile);
        temp->name = get_tempfile_path(&temp->tempfile);
 -      strcpy(temp->hex, sha1_to_hex(sha1));
 -      temp->hex[40] = 0;
 -      sprintf(temp->mode, "%06o", mode);
 +      sha1_to_hex_r(temp->hex, sha1);
 +      xsnprintf(temp->mode, sizeof(temp->mode), "%06o", mode);
        strbuf_release(&buf);
        strbuf_release(&template);
        free(path_dup);
@@@ -2900,8 -2854,8 +2899,8 @@@ static struct diff_tempfile *prepare_te
                 * a '+' entry produces this for file-1.
                 */
                temp->name = "/dev/null";
 -              strcpy(temp->hex, ".");
 -              strcpy(temp->mode, ".");
 +              xsnprintf(temp->hex, sizeof(temp->hex), ".");
 +              xsnprintf(temp->mode, sizeof(temp->mode), ".");
                return temp;
        }
  
                        /* we can borrow from the file in the work tree */
                        temp->name = name;
                        if (!one->sha1_valid)
 -                              strcpy(temp->hex, sha1_to_hex(null_sha1));
 +                              sha1_to_hex_r(temp->hex, null_sha1);
                        else
 -                              strcpy(temp->hex, sha1_to_hex(one->sha1));
 +                              sha1_to_hex_r(temp->hex, one->sha1);
                        /* Even though we may sometimes borrow the
                         * contents from the work tree, we always want
                         * one->mode.  mode is trustworthy even when
                         * !(one->sha1_valid), as long as
                         * DIFF_FILE_VALID(one).
                         */
 -                      sprintf(temp->mode, "%06o", one->mode);
 +                      xsnprintf(temp->mode, sizeof(temp->mode), "%06o", one->mode);
                }
                return temp;
        }
@@@ -3268,7 -3222,6 +3267,7 @@@ void diff_setup(struct diff_options *op
        options->rename_limit = -1;
        options->dirstat_permille = diff_dirstat_permille_default;
        options->context = diff_context_default;
 +      options->ws_error_highlight = WSEH_NEW;
        DIFF_OPT_SET(options, RENAME_EMPTY);
  
        /* pathchange left =NULL by default */
@@@ -3655,45 -3608,6 +3654,45 @@@ static void enable_patch_output(int *fm
        *fmt |= DIFF_FORMAT_PATCH;
  }
  
 +static int parse_one_token(const char **arg, const char *token)
 +{
 +      const char *rest;
 +      if (skip_prefix(*arg, token, &rest) && (!*rest || *rest == ',')) {
 +              *arg = rest;
 +              return 1;
 +      }
 +      return 0;
 +}
 +
 +static int parse_ws_error_highlight(struct diff_options *opt, const char *arg)
 +{
 +      const char *orig_arg = arg;
 +      unsigned val = 0;
 +      while (*arg) {
 +              if (parse_one_token(&arg, "none"))
 +                      val = 0;
 +              else if (parse_one_token(&arg, "default"))
 +                      val = WSEH_NEW;
 +              else if (parse_one_token(&arg, "all"))
 +                      val = WSEH_NEW | WSEH_OLD | WSEH_CONTEXT;
 +              else if (parse_one_token(&arg, "new"))
 +                      val |= WSEH_NEW;
 +              else if (parse_one_token(&arg, "old"))
 +                      val |= WSEH_OLD;
 +              else if (parse_one_token(&arg, "context"))
 +                      val |= WSEH_CONTEXT;
 +              else {
 +                      error("unknown value after ws-error-highlight=%.*s",
 +                            (int)(arg - orig_arg), orig_arg);
 +                      return 0;
 +              }
 +              if (*arg)
 +                      arg++;
 +      }
 +      opt->ws_error_highlight = val;
 +      return 1;
 +}
 +
  int diff_opt_parse(struct diff_options *options, const char **av, int ac)
  {
        const char *arg = av[0];
                DIFF_OPT_SET(options, FIND_COPIES_HARDER);
        else if (!strcmp(arg, "--follow"))
                DIFF_OPT_SET(options, FOLLOW_RENAMES);
 -      else if (!strcmp(arg, "--no-follow"))
 +      else if (!strcmp(arg, "--no-follow")) {
                DIFF_OPT_CLR(options, FOLLOW_RENAMES);
 -      else if (!strcmp(arg, "--color"))
 +              DIFF_OPT_CLR(options, DEFAULT_FOLLOW_RENAMES);
 +      } else if (!strcmp(arg, "--color"))
                options->use_color = 1;
        else if (skip_prefix(arg, "--color=", &arg)) {
                int value = git_config_colorbool(NULL, arg);
                DIFF_OPT_SET(options, SUBMODULE_LOG);
        else if (skip_prefix(arg, "--submodule=", &arg))
                return parse_submodule_opt(options, arg);
 +      else if (skip_prefix(arg, "--ws-error-highlight=", &arg))
 +              return parse_ws_error_highlight(options, arg);
  
        /* misc options */
        else if (!strcmp(arg, "-z"))
@@@ -4084,9 -3995,9 +4083,9 @@@ const char *diff_unique_abbrev(const un
        if (abblen < 37) {
                static char hex[41];
                if (len < abblen && abblen <= len + 2)
 -                      sprintf(hex, "%s%.*s", abbrev, len+3-abblen, "..");
 +                      xsnprintf(hex, sizeof(hex), "%s%.*s", abbrev, len+3-abblen, "..");
                else
 -                      sprintf(hex, "%s...", abbrev);
 +                      xsnprintf(hex, sizeof(hex), "%s...", abbrev);
                return hex;
        }
        return sha1_to_hex(sha1);
@@@ -4513,10 -4424,8 +4512,10 @@@ static int diff_get_patch_id(struct dif
                xpp.flags = 0;
                xecfg.ctxlen = 3;
                xecfg.flags = 0;
 -              xdi_diff_outf(&mf1, &mf2, patch_id_consume, &data,
 -                            &xpp, &xecfg);
 +              if (xdi_diff_outf(&mf1, &mf2, patch_id_consume, &data,
 +                                &xpp, &xecfg))
 +                      return error("unable to generate patch-id diff for %s",
 +                                   p->one->path);
        }
  
        git_SHA1_Final(sha1, &ctx);
diff --combined read-cache.c
index 87204a50a5cfe2acbdb0563a68f88303a5eb7ae7,b240c41fdcabc992a8b31e3f2cfb9063aff40513..3ecb99dd2f619e89919f27b4e29ff5eaf6f332ba
@@@ -17,7 -17,6 +17,6 @@@
  #include "strbuf.h"
  #include "varint.h"
  #include "split-index.h"
- #include "sigchain.h"
  #include "utf8.h"
  
  static struct cache_entry *refresh_cache_entry(struct cache_entry *ce,
@@@ -1000,8 -999,7 +999,8 @@@ static int add_index_entry_with_check(s
        }
        pos = -pos-1;
  
 -      untracked_cache_add_to_index(istate, ce->name);
 +      if (!(option & ADD_CACHE_KEEP_CACHE_TREE))
 +              untracked_cache_add_to_index(istate, ce->name);
  
        /*
         * Inserting a merged entry ("stage 0") into the index
@@@ -1564,7 -1562,7 +1563,7 @@@ int do_read_index(struct index_state *i
        if (mmap_size < sizeof(struct cache_header) + 20)
                die("index file smaller than expected");
  
 -      mmap = xmmap(NULL, mmap_size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
 +      mmap = xmmap(NULL, mmap_size, PROT_READ, MAP_PRIVATE, fd, 0);
        if (mmap == MAP_FAILED)
                die_errno("unable to map index file");
        close(fd);
@@@ -1654,7 -1652,7 +1653,7 @@@ int read_index_from(struct index_state 
                die("broken index, expect %s in %s, got %s",
                    sha1_to_hex(split_index->base_sha1),
                    git_path("sharedindex.%s",
 -                                   sha1_to_hex(split_index->base_sha1)),
 +                           sha1_to_hex(split_index->base_sha1)),
                    sha1_to_hex(split_index->base->sha1));
        merge_base_index(istate);
        check_ce_order(istate);
diff --combined shallow.c
index d49a3d6e9f02e292a04981e34f0a2d0b1ffa00d0,f1518ce61a043c4b30d78165fc9f0a99dc5887ce..4f9d66723670664fd8a15e271ed0cfc309324059
+++ b/shallow.c
@@@ -10,7 -10,6 +10,6 @@@
  #include "diff.h"
  #include "revision.h"
  #include "commit-slab.h"
- #include "sigchain.h"
  
  static int is_shallow = -1;
  static struct stat_validity shallow_stat;
@@@ -49,7 -48,7 +48,7 @@@ int is_repository_shallow(void
                return is_shallow;
  
        if (!path)
 -              path = git_path("shallow");
 +              path = git_path_shallow();
        /*
         * fetch-pack sets '--shallow-file ""' as an indicator that no
         * shallow file should be used. We could just open it and it
@@@ -143,7 -142,7 +142,7 @@@ static void check_shallow_file_for_upda
        if (is_shallow == -1)
                die("BUG: shallow must be initialized by now");
  
 -      if (!stat_validity_check(&shallow_stat, git_path("shallow")))
 +      if (!stat_validity_check(&shallow_stat, git_path_shallow()))
                die("shallow file has changed since we read it");
  }
  
@@@ -240,7 -239,7 +239,7 @@@ void setup_alternate_shallow(struct loc
        struct strbuf sb = STRBUF_INIT;
        int fd;
  
 -      fd = hold_lock_file_for_update(shallow_lock, git_path("shallow"),
 +      fd = hold_lock_file_for_update(shallow_lock, git_path_shallow(),
                                       LOCK_DIE_ON_ERROR);
        check_shallow_file_for_update();
        if (write_shallow_commits(&sb, 0, extra)) {
@@@ -287,7 -286,7 +286,7 @@@ void prune_shallow(int show_only
                strbuf_release(&sb);
                return;
        }
 -      fd = hold_lock_file_for_update(&shallow_lock, git_path("shallow"),
 +      fd = hold_lock_file_for_update(&shallow_lock, git_path_shallow(),
                                       LOCK_DIE_ON_ERROR);
        check_shallow_file_for_update();
        if (write_shallow_commits_1(&sb, 0, NULL, SEEN_ONLY)) {
                                  get_lock_file_path(&shallow_lock));
                commit_lock_file(&shallow_lock);
        } else {
 -              unlink(git_path("shallow"));
 +              unlink(git_path_shallow());
                rollback_lock_file(&shallow_lock);
        }
        strbuf_release(&sb);