From: Junio C Hamano Date: Mon, 8 Mar 2010 08:36:02 +0000 (-0800) Subject: Merge branch 'gb/maint-submodule-env' into maint X-Git-Tag: v1.7.0.3~22 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/bd08ecc487f3b515196cc4096094799a02de6ae3?ds=inline;hp=-c Merge branch 'gb/maint-submodule-env' into maint * 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 --- bd08ecc487f3b515196cc4096094799a02de6ae3 diff --combined Documentation/git-rev-parse.txt index 1a613aa108,33092a3373..8db600f6ba --- a/Documentation/git-rev-parse.txt +++ b/Documentation/git-rev-parse.txt @@@ -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 (`?`, @@@ -148,6 -149,12 +148,12 @@@ --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 `` is disambiguated by taking the @@@ -197,15 -204,15 +203,15 @@@ . if `$GIT_DIR/` exists, that is what you mean (this is usually useful only for `HEAD`, `FETCH_HEAD`, `ORIG_HEAD` and `MERGE_HEAD`); - . otherwise, `$GIT_DIR/refs/` if exists; + . otherwise, `refs/` if exists; - . otherwise, `$GIT_DIR/refs/tags/` if exists; + . otherwise, `refs/tags/` if exists; - . otherwise, `$GIT_DIR/refs/heads/` if exists; + . otherwise, `refs/heads/` if exists; - . otherwise, `$GIT_DIR/refs/remotes/` if exists; + . otherwise, `refs/remotes/` if exists; - . otherwise, `$GIT_DIR/refs/remotes//HEAD` if exists. + . otherwise, `refs/remotes//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 4d89aa3da4,58209adbd6..6e54993256 --- a/cache.h +++ 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 a37cf6af04,24ce2fc70e..beaff987c7 --- a/connect.c +++ 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, ']'); @@@ -607,18 -607,8 +607,8 @@@ *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 7a095665d7,cf864a6273..6131670860 --- a/git-sh-setup.sh +++ b/git-sh-setup.sh @@@ -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"