Merge branch 'sb/maint-1.6.2-opt-filename-fix' into maint
authorJunio C Hamano <gitster@pobox.com>
Tue, 2 Jun 2009 14:47:03 +0000 (07:47 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 2 Jun 2009 14:47:03 +0000 (07:47 -0700)
* sb/maint-1.6.2-opt-filename-fix:
apply, fmt-merge-msg: use relative filenames
commit: -F overrides -t

1  2 
builtin-apply.c
builtin-fmt-merge-msg.c
t/t6200-fmt-merge-msg.sh
diff --combined builtin-apply.c
index 8a3771e87e1ef2ac7a1ee70133b8206f0f18cbb5,472865b7f199d0ad5e4f8402228e511bdf056dd7..a40b9822425e25272cadf6f4170ba967eacf11bf
@@@ -2394,7 -2394,7 +2394,7 @@@ static int check_to_create_blob(const c
                 * In such a case, path "new_name" does not exist as
                 * far as git is concerned.
                 */
 -              if (has_symlink_leading_path(strlen(new_name), new_name))
 +              if (has_symlink_leading_path(new_name, strlen(new_name)))
                        return 0;
  
                return error("%s: already exists in working directory", new_name);
@@@ -2487,7 -2487,7 +2487,7 @@@ static int check_preimage(struct patch 
        if ((st_mode ^ patch->old_mode) & S_IFMT)
                return error("%s: wrong type", old_name);
        if (st_mode != patch->old_mode)
 -              fprintf(stderr, "warning: %s has type %o, expected %o\n",
 +              warning("%s has type %o, expected %o",
                        old_name, st_mode, patch->old_mode);
        if (!patch->new_mode && !patch->is_delete)
                patch->new_mode = st_mode;
@@@ -2781,7 -2781,7 +2781,7 @@@ static void remove_file(struct patch *p
                        if (rmdir(patch->old_name))
                                warning("unable to remove submodule %s",
                                        patch->old_name);
 -              } else if (!unlink(patch->old_name) && rmdir_empty) {
 +              } else if (!unlink_or_warn(patch->old_name) && rmdir_empty) {
                        remove_path(patch->old_name);
                }
        }
@@@ -2891,7 -2891,7 +2891,7 @@@ static void create_one_file(char *path
                        if (!try_create_file(newpath, mode, buf, size)) {
                                if (!rename(newpath, path))
                                        return;
 -                              unlink(newpath);
 +                              unlink_or_warn(newpath);
                                break;
                        }
                        if (errno != EEXIST)
@@@ -2971,7 -2971,8 +2971,7 @@@ static int write_out_one_reject(struct 
        cnt = strlen(patch->new_name);
        if (ARRAY_SIZE(namebuf) <= cnt + 5) {
                cnt = ARRAY_SIZE(namebuf) - 5;
 -              fprintf(stderr,
 -                      "warning: truncating .rej filename to %.*s.rej",
 +              warning("truncating .rej filename to %.*s.rej",
                        cnt - 1, patch->new_name);
        }
        memcpy(namebuf, patch->new_name, cnt);
@@@ -3262,10 -3263,10 +3262,10 @@@ int cmd_apply(int argc, const char **ar
                        "ignore additions made by the patch"),
                OPT_BOOLEAN(0, "stat", &diffstat,
                        "instead of applying the patch, output diffstat for the input"),
 -              OPT_BOOLEAN(0, "allow-binary-replacement", &binary,
 -                      "now no-op"),
 -              OPT_BOOLEAN(0, "binary", &binary,
 -                      "now no-op"),
 +              { OPTION_BOOLEAN, 0, "allow-binary-replacement", &binary,
 +                NULL, "old option, now no-op", PARSE_OPT_HIDDEN },
 +              { OPTION_BOOLEAN, 0, "binary", &binary,
 +                NULL, "old option, now no-op", PARSE_OPT_HIDDEN },
                OPT_BOOLEAN(0, "numstat", &numstat,
                        "shows number of added and deleted lines in decimal notation"),
                OPT_BOOLEAN(0, "summary", &summary,
  
        argc = parse_options(argc, argv, builtin_apply_options,
                        apply_usage, 0);
+       fake_ancestor = parse_options_fix_filename(prefix, fake_ancestor);
+       if (fake_ancestor)
+               fake_ancestor = xstrdup(fake_ancestor);
        if (apply_with_reject)
                apply = apply_verbosely = 1;
        if (!force_apply && (diffstat || numstat || summary || check || fake_ancestor))
                    squelch_whitespace_errors < whitespace_error) {
                        int squelched =
                                whitespace_error - squelch_whitespace_errors;
 -                      fprintf(stderr, "warning: squelched %d "
 -                              "whitespace error%s\n",
 +                      warning("squelched %d "
 +                              "whitespace error%s",
                                squelched,
                                squelched == 1 ? "" : "s");
                }
                            whitespace_error == 1 ? "" : "s",
                            whitespace_error == 1 ? "s" : "");
                if (applied_after_fixing_ws && apply)
 -                      fprintf(stderr, "warning: %d line%s applied after"
 -                              " fixing whitespace errors.\n",
 +                      warning("%d line%s applied after"
 +                              " fixing whitespace errors.",
                                applied_after_fixing_ws,
                                applied_after_fixing_ws == 1 ? "" : "s");
                else if (whitespace_error)
 -                      fprintf(stderr, "warning: %d line%s add%s whitespace errors.\n",
 +                      warning("%d line%s add%s whitespace errors.",
                                whitespace_error,
                                whitespace_error == 1 ? "" : "s",
                                whitespace_error == 1 ? "s" : "");
diff --combined builtin-fmt-merge-msg.c
index a7883690d74cb1bcef7b20f27ebbea6f6c5dcc53,c566c2df77b1b7da2bff11c70e06b91128fdc71e..fae1482ba91937232f427a3f5dd03c587c3fba57
@@@ -256,7 -256,8 +256,7 @@@ static void shortlog(const char *name, 
  
  int fmt_merge_msg(int merge_summary, struct strbuf *in, struct strbuf *out) {
        int limit = 20, i = 0, pos = 0;
 -      char line[1024];
 -      char *p = line, *sep = "";
 +      char *sep = "";
        unsigned char head_sha1[20];
        const char *current_branch;
  
        /* get a line */
        while (pos < in->len) {
                int len;
 -              char *newline;
 +              char *newline, *p = in->buf + pos;
  
 -              p = in->buf + pos;
                newline = strchr(p, '\n');
                len = newline ? newline - p : strlen(p);
                pos += len + !!newline;
@@@ -363,6 -365,7 +363,7 @@@ int cmd_fmt_merge_msg(int argc, const c
        argc = parse_options(argc, argv, options, fmt_merge_msg_usage, 0);
        if (argc > 0)
                usage_with_options(fmt_merge_msg_usage, options);
+       inpath = parse_options_fix_filename(prefix, inpath);
  
        if (inpath && strcmp(inpath, "-")) {
                in = fopen(inpath, "r");
diff --combined t/t6200-fmt-merge-msg.sh
index 2049ab6cf844da233837b58857cfde8a2d563252,706d93769f0705848d95031eb4e3f3216ed81859..42f6fff373ba9707216279011b112c6c59af8780
@@@ -83,13 -83,13 +83,13 @@@ test_expect_success 'merge-msg test #1
  '
  
  cat >expected <<EOF
 -Merge branch 'left' of $TEST_DIRECTORY/$test
 +Merge branch 'left' of $(pwd)
  EOF
  
  test_expect_success 'merge-msg test #2' '
  
        git checkout master &&
 -      git fetch "$TEST_DIRECTORY/$test" left &&
 +      git fetch "$(pwd)" left &&
  
        git fmt-merge-msg <.git/FETCH_HEAD >actual &&
        test_cmp expected actual
@@@ -208,4 -208,36 +208,36 @@@ test_expect_success 'merge-msg test #5-
        test_cmp expected actual
  '
  
+ test_expect_success 'merge-msg -F' '
+       git config --unset-all merge.log
+       git config --unset-all merge.summary
+       git config merge.summary yes &&
+       git checkout master &&
+       setdate &&
+       git fetch . left right &&
+       git fmt-merge-msg -F .git/FETCH_HEAD >actual &&
+       test_cmp expected actual
+ '
+ test_expect_success 'merge-msg -F in subdirectory' '
+       git config --unset-all merge.log
+       git config --unset-all merge.summary
+       git config merge.summary yes &&
+       git checkout master &&
+       setdate &&
+       git fetch . left right &&
+       mkdir sub &&
+       cp .git/FETCH_HEAD sub/FETCH_HEAD &&
+       (
+               cd sub &&
+               git fmt-merge-msg -F FETCH_HEAD >../actual
+       ) &&
+       test_cmp expected actual
+ '
  test_done