Code

Merge branch 'ab/clang-lints'
authorJunio C Hamano <gitster@pobox.com>
Mon, 5 Dec 2011 23:12:34 +0000 (15:12 -0800)
committerJunio C Hamano <gitster@pobox.com>
Mon, 5 Dec 2011 23:12:34 +0000 (15:12 -0800)
* ab/clang-lints:
  cast variable in call to free() in builtin/diff.c and submodule.c
  apply: get rid of useless x < 0 comparison on a size_t type

1  2 
builtin/apply.c
submodule.c

diff --combined builtin/apply.c
index 84a8a0b52136c4d1e43ec10f9ef5ed76b7d3c12f,d600ac63abb44be0580addd855f636a05701b9a2..b3b59db534ff0763c822ae9da571d5643a8b709a
@@@ -250,9 -250,6 +250,6 @@@ static int fuzzy_matchlines(const char 
        const char *last2 = s2 + n2 - 1;
        int result = 0;
  
-       if (n1 < 0 || n2 < 0)
-               return 0;
        /* ignore line endings */
        while ((*last1 == '\r') || (*last1 == '\n'))
                last1--;
@@@ -1407,9 -1404,6 +1404,9 @@@ static int find_header(char *line, unsi
                                            "%d leading pathname components (line %d)" , p_value, linenr);
                                patch->old_name = patch->new_name = patch->def_name;
                        }
 +                      if (!patch->is_delete && !patch->new_name)
 +                              die("git diff header lacks filename information "
 +                                  "(line %d)", linenr);
                        patch->is_toplevel_relative = 1;
                        *hdrsize = git_hdr_len;
                        return offset;
@@@ -2450,8 -2444,6 +2447,8 @@@ static int apply_one_fragment(struct im
        char *old, *oldlines;
        struct strbuf newlines;
        int new_blank_lines_at_end = 0;
 +      int found_new_blank_lines_at_end = 0;
 +      int hunk_linenr = frag->linenr;
        unsigned long leading, trailing;
        int pos, applied_pos;
        struct image preimage;
                                error("invalid start of line: '%c'", first);
                        return -1;
                }
 -              if (added_blank_line)
 +              if (added_blank_line) {
 +                      if (!new_blank_lines_at_end)
 +                              found_new_blank_lines_at_end = hunk_linenr;
                        new_blank_lines_at_end++;
 +              }
                else if (is_blank_context)
                        ;
                else
                        new_blank_lines_at_end = 0;
                patch += len;
                size -= len;
 +              hunk_linenr++;
        }
        if (inaccurate_eof &&
            old > oldlines && old[-1] == '\n' &&
                    preimage.nr + applied_pos >= img->nr &&
                    (ws_rule & WS_BLANK_AT_EOF) &&
                    ws_error_action != nowarn_ws_error) {
 -                      record_ws_error(WS_BLANK_AT_EOF, "+", 1, frag->linenr);
 +                      record_ws_error(WS_BLANK_AT_EOF, "+", 1,
 +                                      found_new_blank_lines_at_end);
                        if (ws_error_action == correct_ws_error) {
                                while (new_blank_lines_at_end--)
                                        remove_last_line(&postimage);
@@@ -3841,6 -3828,7 +3838,6 @@@ int cmd_apply(int argc, const char **ar
        int i;
        int errs = 0;
        int is_not_gitdir = !startup_info->have_repository;
 -      int binary;
        int force_apply = 0;
  
        const char *whitespace_option = NULL;
                        "ignore additions made by the patch"),
                OPT_BOOLEAN(0, "stat", &diffstat,
                        "instead of applying the patch, output diffstat for the input"),
 -              { OPTION_BOOLEAN, 0, "allow-binary-replacement", &binary,
 -                NULL, "old option, now no-op",
 -                PARSE_OPT_HIDDEN | PARSE_OPT_NOARG },
 -              { OPTION_BOOLEAN, 0, "binary", &binary,
 -                NULL, "old option, now no-op",
 -                PARSE_OPT_HIDDEN | PARSE_OPT_NOARG },
 +              OPT_NOOP_NOARG(0, "allow-binary-replacement"),
 +              OPT_NOOP_NOARG(0, "binary"),
                OPT_BOOLEAN(0, "numstat", &numstat,
                        "shows number of added and deleted lines in decimal notation"),
                OPT_BOOLEAN(0, "summary", &summary,
diff --combined submodule.c
index 0fd10a0fdbf5d1af10819dea808b43f6b13b98a8,09181ff6e575d5aa5e2fa850bc794fac5953587d..52cdcc6a6347a786deafad34efdb9dc4dc3670ff
@@@ -8,18 -8,12 +8,18 @@@
  #include "diffcore.h"
  #include "refs.h"
  #include "string-list.h"
 +#include "sha1-array.h"
 +#include "argv-array.h"
  
  static struct string_list config_name_for_path;
  static struct string_list config_fetch_recurse_submodules_for_name;
  static struct string_list config_ignore_for_name;
  static int config_fetch_recurse_submodules = RECURSE_SUBMODULES_ON_DEMAND;
  static struct string_list changed_submodule_paths;
 +static int initialized_fetch_ref_tips;
 +static struct sha1_array ref_tips_before_fetch;
 +static struct sha1_array ref_tips_after_fetch;
 +
  /*
   * The following flag is set if the .gitmodules file is unmerged. We then
   * disable recursion for all submodules where .git/config doesn't have a
@@@ -391,7 -385,7 +391,7 @@@ static void commit_need_pushing(struct 
        rev.diffopt.format_callback_data = needs_pushing;
        diff_tree_combined(commit->object.sha1, parents, n, 1, &rev);
  
-       free(parents);
+       free((void *)parents);
  }
  
  int check_submodule_needs_pushing(unsigned char new_sha1[20], const char *remotes_name)
@@@ -480,46 -474,20 +480,46 @@@ static void submodule_collect_changed_c
        }
  }
  
 +static int add_sha1_to_array(const char *ref, const unsigned char *sha1,
 +                           int flags, void *data)
 +{
 +      sha1_array_append(data, sha1);
 +      return 0;
 +}
 +
  void check_for_new_submodule_commits(unsigned char new_sha1[20])
 +{
 +      if (!initialized_fetch_ref_tips) {
 +              for_each_ref(add_sha1_to_array, &ref_tips_before_fetch);
 +              initialized_fetch_ref_tips = 1;
 +      }
 +
 +      sha1_array_append(&ref_tips_after_fetch, new_sha1);
 +}
 +
 +static void add_sha1_to_argv(const unsigned char sha1[20], void *data)
 +{
 +      argv_array_push(data, sha1_to_hex(sha1));
 +}
 +
 +static void calculate_changed_submodule_paths(void)
  {
        struct rev_info rev;
        struct commit *commit;
 -      const char *argv[] = {NULL, NULL, "--not", "--all", NULL};
 -      int argc = ARRAY_SIZE(argv) - 1;
 +      struct argv_array argv = ARGV_ARRAY_INIT;
  
        /* No need to check if there are no submodules configured */
        if (!config_name_for_path.nr)
                return;
  
        init_revisions(&rev, NULL);
 -      argv[1] = xstrdup(sha1_to_hex(new_sha1));
 -      setup_revisions(argc, argv, &rev, NULL);
 +      argv_array_push(&argv, "--"); /* argv[0] program name */
 +      sha1_array_for_each_unique(&ref_tips_after_fetch,
 +                                 add_sha1_to_argv, &argv);
 +      argv_array_push(&argv, "--not");
 +      sha1_array_for_each_unique(&ref_tips_before_fetch,
 +                                 add_sha1_to_argv, &argv);
 +      setup_revisions(argv.argc, argv.argv, &rev, NULL);
        if (prepare_revision_walk(&rev))
                die("revision walk setup failed");
  
                        parent = parent->next;
                }
        }
 -      free((char *)argv[1]);
 +
 +      argv_array_clear(&argv);
 +      sha1_array_clear(&ref_tips_before_fetch);
 +      sha1_array_clear(&ref_tips_after_fetch);
 +      initialized_fetch_ref_tips = 0;
  }
  
  int fetch_populated_submodules(int num_options, const char **options,
        cp.git_cmd = 1;
        cp.no_stdin = 1;
  
 +      calculate_changed_submodule_paths();
 +
        for (i = 0; i < active_nr; i++) {
                struct strbuf submodule_path = STRBUF_INIT;
                struct strbuf submodule_git_dir = STRBUF_INIT;
@@@ -794,7 -756,7 +794,7 @@@ static void print_commit(struct commit 
  
  int merge_submodule(unsigned char result[20], const char *path,
                    const unsigned char base[20], const unsigned char a[20],
 -                  const unsigned char b[20])
 +                  const unsigned char b[20], int search)
  {
        struct commit *commit_base, *commit_a, *commit_b;
        int parent_count;
         * user needs to confirm the resolution.
         */
  
 +      /* Skip the search if makes no sense to the calling context.  */
 +      if (!search)
 +              return 0;
 +
        /* find commit which merges them */
        parent_count = find_first_merges(&merges, path, commit_a, commit_b);
        switch (parent_count) {