From: Junio C Hamano Date: Tue, 6 Mar 2012 22:53:06 +0000 (-0800) Subject: Merge branch 'zj/diff-stat-dyncol' X-Git-Tag: v1.7.10-rc0~9 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/af050219e44051426179248614a046896b5d40c0?ds=inline;hp=-c Merge branch 'zj/diff-stat-dyncol' By Zbigniew Jędrzejewski-Szmek (8) and Junio C Hamano (1) * zj/diff-stat-dyncol: : This breaks tests. Perhaps it is not worth using the decimal-width stuff : for this series, at least initially. diff --stat: add config option to limit graph width diff --stat: enable limiting of the graph part diff --stat: add a test for output with COLUMNS=40 diff --stat: use a maximum of 5/8 for the filename part merge --stat: use the full terminal width log --stat: use the full terminal width show --stat: use the full terminal width diff --stat: use the full terminal width diff --stat: tests for long filenames and big change counts --- af050219e44051426179248614a046896b5d40c0 diff --combined Documentation/diff-options.txt index ba7cd13483,87f0a5fb8f..7d4566f829 --- a/Documentation/diff-options.txt +++ b/Documentation/diff-options.txt @@@ -52,17 -52,20 +52,23 @@@ endif::git-format-patch[ --patience:: Generate a diff using the "patience diff" algorithm. +--histogram:: + Generate a diff using the "histogram diff" algorithm. + --stat[=[,[,]]]:: - Generate a diffstat. You can override the default - output width for 80-column terminal by `--stat=`. - The width of the filename part can be controlled by - giving another width to it separated by a comma. + Generate a diffstat. By default, as much space as necessary + will be used for the filename part, and the rest for the graph + part. Maximum width defaults to terminal width, or 80 columns + if not connected to a terminal, and can be overriden by + ``. The width of the filename part can be limited by + giving another width `` after a comma. The width + of the graph part can be limited by using + `--stat-graph-width=` (affects all commands generating + a stat graph) or by setting `diff.statGraphWidth=` + (does not affect `git format-patch`). By giving a third parameter ``, you can limit the - output to the first `` lines, followed by - `...` if there are more. + output to the first `` lines, followed by `...` if + there are more. + These parameters can also be set individually with `--stat-width=`, `--stat-name-width=` and `--stat-count=`. diff --combined builtin/merge.c index d3e1e8dc9e,34a5034a76..cb8f14910b --- a/builtin/merge.c +++ b/builtin/merge.c @@@ -48,7 -48,7 +48,7 @@@ static const char * const builtin_merge static int show_diffstat = 1, shortlog_len = -1, squash; static int option_commit = 1, allow_fast_forward = 1; -static int fast_forward_only, option_edit; +static int fast_forward_only, option_edit = -1; static int allow_trivial = 1, have_message; static int overwrite_ignore = 1; static struct strbuf merge_msg = STRBUF_INIT; @@@ -193,7 -193,7 +193,7 @@@ static struct option builtin_merge_opti "create a single commit instead of doing a merge"), OPT_BOOLEAN(0, "commit", &option_commit, "perform a commit if the merge succeeds (default)"), - OPT_BOOLEAN('e', "edit", &option_edit, + OPT_BOOL('e', "edit", &option_edit, "edit message before committing"), OPT_BOOLEAN(0, "ff", &allow_fast_forward, "allow fast-forward (default)"), @@@ -399,6 -399,8 +399,8 @@@ static void finish(struct commit *head_ if (new_head && show_diffstat) { struct diff_options opts; diff_setup(&opts); + opts.stat_width = -1; /* use full terminal width */ + opts.stat_graph_width = -1; /* respect statGraphWidth config */ opts.output_format |= DIFF_FORMAT_SUMMARY | DIFF_FORMAT_DIFFSTAT; opts.detect_rename = DIFF_DETECT_RENAME; @@@ -885,30 -887,20 +887,30 @@@ static void abort_commit(const char *er exit(1); } +static const char merge_editor_comment[] = +N_("Please enter a commit message to explain why this merge is necessary,\n" + "especially if it merges an updated upstream into a topic branch.\n" + "\n" + "Lines starting with '#' will be ignored, and an empty message aborts\n" + "the commit.\n"); + static void prepare_to_commit(void) { struct strbuf msg = STRBUF_INIT; + const char *comment = _(merge_editor_comment); strbuf_addbuf(&msg, &merge_msg); strbuf_addch(&msg, '\n'); + if (0 < option_edit) + strbuf_add_lines(&msg, "# ", comment, strlen(comment)); write_merge_msg(&msg); run_hook(get_index_file(), "prepare-commit-msg", git_path("MERGE_MSG"), "merge", NULL, NULL); - if (option_edit) { + if (0 < option_edit) { if (launch_editor(git_path("MERGE_MSG"), NULL, NULL)) abort_commit(NULL); } read_merge_msg(&msg); - stripspace(&msg, option_edit); + stripspace(&msg, 0 < option_edit); if (!msg.len) abort_commit(_("Empty commit message.")); strbuf_release(&merge_msg); @@@ -1109,33 -1101,6 +1111,33 @@@ static void write_merge_state(void close(fd); } +static int default_edit_option(void) +{ + static const char name[] = "GIT_MERGE_AUTOEDIT"; + const char *e = getenv(name); + struct stat st_stdin, st_stdout; + + if (have_message) + /* an explicit -m msg without --[no-]edit */ + return 0; + + if (e) { + int v = git_config_maybe_bool(name, e); + if (v < 0) + die("Bad value '%s' in environment '%s'", e, name); + return v; + } + + /* Use editor if stdin and stdout are the same and is a tty */ + return (!fstat(0, &st_stdin) && + !fstat(1, &st_stdout) && + isatty(0) && isatty(1) && + st_stdin.st_dev == st_stdout.st_dev && + st_stdin.st_ino == st_stdout.st_ino && + st_stdin.st_mode == st_stdout.st_mode); +} + + int cmd_merge(int argc, const char **argv, const char *prefix) { unsigned char result_tree[20]; @@@ -1324,15 -1289,11 +1326,15 @@@ merge_remote_util(commit) && merge_remote_util(commit)->obj && merge_remote_util(commit)->obj->type == OBJ_TAG) { - option_edit = 1; + if (option_edit < 0) + option_edit = 1; allow_fast_forward = 0; } } + if (option_edit < 0) + option_edit = default_edit_option(); + if (!use_strategies) { if (!remoteheads->next) add_strategies(pull_twohead, DEFAULT_TWOHEAD); diff --combined contrib/completion/git-completion.bash index 33f0e4dd69,bacf40365b..fba076dde2 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@@ -60,6 -60,18 +60,6 @@@ # per-repository basis by setting the bash.showUpstream config # variable. # -# -# To submit patches: -# -# *) Read Documentation/SubmittingPatches -# *) Send all patches to the current maintainer: -# -# "Shawn O. Pearce" -# -# *) Always CC the Git mailing list: -# -# git@vger.kernel.org -# if [[ -n ${ZSH_VERSION-} ]]; then autoload -U +X bashcompinit && bashcompinit @@@ -137,7 -149,7 +137,7 @@@ __git_ps1_show_upstream ( svn_upstream=${svn_upstream[ ${#svn_upstream[@]} - 2 ]} svn_upstream=${svn_upstream%@*} local n_stop="${#svn_remote[@]}" - for ((n=1; n <= n_stop; ++n)); do + for ((n=1; n <= n_stop; n++)); do svn_upstream=${svn_upstream#${svn_remote[$n]}} done @@@ -166,8 -178,10 +166,8 @@@ for commit in $commits do case "$commit" in - "<"*) let ++behind - ;; - *) let ++ahead - ;; + "<"*) ((behind++)) ;; + *) ((ahead++)) ;; esac done count="$behind $ahead" @@@ -284,13 -298,13 +284,13 @@@ __git_ps1 ( fi fi if [ -n "${GIT_PS1_SHOWSTASHSTATE-}" ]; then - git rev-parse --verify refs/stash >/dev/null 2>&1 && s="$" + git rev-parse --verify refs/stash >/dev/null 2>&1 && s="$" fi if [ -n "${GIT_PS1_SHOWUNTRACKEDFILES-}" ]; then - if [ -n "$(git ls-files --others --exclude-standard)" ]; then - u="%" - fi + if [ -n "$(git ls-files --others --exclude-standard)" ]; then + u="%" + fi fi if [ -n "${GIT_PS1_SHOWUPSTREAM-}" ]; then @@@ -299,7 -313,7 +299,7 @@@ fi local f="$w$i$s$u" - printf "${1:- (%s)}" "$c${b##refs/heads/}${f:+ $f}$r$p" + printf -- "${1:- (%s)}" "$c${b##refs/heads/}${f:+ $f}$r$p" fi } @@@ -481,8 -495,11 +481,8 @@@ f # 4: A suffix to be appended to each possible completion word (optional). __gitcomp () { - local cur_="$cur" + local cur_="${3-$cur}" - if [ $# -gt 2 ]; then - cur_="$3" - fi case "$cur_" in --*=) COMPREPLY=() @@@ -507,8 -524,18 +507,8 @@@ # appended. __gitcomp_nl () { - local s=$'\n' IFS=' '$'\t'$'\n' - local cur_="$cur" suffix=" " - - if [ $# -gt 2 ]; then - cur_="$3" - if [ $# -gt 3 ]; then - suffix="$4" - fi - fi - - IFS=$s - COMPREPLY=($(compgen -P "${2-}" -S "$suffix" -W "$1" -- "$cur_")) + local IFS=$'\n' + COMPREPLY=($(compgen -P "${2-}" -S "${4- }" -W "$1" -- "${3-$cur}")) } __git_heads () @@@ -616,8 -643,13 +616,8 @@@ __git_refs_remotes ( __git_remotes () { - local i ngoff IFS=$'\n' d="$(__gitdir)" - __git_shopt -q nullglob || ngoff=1 - __git_shopt -s nullglob - for i in "$d/remotes"/*; do - echo ${i#$d/remotes/} - done - [ "$ngoff" ] && __git_shopt -u nullglob + local i IFS=$'\n' d="$(__gitdir)" + test -d "$d/remotes" && ls -1 "$d/remotes" for i in $(git --git-dir="$d" config --get-regexp 'remote\..*\.url' 2>/dev/null); do i="${i#remote.}" echo "${i/.url*/}" @@@ -644,8 -676,7 +644,8 @@@ __git_merge_strategies # is needed. __git_compute_merge_strategies () { - : ${__git_merge_strategies:=$(__git_list_merge_strategies)} + test -n "$__git_merge_strategies" || + __git_merge_strategies=$(__git_list_merge_strategies) } __git_complete_revlist_file () @@@ -724,9 -755,6 +724,9 @@@ __git_complete_remote_or_refspec ( { local cur_="$cur" cmd="${words[1]}" local i c=2 remote="" pfx="" lhs=1 no_complete_refspec=0 + if [ "$cmd" = "remote" ]; then + ((c++)) + fi while [ $c -lt $cword ]; do i="${words[c]}" case "$i" in @@@ -744,7 -772,7 +744,7 @@@ -*) ;; *) remote="$i"; break ;; esac - c=$((++c)) + ((c++)) done if [ -z "$remote" ]; then __gitcomp_nl "$(__git_remotes)" @@@ -777,7 -805,7 +777,7 @@@ __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_" fi ;; - pull) + pull|remote) if [ $lhs = 1 ]; then __gitcomp_nl "$(__git_refs "$remote")" "$pfx" "$cur_" else @@@ -826,8 -854,7 +826,8 @@@ __git_list_all_commands ( __git_all_commands= __git_compute_all_commands () { - : ${__git_all_commands:=$(__git_list_all_commands)} + test -n "$__git_all_commands" || + __git_all_commands=$(__git_list_all_commands) } __git_list_porcelain_commands () @@@ -920,8 -947,7 +920,8 @@@ __git_porcelain_commands __git_compute_porcelain_commands () { __git_compute_all_commands - : ${__git_porcelain_commands:=$(__git_list_porcelain_commands)} + test -n "$__git_porcelain_commands" || + __git_porcelain_commands=$(__git_list_porcelain_commands) } __git_pretty_aliases () @@@ -984,7 -1010,7 +984,7 @@@ __git_find_on_cmdline ( return fi done - c=$((++c)) + ((c++)) done } @@@ -995,7 -1021,7 +995,7 @@@ __git_has_doubledash ( if [ "--" = "${words[c]}" ]; then return 0 fi - c=$((++c)) + ((c++)) done return 1 } @@@ -1118,7 -1144,7 +1118,7 @@@ _git_branch ( -d|-m) only_local_ref="y" ;; -r) has_r="y" ;; esac - c=$((++c)) + ((c++)) done case "$cur" in @@@ -1126,7 -1152,7 +1126,7 @@@ __gitcomp " --color --no-color --verbose --abbrev= --no-abbrev --track --no-track --contains --merged --no-merged - --set-upstream + --set-upstream --edit-description --list " ;; *) @@@ -2092,6 -2118,7 +2092,7 @@@ _git_config ( core.whitespace core.worktree diff.autorefreshindex + diff.statGraphWidth diff.external diff.ignoreSubmodules diff.mnemonicprefix @@@ -2278,7 -2305,7 +2279,7 @@@ _git_remote () { - local subcommands="add rename rm show prune update set-head" + local subcommands="add rename rm set-head set-branches set-url show prune update" local subcommand="$(__git_find_on_cmdline "$subcommands")" if [ -z "$subcommand" ]; then __gitcomp "$subcommands" @@@ -2286,12 -2313,9 +2287,12 @@@ fi case "$subcommand" in - rename|rm|show|prune) + rename|rm|set-url|show|prune) __gitcomp_nl "$(__git_remotes)" ;; + set-head|set-branches) + __git_complete_remote_or_refspec + ;; update) local i c='' IFS=$'\n' for i in $(git --git-dir="$(__gitdir)" config --get-regexp "remotes\..*" 2>/dev/null); do @@@ -2504,7 -2528,7 +2505,7 @@@ _git_svn ( __gitcomp " --merge --strategy= --verbose --dry-run --fetch-all --no-rebase --commit-url - --revision $cmt_opts $fc_opts + --revision --interactive $cmt_opts $fc_opts " ;; set-tree,--*) @@@ -2572,7 -2596,7 +2573,7 @@@ _git_tag ( f=1 ;; esac - c=$((++c)) + ((c++)) done case "$prev" in @@@ -2625,7 -2649,7 +2626,7 @@@ _git ( --help) command="help"; break ;; *) command="$i"; break ;; esac - c=$((++c)) + ((c++)) done if [ -z "$command" ]; then @@@ -2710,3 -2734,33 +2711,3 @@@ if [ Cygwin = "$(uname -o 2>/dev/null) complete -o bashdefault -o default -o nospace -F _git git.exe 2>/dev/null \ || complete -o default -o nospace -F _git git.exe fi - -if [[ -n ${ZSH_VERSION-} ]]; then - __git_shopt () { - local option - if [ $# -ne 2 ]; then - echo "USAGE: $0 (-q|-s|-u)