Merge branch 'maint'
authorJunio C Hamano <gitster@pobox.com>
Thu, 6 Dec 2007 01:49:13 +0000 (17:49 -0800)
committerJunio C Hamano <gitster@pobox.com>
Thu, 6 Dec 2007 01:49:13 +0000 (17:49 -0800)
* maint:
git-am -i: report rewritten title
git grep shows the same hit repeatedly for unmerged paths
Do check_repository_format() early (re-fix)
Do check_repository_format() early
Add missing inside_work_tree setting in setup_git_directory_gently

1  2 
git-am.sh
setup.c
diff --combined git-am.sh
index 76c1c844a95d8af19f64a3278706daf907dace01,44c558c940bd86ce8b4a4ab21d979d0688644fbc..65c634f77af98b3598bfb50583de05f0cf5d6eb4
+++ b/git-am.sh
@@@ -2,26 -2,11 +2,26 @@@
  #
  # Copyright (c) 2005, 2006 Junio C Hamano
  
 -USAGE='[--signoff] [--dotest=<dir>] [--keep] [--utf8 | --no-utf8]
 -  [--3way] [--interactive] [--binary]
 -  [--whitespace=<option>] [-C<n>] [-p<n>]
 -  <mbox>|<Maildir>...
 -  or, when resuming [--skip | --resolved]'
 +OPTIONS_KEEPDASHDASH=
 +OPTIONS_SPEC="\
 +git-am [options] <mbox>|<Maildir>...
 +git-am [options] --resolved
 +git-am [options] --skip
 +--
 +d,dotest=       use <dir> and not .dotest
 +i,interactive   run interactively
 +b,binary        pass --allo-binary-replacement to git-apply
 +3,3way          allow fall back on 3way merging if needed
 +s,signoff       add a Signed-off-by line to the commit message
 +u,utf8          recode into utf8 (default)
 +k,keep          pass -k flagg to git-mailinfo
 +whitespace=     pass it through git-apply
 +C=              pass it through git-apply
 +p=              pass it through git-apply
 +resolvemsg=     override error message when patch failure occurs
 +r,resolved      to be used after a patch failure
 +skip            skip the current patch"
 +
  . git-sh-setup
  set_reflog_action am
  require_work_tree
@@@ -117,6 -102,10 +117,10 @@@ It does not apply to blobs recorded in 
      unset GITHEAD_$his_tree
  }
  
+ reread_subject () {
+       git stripspace <"$1" | sed -e 1q
+ }
  prec=4
  dotest=.dotest sign= utf8=t keep= skip= interactive= resolved= binary=
  resolvemsg= resume=
@@@ -125,38 -114,49 +129,38 @@@ git_apply_opt
  while test $# != 0
  do
        case "$1" in
 -      -d=*|--d=*|--do=*|--dot=*|--dote=*|--dotes=*|--dotest=*)
 -      dotest=`expr "z$1" : 'z-[^=]*=\(.*\)'`; shift ;;
 -      -d|--d|--do|--dot|--dote|--dotes|--dotest)
 -      case "$#" in 1) usage ;; esac; shift
 -      dotest="$1"; shift;;
 -
 -      -i|--i|--in|--int|--inte|--inter|--intera|--interac|--interact|\
 -      --interacti|--interactiv|--interactive)
 -      interactive=t; shift ;;
 -
 -      -b|--b|--bi|--bin|--bina|--binar|--binary)
 -      binary=t; shift ;;
 -
 -      -3|--3|--3w|--3wa|--3way)
 -      threeway=t; shift ;;
 -      -s|--s|--si|--sig|--sign|--signo|--signof|--signoff)
 -      sign=t; shift ;;
 -      -u|--u|--ut|--utf|--utf8)
 -      utf8=t; shift ;; # this is now default
 -      --no-u|--no-ut|--no-utf|--no-utf8)
 -      utf8=; shift ;;
 -      -k|--k|--ke|--kee|--keep)
 -      keep=t; shift ;;
 -
 -      -r|--r|--re|--res|--reso|--resol|--resolv|--resolve|--resolved)
 -      resolved=t; shift ;;
 -
 -      --sk|--ski|--skip)
 -      skip=t; shift ;;
 -
 -      --whitespace=*|-C*|-p*)
 -      git_apply_opt="$git_apply_opt $1"; shift ;;
 -
 -      --resolvemsg=*)
 -      resolvemsg=${1#--resolvemsg=}; shift ;;
 -
 +      -i|--interactive)
 +              interactive=t ;;
 +      -b|--binary)
 +              binary=t ;;
 +      -3|--3way)
 +              threeway=t ;;
 +      -s|--signoff)
 +              sign=t ;;
 +      -u|--utf8)
 +              utf8=t ;; # this is now default
 +      --no-utf8)
 +              utf8= ;;
 +      -k|--keep)
 +              keep=t ;;
 +      -r|--resolved)
 +              resolved=t ;;
 +      --skip)
 +              skip=t ;;
 +      -d|--dotest)
 +              shift; dotest=$1;;
 +      --resolvemsg)
 +              shift; resolvemsg=$1 ;;
 +      --whitespace)
 +              git_apply_opt="$git_apply_opt $1=$2"; shift ;;
 +      -C|-p)
 +              git_apply_opt="$git_apply_opt $1$2"; shift ;;
        --)
 -      shift; break ;;
 -      -*)
 -      usage ;;
 +              shift; break ;;
        *)
 -      break ;;
 +              usage ;;
        esac
 +      shift
  done
  
  # If the dotest directory exists, but we have finished applying all the
@@@ -376,6 -376,7 +380,7 @@@ d
                [aA]*) action=yes interactive= ;;
                [nN]*) action=skip ;;
                [eE]*) git_editor "$dotest/final-commit"
+                      SUBJECT=$(reread_subject "$dotest/final-commit")
                       action=again ;;
                [vV]*) action=again
                       LESS=-S ${PAGER:-less} "$dotest/patch" ;;
                stop_here $this
        fi
  
 -      echo
        printf 'Applying %s\n' "$SUBJECT"
 -      echo
  
        case "$resolved" in
        '')
        fi
  
        tree=$(git write-tree) &&
 -      echo Wrote tree $tree &&
        parent=$(git rev-parse --verify HEAD) &&
        commit=$(git commit-tree $tree -p $parent <"$dotest/final-commit") &&
 -      echo Committed: $commit &&
        git update-ref -m "$GIT_REFLOG_ACTION: $SUBJECT" HEAD $commit $parent ||
        stop_here $this
  
                "$GIT_DIR"/hooks/post-applypatch
        fi
  
 +      git gc --auto
 +
        go_next
  done
  
diff --combined setup.c
index 2c7b5cb200414a0fa3f2727c68ea60e51b39c261,067f1be3f92c9f3a334c4b427f32b4f4fdb8225b..e96a316452197ed4b224f0c6839f036a01082bc2
+++ b/setup.c
@@@ -59,7 -59,7 +59,7 @@@ const char *prefix_path(const char *pre
  const char *prefix_filename(const char *pfx, int pfx_len, const char *arg)
  {
        static char path[PATH_MAX];
 -      if (!pfx || !*pfx || arg[0] == '/')
 +      if (!pfx || !*pfx || is_absolute_path(arg))
                return arg;
        memcpy(path, pfx, pfx_len);
        strcpy(path + pfx_len, arg);
@@@ -206,22 -206,22 +206,38 @@@ static const char *set_work_tree(const 
        return NULL;
  }
  
 +void setup_work_tree(void)
 +{
 +      const char *work_tree, *git_dir;
 +      static int initialized = 0;
 +
 +      if (initialized)
 +              return;
 +      work_tree = get_git_work_tree();
 +      git_dir = get_git_dir();
 +      if (!is_absolute_path(git_dir))
 +              set_git_dir(make_absolute_path(git_dir));
 +      if (!work_tree || chdir(work_tree))
 +              die("This operation must be run in a work tree");
 +      initialized = 1;
 +}
 +
+ static int check_repository_format_gently(int *nongit_ok)
+ {
+       git_config(check_repository_format_version);
+       if (GIT_REPO_VERSION < repository_format_version) {
+               if (!nongit_ok)
+                       die ("Expected git repo version <= %d, found %d",
+                            GIT_REPO_VERSION, repository_format_version);
+               warning("Expected git repo version <= %d, found %d",
+                       GIT_REPO_VERSION, repository_format_version);
+               warning("Please upgrade Git");
+               *nongit_ok = -1;
+               return -1;
+       }
+       return 0;
+ }
  /*
   * We cannot decide in this function whether we are in the work tree or
   * not, since the config can only be read _after_ this function was called.
@@@ -246,8 -246,15 +262,15 @@@ const char *setup_git_directory_gently(
                        static char buffer[1024 + 1];
                        const char *retval;
  
-                       if (!work_tree_env)
-                               return set_work_tree(gitdirenv);
+                       if (!work_tree_env) {
+                               retval = set_work_tree(gitdirenv);
+                               /* config may override worktree */
+                               if (check_repository_format_gently(nongit_ok))
+                                       return NULL;
+                               return retval;
+                       }
+                       if (check_repository_format_gently(nongit_ok))
+                               return NULL;
                        retval = get_relative_cwd(buffer, sizeof(buffer) - 1,
                                        get_git_work_tree());
                        if (!retval || !*retval)
                        if (!work_tree_env)
                                inside_work_tree = 0;
                        setenv(GIT_DIR_ENVIRONMENT, ".", 1);
+                       check_repository_format_gently(nongit_ok);
                        return NULL;
                }
                chdir("..");
        if (!work_tree_env)
                inside_work_tree = 1;
        git_work_tree_cfg = xstrndup(cwd, offset);
+       if (check_repository_format_gently(nongit_ok))
+               return NULL;
        if (offset == len)
                return NULL;
  
@@@ -356,11 -366,7 +382,7 @@@ int check_repository_format_version(con
  
  int check_repository_format(void)
  {
-       git_config(check_repository_format_version);
-       if (GIT_REPO_VERSION < repository_format_version)
-               die ("Expected git repo version <= %d, found %d",
-                    GIT_REPO_VERSION, repository_format_version);
-       return 0;
+       return check_repository_format_gently(NULL);
  }
  
  const char *setup_git_directory(void)