Merge branch 'jc/am-state-fix'
authorJunio C Hamano <gitster@pobox.com>
Mon, 31 Aug 2015 22:39:01 +0000 (15:39 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 31 Aug 2015 22:39:03 +0000 (15:39 -0700)
Recent reimplementation of "git am" changed the format of state
files kept in $GIT_DIR/rebase-apply/ without meaning to do so,
primarily because write_file() API was cumbersome to use and it was
easy to mistakenly make text files with incomplete lines. Update
write_file() interface to make it harder to misuse.

* jc/am-state-fix:
write_file(): drop caller-supplied LF from calls to create a one-liner file
write_file_v(): do not leave incomplete line at the end
write_file(): drop "fatal" parameter
builtin/am: make sure state files are text
builtin/am: introduce write_state_*() helper functions

1  2 
builtin/am.c
builtin/worktree.c
cache.h
submodule.c
diff --cc builtin/am.c
Simple merge
index 430b51e7a74bb28ac1532ac836e9770121977096,bbb169a5d05be7748134f4e5286bcdabb48d7aeb..71bb770f7a4b4b864efcbf4c3983bbd4a645f4e2
@@@ -253,40 -228,32 +253,40 @@@ static int add_worktree(const char *pat
                   real_path(get_git_common_dir()), name);
        /*
         * This is to keep resolve_ref() happy. We need a valid HEAD
 -       * or is_git_directory() will reject the directory. Moreover, HEAD
 -       * in the new worktree must resolve to the same value as HEAD in
 -       * the current tree since the command invoked to populate the new
 -       * worktree will be handed the branch/ref specified by the user.
 -       * For instance, if the user asks for the new worktree to be based
 -       * at HEAD~5, then the resolved HEAD~5 in the new worktree must
 -       * match the resolved HEAD~5 in the current tree in order to match
 -       * the user's expectation.
 +       * or is_git_directory() will reject the directory. Any value which
 +       * looks like an object ID will do since it will be immediately
 +       * replaced by the symbolic-ref or update-ref invocation in the new
 +       * worktree.
         */
 -      if (!resolve_ref_unsafe("HEAD", 0, rev, NULL))
 -              die(_("unable to resolve HEAD"));
        strbuf_reset(&sb);
        strbuf_addf(&sb, "%s/HEAD", sb_repo.buf);
-       write_file(sb.buf, 1, "0000000000000000000000000000000000000000\n");
 -      write_file(sb.buf, "%s", sha1_to_hex(rev));
++      write_file(sb.buf, "0000000000000000000000000000000000000000");
        strbuf_reset(&sb);
        strbuf_addf(&sb, "%s/commondir", sb_repo.buf);
-       write_file(sb.buf, 1, "../..\n");
+       write_file(sb.buf, "../..");
  
 -      fprintf_ln(stderr, _("Enter %s (identifier %s)"), path, name);
 +      fprintf_ln(stderr, _("Preparing %s (identifier %s)"), path, name);
  
 -      setenv("GIT_CHECKOUT_NEW_WORKTREE", "1", 1);
 -      setenv(GIT_DIR_ENVIRONMENT, sb_git.buf, 1);
 -      setenv(GIT_WORK_TREE_ENVIRONMENT, path, 1);
 +      argv_array_pushf(&child_env, "%s=%s", GIT_DIR_ENVIRONMENT, sb_git.buf);
 +      argv_array_pushf(&child_env, "%s=%s", GIT_WORK_TREE_ENVIRONMENT, path);
        memset(&cp, 0, sizeof(cp));
        cp.git_cmd = 1;
 -      cp.argv = child_argv;
 +
 +      if (commit)
 +              argv_array_pushl(&cp.args, "update-ref", "HEAD",
 +                               sha1_to_hex(commit->object.sha1), NULL);
 +      else
 +              argv_array_pushl(&cp.args, "symbolic-ref", "HEAD",
 +                               symref.buf, NULL);
 +      cp.env = child_env.argv;
 +      ret = run_command(&cp);
 +      if (ret)
 +              goto done;
 +
 +      cp.argv = NULL;
 +      argv_array_clear(&cp.args);
 +      argv_array_pushl(&cp.args, "reset", "--hard", NULL);
 +      cp.env = child_env.argv;
        ret = run_command(&cp);
        if (!ret) {
                is_junk = 0;
diff --cc cache.h
Simple merge
diff --cc submodule.c
Simple merge