Merge branch 'gb/maint-submodule-env' into maint
authorJunio C Hamano <gitster@pobox.com>
Mon, 8 Mar 2010 08:36:02 +0000 (00:36 -0800)
committerJunio C Hamano <gitster@pobox.com>
Mon, 8 Mar 2010 08:36:02 +0000 (00:36 -0800)
* gb/maint-submodule-env:
is_submodule_modified(): clear environment properly
submodules: ensure clean environment when operating in a submodule
shell setup: clear_local_git_env() function
rev-parse: --local-env-vars option
Refactor list of of repo-local env vars

1  2 
Documentation/git-rev-parse.txt
cache.h
connect.c
git-sh-setup.sh
index 1a613aa108d649c199c30d0d8a29623243631a7c,33092a33739feb59cb1c5912c7f3a221a88ff9ec..8db600f6ba01bcb7f85be6c6606795a0034822b2
@@@ -101,14 -101,15 +101,14 @@@ OPTION
        abbreviation mode.
  
  --all::
 -      Show all refs found in `$GIT_DIR/refs`.
 +      Show all refs found in `refs/`.
  
  --branches[=pattern]::
  --tags[=pattern]::
  --remotes[=pattern]::
        Show all branches, tags, or remote-tracking branches,
 -      respectively (i.e., refs found in `$GIT_DIR/refs/heads`,
 -      `$GIT_DIR/refs/tags`, or `$GIT_DIR/refs/remotes`,
 -      respectively).
 +      respectively (i.e., refs found in `refs/heads`,
 +      `refs/tags`, or `refs/remotes`, respectively).
  +
  If a `pattern` is given, only refs matching the given shell glob are
  shown.  If the pattern does not contain a globbing character (`?`,
  --is-bare-repository::
        When the repository is bare print "true", otherwise "false".
  
+ --local-env-vars::
+       List the GIT_* environment variables that are local to the
+       repository (e.g. GIT_DIR or GIT_WORK_TREE, but not GIT_EDITOR).
+       Only the names of the variables are listed, not their value,
+       even if they are set.
  --short::
  --short=number::
        Instead of outputting the full SHA1 values of object names try to
@@@ -188,7 -195,7 +194,7 @@@ blobs contained in a commit
    `g`, and an abbreviated object name.
  
  * A symbolic ref name.  E.g. 'master' typically means the commit
 -  object referenced by $GIT_DIR/refs/heads/master.  If you
 +  object referenced by refs/heads/master.  If you
    happen to have both heads/master and tags/master, you can
    explicitly say 'heads/master' to tell git which one you mean.
    When ambiguous, a `<name>` is disambiguated by taking the
    . if `$GIT_DIR/<name>` exists, that is what you mean (this is usually
      useful only for `HEAD`, `FETCH_HEAD`, `ORIG_HEAD` and `MERGE_HEAD`);
  
 -  . otherwise, `$GIT_DIR/refs/<name>` if exists;
 +  . otherwise, `refs/<name>` if exists;
  
 -  . otherwise, `$GIT_DIR/refs/tags/<name>` if exists;
 +  . otherwise, `refs/tags/<name>` if exists;
  
 -  . otherwise, `$GIT_DIR/refs/heads/<name>` if exists;
 +  . otherwise, `refs/heads/<name>` if exists;
  
 -  . otherwise, `$GIT_DIR/refs/remotes/<name>` if exists;
 +  . otherwise, `refs/remotes/<name>` if exists;
  
 -  . otherwise, `$GIT_DIR/refs/remotes/<name>/HEAD` if exists.
 +  . otherwise, `refs/remotes/<name>/HEAD` if exists.
  +
  HEAD names the commit your changes in the working tree is based on.
  FETCH_HEAD records the branch you fetched from a remote repository
@@@ -216,9 -223,6 +222,9 @@@ you can change the tip of the branch ba
  them easily.
  MERGE_HEAD records the commit(s) you are merging into your branch
  when you run 'git merge'.
 ++
 +Note that any of the `refs/*` cases above may come either from
 +the `$GIT_DIR/refs` directory or from the `$GIT_DIR/packed-refs` file.
  
  * A ref followed by the suffix '@' with a date specification
    enclosed in a brace
diff --combined cache.h
index 4d89aa3da4d32653289c742f37abe8ef604ab11b,58209adbd6f0c7e72b1e29c36af31c82e842c9ac..6e54993256befed7b77fc54559ff196d01292ef2
+++ b/cache.h
@@@ -388,6 -388,15 +388,15 @@@ static inline enum object_type object_t
  #define GIT_NOTES_REF_ENVIRONMENT "GIT_NOTES_REF"
  #define GIT_NOTES_DEFAULT_REF "refs/notes/commits"
  
+ /*
+  * Repository-local GIT_* environment variables
+  * The array is NULL-terminated to simplify its usage in contexts such
+  * environment creation or simple walk of the list.
+  * The number of non-NULL entries is available as a macro.
+  */
+ #define LOCAL_REPO_ENV_SIZE 8
+ extern const char *const local_repo_env[LOCAL_REPO_ENV_SIZE + 1];
  extern int is_bare_repository_cfg;
  extern int is_bare_repository(void);
  extern int is_inside_git_dir(void);
@@@ -641,10 -650,6 +650,10 @@@ int git_mkstemp(char *path, size_t n, c
  
  int git_mkstemps(char *path, size_t n, const char *template, int suffix_len);
  
 +/* set default permissions by passing mode arguments to open(2) */
 +int git_mkstemps_mode(char *pattern, int suffix_len, int mode);
 +int git_mkstemp_mode(char *pattern, int mode);
 +
  /*
   * NOTE NOTE NOTE!!
   *
@@@ -779,7 -784,7 +788,7 @@@ extern const char *git_committer_info(i
  extern const char *fmt_ident(const char *name, const char *email, const char *date_str, int);
  extern const char *fmt_name(const char *name, const char *email);
  extern const char *git_editor(void);
 -extern const char *git_pager(void);
 +extern const char *git_pager(int stdout_is_tty);
  
  struct checkout {
        const char *base_dir;
diff --combined connect.c
index a37cf6af0428023d2d3ef01ab2e04fc462981af4,24ce2fc70edd1945b5e7b51a9a02afba668eb9ff..beaff987c7bc36096d09b2557f5208c5606ce2dd
+++ b/connect.c
@@@ -504,7 -504,7 +504,7 @@@ struct child_process *git_connect(int f
  
        /*
         * Don't do destructive transforms with git:// as that
 -       * protocol code does '[]' dewrapping of its own.
 +       * protocol code does '[]' unwrapping of its own.
         */
        if (host[0] == '[') {
                end = strchr(host + 1, ']');
                *arg++ = host;
        }
        else {
-               /* remove these from the environment */
-               const char *env[] = {
-                       ALTERNATE_DB_ENVIRONMENT,
-                       DB_ENVIRONMENT,
-                       GIT_DIR_ENVIRONMENT,
-                       GIT_WORK_TREE_ENVIRONMENT,
-                       GRAFT_ENVIRONMENT,
-                       INDEX_ENVIRONMENT,
-                       NO_REPLACE_OBJECTS_ENVIRONMENT,
-                       NULL
-               };
-               conn->env = env;
+               /* remove repo-local variables from the environment */
+               conn->env = local_repo_env;
                conn->use_shell = 1;
        }
        *arg++ = cmd.buf;
diff --combined git-sh-setup.sh
index 7a095665d71f153a970243a9d03d919ddef29c88,cf864a62738292cdd27d4461221369ef034516c5..6131670860514c215a6b9b7417dd05c3124e81b4
@@@ -107,19 -107,6 +107,19 @@@ git_editor() 
        eval "$GIT_EDITOR" '"$@"'
  }
  
 +git_pager() {
 +      if test -t 1
 +      then
 +              GIT_PAGER=$(git var GIT_PAGER)
 +      else
 +              GIT_PAGER=cat
 +      fi
 +      : ${LESS=-FRSX}
 +      export LESS
 +
 +      eval "$GIT_PAGER" '"$@"'
 +}
 +
  sane_grep () {
        GREP_OPTIONS= LC_ALL=C grep "$@"
  }
@@@ -141,7 -128,7 +141,7 @@@ cd_to_toplevel () 
  }
  
  require_work_tree () {
 -      test $(git rev-parse --is-inside-work-tree) = true ||
 +      test "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = true ||
        die "fatal: $0 cannot be used without a working tree."
  }
  
@@@ -172,6 -159,13 +172,13 @@@ get_author_ident_from_commit () 
        LANG=C LC_ALL=C sed -ne "$pick_author_script"
  }
  
+ # Clear repo-local GIT_* environment variables. Useful when switching to
+ # another repository (e.g. when entering a submodule). See also the env
+ # list in git_connect()
+ clear_local_git_env() {
+       unset $(git rev-parse --local-env-vars)
+ }
  # Make sure we are in a valid repository of a vintage we understand,
  # if we require to be in a git repository.
  if test -z "$NONGIT_OK"