Merge branch 'jc/reflog-doc'
authorJunio C Hamano <gitster@pobox.com>
Fri, 18 Oct 2013 20:50:12 +0000 (13:50 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 18 Oct 2013 20:50:12 +0000 (13:50 -0700)
Document rules to use GIT_REFLOG_ACTION variable in the scripted
Porcelain. git-rebase--interactive locally violates them, but it
is a leaf user that does not call out to or dot-source other
scripts, so it does not urgently need to be fixed.

* jc/reflog-doc:
setup_reflog_action: document the rules for using GIT_REFLOG_ACTION

1  2 
Documentation/git-sh-setup.txt
Documentation/git.txt
git-sh-setup.sh
index 5d709d02c39e10ac946c3870a10d959a4c12a5d4,79a88b92054234b0cc50e6ce8872f44979904564..4f67c4cde679cf03e8cc43ac0630a45b5e68aa2d
@@@ -41,9 -41,11 +41,11 @@@ usage:
        die with the usage message.
  
  set_reflog_action::
-       set the message that will be recorded to describe the
-       end-user action in the reflog, when the script updates a
-       ref.
+       Set GIT_REFLOG_ACTION environment to a given string (typically
+       the name of the program) unless it is already set.  Whenever
+       the script runs a `git` command that updates refs, a reflog
+       entry is created using the value of this string to leave the
+       record of what command updated the ref.
  
  git_editor::
        runs an editor of user's choice (GIT_EDITOR, core.editor, VISUAL or
@@@ -82,12 -84,6 +84,12 @@@ get_author_ident_from_commit:
        outputs code for use with eval to set the GIT_AUTHOR_NAME,
        GIT_AUTHOR_EMAIL and GIT_AUTHOR_DATE variables for a given commit.
  
 +create_virtual_base::
 +      modifies the first file so only lines in common with the
 +      second file remain. If there is insufficient common material,
 +      then the first file is left empty. The result is suitable
 +      as a virtual base input for a 3-way merge.
 +
  GIT
  ---
  Part of the linkgit:git[1] suite
diff --combined Documentation/git.txt
index da7be1fdf4d9654d962984d3b25f655439237e30,78db385fb73c0f71db68516a63e857b9f0d194e0..4f7e07f2e0f4f6317c81467f7f880b4113b12de1
@@@ -9,7 -9,7 +9,7 @@@ git - the stupid content tracke
  SYNOPSIS
  --------
  [verse]
 -'git' [--version] [--help] [-c <name>=<value>]
 +'git' [--version] [--help] [-C <path>] [-c <name>=<value>]
      [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
      [-p|--paginate|--no-pager] [--no-replace-objects] [--bare]
      [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
@@@ -43,27 -43,12 +43,27 @@@ unreleased) version of Git, that is ava
  branch of the `git.git` repository.
  Documentation for older releases are available here:
  
 +* link:v1.8.4.1/git.html[documentation for release 1.8.4.1]
 +
 +* release notes for
 +  link:RelNotes/1.8.4.1.txt[1.8.4.1],
 +  link:RelNotes/1.8.4.txt[1.8.4].
 +
 +* link:v1.8.3.4/git.html[documentation for release 1.8.3.4]
 +
 +* release notes for
 +  link:RelNotes/1.8.3.4.txt[1.8.3.4],
 +  link:RelNotes/1.8.3.3.txt[1.8.3.3],
 +  link:RelNotes/1.8.3.2.txt[1.8.3.2],
 +  link:RelNotes/1.8.3.1.txt[1.8.3.1],
 +  link:RelNotes/1.8.3.txt[1.8.3].
 +
  * link:v1.8.2.3/git.html[documentation for release 1.8.2.3]
  
  * release notes for
 -  link:RelNotes/1.8.2.3.txt[1.8.2.3].
 -  link:RelNotes/1.8.2.2.txt[1.8.2.2].
 -  link:RelNotes/1.8.2.1.txt[1.8.2.1].
 +  link:RelNotes/1.8.2.3.txt[1.8.2.3],
 +  link:RelNotes/1.8.2.2.txt[1.8.2.2],
 +  link:RelNotes/1.8.2.1.txt[1.8.2.1],
    link:RelNotes/1.8.2.txt[1.8.2].
  
  * link:v1.8.1.6/git.html[documentation for release 1.8.1.6]
@@@ -396,20 -381,6 +396,20 @@@ displayed. See linkgit:git-help[1] for 
  because `git --help ...` is converted internally into `git
  help ...`.
  
 +-C <path>::
 +      Run as if git was started in '<path>' instead of the current working
 +      directory.  When multiple `-C` options are given, each subsequent
 +      non-absolute `-C <path>` is interpreted relative to the preceding `-C
 +      <path>`.
 ++
 +This option affects options that expect path name like `--git-dir` and
 +`--work-tree` in that their interpretations of the path names would be
 +made relative to the working directory caused by the `-C` option. For
 +example the following invocations are equivalent:
 +
 +    git --git-dir=a.git --work-tree=b -C c status
 +    git --git-dir=c/a.git --work-tree=c/b status
 +
  -c <name>=<value>::
        Pass a configuration parameter to the command. The value
        given will override values from configuration files.
        linkgit:git-replace[1] for more information.
  
  --literal-pathspecs::
 -      Treat pathspecs literally, rather than as glob patterns. This is
 -      equivalent to setting the `GIT_LITERAL_PATHSPECS` environment
 +      Treat pathspecs literally (i.e. no globbing, no pathspec magic).
 +      This is equivalent to setting the `GIT_LITERAL_PATHSPECS` environment
        variable to `1`.
  
 +--glob-pathspecs::
 +      Add "glob" magic to all pathspec. This is equivalent to setting
 +      the `GIT_GLOB_PATHSPECS` environment variable to `1`. Disabling
 +      globbing on individual pathspecs can be done using pathspec
 +      magic ":(literal)"
 +
 +--noglob-pathspecs::
 +      Add "literal" magic to all pathspec. This is equivalent to setting
 +      the `GIT_NOGLOB_PATHSPECS` environment variable to `1`. Enabling
 +      globbing on individual pathspecs can be done using pathspec
 +      magic ":(glob)"
 +
 +--icase-pathspecs::
 +      Add "icase" magic to all pathspec. This is equivalent to setting
 +      the `GIT_ICASE_PATHSPECS` environment variable to `1`.
  
  GIT COMMANDS
  ------------
@@@ -721,7 -677,9 +721,7 @@@ Git so take care if using Cogito etc
        The '--git-dir' command-line option also sets this value.
  
  'GIT_WORK_TREE'::
 -      Set the path to the working tree.  The value will not be
 -      used in combination with repositories found automatically in
 -      a .git directory (i.e. $GIT_DIR is not set).
 +      Set the path to the root of the working tree.
        This can also be controlled by the '--work-tree' command line
        option and the core.worktree configuration variable.
  
@@@ -853,9 -811,8 +853,9 @@@ for further details
  'GIT_FLUSH'::
        If this environment variable is set to "1", then commands such
        as 'git blame' (in incremental mode), 'git rev-list', 'git log',
 -      and 'git whatchanged' will force a flush of the output stream
 -      after each commit-oriented record have been flushed.   If this
 +      'git check-attr' and 'git check-ignore' will
 +      force a flush of the output stream after each record have been
 +      flushed. If this
        variable is set to "0", the output of these commands will be done
        using completely buffered I/O.   If this environment variable is
        not set, Git will choose buffered or record-oriented flushing
        as a file path and will try to write the trace messages
        into it.
  
 +'GIT_TRACE_PACK_ACCESS'::
 +      If this variable is set to a path, a file will be created at
 +      the given path logging all accesses to any packs. For each
 +      access, the pack file name and an offset in the pack is
 +      recorded. This may be helpful for troubleshooting some
 +      pack-related performance problems.
 +
 +'GIT_TRACE_PACKET'::
 +      If this variable is set, it shows a trace of all packets
 +      coming in or out of a given program. This can help with
 +      debugging object negotiation or other protocol issues. Tracing
 +      is turned off at a packet starting with "PACK".
 +
  GIT_LITERAL_PATHSPECS::
        Setting this variable to `1` will cause Git to treat all
        pathspecs literally, rather than as glob patterns. For example,
        literal paths to Git (e.g., paths previously given to you by
        `git ls-tree`, `--raw` diff output, etc).
  
 +GIT_GLOB_PATHSPECS::
 +      Setting this variable to `1` will cause Git to treat all
 +      pathspecs as glob patterns (aka "glob" magic).
 +
 +GIT_NOGLOB_PATHSPECS::
 +      Setting this variable to `1` will cause Git to treat all
 +      pathspecs as literal (aka "literal" magic).
 +
 +GIT_ICASE_PATHSPECS::
 +      Setting this variable to `1` will cause Git to treat all
 +      pathspecs as case-insensitive.
 +
+ 'GIT_REFLOG_ACTION'::
+       When a ref is updated, reflog entries are created to keep
+       track of the reason why the ref was updated (which is
+       typically the name of the high-level command that updated
+       the ref), in addition to the old and new values of the ref.
+       A scripted Porcelain command can use set_reflog_action
+       helper function in `git-sh-setup` to set its name to this
+       variable when it is invoked as the top level command by the
+       end user, to be recorded in the body of the reflog.
  
  Discussion[[Discussion]]
  ------------------------
diff --combined git-sh-setup.sh
index e15be516369e5e5a9096bb957966938e134e616c,53ab0684f27f071b802abac26f62543ab27fae92..ebfe8f7a4d0697422a826d7878855bf9e92d0060
@@@ -53,7 -53,7 +53,7 @@@ die () 
  die_with_status () {
        status=$1
        shift
 -      echo >&2 "$*"
 +      printf >&2 '%s\n' "$*"
        exit "$status"
  }
  
@@@ -103,6 -103,40 +103,40 @@@ $LONG_USAGE
        esac
  fi
  
+ # Set the name of the end-user facing command in the reflog when the
+ # script may update refs.  When GIT_REFLOG_ACTION is already set, this
+ # will not overwrite it, so that a scripted Porcelain (e.g. "git
+ # rebase") can set it to its own name (e.g. "rebase") and then call
+ # another scripted Porcelain (e.g. "git am") and a call to this
+ # function in the latter will keep the name of the end-user facing
+ # program (e.g. "rebase") in GIT_REFLOG_ACTION, ensuring whatever it
+ # does will be record as actions done as part of the end-user facing
+ # operation (e.g. "rebase").
+ #
+ # NOTE NOTE NOTE: consequently, after assigning a specific message to
+ # GIT_REFLOG_ACTION when calling a "git" command to record a custom
+ # reflog message, do not leave that custom value in GIT_REFLOG_ACTION,
+ # after you are done.  Other callers of "git" commands that rely on
+ # writing the default "program name" in reflog expect the variable to
+ # contain the value set by this function.
+ #
+ # To use a custom reflog message, do either one of these three:
+ #
+ # (a) use a single-shot export form:
+ #     GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION: preparing frotz" \
+ #         git command-that-updates-a-ref
+ #
+ # (b) save the original away and restore:
+ #     SAVED_ACTION=$GIT_REFLOG_ACTION
+ #     GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION: preparing frotz"
+ #     git command-that-updates-a-ref
+ #     GIT_REFLOG_ACITON=$SAVED_ACTION
+ #
+ # (c) assign the variable in a subshell:
+ #     (
+ #         GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION: preparing frotz"
+ #         git command-that-updates-a-ref
+ #     )
  set_reflog_action() {
        if [ -z "${GIT_REFLOG_ACTION:+set}" ]
        then
@@@ -249,18 -283,6 +283,18 @@@ clear_local_git_env() 
        unset $(git rev-parse --local-env-vars)
  }
  
 +# Generate a virtual base file for a two-file merge. Uses git apply to
 +# remove lines from $1 that are not in $2, leaving only common lines.
 +create_virtual_base() {
 +      sz0=$(wc -c <"$1")
 +      @@DIFF@@ -u -La/"$1" -Lb/"$1" "$1" "$2" | git apply --no-add
 +      sz1=$(wc -c <"$1")
 +
 +      # If we do not have enough common material, it is not
 +      # worth trying two-file merge using common subsections.
 +      expr $sz0 \< $sz1 \* 2 >/dev/null || : >"$1"
 +}
 +
  
  # Platform specific tweaks to work around some commands
  case $(uname -s) in
@@@ -313,15 -335,3 +347,15 @@@ the
        }
        : ${GIT_OBJECT_DIRECTORY="$GIT_DIR/objects"}
  fi
 +
 +peel_committish () {
 +      case "$1" in
 +      :/*)
 +              peeltmp=$(git rev-parse --verify "$1") &&
 +              git rev-parse --verify "${peeltmp}^0"
 +              ;;
 +      *)
 +              git rev-parse --verify "${1}^0"
 +              ;;
 +      esac
 +}