diff options
238 files changed, 6951 insertions, 2099 deletions
diff --git a/.gitignore b/.gitignore index dc600f9b36..42294e59a1 100644 --- a/.gitignore +++ b/.gitignore @@ -226,6 +226,7 @@ /config.mak.autogen /config.mak.append /configure +/unicode /tags /TAGS /cscope* diff --git a/Documentation/CodingGuidelines b/Documentation/CodingGuidelines index f424dbd75c..4d90c77c7b 100644 --- a/Documentation/CodingGuidelines +++ b/Documentation/CodingGuidelines @@ -18,6 +18,14 @@ code. For Git in general, three rough rules are: judgement call, the decision based more on real world constraints people face than what the paper standard says. + - Fixing style violations while working on a real change as a + preparatory clean-up step is good, but otherwise avoid useless code + churn for the sake of conforming to the style. + + "Once it _is_ in the tree, it's not really worth the patch noise to + go and fix it up." + Cf. http://article.gmane.org/gmane.linux.kernel/943020 + Make your code readable and sensible, and don't try to be clever. As for more concrete guidelines, just imitate the existing code @@ -34,7 +42,17 @@ For shell scripts specifically (not exhaustive): - We use tabs for indentation. - - Case arms are indented at the same depth as case and esac lines. + - Case arms are indented at the same depth as case and esac lines, + like this: + + case "$variable" in + pattern1) + do this + ;; + pattern2) + do that + ;; + esac - Redirection operators should be written with space before, but no space after them. In other words, write 'echo test >"$file"' @@ -43,6 +61,14 @@ For shell scripts specifically (not exhaustive): redirection target in a variable (as shown above), our code does so because some versions of bash issue a warning without the quotes. + (incorrect) + cat hello > world < universe + echo hello >$world + + (correct) + cat hello >world <universe + echo hello >"$world" + - We prefer $( ... ) for command substitution; unlike ``, it properly nests. It should have been the way Bourne spelled it from day one, but unfortunately isn't. @@ -81,14 +107,33 @@ For shell scripts specifically (not exhaustive): "then" should be on the next line for if statements, and "do" should be on the next line for "while" and "for". + (incorrect) + if test -f hello; then + do this + fi + + (correct) + if test -f hello + then + do this + fi + - We prefer "test" over "[ ... ]". - We do not write the noiseword "function" in front of shell functions. - - We prefer a space between the function name and the parentheses. The - opening "{" should also be on the same line. - E.g.: my_function () { + - We prefer a space between the function name and the parentheses, + and no space inside the parentheses. The opening "{" should also + be on the same line. + + (incorrect) + my_function(){ + ... + + (correct) + my_function () { + ... - As to use of grep, stick to a subset of BRE (namely, no \{m,n\}, [::], [==], or [..]) for portability. @@ -106,6 +151,19 @@ For shell scripts specifically (not exhaustive): interface translatable. See "Marking strings for translation" in po/README. + - We do not write our "test" command with "-a" and "-o" and use "&&" + or "||" to concatenate multiple "test" commands instead, because + the use of "-a/-o" is often error-prone. E.g. + + test -n "$x" -a "$a" = "$b" + + is buggy and breaks when $x is "=", but + + test -n "$x" && test "$a" = "$b" + + does not have such a problem. + + For C programs: - We use tabs to indent, and interpret tabs as taking up to @@ -149,7 +207,7 @@ For C programs: of "else if" statements, it can make sense to add braces to single line blocks. - - We try to avoid assignments inside if(). + - We try to avoid assignments in the condition of an "if" statement. - Try to make your code understandable. You may put comments in, but comments invariably tend to stale out when the code @@ -177,6 +235,88 @@ For C programs: - Double negation is often harder to understand than no negation at all. + - There are two schools of thought when it comes to comparison, + especially inside a loop. Some people prefer to have the less stable + value on the left hand side and the more stable value on the right hand + side, e.g. if you have a loop that counts variable i down to the + lower bound, + + while (i > lower_bound) { + do something; + i--; + } + + Other people prefer to have the textual order of values match the + actual order of values in their comparison, so that they can + mentally draw a number line from left to right and place these + values in order, i.e. + + while (lower_bound < i) { + do something; + i--; + } + + Both are valid, and we use both. However, the more "stable" the + stable side becomes, the more we tend to prefer the former + (comparison with a constant, "i > 0", is an extreme example). + Just do not mix styles in the same part of the code and mimic + existing styles in the neighbourhood. + + - There are two schools of thought when it comes to splitting a long + logical line into multiple lines. Some people push the second and + subsequent lines far enough to the right with tabs and align them: + + if (the_beginning_of_a_very_long_expression_that_has_to || + span_more_than_a_single_line_of || + the_source_text) { + ... + + while other people prefer to align the second and the subsequent + lines with the column immediately inside the opening parenthesis, + with tabs and spaces, following our "tabstop is always a multiple + of 8" convention: + + if (the_beginning_of_a_very_long_expression_that_has_to || + span_more_than_a_single_line_of || + the_source_text) { + ... + + Both are valid, and we use both. Again, just do not mix styles in + the same part of the code and mimic existing styles in the + neighbourhood. + + - When splitting a long logical line, some people change line before + a binary operator, so that the result looks like a parse tree when + you turn your head 90-degrees counterclockwise: + + if (the_beginning_of_a_very_long_expression_that_has_to + || span_more_than_a_single_line_of_the_source_text) { + + while other people prefer to leave the operator at the end of the + line: + + if (the_beginning_of_a_very_long_expression_that_has_to || + span_more_than_a_single_line_of_the_source_text) { + + Both are valid, but we tend to use the latter more, unless the + expression gets fairly complex, in which case the former tends to + be easier to read. Again, just do not mix styles in the same part + of the code and mimic existing styles in the neighbourhood. + + - When splitting a long logical line, with everything else being + equal, it is preferable to split after the operator at higher + level in the parse tree. That is, this is more preferable: + + if (a_very_long_variable * that_is_used_in + + a_very_long_expression) { + ... + + than + + if (a_very_long_variable * + that_is_used_in + a_very_long_expression) { + ... + - Some clever tricks, like using the !! operator with arithmetic constructs, can be extremely confusing to others. Avoid them, unless there is a compelling reason to use them. diff --git a/Documentation/Makefile b/Documentation/Makefile index fc6b2cf9ec..cea0e7ae3d 100644 --- a/Documentation/Makefile +++ b/Documentation/Makefile @@ -59,6 +59,7 @@ SP_ARTICLES += howto/recover-corrupted-blob-object SP_ARTICLES += howto/recover-corrupted-object-harder SP_ARTICLES += howto/rebuild-from-update-hook SP_ARTICLES += howto/rebase-from-internal-branch +SP_ARTICLES += howto/keep-canonical-history-correct SP_ARTICLES += howto/maintain-git API_DOCS = $(patsubst %.txt,%,$(filter-out technical/api-index-skel.txt technical/api-index.txt, $(wildcard technical/api-*.txt))) SP_ARTICLES += $(API_DOCS) diff --git a/Documentation/RelNotes/2.0.1.txt b/Documentation/RelNotes/2.0.1.txt new file mode 100644 index 0000000000..ce5579db3e --- /dev/null +++ b/Documentation/RelNotes/2.0.1.txt @@ -0,0 +1,115 @@ +Git v2.0.1 Release Notes +======================== + + * We used to unconditionally disable the pager in the pager process + we spawn to feed out output, but that prevented people who want to + run "less" within "less" from doing so. + + * Tools that read diagnostic output in our standard error stream do + not want to see terminal control sequence (e.g. erase-to-eol). + Detect them by checking if the standard error stream is connected + to a tty. + * Reworded the error message given upon a failure to open an existing + loose object file due to e.g. permission issues; it was reported as + the object being corrupt, but that is not quite true. + + * "git log -2master" is a common typo that shows two commits starting + from whichever random branch that is not 'master' that happens to + be checked out currently. + + * The "%<(10,trunc)%s" pretty format specifier in the log family of + commands is used to truncate the string to a given length (e.g. 10 + in the example) with padding to column-align the output, but did + not take into account that number of bytes and number of display + columns are different. + + * The "mailmap.file" configuration option did not support the tilde + expansion (i.e. ~user/path and ~/path). + + * The completion scripts (in contrib/) did not know about quite a few + options that are common between "git merge" and "git pull", and a + couple of options unique to "git merge". + + * "--ignore-space-change" option of "git apply" ignored the spaces + at the beginning of line too aggressively, which is inconsistent + with the option of the same name "diff" and "git diff" have. + + * "git blame" miscounted number of columns needed to show localized + timestamps, resulting in jaggy left-side-edge of the source code + lines in its output. + + * "git blame" assigned the blame to the copy in the working-tree if + the repository is set to core.autocrlf=input and the file used CRLF + line endings. + + * "git commit --allow-empty-message -C $commit" did not work when the + commit did not have any log message. + + * "git diff --find-copies-harder" sometimes pretended as if the mode + bits have changed for paths that are marked with assume-unchanged + bit. + + * "git format-patch" did not enforce the rule that the "--follow" + option from the log/diff family of commands must be used with + exactly one pathspec. + + * "git gc --auto" was recently changed to run in the background to + give control back early to the end-user sitting in front of the + terminal, but it forgot that housekeeping involving reflogs should + be done without other processes competing for accesses to the refs. + + * "git grep -O" to show the lines that hit in the pager did not work + well with case insensitive search. We now spawn "less" with its + "-I" option when it is used as the pager (which is the default). + + * We used to disable threaded "git index-pack" on platforms without + thread-safe pread(); use a different workaround for such + platforms to allow threaded "git index-pack". + + * The error reporting from "git index-pack" has been improved to + distinguish missing objects from type errors. + + * "git mailinfo" used to read beyond the end of header string while + parsing an incoming e-mail message to extract the patch. + + * On a case insensitive filesystem, merge-recursive incorrectly + deleted the file that is to be renamed to a name that is the same + except for case differences. + + * "git pack-objects" unnecessarily copied the previous contents when + extending the hashtable, even though it will populate the table + from scratch anyway. + + * "git rerere forget" did not work well when merge.conflictstyle + was set to a non-default value. + + * "git remote rm" and "git remote prune" can involve removing many + refs at once, which is not a very efficient thing to do when very + many refs exist in the packed-refs file. + + * "git log --exclude=<glob> --all | git shortlog" worked as expected, + but "git shortlog --exclude=<glob> --all", which is supposed to be + identical to the above pipeline, was not accepted at the command + line argument parser level. + + * The autostash mode of "git rebase -i" did not restore the dirty + working tree state if the user aborted the interactive rebase by + emptying the insn sheet. + + * "git show -s" (i.e. show log message only) used to incorrectly emit + an extra blank line after a merge commit. + + * "git status", even though it is a read-only operation, tries to + update the index with refreshed lstat(2) info to optimize future + accesses to the working tree opportunistically, but this could + race with a "read-write" operation that modify the index while it + is running. Detect such a race and avoid overwriting the index. + + * "git status" (and "git commit") behaved as if changes in a modified + submodule are not there if submodule.*.ignore configuration is set, + which was misleading. The configuration is only to unclutter diff + output during the course of development, and should not to hide + changes in the "status" output to cause the users forget to commit + them. + + * The mode to run tests with HTTP server tests disabled was broken. diff --git a/Documentation/RelNotes/2.1.0.txt b/Documentation/RelNotes/2.1.0.txt index ad53d0deb6..828a439dc1 100644 --- a/Documentation/RelNotes/2.1.0.txt +++ b/Documentation/RelNotes/2.1.0.txt @@ -1,18 +1,78 @@ Git v2.1 Release Notes ====================== +Backward compatibility notes +---------------------------- + + * The default value we give to the environment variable LESS has been + changed from "FRSX" to "FRX", losing "S" (chop long lines instead + of wrapping). Existing users who prefer not to see line-wrapped + output may want to set + + $ git config core.pager "less -S" + + to restore the traditional behaviour. It is expected that people + find output from the most subcommands easier to read with the new + default, except for "blame" which tends to produce really long + lines. To override the new default only for "git blame", you can + do this: + + $ git config pager.blame "less -S" + + * A few disused directories in contrib/ have been retired. + + Updates since v2.0 ------------------ UI, Workflows & Features + * Since the very beginning of Git, we gave the LESS environment a + default value "FRSX" when we spawn "less" as the pager. "S" (chop + long lines instead of wrapping) has been removed from this default + set of options, because it is more or less a personal taste thing, + as opposed to others that have good justifications (i.e. "R" is + very much justified because many kinds of output we produce are + colored and "FX" is justified because output we produce is often + shorter than a page). + + * The logic and data used to compute the display width needed for + UTF-8 strings have been updated to match Unicode 7.0 better. + + * HTTP-based transports learned to propagate the error messages from + the webserver better to the client coming over the HTTP transport. + + * The completion script for bash (in contrib/) has been updated to + handle aliases that define complex sequence of commands better. + + * The "core.preloadindex" configuration variable is by default + enabled, allowing modern platforms to take advantage of the + multiple cores they have. + * "git commit --date=<date>" option learned to read from more timestamp formats, including "--date=now". + * The `core.commentChar` configuration variable is used to specify a + custom comment character other than the default "#" to be used in + the commit log editor. This can be set to `auto` to attempt to + choose a different character that does not conflict with what + already starts a line in the message being edited for cases like + "git commit --amend". + + * "git format-patch" learned --signature-file=<file> to take the mail + signature from. + * "git grep" learned grep.fullname configuration variable to force "--full-name" to be default. This may cause regressions on scripted users that do not expect this new behaviour. + * "git imap-send" learned to ask the credential helper for auth + material. + + * "git log" and friends now understand the value "auto" set to the + "log.decorate" configuration variable to enable the "--decorate" + option automatically when the output is sent to tty. + * "git merge" without argument, even when there is an upstream defined for the current branch, refused to run until merge.defaultToUpstream is set to true. Flip the default of that @@ -33,13 +93,30 @@ UI, Workflows & Features users need to explicitly set the variable to 'true' if they want to resurrect the now-ignored use case. + * "git replace" learned the "--edit" subcommand. + + * "git send-email" learned "--to-cover" and "--cc-cover" options, to + tell it to copy To: and Cc: headers found in the first input file + when emitting later input files. + * "git svn" learned to cope with malformed timestamps with only one digit in the hour part, e.g. 2014-01-07T5:01:02.048176Z, emitted by some broken subversion server implementations. + * "git tag" when editing the tag message shows the name of the tag + being edited as a comment in the editor. + Performance, Internal Implementation, etc. + * Build procedure for 'subtree' (in contrib/) has been cleaned up. + + * The `core.deltabasecachelimit` used to default to 16 MiB , but this + proved to be too small, and has been bumped to 96 MiB. + + * "git blame" has been optimized greatly by reorganising the data + structure that is used to keep track of the work to be done. + * "git diff" that compares 3-or-more trees (e.g. parents and the result of a merge) have been optimized. @@ -48,6 +125,10 @@ Performance, Internal Implementation, etc. example, "update-ref --stdin [-z]" has been updated to use this API. + * Parts of the test scripts can be skipped by using a range notation, + e.g. "sh t1234-test.sh --run='1-4 6 8-'" to omit test piece 5 and 7 + and run everything else. + Also contains various documentation updates and code clean-ups. @@ -59,6 +140,48 @@ Unless otherwise noted, all the fixes since v2.0 in the maintenance track are contained in this release (see the maintenance releases' notes for details). + * We used to unconditionally disable the pager in the pager process + we spawn to feed out output, but that prevented people who want to + run "less" within "less" from doing so. + (merge c0459ca je/pager-do-not-recurse later to maint). + + * Tools that read diagnostic output in our standard error stream do + not want to see terminal control sequence (e.g. erase-to-eol). + Detect them by checking if the standard error stream is connected + to a tty. + (merge 38de156 mn/sideband-no-ansi later to maint). + + * Mishandling of patterns in .gitignore that has trailing SPs quoted + with backslashes (e.g. ones that end with "\ ") have been + corrected. + (merge 97c1364be6b pb/trim-trailing-spaces later to maint). + + * Reworded the error message given upon a failure to open an existing + loose object file due to e.g. permission issues; it was reported as + the object being corrupt, but that is not quite true. + (merge d6c8a05 jk/report-fail-to-read-objects-better later to maint). + + * "git log -2master" is a common typo that shows two commits starting + from whichever random branch that is not 'master' that happens to + be checked out currently. + (merge e3fa568 jc/revision-dash-count-parsing later to maint). + + * The "%<(10,trunc)%s" pretty format specifier in the log family of + commands is used to truncate the string to a given length (e.g. 10 + in the example) with padding to column-align the output, but did + not take into account that number of bytes and number of display + columns are different. + (merge 7d50987 as/pretty-truncate later to maint). + + * The "mailmap.file" configuration option did not support the tilde + expansion (i.e. ~user/path and ~/path). + (merge 9352fd5 ow/config-mailmap-pathname later to maint). + + * The completion scripts (in contrib/) did not know about quite a few + options that are common between "git merge" and "git pull", and a + couple of options unique to "git merge". + (merge 8fee872 jk/complete-merge-pull later to maint). + * "--ignore-space-change" option of "git apply" ignored the spaces at the beginning of line too aggressively, which is inconsistent with the option of the same name "diff" and "git diff" have. @@ -69,18 +192,110 @@ notes for details). lines in its output. (merge dd75553 jx/blame-align-relative-time later to maint). + * "git blame" assigned the blame to the copy in the working-tree if + the repository is set to core.autocrlf=input and the file used CRLF + line endings. + (merge 4d4813a bc/blame-crlf-test later to maint). + + * "git commit --allow-empty-messag -C $commit" did not work when the + commit did not have any log message. + (merge 076cbd6 jk/commit-C-pick-empty later to maint). + + * "git diff --find-copies-harder" sometimes pretended as if the mode + bits have changed for paths that are marked with assume-unchanged + bit. + (merge 5304810 jk/diff-files-assume-unchanged later to maint). + + * "git format-patch" did not enforce the rule that the "--follow" + option from the log/diff family of commands must be used with + exactly one pathspec. + (merge dd63f16 jk/diff-follow-must-take-one-pathspec later to maint). + + * "git gc --auto" was recently changed to run in the background to + give control back early to the end-user sitting in front of the + terminal, but it forgot that housekeeping involving reflogs should + be done without other processes competing for accesses to the refs. + (merge 62aad18 nd/daemonize-gc later to maint). + + * "git grep -O" to show the lines that hit in the pager did not work + well with case insensitive search. We now spawn "less" with its + "-I" option when it is used as the pager (which is the default). + (merge f7febbe sk/spawn-less-case-insensitively-from-grep-O-i later to maint). + * We used to disable threaded "git index-pack" on platforms without thread-safe pread(); use a different workaround for such platforms to allow threaded "git index-pack". (merge 3953949 nd/index-pack-one-fd-per-thread later to maint). + * The error reporting from "git index-pack" has been improved to + distinguish missing objects from type errors. + (merge 77583e7 jk/index-pack-report-missing later to maint). + + * "git mailinfo" used to read beyond the end of header string while + parsing an incoming e-mail message to extract the patch. + (merge b1a013d rs/mailinfo-header-cmp later to maint). + + * On a case insensitive filesystem, merge-recursive incorrectly + deleted the file that is to be renamed to a name that is the same + except for case differences. + (merge baa37bf dt/merge-recursive-case-insensitive later to maint). + + * "git pack-objects" unnecessarily copied the previous contents when + extending the hashtable, even though it will populate the table + from scratch anyway. + (merge fb79947 rs/pack-objects-no-unnecessary-realloc later to maint). + + * Recent updates to "git repack" started to duplicate objects that + are in packfiles marked with .keep flag into the new packfile by + mistake. + (merge d078d85 jk/repack-pack-keep-objects later to maint). + * "git rerere forget" did not work well when merge.conflictstyle was set to a non-default value. (merge de3d8bb fc/rerere-conflict-style later to maint). + * "git remote rm" and "git remote prune" can involve removing many + refs at once, which is not a very efficient thing to do when very + many refs exist in the packed-refs file. + (merge e6bea66 jl/remote-rm-prune later to maint). + + * "git log --exclude=<glob> --all | git shortlog" worked as expected, + but "git shortlog --exclude=<glob> --all", which is supposed to be + identical to the above pipeline, was not accepted at the command + line argument parser level. + (merge eb07774 jc/shortlog-ref-exclude later to maint). + + * The autostash mode of "git rebase -i" did not restore the dirty + working tree state if the user aborted the interactive rebase by + emptying the insn sheet. + (merge ddb5432 rr/rebase-autostash-fix later to maint). + + * "git show -s" (i.e. show log message only) used to incorrectly emit + an extra blank line after a merge commit. + (merge ad2f725 mk/show-s-no-extra-blank-line-for-merges later to maint). + * "git status", even though it is a read-only operation, tries to update the index with refreshed lstat(2) info to optimize future accesses to the working tree opportunistically, but this could race with a "read-write" operation that modify the index while it is running. Detect such a race and avoid overwriting the index. (merge 426ddee ym/fix-opportunistic-index-update-race later to maint). + + * "git status" (and "git commit") behaved as if changes in a modified + submodule are not there if submodule.*.ignore configuration is set, + which was misleading. The configuration is only to unclutter diff + output during the course of development, and should not to hide + changes in the "status" output to cause the users forget to commit + them. + (merge c215d3d jl/status-added-submodule-is-never-ignored later to maint). + + * Documentation for "git submodule sync" forgot to say that the subcommand + can take the "--recursive" option. + (merge 9393ae7 mc/doc-submodule-sync-recurse later to maint). + + * "git update-index --cacheinfo" in 2.0 release crashed on a + malformed command line. + (merge c8e1ee4 jc/rev-parse-argh-dashed-multi-words later to maint). + + * The mode to run tests with HTTP server tests disabled was broken. + (merge afa53fe na/no-http-test-in-the-middle later to maint). diff --git a/Documentation/config.txt b/Documentation/config.txt index 1932e9b9a2..1d718bdb96 100644 --- a/Documentation/config.txt +++ b/Documentation/config.txt @@ -381,7 +381,7 @@ false), while all other repositories are assumed to be bare (bare core.worktree:: Set the path to the root of the working tree. This can be overridden by the GIT_WORK_TREE environment - variable and the '--work-tree' command line option. + variable and the '--work-tree' command-line option. The value can be an absolute path or relative to the path to the .git directory, which is either specified by --git-dir or GIT_DIR, or automatically discovered. @@ -489,7 +489,7 @@ core.deltaBaseCacheLimit:: to avoid unpacking and decompressing frequently used base objects multiple times. + -Default is 16 MiB on all platforms. This should be reasonable +Default is 96 MiB on all platforms. This should be reasonable for all users/operating systems, except on the largest projects. You probably do not need to adjust this value. + @@ -523,7 +523,7 @@ core.askpass:: environment variable. If not set, fall back to the value of the 'SSH_ASKPASS' environment variable or, failing that, a simple password prompt. The external program shall be given a suitable prompt as - command line argument and write the password on its STDOUT. + command-line argument and write the password on its STDOUT. core.attributesfile:: In addition to '.gitattributes' (per-directory) and @@ -544,6 +544,9 @@ core.commentchar:: messages consider a line that begins with this character commented, and removes them after the editor returns (default '#'). ++ +If set to "auto", `git-commit` would select a character that is not +the beginning character of any line in existing commit messages. sequence.editor:: Text editor used by `git rebase -i` for editing the rebase instruction file. @@ -558,14 +561,19 @@ core.pager:: configuration, then `$PAGER`, and then the default chosen at compile time (usually 'less'). + -When the `LESS` environment variable is unset, Git sets it to `FRSX` +When the `LESS` environment variable is unset, Git sets it to `FRX` (if `LESS` environment variable is set, Git does not change it at all). If you want to selectively override Git's default setting -for `LESS`, you can set `core.pager` to e.g. `less -+S`. This will +for `LESS`, you can set `core.pager` to e.g. `less -S`. This will be passed to the shell by Git, which will translate the final -command to `LESS=FRSX less -+S`. The environment tells the command -to set the `S` option to chop long lines but the command line -resets it to the default to fold long lines. +command to `LESS=FRX less -S`. The environment does not set the +`S` option but the command line does, instructing less to truncate +long lines. Similarly, setting `core.pager` to `less -+F` will +deactivate the `F` option specified by the environment from the +command-line, deactivating the "quit if one screen" behavior of +`less`. One can specifically activate some flags for particular +commands: for example, setting `pager.blame` to `less -S` enables +line truncation only for `git blame`. + Likewise, when the `LV` environment variable is unset, Git sets it to `-c`. You can override this setting by exporting `LV` with @@ -613,9 +621,9 @@ core.preloadindex:: + This can speed up operations like 'git diff' and 'git status' especially on filesystems like NFS that have weak caching semantics and thus -relatively high IO latencies. With this set to 'true', Git will do the +relatively high IO latencies. When enabled, Git will do the index comparison to the filesystem data in parallel, allowing -overlapping IO's. +overlapping IO's. Defaults to true. core.createObject:: You can set this to 'link', in which case a hardlink followed by @@ -1114,6 +1122,10 @@ format.signature:: Set this variable to the empty string ("") to suppress signature generation. +format.signaturefile:: + Works just like format.signature except the contents of the + file specified by this variable will be used as the signature. + format.suffix:: The default for format-patch is to output files with the suffix `.patch`. Use this variable to change that suffix (make sure to @@ -1324,7 +1336,7 @@ grep.extendedRegexp:: gpg.program:: Use this custom program instead of "gpg" found on $PATH when making or verifying a PGP signature. The program must support the - same command line interface as GPG, namely, to verify a detached + same command-line interface as GPG, namely, to verify a detached signature, "gpg --verify $file - <$signature" is run, and the program is expected to signal a good signature by exiting with code 0, and to generate an ascii-armored detached signature, the @@ -1893,12 +1905,7 @@ pack.useBitmaps:: you are debugging pack bitmaps. pack.writebitmaps:: - When true, git will write a bitmap index when packing all - objects to disk (e.g., when `git repack -a` is run). This - index can speed up the "counting objects" phase of subsequent - packs created for clones and fetches, at the cost of some disk - space and extra time spent on the initial repack. Defaults to - false. + This is a deprecated synonym for `repack.writeBitmaps`. pack.writeBitmapHashCache:: When true, git will include a "hash cache" section in the bitmap @@ -2175,7 +2182,15 @@ repack.packKeptObjects:: `--pack-kept-objects` was passed. See linkgit:git-repack[1] for details. Defaults to `false` normally, but `true` if a bitmap index is being written (either via `--write-bitmap-index` or - `pack.writeBitmaps`). + `repack.writeBitmaps`). + +repack.writeBitmaps:: + When true, git will write a bitmap index when packing all + objects to disk (e.g., when `git repack -a` is run). This + index can speed up the "counting objects" phase of subsequent + packs created for clones and fetches, at the cost of some disk + space and extra time spent on the initial repack. Defaults to + false. rerere.autoupdate:: When set to true, `git-rerere` updates the index with the @@ -2293,9 +2308,11 @@ status.submodulesummary:: --summary-limit option of linkgit:git-submodule[1]). Please note that the summary output command will be suppressed for all submodules when `diff.ignoreSubmodules` is set to 'all' or only - for those submodules where `submodule.<name>.ignore=all`. To + for those submodules where `submodule.<name>.ignore=all`. The only + exception to that rule is that status and commit will show staged + submodule changes. To also view the summary for ignored submodules you can either use - the --ignore-submodules=dirty command line option or the 'git + the --ignore-submodules=dirty command-line option or the 'git submodule summary' command, which shows a similar output but does not honor these settings. @@ -2317,14 +2334,16 @@ submodule.<name>.branch:: submodule.<name>.fetchRecurseSubmodules:: This option can be used to control recursive fetching of this submodule. It can be overridden by using the --[no-]recurse-submodules - command line option to "git fetch" and "git pull". + command-line option to "git fetch" and "git pull". This setting will override that from in the linkgit:gitmodules[5] file. submodule.<name>.ignore:: Defines under what circumstances "git status" and the diff family show a submodule as modified. When set to "all", it will never be considered - modified, "dirty" will ignore all changes to the submodules work tree and + modified (but it will nonetheless show up in the output of status and + commit when it has been staged), "dirty" will ignore all changes + to the submodules work tree and takes only differences between the HEAD of the submodule and the commit recorded in the superproject into account. "untracked" will additionally let submodules with modified tracked files in their work tree show up. diff --git a/Documentation/diff-config.txt b/Documentation/diff-config.txt index f07b4513ed..b001779520 100644 --- a/Documentation/diff-config.txt +++ b/Documentation/diff-config.txt @@ -76,7 +76,7 @@ diff.ignoreSubmodules:: this setting when reporting uncommitted changes. Setting it to 'all' disables the submodule summary normally shown by 'git commit' and 'git status' when 'status.submodulesummary' is set unless it is - overridden by using the --ignore-submodules command line option. + overridden by using the --ignore-submodules command-line option. The 'git submodule' commands are not affected by this setting. diff.mnemonicprefix:: diff --git a/Documentation/fetch-options.txt b/Documentation/fetch-options.txt index 92c68c3fda..b09a783ee3 100644 --- a/Documentation/fetch-options.txt +++ b/Documentation/fetch-options.txt @@ -72,6 +72,14 @@ endif::git-pull[] setting. See linkgit:git-config[1]. ifndef::git-pull[] +--refmap=<refspec>:: + When fetching refs listed on the command line, use the + specified refspec (can be given more than once) to map the + refs to remote-tracking branches, instead of the values of + `remote.*.fetch` configuration variables for the remote + repository. See section on "Configured Remote-tracking + Branches" for details. + -t:: --tags:: Fetch all tags from the remote (i.e., fetch remote tags diff --git a/Documentation/git-bisect.txt b/Documentation/git-bisect.txt index f986c5cb3a..4cb52a7302 100644 --- a/Documentation/git-bisect.txt +++ b/Documentation/git-bisect.txt @@ -117,7 +117,7 @@ $ git bisect visualize `view` may also be used as a synonym for `visualize`. If the 'DISPLAY' environment variable is not set, 'git log' is used -instead. You can also give command line options such as `-p` and +instead. You can also give command-line options such as `-p` and `--stat`. ------------ diff --git a/Documentation/git-config.txt b/Documentation/git-config.txt index e9917b89a9..9dfa1a5ce2 100644 --- a/Documentation/git-config.txt +++ b/Documentation/git-config.txt @@ -256,7 +256,7 @@ All writing options will per default write to the repository specific configuration file. Note that this also affects options like '--replace-all' and '--unset'. *'git config' will only ever change one file at a time*. -You can override these rules either by command line options or by environment +You can override these rules either by command-line options or by environment variables. The '--global' and the '--system' options will limit the file used to the global or system-wide file respectively. The GIT_CONFIG environment variable has a similar effect, but you can specify any filename you want. diff --git a/Documentation/git-daemon.txt b/Documentation/git-daemon.txt index 223f731523..a69b3616ec 100644 --- a/Documentation/git-daemon.txt +++ b/Documentation/git-daemon.txt @@ -169,7 +169,7 @@ Git configuration files in that directory are readable by `<user>`. --forbid-override=<service>:: Allow/forbid overriding the site-wide default with per repository configuration. By default, all the services - are overridable. + may be overridden. --[no-]informative-errors:: When informative errors are turned on, git-daemon will report @@ -184,7 +184,7 @@ Git configuration files in that directory are readable by `<user>`. Every time a client connects, first run an external command specified by the <path> with service name (e.g. "upload-pack"), path to the repository, hostname (%H), canonical hostname - (%CH), ip address (%IP), and tcp port (%P) as its command line + (%CH), IP address (%IP), and TCP port (%P) as its command-line arguments. The external command can decide to decline the service by exiting with a non-zero status (or to allow it by exiting with a zero status). It can also look at the $REMOTE_ADDR @@ -204,7 +204,7 @@ SERVICES -------- These services can be globally enabled/disabled using the -command line options of this command. If a finer-grained +command-line options of this command. If finer-grained control is desired (e.g. to allow 'git archive' to be run against only in a few selected repositories the daemon serves), the per-repository configuration file can be used to enable or diff --git a/Documentation/git-fast-export.txt b/Documentation/git-fast-export.txt index 85f1f30fdf..221506b04b 100644 --- a/Documentation/git-fast-export.txt +++ b/Documentation/git-fast-export.txt @@ -105,6 +105,10 @@ marks the same across runs. in the commit (as opposed to just listing the files which are different from the commit's first parent). +--refspec:: + Apply the specified refspec to each ref exported. Multiple of them can + be specified. + [<git-rev-list-args>...]:: A list of arguments, acceptable to 'git rev-parse' and 'git rev-list', that specifies the specific objects and references diff --git a/Documentation/git-fast-import.txt b/Documentation/git-fast-import.txt index fd22a9a0c1..377eeaa36d 100644 --- a/Documentation/git-fast-import.txt +++ b/Documentation/git-fast-import.txt @@ -231,7 +231,7 @@ Date Formats ~~~~~~~~~~~~ The following date formats are supported. A frontend should select the format it will use for this import by passing the format name -in the \--date-format=<fmt> command line option. +in the \--date-format=<fmt> command-line option. `raw`:: This is the Git native format and is `<time> SP <offutc>`. @@ -348,7 +348,7 @@ and control the current import process. More detailed discussion `done`:: Marks the end of the stream. This command is optional unless the `done` feature was requested using the - `--done` command line option or `feature done` command. + `--done` command-line option or `feature done` command. `cat-blob`:: Causes fast-import to print a blob in 'cat-file --batch' @@ -437,7 +437,7 @@ the email address from the other fields in the line. Note that of bytes, except `LT`, `GT` and `LF`. `<name>` is typically UTF-8 encoded. The time of the change is specified by `<when>` using the date format -that was selected by the \--date-format=<fmt> command line option. +that was selected by the \--date-format=<fmt> command-line option. See ``Date Formats'' above for the set of supported formats, and their syntax. @@ -483,6 +483,9 @@ Marks must be declared (via `mark`) before they can be used. * Any valid Git SHA-1 expression that resolves to a commit. See ``SPECIFYING REVISIONS'' in linkgit:gitrevisions[7] for details. +* The special null SHA-1 (40 zeros) specifies that the branch is to be + removed. + The special case of restarting an incremental import from the current branch value should be written as: ---- @@ -1085,7 +1088,7 @@ Option commands must be the first commands on the input (not counting feature commands), to give an option command after any non-option command is an error. -The following commandline options change import semantics and may therefore +The following command-line options change import semantics and may therefore not be passed as option: * date-format @@ -1099,7 +1102,7 @@ not be passed as option: If the `done` feature is not in use, treated as if EOF was read. This can be used to tell fast-import to finish early. -If the `--done` command line option or `feature done` command is +If the `--done` command-line option or `feature done` command is in use, the `done` command is mandatory and marks the end of the stream. diff --git a/Documentation/git-fetch.txt b/Documentation/git-fetch.txt index 5809aa4eb9..8deb61469d 100644 --- a/Documentation/git-fetch.txt +++ b/Documentation/git-fetch.txt @@ -17,22 +17,20 @@ SYNOPSIS DESCRIPTION ----------- -Fetches named heads or tags from one or more other repositories, -along with the objects necessary to complete them. +Fetch branches and/or tags (collectively, "refs") from one or more +other repositories, along with the objects necessary to complete their +histories. Remote-tracking branches are updated (see the description +of <refspec> below for ways to control this behavior). -The ref names and their object names of fetched refs are stored -in `.git/FETCH_HEAD`. This information is left for a later merge -operation done by 'git merge'. - -By default, tags are auto-followed. This means that when fetching -from a remote, any tags on the remote that point to objects that exist -in the local repository are fetched. The effect is to fetch tags that +By default, any tag that points into the histories being fetched is +also fetched; the effect is to fetch tags that point at branches that you are interested in. This default behavior -can be changed by using the --tags or --no-tags options, by -configuring remote.<name>.tagopt, or by using a refspec that fetches -tags explicitly. +can be changed by using the --tags or --no-tags options or by +configuring remote.<name>.tagopt. By using a refspec that fetches tags +explicitly, you can fetch tags that do not point into branches you +are interested in as well. -'git fetch' can fetch from either a single named repository, +'git fetch' can fetch from either a single named repository or URL, or from several repositories at once if <group> is given and there is a remotes.<group> entry in the configuration file. (See linkgit:git-config[1]). @@ -40,6 +38,10 @@ there is a remotes.<group> entry in the configuration file. When no remote is specified, by default the `origin` remote will be used, unless there's an upstream branch configured for the current branch. +The names of refs that are fetched, together with the object names +they point at, are written to `.git/FETCH_HEAD`. This information +may be used by scripts or other git commands, such as linkgit:git-pull[1]. + OPTIONS ------- include::fetch-options.txt[] @@ -49,6 +51,55 @@ include::pull-fetch-param.txt[] include::urls-remotes.txt[] +CONFIGURED REMOTE-TRACKING BRANCHES[[CRTB]] +------------------------------------------- + +You often interact with the same remote repository by +regularly and repeatedly fetching from it. In order to keep track +of the progress of such a remote repository, `git fetch` allows you +to configure `remote.<repository>.fetch` configuration variables. + +Typically such a variable may look like this: + +------------------------------------------------ +[remote "origin"] + fetch = +refs/heads/*:refs/remotes/origin/* +------------------------------------------------ + +This configuration is used in two ways: + +* When `git fetch` is run without specifying what branches + and/or tags to fetch on the command line, e.g. `git fetch origin` + or `git fetch`, `remote.<repository>.fetch` values are used as + the refspecs---they specify which refs to fetch and which local refs + to update. The example above will fetch + all branches that exist in the `origin` (i.e. any ref that matches + the left-hand side of the value, `refs/heads/*`) and update the + corresponding remote-tracking branches in the `refs/remotes/origin/*` + hierarchy. + +* When `git fetch` is run with explicit branches and/or tags + to fetch on the command line, e.g. `git fetch origin master`, the + <refspec>s given on the command line determine what are to be + fetched (e.g. `master` in the example, + which is a short-hand for `master:`, which in turn means + "fetch the 'master' branch but I do not explicitly say what + remote-tracking branch to update with it from the command line"), + and the example command will + fetch _only_ the 'master' branch. The `remote.<repository>.fetch` + values determine which + remote-tracking branch, if any, is updated. When used in this + way, the `remote.<repository>.fetch` values do not have any + effect in deciding _what_ gets fetched (i.e. the values are not + used as refspecs when the command-line lists refspecs); they are + only used to decide _where_ the refs that are fetched are stored + by acting as a mapping. + +The latter use of the `remote.<repository>.fetch` values can be +overridden by giving the `--refmap=<refspec>` parameter(s) on the +command line. + + EXAMPLES -------- @@ -76,6 +127,19 @@ the local repository by fetching from the branches (respectively) The `pu` branch will be updated even if it is does not fast-forward, because it is prefixed with a plus sign; `tmp` will not be. +* Peek at a remote's branch, without configuring the remote in your local +repository: ++ +------------------------------------------------ +$ git fetch git://git.kernel.org/pub/scm/git/git.git maint +$ git log FETCH_HEAD +------------------------------------------------ ++ +The first command fetches the `maint` branch from the repository at +`git://git.kernel.org/pub/scm/git/git.git` and the second command uses +`FETCH_HEAD` to examine the branch with linkgit:git-log[1]. The fetched +objects will eventually be removed by git's built-in housekeeping (see +linkgit:git-gc[1]). BUGS ---- diff --git a/Documentation/git-format-patch.txt b/Documentation/git-format-patch.txt index 5c0a4ab2d6..c0fd470da4 100644 --- a/Documentation/git-format-patch.txt +++ b/Documentation/git-format-patch.txt @@ -14,6 +14,7 @@ SYNOPSIS [(--attach|--inline)[=<boundary>] | --no-attach] [-s | --signoff] [--signature=<signature> | --no-signature] + [--signature-file=<file>] [-n | --numbered | -N | --no-numbered] [--start-number <n>] [--numbered-files] [--in-reply-to=Message-Id] [--suffix=.<sfx>] @@ -233,6 +234,9 @@ configuration options in linkgit:git-notes[1] to use this workflow). signature option is omitted the signature defaults to the Git version number. +--signature-file=<file>:: + Works just like --signature except the signature is read from a file. + --suffix=.<sfx>:: Instead of using `.patch` as the suffix for generated filenames, use specified suffix. A common alternative is diff --git a/Documentation/git-help.txt b/Documentation/git-help.txt index b21e9d79be..3956525218 100644 --- a/Documentation/git-help.txt +++ b/Documentation/git-help.txt @@ -80,9 +80,9 @@ CONFIGURATION VARIABLES help.format ~~~~~~~~~~~ -If no command line option is passed, the 'help.format' configuration +If no command-line option is passed, the 'help.format' configuration variable will be checked. The following values are supported for this -variable; they make 'git help' behave as their corresponding command +variable; they make 'git help' behave as their corresponding command- line option: * "man" corresponds to '-m|--man', @@ -93,15 +93,15 @@ help.browser, web.browser and browser.<tool>.path ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The 'help.browser', 'web.browser' and 'browser.<tool>.path' will also -be checked if the 'web' format is chosen (either by command line +be checked if the 'web' format is chosen (either by command-line option or configuration variable). See '-w|--web' in the OPTIONS section above and linkgit:git-web{litdd}browse[1]. man.viewer ~~~~~~~~~~ -The 'man.viewer' config variable will be checked if the 'man' format -is chosen. The following values are currently supported: +The 'man.viewer' configuration variable will be checked if the 'man' +format is chosen. The following values are currently supported: * "man": use the 'man' program as usual, * "woman": use 'emacsclient' to launch the "woman" mode in emacs @@ -124,7 +124,7 @@ For example, this configuration: viewer = woman ------------------------------------------------ -will try to use konqueror first. But this may fail (for example if +will try to use konqueror first. But this may fail (for example, if DISPLAY is not set) and in that case emacs' woman mode will be tried. If everything fails, or if no viewer is configured, the viewer specified diff --git a/Documentation/git-ls-files.txt b/Documentation/git-ls-files.txt index c0856a6e0a..e26f01fb1d 100644 --- a/Documentation/git-ls-files.txt +++ b/Documentation/git-ls-files.txt @@ -185,15 +185,15 @@ specifies the format of exclude patterns. These exclude patterns come from these places, in order: - 1. The command line flag --exclude=<pattern> specifies a + 1. The command-line flag --exclude=<pattern> specifies a single pattern. Patterns are ordered in the same order they appear in the command line. - 2. The command line flag --exclude-from=<file> specifies a + 2. The command-line flag --exclude-from=<file> specifies a file containing a list of patterns. Patterns are ordered in the same order they appear in the file. - 3. The command line flag --exclude-per-directory=<name> specifies + 3. The command-line flag --exclude-per-directory=<name> specifies a name of the file in each directory 'git ls-files' examines, normally `.gitignore`. Files in deeper directories take precedence. Patterns are ordered in the diff --git a/Documentation/git-patch-id.txt b/Documentation/git-patch-id.txt index 312c3b1fe5..31efc587ee 100644 --- a/Documentation/git-patch-id.txt +++ b/Documentation/git-patch-id.txt @@ -8,14 +8,14 @@ git-patch-id - Compute unique ID for a patch SYNOPSIS -------- [verse] -'git patch-id' < <patch> +'git patch-id' [--stable | --unstable] < <patch> DESCRIPTION ----------- -A "patch ID" is nothing but a SHA-1 of the diff associated with a patch, with -whitespace and line numbers ignored. As such, it's "reasonably stable", but at -the same time also reasonably unique, i.e., two patches that have the same "patch -ID" are almost guaranteed to be the same thing. +A "patch ID" is nothing but a sum of SHA-1 of the file diffs associated with a +patch, with whitespace and line numbers ignored. As such, it's "reasonably +stable", but at the same time also reasonably unique, i.e., two patches that +have the same "patch ID" are almost guaranteed to be the same thing. IOW, you can use this thing to look for likely duplicate commits. @@ -27,6 +27,33 @@ This can be used to make a mapping from patch ID to commit ID. OPTIONS ------- + +--stable:: + Use a "stable" sum of hashes as the patch ID. With this option: + - Reordering file diffs that make up a patch does not affect the ID. + In particular, two patches produced by comparing the same two trees + with two different settings for "-O<orderfile>" result in the same + patch ID signature, thereby allowing the computed result to be used + as a key to index some meta-information about the change between + the two trees; + + - Result is different from the value produced by git 1.9 and older + or produced when an "unstable" hash (see --unstable below) is + configured - even when used on a diff output taken without any use + of "-O<orderfile>", thereby making existing databases storing such + "unstable" or historical patch-ids unusable. + + This is the default if patchid.stable is set to true. + +--unstable:: + Use an "unstable" hash as the patch ID. With this option, + the result produced is compatible with the patch-id value produced + by git 1.9 and older. Users with pre-existing databases storing + patch-ids produced by git 1.9 and older (who do not deal with reordered + patches) may want to use this option. + + This is the default. + <patch>:: The diff to create the ID of. diff --git a/Documentation/git-read-tree.txt b/Documentation/git-read-tree.txt index 056c0dba81..fa1d557e5b 100644 --- a/Documentation/git-read-tree.txt +++ b/Documentation/git-read-tree.txt @@ -283,7 +283,7 @@ merge. The different stages represent the "result tree" (stage 0, aka you are trying to merge (stage 2 and 3 respectively). The order of stages 1, 2 and 3 (hence the order of three -<tree-ish> command line arguments) are significant when you +<tree-ish> command-line arguments) are significant when you start a 3-way merge with an index file that is already populated. Here is an outline of how the algorithm works: diff --git a/Documentation/git-replace.txt b/Documentation/git-replace.txt index 0a02f70657..61461b9f33 100644 --- a/Documentation/git-replace.txt +++ b/Documentation/git-replace.txt @@ -9,6 +9,7 @@ SYNOPSIS -------- [verse] 'git replace' [-f] <object> <replacement> +'git replace' [-f] --edit <object> 'git replace' -d <object>... 'git replace' [--format=<format>] [-l [<pattern>]] @@ -63,6 +64,15 @@ OPTIONS --delete:: Delete existing replace refs for the given objects. +--edit <object>:: + Edit an object's content interactively. The existing content + for <object> is pretty-printed into a temporary file, an + editor is launched on the file, and the result is parsed to + create a new object of the same type as <object>. A + replacement ref is then created to replace <object> with the + newly created object. See linkgit:git-var[1] for details about + how the editor will be chosen. + -l <pattern>:: --list <pattern>:: List replace refs for objects that match the given pattern (or @@ -92,7 +102,9 @@ CREATING REPLACEMENT OBJECTS linkgit:git-filter-branch[1], linkgit:git-hash-object[1] and linkgit:git-rebase[1], among other git commands, can be used to create -replacement objects from existing objects. +replacement objects from existing objects. The `--edit` option can +also be used with 'git replace' to create a replacement object by +editing an existing object. If you want to replace many blobs, trees or commits that are part of a string of commits, you may just want to create a replacement string of @@ -117,6 +129,8 @@ linkgit:git-filter-branch[1] linkgit:git-rebase[1] linkgit:git-tag[1] linkgit:git-branch[1] +linkgit:git-commit[1] +linkgit:git-var[1] linkgit:git[1] GIT diff --git a/Documentation/git-send-email.txt b/Documentation/git-send-email.txt index f0e57a597b..a60776eb57 100644 --- a/Documentation/git-send-email.txt +++ b/Documentation/git-send-email.txt @@ -20,7 +20,7 @@ files in the directory), or directly as a revision list. In the last case, any format accepted by linkgit:git-format-patch[1] can be passed to git send-email. -The header of the email is configurable by command line options. If not +The header of the email is configurable via command-line options. If not specified on the command line, the user will be prompted with a ReadLine enabled interface to provide the necessary information. @@ -68,7 +68,7 @@ The --cc option must be repeated for each user you want on the cc list. When '--compose' is used, git send-email will use the From, Subject, and In-Reply-To headers specified in the message. If the body of the message (what you type after the headers and a blank line) only contains blank -(or Git: prefixed) lines the summary won't be sent, but From, Subject, +(or Git: prefixed) lines, the summary won't be sent, but From, Subject, and In-Reply-To headers will be used unless they are removed. + Missing From or In-Reply-To headers will be prompted for. @@ -78,7 +78,7 @@ See the CONFIGURATION section for 'sendemail.multiedit'. --from=<address>:: Specify the sender of the emails. If not specified on the command line, the value of the 'sendemail.from' configuration option is used. If - neither the command line option nor 'sendemail.from' are set, then the + neither the command-line option nor 'sendemail.from' are set, then the user will be prompted for the value. The default for the prompt will be the value of GIT_AUTHOR_IDENT, or GIT_COMMITTER_IDENT if that is not set, as returned by "git var -l". @@ -248,6 +248,18 @@ Automating cc list. Default is the value of 'sendemail.signedoffbycc' configuration value; if that is unspecified, default to --signed-off-by-cc. +--[no-]cc-cover:: + If this is set, emails found in Cc: headers in the first patch of + the series (typically the cover letter) are added to the cc list + for each email set. Default is the value of 'sendemail.cccover' + configuration value; if that is unspecified, default to --no-cc-cover. + +--[no-]to-cover:: + If this is set, emails found in To: headers in the first patch of + the series (typically the cover letter) are added to the to list + for each email set. Default is the value of 'sendemail.tocover' + configuration value; if that is unspecified, default to --no-to-cover. + --suppress-cc=<category>:: Specify an additional category of recipients to suppress the auto-cc of: diff --git a/Documentation/git-submodule.txt b/Documentation/git-submodule.txt index 89c4d3e394..8e6af65da0 100644 --- a/Documentation/git-submodule.txt +++ b/Documentation/git-submodule.txt @@ -20,7 +20,7 @@ SYNOPSIS 'git submodule' [--quiet] summary [--cached|--files] [(-n|--summary-limit) <n>] [commit] [--] [<path>...] 'git submodule' [--quiet] foreach [--recursive] <command> -'git submodule' [--quiet] sync [--] [<path>...] +'git submodule' [--quiet] sync [--recursive] [--] [<path>...] DESCRIPTION diff --git a/Documentation/git-svn.txt b/Documentation/git-svn.txt index fce585388c..44c970ce18 100644 --- a/Documentation/git-svn.txt +++ b/Documentation/git-svn.txt @@ -148,8 +148,8 @@ the same local time zone. [verse] config key: svn-remote.<name>.ignore-paths + -If the ignore-paths config key is set and the command line option is -also given, both regular expressions will be used. +If the ignore-paths configuration key is set, and the command-line +option is also given, both regular expressions will be used. + Examples: + diff --git a/Documentation/git-web--browse.txt b/Documentation/git-web--browse.txt index 2de575f5be..16ede5b4c3 100644 --- a/Documentation/git-web--browse.txt +++ b/Documentation/git-web--browse.txt @@ -62,7 +62,7 @@ CONF.VAR (from -c option) and web.browser ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The web browser can be specified using a configuration variable passed -with the -c (or --config) command line option, or the 'web.browser' +with the -c (or --config) command-line option, or the 'web.browser' configuration variable if the former is not used. browser.<tool>.path @@ -87,7 +87,7 @@ the URLs passed as arguments. Note about konqueror -------------------- -When 'konqueror' is specified by a command line option or a +When 'konqueror' is specified by a command-line option or a configuration variable, we launch 'kfmclient' to try to open the HTML man page on an already opened konqueror in a new tab if possible. diff --git a/Documentation/git.txt b/Documentation/git.txt index b075e0bed5..7924209671 100644 --- a/Documentation/git.txt +++ b/Documentation/git.txt @@ -29,7 +29,7 @@ in-depth introduction. After you mastered the basic concepts, you can come back to this page to learn what commands Git offers. You can learn more about individual Git commands with "git help command". linkgit:gitcli[7] -manual page gives you an overview of the command line command syntax. +manual page gives you an overview of the command-line command syntax. Formatted and hyperlinked version of the latest Git documentation can be viewed at `http://git-htmldocs.googlecode.com/git/git.html`. @@ -39,13 +39,14 @@ ifdef::stalenotes[] ============ You are reading the documentation for the latest (possibly -unreleased) version of Git, that is available from 'master' +unreleased) version of Git, that is available from the 'master' branch of the `git.git` repository. Documentation for older releases are available here: -* link:v2.0.0/git.html[documentation for release 2.0] +* link:v2.0.1/git.html[documentation for release 2.0.1] * release notes for + link:RelNotes/2.0.1.txt[2.0.1], link:RelNotes/2.0.0.txt[2.0.0]. * link:v1.9.4/git.html[documentation for release 1.9.4] @@ -755,7 +756,7 @@ Git so take care if using Cogito etc. 'GIT_WORK_TREE':: Set the path to the root of the working tree. - This can also be controlled by the '--work-tree' command line + This can also be controlled by the '--work-tree' command-line option and the core.worktree configuration variable. 'GIT_NAMESPACE':: @@ -880,7 +881,7 @@ for further details. 'GIT_ASKPASS':: If this environment variable is set, then Git commands which need to acquire passwords or passphrases (e.g. for HTTP or IMAP authentication) - will call this program with a suitable prompt as command line argument + will call this program with a suitable prompt as command-line argument and read the password from its STDOUT. See also the 'core.askpass' option in linkgit:git-config[1]. diff --git a/Documentation/gitcli.txt b/Documentation/gitcli.txt index 1c3e109cb3..dfe7d83727 100644 --- a/Documentation/gitcli.txt +++ b/Documentation/gitcli.txt @@ -3,7 +3,7 @@ gitcli(7) NAME ---- -gitcli - Git command line interface and conventions +gitcli - Git command-line interface and conventions SYNOPSIS -------- @@ -66,13 +66,13 @@ you will. Here are the rules regarding the "flags" that you should follow when you are scripting Git: - * it's preferred to use the non dashed form of Git commands, which means that + * it's preferred to use the non-dashed form of Git commands, which means that you should prefer `git foo` to `git-foo`. * splitting short options to separate words (prefer `git foo -a -b` to `git foo -ab`, the latter may not even work). - * when a command line option takes an argument, use the 'stuck' form. In + * when a command-line option takes an argument, use the 'stuck' form. In other words, write `git foo -oArg` instead of `git foo -o Arg` for short options, and `git foo --long-opt=Arg` instead of `git foo --long-opt Arg` for long options. An option that takes optional option-argument must be @@ -103,7 +103,7 @@ Here is a list of the facilities provided by this option parser. Magic Options ~~~~~~~~~~~~~ Commands which have the enhanced option parser activated all understand a -couple of magic command line options: +couple of magic command-line options: -h:: gives a pretty printed usage of the command. diff --git a/Documentation/gitk.txt b/Documentation/gitk.txt index 7e03fcc62d..7ae50aa26a 100644 --- a/Documentation/gitk.txt +++ b/Documentation/gitk.txt @@ -27,7 +27,7 @@ gitk-specific options. gitk generally only understands options with arguments in the 'sticked' form (see linkgit:gitcli[7]) due to limitations in the -command line parser. +command-line parser. rev-list options and arguments ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/Documentation/gitmodules.txt b/Documentation/gitmodules.txt index 347a9f76ee..f6c0dfd029 100644 --- a/Documentation/gitmodules.txt +++ b/Documentation/gitmodules.txt @@ -67,7 +67,9 @@ submodule.<name>.fetchRecurseSubmodules:: submodule.<name>.ignore:: Defines under what circumstances "git status" and the diff family show a submodule as modified. When set to "all", it will never be considered - modified, "dirty" will ignore all changes to the submodules work tree and + modified (but will nonetheless show up in the output of status and + commit when it has been staged), "dirty" will ignore all changes + to the submodules work tree and takes only differences between the HEAD of the submodule and the commit recorded in the superproject into account. "untracked" will additionally let submodules with modified tracked files in their work tree show up. diff --git a/Documentation/gitweb.conf.txt b/Documentation/gitweb.conf.txt index 952f503afb..ebe7a6c24c 100644 --- a/Documentation/gitweb.conf.txt +++ b/Documentation/gitweb.conf.txt @@ -904,7 +904,7 @@ the following in your GITWEB_CONFIG file: $feature{'snapshot'}{'override'} = 1; If you allow overriding for the snapshot feature, you can specify which -snapshot formats are globally disabled. You can also add any command line +snapshot formats are globally disabled. You can also add any command-line options you want (such as setting the compression level). For instance, you can disable Zip compressed snapshots and set *gzip*(1) to run at level 6 by adding the following lines to your gitweb configuration file: diff --git a/Documentation/glossary-content.txt b/Documentation/glossary-content.txt index be0858c188..4e0b971824 100644 --- a/Documentation/glossary-content.txt +++ b/Documentation/glossary-content.txt @@ -1,7 +1,7 @@ [[def_alternate_object_database]]alternate object database:: Via the alternates mechanism, a <<def_repository,repository>> can inherit part of its <<def_object_database,object database>> - from another object database, which is called "alternate". + from another object database, which is called an "alternate". [[def_bare_repository]]bare repository:: A bare repository is normally an appropriately diff --git a/Documentation/howto/keep-canonical-history-correct.txt b/Documentation/howto/keep-canonical-history-correct.txt new file mode 100644 index 0000000000..35d48ef714 --- /dev/null +++ b/Documentation/howto/keep-canonical-history-correct.txt @@ -0,0 +1,216 @@ +From: Junio C Hamano <gitster@pobox.com> +Date: Wed, 07 May 2014 13:15:39 -0700 +Subject: Beginner question on "Pull is mostly evil" +Abstract: This how-to explains a method for keeping a + project's history correct when using git pull. +Content-type: text/asciidoc + +Keep authoritative canonical history correct with git pull +========================================================== + +Sometimes a new project integrator will end up with project history +that appears to be "backwards" from what other project developers +expect. This howto presents a suggested integration workflow for +maintaining a central repository. + +Suppose that that central repository has this history: + +------------ + ---o---o---A +------------ + +which ends at commit `A` (time flows from left to right and each node +in the graph is a commit, lines between them indicating parent-child +relationship). + +Then you clone it and work on your own commits, which leads you to +have this history in *your* repository: + +------------ + ---o---o---A---B---C +------------ + +Imagine your coworker did the same and built on top of `A` in *his* +repository in the meantime, and then pushed it to the +central repository: + +------------ + ---o---o---A---X---Y---Z +------------ + +Now, if you `git push` at this point, because your history that leads +to `C` lacks `X`, `Y` and `Z`, it will fail. You need to somehow make +the tip of your history a descendant of `Z`. + +One suggested way to solve the problem is "fetch and then merge", aka +`git pull`. When you fetch, your repository will have a history like +this: + +------------ + ---o---o---A---B---C + \ + X---Y---Z +------------ + +Once you run merge after that, while still on *your* branch, i.e. `C`, +you will create a merge `M` and make the history look like this: + +------------ + ---o---o---A---B---C---M + \ / + X---Y---Z +------------ + +`M` is a descendant of `Z`, so you can push to update the central +repository. Such a merge `M` does not lose any commit in both +histories, so in that sense it may not be wrong, but when people want +to talk about "the authoritative canonical history that is shared +among the project participants", i.e. "the trunk", they often view +it as "commits you see by following the first-parent chain", and use +this command to view it: + +------------ + $ git log --first-parent +------------ + +For all other people who observed the central repository after your +coworker pushed `Z` but before you pushed `M`, the commit on the trunk +used to be `o-o-A-X-Y-Z`. But because you made `M` while you were on +`C`, `M`'s first parent is `C`, so by pushing `M` to advance the +central repository, you made `X-Y-Z` a side branch, not on the trunk. + +You would rather want to have a history of this shape: + +------------ + ---o---o---A---X---Y---Z---M' + \ / + B-----------C +------------ + +so that in the first-parent chain, it is clear that the project first +did `X` and then `Y` and then `Z` and merged a change that consists of +two commits `B` and `C` that achieves a single goal. You may have +worked on fixing the bug #12345 with these two patches, and the merge +`M'` with swapped parents can say in its log message "Merge +fix-bug-12345". Having a way to tell `git pull` to create a merge +but record the parents in reverse order may be a way to do so. + +Note that I said "achieves a single goal" above, because this is +important. "Swapping the merge order" only covers a special case +where the project does not care too much about having unrelated +things done on a single merge but cares a lot about first-parent +chain. + +There are multiple schools of thought about the "trunk" management. + + 1. Some projects want to keep a completely linear history without any + merges. Obviously, swapping the merge order would not match their + taste. You would need to flatten your history on top of the + updated upstream to result in a history of this shape instead: ++ +------------ + ---o---o---A---X---Y---Z---B---C +------------ ++ +with `git pull --rebase` or something. + + 2. Some projects tolerate merges in their history, but do not worry + too much about the first-parent order, and allow fast-forward + merges. To them, swapping the merge order does not hurt, but + it is unnecessary. + + 3. Some projects want each commit on the "trunk" to do one single + thing. The output of `git log --first-parent` in such a project + would show either a merge of a side branch that completes a single + theme, or a single commit that completes a single theme by itself. + If your two commits `B` and `C` (or they may even be two groups of + commits) were solving two independent issues, then the merge `M'` + we made in the earlier example by swapping the merge order is + still not up to the project standard. It merges two unrelated + efforts `B` and `C` at the same time. + +For projects in the last category (Git itself is one of them), +individual developers would want to prepare a history more like +this: + +------------ + C0--C1--C2 topic-c + / + ---o---o---A master + \ + B0--B1--B2 topic-b +------------ + +That is, keeping separate topics on separate branches, perhaps like +so: + +------------ + $ git clone $URL work && cd work + $ git checkout -b topic-b master + $ ... work to create B0, B1 and B2 to complete one theme + $ git checkout -b topic-c master + $ ... same for the theme of topic-c +------------ + +And then + +------------ + $ git checkout master + $ git pull --ff-only +------------ + +would grab `X`, `Y` and `Z` from the upstream and advance your master +branch: + +------------ + C0--C1--C2 topic-c + / + ---o---o---A---X---Y---Z master + \ + B0--B1--B2 topic-b +------------ + +And then you would merge these two branches separately: + +------------ + $ git merge topic-b + $ git merge topic-c +------------ + +to result in + +------------ + C0--C1---------C2 + / \ + ---o---o---A---X---Y---Z---M---N + \ / + B0--B1-----B2 +------------ + +and push it back to the central repository. + +It is very much possible that while you are merging topic-b and +topic-c, somebody again advanced the history in the central repository +to put `W` on top of `Z`, and make your `git push` fail. + +In such a case, you would rewind to discard `M` and `N`, update the +tip of your 'master' again and redo the two merges: + +------------ + $ git reset --hard origin/master + $ git pull --ff-only + $ git merge topic-b + $ git merge topic-c +------------ + +The procedure will result in a history that looks like this: + +------------ + C0--C1--------------C2 + / \ + ---o---o---A---X---Y---Z---W---M'--N' + \ / + B0--B1---------B2 +------------ + +See also http://git-blame.blogspot.com/2013/09/fun-with-first-parent-history.html diff --git a/Documentation/howto/setup-git-server-over-http.txt b/Documentation/howto/setup-git-server-over-http.txt index 6de4f3c487..f44e5e9458 100644 --- a/Documentation/howto/setup-git-server-over-http.txt +++ b/Documentation/howto/setup-git-server-over-http.txt @@ -181,7 +181,7 @@ On Debian: Most tests should pass. -A command line tool to test WebDAV is cadaver. If you prefer GUIs, for +A command-line tool to test WebDAV is cadaver. If you prefer GUIs, for example, konqueror can open WebDAV URLs as "webdav://..." or "webdavs://...". diff --git a/Documentation/pull-fetch-param.txt b/Documentation/pull-fetch-param.txt index 18cffc25b8..1ebbf1d738 100644 --- a/Documentation/pull-fetch-param.txt +++ b/Documentation/pull-fetch-param.txt @@ -12,9 +12,23 @@ ifndef::git-pull[] endif::git-pull[] <refspec>:: - The format of a <refspec> parameter is an optional plus - `+`, followed by the source ref <src>, followed - by a colon `:`, followed by the destination ref <dst>. + Specifies which refs to fetch and which local refs to update. + When no <refspec>s appear on the command line, the refs to fetch + are read from `remote.<repository>.fetch` variables instead +ifndef::git-pull[] + (see <<CRTB,CONFIGURED REMOTE-TRACKING BRANCHES>> below). +endif::git-pull[] +ifdef::git-pull[] + (see linkgit:git-fetch[1]). +endif::git-pull[] ++ +The format of a <refspec> parameter is an optional plus +`+`, followed by the source ref <src>, followed +by a colon `:`, followed by the destination ref <dst>. +The colon can be omitted when <dst> is empty. ++ +`tag <tag>` means the same as `refs/tags/<tag>:refs/tags/<tag>`; +it requests fetching everything up to the given tag. + The remote ref that matches <src> is fetched, and if <dst> is not empty string, the local @@ -24,55 +38,34 @@ is updated even if it does not result in a fast-forward update. + [NOTE] -If the remote branch from which you want to pull is -modified in non-linear ways such as being rewound and -rebased frequently, then a pull will attempt a merge with -an older version of itself, likely conflict, and fail. -It is under these conditions that you would want to use -the `+` sign to indicate non-fast-forward updates will -be needed. There is currently no easy way to determine -or declare that a branch will be made available in a -repository with this behavior; the pulling user simply +When the remote branch you want to fetch is known to +be rewound and rebased regularly, it is expected that +its new tip will not be descendant of its previous tip +(as stored in your remote-tracking branch the last time +you fetched). You would want +to use the `+` sign to indicate non-fast-forward updates +will be needed for such branches. There is no way to +determine or declare that a branch will be made available +in a repository with this behavior; the pulling user simply must know this is the expected usage pattern for a branch. -+ -[NOTE] -You never do your own development on branches that appear -on the right hand side of a <refspec> colon on `Pull:` lines; -they are to be updated by 'git fetch'. If you intend to do -development derived from a remote branch `B`, have a `Pull:` -line to track it (i.e. `Pull: B:remote-B`), and have a separate -branch `my-B` to do your development on top of it. The latter -is created by `git branch my-B remote-B` (or its equivalent `git -checkout -b my-B remote-B`). Run `git fetch` to keep track of -the progress of the remote side, and when you see something new -on the remote branch, merge it into your development branch with -`git pull . remote-B`, while you are on `my-B` branch. +ifdef::git-pull[] + [NOTE] There is a difference between listing multiple <refspec> directly on 'git pull' command line and having multiple -`Pull:` <refspec> lines for a <repository> and running +`remote.<repository>.fetch` entries in your configuration +for a <repository> and running a 'git pull' command without any explicit <refspec> parameters. -<refspec> listed explicitly on the command line are always +<refspec>s listed explicitly on the command line are always merged into the current branch after fetching. In other words, -if you list more than one remote refs, you would be making -an Octopus. While 'git pull' run without any explicit <refspec> -parameter takes default <refspec>s from `Pull:` lines, it -merges only the first <refspec> found into the current branch, -after fetching all the remote refs. This is because making an +if you list more than one remote ref, 'git pull' will create +an Octopus merge. On the other hand, if you do not list any +explicit <refspec> parameter on the command line, 'git pull' +will fetch all the <refspec>s it finds in the +`remote.<repository>.fetch` configuration and merge +only the first <refspec> found into the current branch. +This is because making an Octopus from remote refs is rarely done, while keeping track of multiple remote heads in one-go by fetching more than one is often useful. -+ -Some short-cut notations are also supported. -+ -* `tag <tag>` means the same as `refs/tags/<tag>:refs/tags/<tag>`; - it requests fetching everything up to the given tag. -ifndef::git-pull[] -* A parameter <ref> without a colon fetches that ref into FETCH_HEAD, -endif::git-pull[] -ifdef::git-pull[] -* A parameter <ref> without a colon merges <ref> into the current - branch, endif::git-pull[] - and updates the remote-tracking branches (if any). diff --git a/Documentation/revisions.txt b/Documentation/revisions.txt index 5a286d0d61..07961185fe 100644 --- a/Documentation/revisions.txt +++ b/Documentation/revisions.txt @@ -94,7 +94,9 @@ some output processing may assume ref names in UTF-8. '<branchname>@\{upstream\}', e.g. 'master@\{upstream\}', '@\{u\}':: The suffix '@\{upstream\}' to a branchname (short form '<branchname>@\{u\}') refers to the branch that the branch specified by branchname is set to build on - top of. A missing branchname defaults to the current one. + top of (configured with `branch.<name>.remote` and + `branch.<name>.merge`). A missing branchname defaults to the + current one. '<rev>{caret}', e.g. 'HEAD{caret}, v1.5.1{caret}0':: A suffix '{caret}' to a revision parameter means the first parent of diff --git a/Documentation/technical/api-argv-array.txt b/Documentation/technical/api-argv-array.txt index a6b7d83a8e..1a797812fb 100644 --- a/Documentation/technical/api-argv-array.txt +++ b/Documentation/technical/api-argv-array.txt @@ -53,11 +53,3 @@ Functions `argv_array_clear`:: Free all memory associated with the array and return it to the initial, empty state. - -`argv_array_detach`:: - Detach the argv array from the `struct argv_array`, transferring - ownership of the allocated array and strings. - -`argv_array_free_detached`:: - Free the memory allocated by a `struct argv_array` that was later - detached and is now no longer needed. diff --git a/Documentation/technical/api-run-command.txt b/Documentation/technical/api-run-command.txt index 5d7d7f2d32..69510ae57a 100644 --- a/Documentation/technical/api-run-command.txt +++ b/Documentation/technical/api-run-command.txt @@ -109,6 +109,13 @@ terminated), of which .argv[0] is the program name to run (usually without a path). If the command to run is a git command, set argv[0] to the command name without the 'git-' prefix and set .git_cmd = 1. +Note that the ownership of the memory pointed to by .argv stays with the +caller, but it should survive until `finish_command` completes. If the +.argv member is NULL, `start_command` will point it at the .args +`argv_array` (so you may use one or the other, but you must use exactly +one). The memory in .args will be cleaned up automatically during +`finish_command` (or during `start_command` when it is unsuccessful). + The members .in, .out, .err are used to redirect stdin, stdout, stderr as follows: diff --git a/Documentation/technical/api-strbuf.txt b/Documentation/technical/api-strbuf.txt index 4396be9dda..f9c06a7573 100644 --- a/Documentation/technical/api-strbuf.txt +++ b/Documentation/technical/api-strbuf.txt @@ -7,10 +7,10 @@ use the mem* functions than a str* one (memchr vs. strchr e.g.). Though, one has to be careful about the fact that str* functions often stop on NULs and that strbufs may have embedded NULs. -An strbuf is NUL terminated for convenience, but no function in the +A strbuf is NUL terminated for convenience, but no function in the strbuf API actually relies on the string being free of NULs. -strbufs has some invariants that are very important to keep in mind: +strbufs have some invariants that are very important to keep in mind: . The `buf` member is never NULL, so it can be used in any usual C string operations safely. strbuf's _have_ to be initialized either by @@ -56,8 +56,8 @@ Data structures * `struct strbuf` This is the string buffer structure. The `len` member can be used to -determine the current length of the string, and `buf` member provides access to -the string itself. +determine the current length of the string, and `buf` member provides +access to the string itself. Functions --------- @@ -134,6 +134,15 @@ Functions Strip whitespace from the beginning of a string. +`strbuf_reencode`:: + + Replace the contents of the strbuf with a reencoded form. Returns -1 + on error, 0 on success. + +`strbuf_tolower`:: + + Lowercase each character in the buffer using `tolower`. + `strbuf_cmp`:: Compare two buffers. Returns an integer less than, equal to, or greater @@ -193,7 +202,7 @@ strbuf_addstr(sb, "immediate string"); `strbuf_addbuf`:: - Copy the contents of an other buffer at the end of the current one. + Copy the contents of another buffer at the end of the current one. `strbuf_adddup`:: diff --git a/Documentation/technical/api-string-list.txt b/Documentation/technical/api-string-list.txt index 20be348834..f1add51efe 100644 --- a/Documentation/technical/api-string-list.txt +++ b/Documentation/technical/api-string-list.txt @@ -200,3 +200,5 @@ Represents the list itself. You should not tamper with it. . Setting the `strdup_strings` member to 1 will strdup() the strings before adding them, see above. +. The `compare_strings_fn` member is used to specify a custom compare + function, otherwise `strcmp()` is used as the default function. diff --git a/Documentation/technical/http-protocol.txt b/Documentation/technical/http-protocol.txt index 20525d98bb..229f845dfa 100644 --- a/Documentation/technical/http-protocol.txt +++ b/Documentation/technical/http-protocol.txt @@ -60,7 +60,7 @@ Because Git repositories are accessed by standard path components server administrators MAY use directory based permissions within their HTTP server to control repository access. -Clients SHOULD support Basic authentication as described by RFC 2616. +Clients SHOULD support Basic authentication as described by RFC 2617. Servers SHOULD support Basic authentication by relying upon the HTTP server placed in front of the Git server software. @@ -374,7 +374,7 @@ C: Send one `$GIT_URL/git-upload-pack` request: C: 0000 The stream is organized into "commands", with each command -appearing by itself in a pkt-line. Within a command line +appearing by itself in a pkt-line. Within a command line, the text leading up to the first space is the command name, and the remainder of the line to the first LF is the value. Command lines are terminated with an LF as the last byte of diff --git a/Documentation/user-manual.txt b/Documentation/user-manual.txt index 022e74e616..7330d880f3 100644 --- a/Documentation/user-manual.txt +++ b/Documentation/user-manual.txt @@ -416,12 +416,11 @@ REVISIONS" section of linkgit:gitrevisions[7]. Updating a repository with git fetch ------------------------------------ -Eventually the developer cloned from will do additional work in her -repository, creating new commits and advancing the branches to point -at the new commits. +After you clone a repository and commit a few changes of your own, you +may wish to check the original repository for updates. -The command `git fetch`, with no arguments, will update all of the -remote-tracking branches to the latest version found in her +The `git-fetch` command, with no arguments, will update all of the +remote-tracking branches to the latest version found in the original repository. It will not touch any of your own branches--not even the "master" branch that was created for you on clone. @@ -1811,8 +1810,8 @@ manner. You can then import these into your mail client and send them by hand. However, if you have a lot to send at once, you may prefer to use the linkgit:git-send-email[1] script to automate the process. -Consult the mailing list for your project first to determine how they -prefer such patches be handled. +Consult the mailing list for your project first to determine +their requirements for submitting patches. [[importing-patches]] Importing patches to a project @@ -2255,7 +2254,7 @@ $ git checkout test && git merge speed-up-spinlocks It is unlikely that you would have any conflicts here ... but you might if you spent a while on this step and had also pulled new versions from upstream. -Some time later when enough time has passed and testing done, you can pull the +Sometime later when enough time has passed and testing done, you can pull the same branch into the `release` tree ready to go upstream. This is where you see the value of keeping each patch (or patch series) in its own branch. It means that the patches can be moved into the `release` tree in any order. @@ -4231,9 +4230,9 @@ Most of what `git rev-list` did is contained in `revision.c` and controls how and what revisions are walked, and more. The original job of `git rev-parse` is now taken by the function -`setup_revisions()`, which parses the revisions and the common command line +`setup_revisions()`, which parses the revisions and the common command-line options for the revision walker. This information is stored in the struct -`rev_info` for later consumption. You can do your own command line option +`rev_info` for later consumption. You can do your own command-line option parsing after calling `setup_revisions()`. After that, you have to call `prepare_revision_walk()` for initialization, and then you can get the commits one by one with the function `get_revision()`. @@ -729,6 +729,7 @@ LIB_H += transport.h LIB_H += tree-walk.h LIB_H += tree.h LIB_H += unpack-trees.h +LIB_H += unicode_width.h LIB_H += url.h LIB_H += urlmatch.h LIB_H += userdiff.h @@ -76,16 +76,15 @@ int git_default_advice_config(const char *var, const char *value) int error_resolve_conflict(const char *me) { - error("'%s' is not possible because you have unmerged files.", me); + error("%s is not possible because you have unmerged files.", me); if (advice_resolve_conflict) /* * Message used both when 'git commit' fails and when * other commands doing a merge do. */ - advise(_("Fix them up in the work tree,\n" - "and then use 'git add/rm <file>' as\n" - "appropriate to mark resolution and make a commit,\n" - "or use 'git commit -a'.")); + advise(_("Fix them up in the work tree, and then use 'git add/rm <file>'\n" + "as appropriate to mark resolution and make a commit, or use\n" + "'git commit -a'.")); return -1; } @@ -47,23 +47,32 @@ union any_object { DEFINE_ALLOCATOR(blob, struct blob) DEFINE_ALLOCATOR(tree, struct tree) -DEFINE_ALLOCATOR(commit, struct commit) +DEFINE_ALLOCATOR(raw_commit, struct commit) DEFINE_ALLOCATOR(tag, struct tag) DEFINE_ALLOCATOR(object, union any_object) +void *alloc_commit_node(void) +{ + static int commit_count; + struct commit *c = alloc_raw_commit_node(); + c->index = commit_count++; + return c; +} + static void report(const char *name, unsigned int count, size_t size) { fprintf(stderr, "%10s: %8u (%"PRIuMAX" kB)\n", name, count, (uintmax_t) size); } -#define REPORT(name) \ - report(#name, name##_allocs, name##_allocs * sizeof(struct name) >> 10) +#define REPORT(name, type) \ + report(#name, name##_allocs, name##_allocs * sizeof(type) >> 10) void alloc_report(void) { - REPORT(blob); - REPORT(tree); - REPORT(commit); - REPORT(tag); + REPORT(blob, struct blob); + REPORT(tree, struct tree); + REPORT(raw_commit, struct commit); + REPORT(tag, struct tag); + REPORT(object, union any_object); } diff --git a/argv-array.c b/argv-array.c index 9e960d549c..256741d226 100644 --- a/argv-array.c +++ b/argv-array.c @@ -68,23 +68,3 @@ void argv_array_clear(struct argv_array *array) } argv_array_init(array); } - -const char **argv_array_detach(struct argv_array *array, int *argc) -{ - const char **argv = - array->argv == empty_argv || array->argc == 0 ? NULL : array->argv; - if (argc) - *argc = array->argc; - argv_array_init(array); - return argv; -} - -void argv_array_free_detached(const char **argv) -{ - if (argv) { - int i; - for (i = 0; argv[i]; i++) - free((char **)argv[i]); - free(argv); - } -} diff --git a/argv-array.h b/argv-array.h index 85ba438ac1..c65e6e825a 100644 --- a/argv-array.h +++ b/argv-array.h @@ -19,7 +19,5 @@ LAST_ARG_MUST_BE_NULL void argv_array_pushl(struct argv_array *, ...); void argv_array_pop(struct argv_array *); void argv_array_clear(struct argv_array *); -const char **argv_array_detach(struct argv_array *array, int *argc); -void argv_array_free_detached(const char **argv); #endif /* ARGV_ARRAY_H */ diff --git a/builtin/blame.c b/builtin/blame.c index 128fc64d64..d3b256e545 100644 --- a/builtin/blame.c +++ b/builtin/blame.c @@ -1,7 +1,8 @@ /* * Blame * - * Copyright (c) 2006, Junio C Hamano + * Copyright (c) 2006, 2014 by its authors + * See COPYING for licensing conditions */ #include "cache.h" @@ -18,7 +19,9 @@ #include "cache-tree.h" #include "string-list.h" #include "mailmap.h" +#include "mergesort.h" #include "parse-options.h" +#include "prio-queue.h" #include "utf8.h" #include "userdiff.h" #include "line-range.h" @@ -83,11 +86,42 @@ static unsigned blame_copy_score; */ struct origin { int refcnt; + /* Record preceding blame record for this blob */ struct origin *previous; + /* origins are put in a list linked via `next' hanging off the + * corresponding commit's util field in order to make finding + * them fast. The presence in this chain does not count + * towards the origin's reference count. It is tempting to + * let it count as long as the commit is pending examination, + * but even under circumstances where the commit will be + * present multiple times in the priority queue of unexamined + * commits, processing the first instance will not leave any + * work requiring the origin data for the second instance. An + * interspersed commit changing that would have to be + * preexisting with a different ancestry and with the same + * commit date in order to wedge itself between two instances + * of the same commit in the priority queue _and_ produce + * blame entries relevant for it. While we don't want to let + * us get tripped up by this case, it certainly does not seem + * worth optimizing for. + */ + struct origin *next; struct commit *commit; + /* `suspects' contains blame entries that may be attributed to + * this origin's commit or to parent commits. When a commit + * is being processed, all suspects will be moved, either by + * assigning them to an origin in a different commit, or by + * shipping them to the scoreboard's ent list because they + * cannot be attributed to a different commit. + */ + struct blame_entry *suspects; mmfile_t file; unsigned char blob_sha1[20]; unsigned mode; + /* guilty gets set when shipping any suspects to the final + * blame list instead of other commits + */ + char guilty; char path[FLEX_ARRAY]; }; @@ -176,10 +210,22 @@ static inline struct origin *origin_incref(struct origin *o) static void origin_decref(struct origin *o) { if (o && --o->refcnt <= 0) { + struct origin *p, *l = NULL; if (o->previous) origin_decref(o->previous); free(o->file.ptr); - free(o); + /* Should be present exactly once in commit chain */ + for (p = o->commit->util; p; l = p, p = p->next) { + if (p == o) { + if (l) + l->next = p->next; + else + o->commit->util = p->next; + free(o); + return; + } + } + die("internal error in blame::origin_decref"); } } @@ -193,8 +239,12 @@ static void drop_origin_blob(struct origin *o) /* * Each group of lines is described by a blame_entry; it can be split - * as we pass blame to the parents. They form a linked list in the - * scoreboard structure, sorted by the target line number. + * as we pass blame to the parents. They are arranged in linked lists + * kept as `suspects' of some unprocessed origin, or entered (when the + * blame origin has been finalized) into the scoreboard structure. + * While the scoreboard structure is only sorted at the end of + * processing (according to final image line number), the lists + * attached to an origin are sorted by the target line number. */ struct blame_entry { struct blame_entry *next; @@ -210,15 +260,6 @@ struct blame_entry { /* the commit that introduced this group into the final image */ struct origin *suspect; - /* true if the suspect is truly guilty; false while we have not - * checked if the group came from one of its parents. - */ - char guilty; - - /* true if the entry has been scanned for copies in the current parent - */ - char scanned; - /* the line number of the first line of this group in the * suspect's file; internally all line numbers are 0 based. */ @@ -231,11 +272,112 @@ struct blame_entry { }; /* + * Any merge of blames happens on lists of blames that arrived via + * different parents in a single suspect. In this case, we want to + * sort according to the suspect line numbers as opposed to the final + * image line numbers. The function body is somewhat longish because + * it avoids unnecessary writes. + */ + +static struct blame_entry *blame_merge(struct blame_entry *list1, + struct blame_entry *list2) +{ + struct blame_entry *p1 = list1, *p2 = list2, + **tail = &list1; + + if (!p1) + return p2; + if (!p2) + return p1; + + if (p1->s_lno <= p2->s_lno) { + do { + tail = &p1->next; + if ((p1 = *tail) == NULL) { + *tail = p2; + return list1; + } + } while (p1->s_lno <= p2->s_lno); + } + for (;;) { + *tail = p2; + do { + tail = &p2->next; + if ((p2 = *tail) == NULL) { + *tail = p1; + return list1; + } + } while (p1->s_lno > p2->s_lno); + *tail = p1; + do { + tail = &p1->next; + if ((p1 = *tail) == NULL) { + *tail = p2; + return list1; + } + } while (p1->s_lno <= p2->s_lno); + } +} + +static void *get_next_blame(const void *p) +{ + return ((struct blame_entry *)p)->next; +} + +static void set_next_blame(void *p1, void *p2) +{ + ((struct blame_entry *)p1)->next = p2; +} + +/* + * Final image line numbers are all different, so we don't need a + * three-way comparison here. + */ + +static int compare_blame_final(const void *p1, const void *p2) +{ + return ((struct blame_entry *)p1)->lno > ((struct blame_entry *)p2)->lno + ? 1 : -1; +} + +static int compare_blame_suspect(const void *p1, const void *p2) +{ + const struct blame_entry *s1 = p1, *s2 = p2; + /* + * to allow for collating suspects, we sort according to the + * respective pointer value as the primary sorting criterion. + * The actual relation is pretty unimportant as long as it + * establishes a total order. Comparing as integers gives us + * that. + */ + if (s1->suspect != s2->suspect) + return (intptr_t)s1->suspect > (intptr_t)s2->suspect ? 1 : -1; + if (s1->s_lno == s2->s_lno) + return 0; + return s1->s_lno > s2->s_lno ? 1 : -1; +} + +static struct blame_entry *blame_sort(struct blame_entry *head, + int (*compare_fn)(const void *, const void *)) +{ + return llist_mergesort (head, get_next_blame, set_next_blame, compare_fn); +} + +static int compare_commits_by_reverse_commit_date(const void *a, + const void *b, + void *c) +{ + return -compare_commits_by_commit_date(a, b, c); +} + +/* * The current state of the blame assignment. */ struct scoreboard { /* the final commit (i.e. where we started digging from) */ struct commit *final; + /* Priority queue for commits with unassigned blame records */ + struct prio_queue commits; struct rev_info *revs; const char *path; @@ -268,7 +410,6 @@ static void coalesce(struct scoreboard *sb) for (ent = sb->ent; ent && (next = ent->next); ent = next) { if (ent->suspect == next->suspect && - ent->guilty == next->guilty && ent->s_lno + ent->num_lines == next->s_lno) { ent->num_lines += next->num_lines; ent->next = next->next; @@ -284,6 +425,30 @@ static void coalesce(struct scoreboard *sb) } /* + * Merge the given sorted list of blames into a preexisting origin. + * If there were no previous blames to that commit, it is entered into + * the commit priority queue of the score board. + */ + +static void queue_blames(struct scoreboard *sb, struct origin *porigin, + struct blame_entry *sorted) +{ + if (porigin->suspects) + porigin->suspects = blame_merge(porigin->suspects, sorted); + else { + struct origin *o; + for (o = porigin->commit->util; o; o = o->next) { + if (o->suspects) { + porigin->suspects = sorted; + return; + } + } + porigin->suspects = sorted; + prio_queue_put(&sb->commits, porigin->commit); + } +} + +/* * Given a commit and a path in it, create a new origin structure. * The callers that add blame to the scoreboard should use * get_origin() to obtain shared, refcounted copy instead of calling @@ -295,23 +460,32 @@ static struct origin *make_origin(struct commit *commit, const char *path) o = xcalloc(1, sizeof(*o) + strlen(path) + 1); o->commit = commit; o->refcnt = 1; + o->next = commit->util; + commit->util = o; strcpy(o->path, path); return o; } /* * Locate an existing origin or create a new one. + * This moves the origin to front position in the commit util list. */ static struct origin *get_origin(struct scoreboard *sb, struct commit *commit, const char *path) { - struct blame_entry *e; + struct origin *o, *l; - for (e = sb->ent; e; e = e->next) { - if (e->suspect->commit == commit && - !strcmp(e->suspect->path, path)) - return origin_incref(e->suspect); + for (o = commit->util, l = NULL; o; l = o, o = o->next) { + if (!strcmp(o->path, path)) { + /* bump to front */ + if (l) { + l->next = o->next; + o->next = commit->util; + commit->util = o; + } + return origin_incref(o); + } } return make_origin(commit, path); } @@ -350,41 +524,19 @@ static struct origin *find_origin(struct scoreboard *sb, struct commit *parent, struct origin *origin) { - struct origin *porigin = NULL; + struct origin *porigin; struct diff_options diff_opts; const char *paths[2]; - if (parent->util) { - /* - * Each commit object can cache one origin in that - * commit. This is a freestanding copy of origin and - * not refcounted. - */ - struct origin *cached = parent->util; - if (!strcmp(cached->path, origin->path)) { + /* First check any existing origins */ + for (porigin = parent->util; porigin; porigin = porigin->next) + if (!strcmp(porigin->path, origin->path)) { /* * The same path between origin and its parent * without renaming -- the most common case. */ - porigin = get_origin(sb, parent, cached->path); - - /* - * If the origin was newly created (i.e. get_origin - * would call make_origin if none is found in the - * scoreboard), it does not know the blob_sha1/mode, - * so copy it. Otherwise porigin was in the - * scoreboard and already knows blob_sha1/mode. - */ - if (porigin->refcnt == 1) { - hashcpy(porigin->blob_sha1, cached->blob_sha1); - porigin->mode = cached->mode; - } - return porigin; + return origin_incref (porigin); } - /* otherwise it was not very useful; free it */ - free(parent->util); - parent->util = NULL; - } /* See if the origin->path is different between parent * and origin first. Most of the time they are the @@ -450,19 +602,6 @@ static struct origin *find_origin(struct scoreboard *sb, } diff_flush(&diff_opts); free_pathspec(&diff_opts.pathspec); - if (porigin) { - /* - * Create a freestanding copy that is not part of - * the refcounted origin found in the scoreboard, and - * cache it in the commit. - */ - struct origin *cached; - - cached = make_origin(porigin->commit, porigin->path); - hashcpy(cached->blob_sha1, porigin->blob_sha1); - cached->mode = porigin->mode; - parent->util = cached; - } return porigin; } @@ -509,46 +648,31 @@ static struct origin *find_rename(struct scoreboard *sb, } /* - * Link in a new blame entry to the scoreboard. Entries that cover the - * same line range have been removed from the scoreboard previously. + * Append a new blame entry to a given output queue. */ -static void add_blame_entry(struct scoreboard *sb, struct blame_entry *e) +static void add_blame_entry(struct blame_entry ***queue, struct blame_entry *e) { - struct blame_entry *ent, *prev = NULL; - origin_incref(e->suspect); - for (ent = sb->ent; ent && ent->lno < e->lno; ent = ent->next) - prev = ent; - - /* prev, if not NULL, is the last one that is below e */ - - if (prev) { - e->next = prev->next; - prev->next = e; - } - else { - e->next = sb->ent; - sb->ent = e; - } + e->next = **queue; + **queue = e; + *queue = &e->next; } /* * src typically is on-stack; we want to copy the information in it to - * a malloced blame_entry that is already on the linked list of the - * scoreboard. The origin of dst loses a refcnt while the origin of src - * gains one. + * a malloced blame_entry that gets added to the given queue. The + * origin of dst loses a refcnt. */ -static void dup_entry(struct blame_entry *dst, struct blame_entry *src) +static void dup_entry(struct blame_entry ***queue, + struct blame_entry *dst, struct blame_entry *src) { - struct blame_entry *n; - - n = dst->next; origin_incref(src->suspect); origin_decref(dst->suspect); memcpy(dst, src, sizeof(*src)); - dst->next = n; - dst->score = 0; + dst->next = **queue; + **queue = dst; + *queue = &dst->next; } static const char *nth_line(struct scoreboard *sb, long lno) @@ -620,10 +744,11 @@ static void split_overlap(struct blame_entry *split, /* * split_overlap() divided an existing blame e into up to three parts - * in split. Adjust the linked list of blames in the scoreboard to + * in split. Any assigned blame is moved to queue to * reflect the split. */ -static void split_blame(struct scoreboard *sb, +static void split_blame(struct blame_entry ***blamed, + struct blame_entry ***unblamed, struct blame_entry *split, struct blame_entry *e) { @@ -631,61 +756,39 @@ static void split_blame(struct scoreboard *sb, if (split[0].suspect && split[2].suspect) { /* The first part (reuse storage for the existing entry e) */ - dup_entry(e, &split[0]); + dup_entry(unblamed, e, &split[0]); /* The last part -- me */ new_entry = xmalloc(sizeof(*new_entry)); memcpy(new_entry, &(split[2]), sizeof(struct blame_entry)); - add_blame_entry(sb, new_entry); + add_blame_entry(unblamed, new_entry); /* ... and the middle part -- parent */ new_entry = xmalloc(sizeof(*new_entry)); memcpy(new_entry, &(split[1]), sizeof(struct blame_entry)); - add_blame_entry(sb, new_entry); + add_blame_entry(blamed, new_entry); } else if (!split[0].suspect && !split[2].suspect) /* * The parent covers the entire area; reuse storage for * e and replace it with the parent. */ - dup_entry(e, &split[1]); + dup_entry(blamed, e, &split[1]); else if (split[0].suspect) { /* me and then parent */ - dup_entry(e, &split[0]); + dup_entry(unblamed, e, &split[0]); new_entry = xmalloc(sizeof(*new_entry)); memcpy(new_entry, &(split[1]), sizeof(struct blame_entry)); - add_blame_entry(sb, new_entry); + add_blame_entry(blamed, new_entry); } else { /* parent and then me */ - dup_entry(e, &split[1]); + dup_entry(blamed, e, &split[1]); new_entry = xmalloc(sizeof(*new_entry)); memcpy(new_entry, &(split[2]), sizeof(struct blame_entry)); - add_blame_entry(sb, new_entry); - } - - if (DEBUG) { /* sanity */ - struct blame_entry *ent; - int lno = sb->ent->lno, corrupt = 0; - - for (ent = sb->ent; ent; ent = ent->next) { - if (lno != ent->lno) - corrupt = 1; - if (ent->s_lno < 0) - corrupt = 1; - lno += ent->num_lines; - } - if (corrupt) { - lno = sb->ent->lno; - for (ent = sb->ent; ent; ent = ent->next) { - printf("L %8d l %8d n %8d\n", - lno, ent->lno, ent->num_lines); - lno = ent->lno + ent->num_lines; - } - die("oops"); - } + add_blame_entry(unblamed, new_entry); } } @@ -702,74 +805,146 @@ static void decref_split(struct blame_entry *split) } /* - * Helper for blame_chunk(). blame_entry e is known to overlap with - * the patch hunk; split it and pass blame to the parent. + * reverse_blame reverses the list given in head, appending tail. + * That allows us to build lists in reverse order, then reverse them + * afterwards. This can be faster than building the list in proper + * order right away. The reason is that building in proper order + * requires writing a link in the _previous_ element, while building + * in reverse order just requires placing the list head into the + * _current_ element. */ -static void blame_overlap(struct scoreboard *sb, struct blame_entry *e, - int tlno, int plno, int same, - struct origin *parent) -{ - struct blame_entry split[3]; - - split_overlap(split, e, tlno, plno, same, parent); - if (split[1].suspect) - split_blame(sb, split, e); - decref_split(split); -} -/* - * Find the line number of the last line the target is suspected for. - */ -static int find_last_in_target(struct scoreboard *sb, struct origin *target) +static struct blame_entry *reverse_blame(struct blame_entry *head, + struct blame_entry *tail) { - struct blame_entry *e; - int last_in_target = -1; - - for (e = sb->ent; e; e = e->next) { - if (e->guilty || e->suspect != target) - continue; - if (last_in_target < e->s_lno + e->num_lines) - last_in_target = e->s_lno + e->num_lines; + while (head) { + struct blame_entry *next = head->next; + head->next = tail; + tail = head; + head = next; } - return last_in_target; + return tail; } /* * Process one hunk from the patch between the current suspect for - * blame_entry e and its parent. Find and split the overlap, and - * pass blame to the overlapping part to the parent. + * blame_entry e and its parent. This first blames any unfinished + * entries before the chunk (which is where target and parent start + * differing) on the parent, and then splits blame entries at the + * start and at the end of the difference region. Since use of -M and + * -C options may lead to overlapping/duplicate source line number + * ranges, all we can rely on from sorting/merging is the order of the + * first suspect line number. */ -static void blame_chunk(struct scoreboard *sb, - int tlno, int plno, int same, - struct origin *target, struct origin *parent) +static void blame_chunk(struct blame_entry ***dstq, struct blame_entry ***srcq, + int tlno, int offset, int same, + struct origin *parent) { - struct blame_entry *e; + struct blame_entry *e = **srcq; + struct blame_entry *samep = NULL, *diffp = NULL; - for (e = sb->ent; e; e = e->next) { - if (e->guilty || e->suspect != target) - continue; - if (same <= e->s_lno) - continue; - if (tlno < e->s_lno + e->num_lines) - blame_overlap(sb, e, tlno, plno, same, parent); + while (e && e->s_lno < tlno) { + struct blame_entry *next = e->next; + /* + * current record starts before differing portion. If + * it reaches into it, we need to split it up and + * examine the second part separately. + */ + if (e->s_lno + e->num_lines > tlno) { + /* Move second half to a new record */ + int len = tlno - e->s_lno; + struct blame_entry *n = xcalloc(1, sizeof (struct blame_entry)); + n->suspect = e->suspect; + n->lno = e->lno + len; + n->s_lno = e->s_lno + len; + n->num_lines = e->num_lines - len; + e->num_lines = len; + e->score = 0; + /* Push new record to diffp */ + n->next = diffp; + diffp = n; + } else + origin_decref(e->suspect); + /* Pass blame for everything before the differing + * chunk to the parent */ + e->suspect = origin_incref(parent); + e->s_lno += offset; + e->next = samep; + samep = e; + e = next; + } + /* + * As we don't know how much of a common stretch after this + * diff will occur, the currently blamed parts are all that we + * can assign to the parent for now. + */ + + if (samep) { + **dstq = reverse_blame(samep, **dstq); + *dstq = &samep->next; + } + /* + * Prepend the split off portions: everything after e starts + * after the blameable portion. + */ + e = reverse_blame(diffp, e); + + /* + * Now retain records on the target while parts are different + * from the parent. + */ + samep = NULL; + diffp = NULL; + while (e && e->s_lno < same) { + struct blame_entry *next = e->next; + + /* + * If current record extends into sameness, need to split. + */ + if (e->s_lno + e->num_lines > same) { + /* + * Move second half to a new record to be + * processed by later chunks + */ + int len = same - e->s_lno; + struct blame_entry *n = xcalloc(1, sizeof (struct blame_entry)); + n->suspect = origin_incref(e->suspect); + n->lno = e->lno + len; + n->s_lno = e->s_lno + len; + n->num_lines = e->num_lines - len; + e->num_lines = len; + e->score = 0; + /* Push new record to samep */ + n->next = samep; + samep = n; + } + e->next = diffp; + diffp = e; + e = next; } + **srcq = reverse_blame(diffp, reverse_blame(samep, e)); + /* Move across elements that are in the unblamable portion */ + if (diffp) + *srcq = &diffp->next; } struct blame_chunk_cb_data { - struct scoreboard *sb; - struct origin *target; struct origin *parent; - long plno; - long tlno; + long offset; + struct blame_entry **dstq; + struct blame_entry **srcq; }; +/* diff chunks are from parent to target */ static int blame_chunk_cb(long start_a, long count_a, long start_b, long count_b, void *data) { struct blame_chunk_cb_data *d = data; - blame_chunk(d->sb, d->tlno, d->plno, start_b, d->target, d->parent); - d->plno = start_a + count_a; - d->tlno = start_b + count_b; + if (start_a - start_b != d->offset) + die("internal error in blame::blame_chunk_cb"); + blame_chunk(&d->dstq, &d->srcq, start_b, start_a - start_b, + start_b + count_b, d->parent); + d->offset = start_a + count_a - (start_b + count_b); return 0; } @@ -778,29 +953,32 @@ static int blame_chunk_cb(long start_a, long count_a, * for the lines it is suspected to its parent. Run diff to find * which lines came from parent and pass blame for them. */ -static int pass_blame_to_parent(struct scoreboard *sb, - struct origin *target, - struct origin *parent) +static void pass_blame_to_parent(struct scoreboard *sb, + struct origin *target, + struct origin *parent) { - int last_in_target; mmfile_t file_p, file_o; struct blame_chunk_cb_data d; + struct blame_entry *newdest = NULL; - memset(&d, 0, sizeof(d)); - d.sb = sb; d.target = target; d.parent = parent; - last_in_target = find_last_in_target(sb, target); - if (last_in_target < 0) - return 1; /* nothing remains for this target */ + if (!target->suspects) + return; /* nothing remains for this target */ + + d.parent = parent; + d.offset = 0; + d.dstq = &newdest; d.srcq = &target->suspects; fill_origin_blob(&sb->revs->diffopt, parent, &file_p); fill_origin_blob(&sb->revs->diffopt, target, &file_o); num_get_patch++; diff_hunks(&file_p, &file_o, 0, blame_chunk_cb, &d); - /* The rest (i.e. anything after tlno) are the same as the parent */ - blame_chunk(sb, d.tlno, d.plno, last_in_target, target, parent); + /* The rest are the same as the parent */ + blame_chunk(&d.dstq, &d.srcq, INT_MAX, d.offset, INT_MAX, parent); + *d.dstq = NULL; + queue_blames(sb, parent, newdest); - return 0; + return; } /* @@ -945,43 +1123,80 @@ static void find_copy_in_blob(struct scoreboard *sb, handle_split(sb, ent, d.tlno, d.plno, ent->num_lines, parent, split); } +/* Move all blame entries from list *source that have a score smaller + * than score_min to the front of list *small. + * Returns a pointer to the link pointing to the old head of the small list. + */ + +static struct blame_entry **filter_small(struct scoreboard *sb, + struct blame_entry **small, + struct blame_entry **source, + unsigned score_min) +{ + struct blame_entry *p = *source; + struct blame_entry *oldsmall = *small; + while (p) { + if (ent_score(sb, p) <= score_min) { + *small = p; + small = &p->next; + p = *small; + } else { + *source = p; + source = &p->next; + p = *source; + } + } + *small = oldsmall; + *source = NULL; + return small; +} + /* * See if lines currently target is suspected for can be attributed to * parent. */ -static int find_move_in_parent(struct scoreboard *sb, - struct origin *target, - struct origin *parent) +static void find_move_in_parent(struct scoreboard *sb, + struct blame_entry ***blamed, + struct blame_entry **toosmall, + struct origin *target, + struct origin *parent) { - int last_in_target, made_progress; struct blame_entry *e, split[3]; + struct blame_entry *unblamed = target->suspects; + struct blame_entry *leftover = NULL; mmfile_t file_p; - last_in_target = find_last_in_target(sb, target); - if (last_in_target < 0) - return 1; /* nothing remains for this target */ + if (!unblamed) + return; /* nothing remains for this target */ fill_origin_blob(&sb->revs->diffopt, parent, &file_p); if (!file_p.ptr) - return 0; + return; - made_progress = 1; - while (made_progress) { - made_progress = 0; - for (e = sb->ent; e; e = e->next) { - if (e->guilty || e->suspect != target || - ent_score(sb, e) < blame_move_score) - continue; + /* At each iteration, unblamed has a NULL-terminated list of + * entries that have not yet been tested for blame. leftover + * contains the reversed list of entries that have been tested + * without being assignable to the parent. + */ + do { + struct blame_entry **unblamedtail = &unblamed; + struct blame_entry *next; + for (e = unblamed; e; e = next) { + next = e->next; find_copy_in_blob(sb, e, parent, split, &file_p); if (split[1].suspect && blame_move_score < ent_score(sb, &split[1])) { - split_blame(sb, split, e); - made_progress = 1; + split_blame(blamed, &unblamedtail, split, e); + } else { + e->next = leftover; + leftover = e; } decref_split(split); } - } - return 0; + *unblamedtail = NULL; + toosmall = filter_small(sb, toosmall, &unblamed, blame_move_score); + } while (unblamed); + target->suspects = reverse_blame(leftover, NULL); } struct blame_list { @@ -993,62 +1208,46 @@ struct blame_list { * Count the number of entries the target is suspected for, * and prepare a list of entry and the best split. */ -static struct blame_list *setup_blame_list(struct scoreboard *sb, - struct origin *target, - int min_score, +static struct blame_list *setup_blame_list(struct blame_entry *unblamed, int *num_ents_p) { struct blame_entry *e; int num_ents, i; struct blame_list *blame_list = NULL; - for (e = sb->ent, num_ents = 0; e; e = e->next) - if (!e->scanned && !e->guilty && - e->suspect == target && - min_score < ent_score(sb, e)) - num_ents++; + for (e = unblamed, num_ents = 0; e; e = e->next) + num_ents++; if (num_ents) { blame_list = xcalloc(num_ents, sizeof(struct blame_list)); - for (e = sb->ent, i = 0; e; e = e->next) - if (!e->scanned && !e->guilty && - e->suspect == target && - min_score < ent_score(sb, e)) - blame_list[i++].ent = e; + for (e = unblamed, i = 0; e; e = e->next) + blame_list[i++].ent = e; } *num_ents_p = num_ents; return blame_list; } /* - * Reset the scanned status on all entries. - */ -static void reset_scanned_flag(struct scoreboard *sb) -{ - struct blame_entry *e; - for (e = sb->ent; e; e = e->next) - e->scanned = 0; -} - -/* * For lines target is suspected for, see if we can find code movement * across file boundary from the parent commit. porigin is the path * in the parent we already tried. */ -static int find_copy_in_parent(struct scoreboard *sb, - struct origin *target, - struct commit *parent, - struct origin *porigin, - int opt) +static void find_copy_in_parent(struct scoreboard *sb, + struct blame_entry ***blamed, + struct blame_entry **toosmall, + struct origin *target, + struct commit *parent, + struct origin *porigin, + int opt) { struct diff_options diff_opts; int i, j; - int retval; struct blame_list *blame_list; int num_ents; + struct blame_entry *unblamed = target->suspects; + struct blame_entry *leftover = NULL; - blame_list = setup_blame_list(sb, target, blame_copy_score, &num_ents); - if (!blame_list) - return 1; /* nothing remains for this target */ + if (!unblamed) + return; /* nothing remains for this target */ diff_setup(&diff_opts); DIFF_OPT_SET(&diff_opts, RECURSIVE); @@ -1078,9 +1277,9 @@ static int find_copy_in_parent(struct scoreboard *sb, if (!DIFF_OPT_TST(&diff_opts, FIND_COPIES_HARDER)) diffcore_std(&diff_opts); - retval = 0; - while (1) { - int made_progress = 0; + do { + struct blame_entry **unblamedtail = &unblamed; + blame_list = setup_blame_list(unblamed, &num_ents); for (i = 0; i < diff_queued_diff.nr; i++) { struct diff_filepair *p = diff_queued_diff.queue[i]; @@ -1117,27 +1316,21 @@ static int find_copy_in_parent(struct scoreboard *sb, struct blame_entry *split = blame_list[j].split; if (split[1].suspect && blame_copy_score < ent_score(sb, &split[1])) { - split_blame(sb, split, blame_list[j].ent); - made_progress = 1; + split_blame(blamed, &unblamedtail, split, + blame_list[j].ent); + } else { + blame_list[j].ent->next = leftover; + leftover = blame_list[j].ent; } - else - blame_list[j].ent->scanned = 1; decref_split(split); } free(blame_list); - - if (!made_progress) - break; - blame_list = setup_blame_list(sb, target, blame_copy_score, &num_ents); - if (!blame_list) { - retval = 1; - break; - } - } - reset_scanned_flag(sb); + *unblamedtail = NULL; + toosmall = filter_small(sb, toosmall, &unblamed, blame_copy_score); + } while (unblamed); + target->suspects = reverse_blame(leftover, NULL); diff_flush(&diff_opts); free_pathspec(&diff_opts.pathspec); - return retval; } /* @@ -1147,20 +1340,21 @@ static int find_copy_in_parent(struct scoreboard *sb, static void pass_whole_blame(struct scoreboard *sb, struct origin *origin, struct origin *porigin) { - struct blame_entry *e; + struct blame_entry *e, *suspects; if (!porigin->file.ptr && origin->file.ptr) { /* Steal its file */ porigin->file = origin->file; origin->file.ptr = NULL; } - for (e = sb->ent; e; e = e->next) { - if (e->suspect != origin) - continue; + suspects = origin->suspects; + origin->suspects = NULL; + for (e = suspects; e; e = e->next) { origin_incref(porigin); origin_decref(e->suspect); e->suspect = porigin; } + queue_blames(sb, porigin, suspects); } /* @@ -1184,6 +1378,27 @@ static int num_scapegoats(struct rev_info *revs, struct commit *commit) return cnt; } +/* Distribute collected unsorted blames to the respected sorted lists + * in the various origins. + */ +static void distribute_blame(struct scoreboard *sb, struct blame_entry *blamed) +{ + blamed = blame_sort(blamed, compare_blame_suspect); + while (blamed) + { + struct origin *porigin = blamed->suspect; + struct blame_entry *suspects = NULL; + do { + struct blame_entry *next = blamed->next; + blamed->next = suspects; + suspects = blamed; + blamed = next; + } while (blamed && blamed->suspect == porigin); + suspects = reverse_blame(suspects, NULL); + queue_blames(sb, porigin, suspects); + } +} + #define MAXSG 16 static void pass_blame(struct scoreboard *sb, struct origin *origin, int opt) @@ -1194,6 +1409,8 @@ static void pass_blame(struct scoreboard *sb, struct origin *origin, int opt) struct commit_list *sg; struct origin *sg_buf[MAXSG]; struct origin *porigin, **sg_origin = sg_buf; + struct blame_entry *toosmall = NULL; + struct blame_entry *blames, **blametail = &blames; num_sg = num_scapegoats(revs, commit); if (!num_sg) @@ -1255,38 +1472,71 @@ static void pass_blame(struct scoreboard *sb, struct origin *origin, int opt) origin_incref(porigin); origin->previous = porigin; } - if (pass_blame_to_parent(sb, origin, porigin)) + pass_blame_to_parent(sb, origin, porigin); + if (!origin->suspects) goto finish; } /* * Optionally find moves in parents' files. */ - if (opt & PICKAXE_BLAME_MOVE) - for (i = 0, sg = first_scapegoat(revs, commit); - i < num_sg && sg; - sg = sg->next, i++) { - struct origin *porigin = sg_origin[i]; - if (!porigin) - continue; - if (find_move_in_parent(sb, origin, porigin)) - goto finish; + if (opt & PICKAXE_BLAME_MOVE) { + filter_small(sb, &toosmall, &origin->suspects, blame_move_score); + if (origin->suspects) { + for (i = 0, sg = first_scapegoat(revs, commit); + i < num_sg && sg; + sg = sg->next, i++) { + struct origin *porigin = sg_origin[i]; + if (!porigin) + continue; + find_move_in_parent(sb, &blametail, &toosmall, origin, porigin); + if (!origin->suspects) + break; + } } + } /* * Optionally find copies from parents' files. */ - if (opt & PICKAXE_BLAME_COPY) + if (opt & PICKAXE_BLAME_COPY) { + if (blame_copy_score > blame_move_score) + filter_small(sb, &toosmall, &origin->suspects, blame_copy_score); + else if (blame_copy_score < blame_move_score) { + origin->suspects = blame_merge(origin->suspects, toosmall); + toosmall = NULL; + filter_small(sb, &toosmall, &origin->suspects, blame_copy_score); + } + if (!origin->suspects) + goto finish; + for (i = 0, sg = first_scapegoat(revs, commit); i < num_sg && sg; sg = sg->next, i++) { struct origin *porigin = sg_origin[i]; - if (find_copy_in_parent(sb, origin, sg->item, - porigin, opt)) + find_copy_in_parent(sb, &blametail, &toosmall, + origin, sg->item, porigin, opt); + if (!origin->suspects) goto finish; } + } - finish: +finish: + *blametail = NULL; + distribute_blame(sb, blames); + /* + * prepend toosmall to origin->suspects + * + * There is no point in sorting: this ends up on a big + * unsorted list in the caller anyway. + */ + if (toosmall) { + struct blame_entry **tail = &toosmall; + while (*tail) + tail = &(*tail)->next; + *tail = origin->suspects; + origin->suspects = toosmall; + } for (i = 0; i < num_sg; i++) { if (sg_origin[i]) { drop_origin_blob(sg_origin[i]); @@ -1405,7 +1655,7 @@ static void get_commit_info(struct commit *commit, { int len; const char *subject, *encoding; - char *message; + const char *message; commit_info_init(ret); @@ -1416,7 +1666,7 @@ static void get_commit_info(struct commit *commit, &ret->author_time, &ret->author_tz); if (!detailed) { - logmsg_free(message, commit); + unuse_commit_buffer(commit, message); return; } @@ -1430,7 +1680,7 @@ static void get_commit_info(struct commit *commit, else strbuf_addf(&ret->summary, "(%s)", sha1_to_hex(commit->object.sha1)); - logmsg_free(message, commit); + unuse_commit_buffer(commit, message); } /* @@ -1481,14 +1731,11 @@ static int emit_one_suspect_detail(struct origin *suspect, int repeat) } /* - * The blame_entry is found to be guilty for the range. Mark it - * as such, and show it in incremental output. + * The blame_entry is found to be guilty for the range. + * Show it in incremental output. */ static void found_guilty_entry(struct blame_entry *ent) { - if (ent->guilty) - return; - ent->guilty = 1; if (incremental) { struct origin *suspect = ent->suspect; @@ -1502,32 +1749,34 @@ static void found_guilty_entry(struct blame_entry *ent) } /* - * The main loop -- while the scoreboard has lines whose true origin - * is still unknown, pick one blame_entry, and allow its current - * suspect to pass blames to its parents. - */ + * The main loop -- while we have blobs with lines whose true origin + * is still unknown, pick one blob, and allow its lines to pass blames + * to its parents. */ static void assign_blame(struct scoreboard *sb, int opt) { struct rev_info *revs = sb->revs; + struct commit *commit = prio_queue_get(&sb->commits); - while (1) { + while (commit) { struct blame_entry *ent; - struct commit *commit; - struct origin *suspect = NULL; + struct origin *suspect = commit->util; /* find one suspect to break down */ - for (ent = sb->ent; !suspect && ent; ent = ent->next) - if (!ent->guilty) - suspect = ent->suspect; - if (!suspect) - return; /* all done */ + while (suspect && !suspect->suspects) + suspect = suspect->next; + + if (!suspect) { + commit = prio_queue_get(&sb->commits); + continue; + } + + assert(commit == suspect->commit); /* * We will use this suspect later in the loop, * so hold onto it in the meantime. */ origin_incref(suspect); - commit = suspect->commit; parse_commit(commit); if (reverse || (!(commit->object.flags & UNINTERESTING) && @@ -1543,9 +1792,22 @@ static void assign_blame(struct scoreboard *sb, int opt) commit->object.flags |= UNINTERESTING; /* Take responsibility for the remaining entries */ - for (ent = sb->ent; ent; ent = ent->next) - if (ent->suspect == suspect) + ent = suspect->suspects; + if (ent) { + suspect->guilty = 1; + for (;;) { + struct blame_entry *next = ent->next; found_guilty_entry(ent); + if (next) { + ent = next; + continue; + } + ent->next = sb->ent; + sb->ent = suspect->suspects; + suspect->suspects = NULL; + break; + } + } origin_decref(suspect); if (DEBUG) /* sanity */ @@ -1609,9 +1871,8 @@ static void emit_porcelain(struct scoreboard *sb, struct blame_entry *ent, char hex[41]; strcpy(hex, sha1_to_hex(suspect->commit->object.sha1)); - printf("%s%c%d %d %d\n", + printf("%s %d %d %d\n", hex, - ent->guilty ? ' ' : '*', /* purely for debugging */ ent->s_lno + 1, ent->lno + 1, ent->num_lines); @@ -1724,17 +1985,16 @@ static void output(struct scoreboard *sb, int option) if (option & OUTPUT_PORCELAIN) { for (ent = sb->ent; ent; ent = ent->next) { - struct blame_entry *oth; - struct origin *suspect = ent->suspect; - struct commit *commit = suspect->commit; + int count = 0; + struct origin *suspect; + struct commit *commit = ent->suspect->commit; if (commit->object.flags & MORE_THAN_ONE_PATH) continue; - for (oth = ent->next; oth; oth = oth->next) { - if ((oth->suspect->commit != commit) || - !strcmp(oth->suspect->path, suspect->path)) - continue; - commit->object.flags |= MORE_THAN_ONE_PATH; - break; + for (suspect = commit->util; suspect; suspect = suspect->next) { + if (suspect->guilty && count++) { + commit->object.flags |= MORE_THAN_ONE_PATH; + break; + } } } } @@ -1748,6 +2008,12 @@ static void output(struct scoreboard *sb, int option) } } +static const char *get_next_line(const char *start, const char *end) +{ + const char *nl = memchr(start, '\n', end - start); + return nl ? nl + 1 : end; +} + /* * To allow quick access to the contents of nth line in the * final image, prepare an index in the scoreboard. @@ -1759,39 +2025,19 @@ static int prepare_lines(struct scoreboard *sb) const char *end = buf + len; const char *p; int *lineno; - int num = 0, incomplete = 0; + int num = 0; - for (p = buf;;) { - p = memchr(p, '\n', end - p); - if (p) { - p++; - num++; - continue; - } - break; - } + for (p = buf; p < end; p = get_next_line(p, end)) + num++; - if (len && end[-1] != '\n') - incomplete++; /* incomplete line at the end */ + sb->lineno = lineno = xmalloc(sizeof(*sb->lineno) * (num + 1)); - sb->lineno = xmalloc(sizeof(*sb->lineno) * (num + incomplete + 1)); - lineno = sb->lineno; + for (p = buf; p < end; p = get_next_line(p, end)) + *lineno++ = p - buf; - *lineno++ = 0; - for (p = buf;;) { - p = memchr(p, '\n', end - p); - if (p) { - p++; - *lineno++ = p - buf; - continue; - } - break; - } + *lineno = len; - if (incomplete) - *lineno++ = len; - - sb->num_lines = num + incomplete; + sb->num_lines = num; return sb->num_lines; } @@ -2006,6 +2252,18 @@ static void append_merge_parents(struct commit_list **tail) } /* + * This isn't as simple as passing sb->buf and sb->len, because we + * want to transfer ownership of the buffer to the commit (so we + * must use detach). + */ +static void set_commit_buffer_from_strbuf(struct commit *c, struct strbuf *sb) +{ + size_t len; + void *buf = strbuf_detach(sb, &len); + set_commit_buffer(c, buf, len); +} + +/* * Prepare a dummy commit that represents the work tree (or staged) item. * Note that annotating work tree item never works in the reverse. */ @@ -2026,7 +2284,7 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt, struct strbuf msg = STRBUF_INIT; time(&now); - commit = xcalloc(1, sizeof(*commit)); + commit = alloc_commit_node(); commit->object.parsed = 1; commit->date = now; commit->object.type = OBJ_COMMIT; @@ -2053,7 +2311,7 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt, ident, ident, path, (!contents_from ? path : (!strcmp(contents_from, "-") ? "standard input" : contents_from))); - commit->buffer = strbuf_detach(&msg, NULL); + set_commit_buffer_from_strbuf(commit, &msg); if (!contents_from || strcmp("-", contents_from)) { struct stat st; @@ -2095,11 +2353,9 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt, if (strbuf_read(&buf, 0, 0) < 0) die_errno("failed to read from stdin"); } - convert_to_git(path, buf.buf, buf.len, &buf, 0); origin->file.ptr = buf.buf; origin->file.size = buf.len; pretend_sha1_file(buf.buf, buf.len, OBJ_BLOB, origin->blob_sha1); - commit->util = origin; /* * Read the current index, replace the path entry with @@ -2417,12 +2673,16 @@ parse_done: memset(&sb, 0, sizeof(sb)); sb.revs = &revs; - if (!reverse) + if (!reverse) { final_commit_name = prepare_final(&sb); + sb.commits.compare = compare_commits_by_commit_date; + } else if (contents_from) die("--contents and --children do not blend well."); - else + else { final_commit_name = prepare_initial(&sb); + sb.commits.compare = compare_commits_by_reverse_commit_date; + } if (!sb.final) { /* @@ -2511,12 +2771,16 @@ parse_done: ent->next = next; origin_incref(o); } + + o->suspects = ent; + prio_queue_put(&sb.commits, o->commit); + origin_decref(o); range_set_release(&ranges); string_list_clear(&range_list, 0); - sb.ent = ent; + sb.ent = NULL; sb.path = path; read_mailmap(&mailmap, NULL); @@ -2529,6 +2793,8 @@ parse_done: if (incremental) return 0; + sb.ent = blame_sort(sb.ent, compare_blame_final); + coalesce(&sb); if (!(output_option & OUTPUT_PORCELAIN)) diff --git a/builtin/checkout.c b/builtin/checkout.c index ff4492162d..f1dc56e55f 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -651,12 +651,8 @@ static void update_refs_for_switch(const struct checkout_opts *opts, } } if (old->path && old->name) { - char log_file[PATH_MAX], ref_file[PATH_MAX]; - - git_snpath(log_file, sizeof(log_file), "logs/%s", old->path); - git_snpath(ref_file, sizeof(ref_file), "%s", old->path); - if (!file_exists(ref_file) && file_exists(log_file)) - remove_path(log_file); + if (!ref_exists(old->path) && reflog_exists(old->path)) + delete_reflog(old->path); } } remove_branch_state(); diff --git a/builtin/clean.c b/builtin/clean.c index 9a9151575d..27701d222c 100644 --- a/builtin/clean.c +++ b/builtin/clean.c @@ -48,7 +48,7 @@ enum color_clean { CLEAN_COLOR_PROMPT = 2, CLEAN_COLOR_HEADER = 3, CLEAN_COLOR_HELP = 4, - CLEAN_COLOR_ERROR = 5, + CLEAN_COLOR_ERROR = 5 }; #define MENU_OPTS_SINGLETON 01 diff --git a/builtin/commit-tree.c b/builtin/commit-tree.c index 987a4c3d73..8a66c74e0f 100644 --- a/builtin/commit-tree.c +++ b/builtin/commit-tree.c @@ -123,8 +123,8 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix) die_errno("git commit-tree: failed to read"); } - if (commit_tree(&buffer, tree_sha1, parents, commit_sha1, - NULL, sign_commit)) { + if (commit_tree(buffer.buf, buffer.len, tree_sha1, parents, + commit_sha1, NULL, sign_commit)) { strbuf_release(&buffer); return 1; } diff --git a/builtin/commit.c b/builtin/commit.c index caec5c0e18..84cec9a715 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -620,6 +620,36 @@ static int author_date_is_interesting(void) return author_message || force_date; } +static void adjust_comment_line_char(const struct strbuf *sb) +{ + char candidates[] = "#;@!$%^&|:"; + char *candidate; + const char *p; + + comment_line_char = candidates[0]; + if (!memchr(sb->buf, comment_line_char, sb->len)) + return; + + p = sb->buf; + candidate = strchr(candidates, *p); + if (candidate) + *candidate = ' '; + for (p = sb->buf; *p; p++) { + if ((p[0] == '\n' || p[0] == '\r') && p[1]) { + candidate = strchr(candidates, p[1]); + if (candidate) + *candidate = ' '; + } + } + + for (p = candidates; *p == ' '; p++) + ; + if (!*p) + die(_("unable to select a comment character that is not used\n" + "in the current commit message")); + comment_line_char = *p; +} + static int prepare_to_commit(const char *index_file, const char *prefix, struct commit *current_head, struct wt_status *s, @@ -676,9 +706,8 @@ static int prepare_to_commit(const char *index_file, const char *prefix, } else if (use_message) { char *buffer; buffer = strstr(use_message_buffer, "\n\n"); - if (!use_editor && (!buffer || buffer[2] == '\0')) - die(_("commit has empty message")); - strbuf_add(&sb, buffer + 2, strlen(buffer + 2)); + if (buffer) + strbuf_add(&sb, buffer + 2, strlen(buffer + 2)); hook_arg1 = "commit"; hook_arg2 = use_message; } else if (fixup_message) { @@ -774,6 +803,8 @@ static int prepare_to_commit(const char *index_file, const char *prefix, if (fwrite(sb.buf, 1, sb.len, s->fp) < sb.len) die_errno(_("could not write commit template")); + if (auto_comment_line_char) + adjust_comment_line_char(&sb); strbuf_release(&sb); /* This checks if committer ident is explicitly given */ @@ -849,7 +880,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix, (int)(ci.mail_end - ci.mail_begin), ci.mail_begin); if (ident_shown) - status_printf_ln(s, GIT_COLOR_NORMAL, ""); + status_printf_ln(s, GIT_COLOR_NORMAL, "%s", ""); saved_color_setting = s->use_color; s->use_color = 0; @@ -867,8 +898,22 @@ static int prepare_to_commit(const char *index_file, const char *prefix, if (get_sha1(parent, sha1)) commitable = !!active_nr; - else - commitable = index_differs_from(parent, 0); + else { + /* + * Unless the user did explicitly request a submodule + * ignore mode by passing a command line option we do + * not ignore any changed submodule SHA-1s when + * comparing index and parent, no matter what is + * configured. Otherwise we won't commit any + * submodules which were manually staged, which would + * be really confusing. + */ + int diff_flags = DIFF_OPT_OVERRIDE_SUBMODULE_CONFIG; + if (ignore_submodule_arg && + !strcmp(ignore_submodule_arg, "all")) + diff_flags |= DIFF_OPT_IGNORE_SUBMODULES; + commitable = index_differs_from(parent, diff_flags); + } } strbuf_release(&committer_ident); @@ -1700,8 +1745,8 @@ int cmd_commit(int argc, const char **argv, const char *prefix) append_merge_tag_headers(parents, &tail); } - if (commit_tree_extended(&sb, active_cache_tree->sha1, parents, sha1, - author_ident.buf, sign_commit, extra)) { + if (commit_tree_extended(sb.buf, sb.len, active_cache_tree->sha1, + parents, sha1, author_ident.buf, sign_commit, extra)) { rollback_index_files(); die(_("failed to write commit object")); } diff --git a/builtin/config.c b/builtin/config.c index 5677c942b6..fcd8474701 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -395,19 +395,6 @@ static int urlmatch_collect_fn(const char *var, const char *value, void *cb) return 0; } -static char *dup_downcase(const char *string) -{ - char *result; - size_t len, i; - - len = strlen(string); - result = xmalloc(len + 1); - for (i = 0; i < len; i++) - result[i] = tolower(string[i]); - result[i] = '\0'; - return result; -} - static int get_urlmatch(const char *var, const char *url) { char *section_tail; @@ -422,7 +409,7 @@ static int get_urlmatch(const char *var, const char *url) if (!url_normalize(url, &config.url)) die("%s", config.url.err); - config.section = dup_downcase(var); + config.section = xstrdup_tolower(var); section_tail = strchr(config.section, '.'); if (section_tail) { *section_tail = '\0'; diff --git a/builtin/fast-export.c b/builtin/fast-export.c index b8d8a3aaf9..92b4624a4b 100644 --- a/builtin/fast-export.c +++ b/builtin/fast-export.c @@ -17,6 +17,7 @@ #include "utf8.h" #include "parse-options.h" #include "quote.h" +#include "remote.h" static const char *fast_export_usage[] = { N_("git fast-export [rev-list-opts]"), @@ -31,6 +32,8 @@ static int use_done_feature; static int no_data; static int full_tree; static struct string_list extra_refs = STRING_LIST_INIT_NODUP; +static struct refspec *refspecs; +static int refspecs_nr; static int parse_opt_signed_tag_mode(const struct option *opt, const char *arg, int unset) @@ -279,6 +282,7 @@ static const char *find_encoding(const char *begin, const char *end) static void handle_commit(struct commit *commit, struct rev_info *rev) { int saved_output_format = rev->diffopt.output_format; + const char *commit_buffer; const char *author, *author_end, *committer, *committer_end; const char *encoding, *message; char *reencoded = NULL; @@ -288,7 +292,8 @@ static void handle_commit(struct commit *commit, struct rev_info *rev) rev->diffopt.output_format = DIFF_FORMAT_CALLBACK; parse_commit_or_die(commit); - author = strstr(commit->buffer, "\nauthor "); + commit_buffer = get_commit_buffer(commit, NULL); + author = strstr(commit_buffer, "\nauthor "); if (!author) die ("Could not find author in commit %s", sha1_to_hex(commit->object.sha1)); @@ -335,6 +340,7 @@ static void handle_commit(struct commit *commit, struct rev_info *rev) ? strlen(message) : 0), reencoded ? reencoded : message ? message : ""); free(reencoded); + unuse_commit_buffer(commit, commit_buffer); for (i = 0, p = commit->parents; p; p = p->next) { int mark = get_object_mark(&p->item->object); @@ -525,6 +531,15 @@ static void get_tags_and_duplicates(struct rev_cmdline_info *info) if (dwim_ref(e->name, strlen(e->name), sha1, &full_name) != 1) continue; + if (refspecs) { + char *private; + private = apply_refspecs(refspecs, refspecs_nr, full_name); + if (private) { + free(full_name); + full_name = private; + } + } + commit = get_commit(e, full_name); if (!commit) { warning("%s: Unexpected object of type %s, skipping.", @@ -661,6 +676,19 @@ static void import_marks(char *input_file) fclose(f); } +static void handle_deletes(void) +{ + int i; + for (i = 0; i < refspecs_nr; i++) { + struct refspec *refspec = &refspecs[i]; + if (*refspec->src) + continue; + + printf("reset %s\nfrom %s\n\n", + refspec->dst, sha1_to_hex(null_sha1)); + } +} + int cmd_fast_export(int argc, const char **argv, const char *prefix) { struct rev_info revs; @@ -668,6 +696,7 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix) struct commit *commit; char *export_filename = NULL, *import_filename = NULL; uint32_t lastimportid; + struct string_list refspecs_list = STRING_LIST_INIT_NODUP; struct option options[] = { OPT_INTEGER(0, "progress", &progress, N_("show progress after <n> objects")), @@ -688,6 +717,8 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix) OPT_BOOL(0, "use-done-feature", &use_done_feature, N_("Use the done feature to terminate the stream")), OPT_BOOL(0, "no-data", &no_data, N_("Skip output of blob data")), + OPT_STRING_LIST(0, "refspec", &refspecs_list, N_("refspec"), + N_("Apply refspec to exported refs")), OPT_END() }; @@ -701,11 +732,27 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix) revs.topo_order = 1; revs.show_source = 1; revs.rewrite_parents = 1; + argc = parse_options(argc, argv, prefix, options, fast_export_usage, + PARSE_OPT_KEEP_ARGV0 | PARSE_OPT_KEEP_UNKNOWN); argc = setup_revisions(argc, argv, &revs, NULL); - argc = parse_options(argc, argv, prefix, options, fast_export_usage, 0); if (argc > 1) usage_with_options (fast_export_usage, options); + if (refspecs_list.nr) { + const char **refspecs_str; + int i; + + refspecs_str = xmalloc(sizeof(*refspecs_str) * refspecs_list.nr); + for (i = 0; i < refspecs_list.nr; i++) + refspecs_str[i] = refspecs_list.items[i].string; + + refspecs_nr = refspecs_list.nr; + refspecs = parse_fetch_refspec(refspecs_nr, refspecs_str); + + string_list_clear(&refspecs_list, 1); + free(refspecs_str); + } + if (use_done_feature) printf("feature done\n"); @@ -733,6 +780,7 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix) } handle_tags_and_duplicates(); + handle_deletes(); if (export_filename && lastimportid != last_idnum) export_marks(export_filename); @@ -740,5 +788,7 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix) if (use_done_feature) printf("done\n"); + free_refspec(refspecs_nr, refspecs); + return 0; } diff --git a/builtin/fetch.c b/builtin/fetch.c index 55f457c04f..dd46b61d9a 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -45,6 +45,8 @@ static struct transport *gsecondary; static const char *submodule_prefix = ""; static const char *recurse_submodules_default; static int shown_url = 0; +static int refmap_alloc, refmap_nr; +static const char **refmap_array; static int option_parse_recurse_submodules(const struct option *opt, const char *arg, int unset) @@ -69,6 +71,19 @@ static int git_fetch_config(const char *k, const char *v, void *cb) return 0; } +static int parse_refmap_arg(const struct option *opt, const char *arg, int unset) +{ + ALLOC_GROW(refmap_array, refmap_nr + 1, refmap_alloc); + + /* + * "git fetch --refmap='' origin foo" + * can be used to tell the command not to store anywhere + */ + if (*arg) + refmap_array[refmap_nr++] = arg; + return 0; +} + static struct option builtin_fetch_options[] = { OPT__VERBOSITY(&verbosity), OPT_BOOL(0, "all", &all, @@ -107,6 +122,8 @@ static struct option builtin_fetch_options[] = { N_("default mode for recursion"), PARSE_OPT_HIDDEN }, OPT_BOOL(0, "update-shallow", &update_shallow, N_("accept refs that update .git/shallow")), + { OPTION_CALLBACK, 0, "refmap", NULL, N_("refmap"), + N_("specify fetch refmap"), PARSE_OPT_NONEG, parse_refmap_arg }, OPT_END() }; @@ -278,6 +295,9 @@ static struct ref *get_ref_map(struct transport *transport, const struct ref *remote_refs = transport_get_remote_refs(transport); if (refspec_count) { + struct refspec *fetch_refspec; + int fetch_refspec_nr; + for (i = 0; i < refspec_count; i++) { get_fetch_map(remote_refs, &refspecs[i], &tail, 0); if (refspecs[i].dst && refspecs[i].dst[0]) @@ -307,12 +327,21 @@ static struct ref *get_ref_map(struct transport *transport, * by ref_remove_duplicates() in favor of one of these * opportunistic entries with FETCH_HEAD_IGNORE. */ - for (i = 0; i < transport->remote->fetch_refspec_nr; i++) - get_fetch_map(ref_map, &transport->remote->fetch[i], - &oref_tail, 1); + if (refmap_array) { + fetch_refspec = parse_fetch_refspec(refmap_nr, refmap_array); + fetch_refspec_nr = refmap_nr; + } else { + fetch_refspec = transport->remote->fetch; + fetch_refspec_nr = transport->remote->fetch_refspec_nr; + } + + for (i = 0; i < fetch_refspec_nr; i++) + get_fetch_map(ref_map, &fetch_refspec[i], &oref_tail, 1); if (tags == TAGS_SET) get_fetch_map(remote_refs, tag_refspec, &tail, 0); + } else if (refmap_array) { + die("--refmap option is only meaningful with command-line refspec(s)."); } else { /* Use the defaults */ struct remote *remote = transport->remote; diff --git a/builtin/fmt-merge-msg.c b/builtin/fmt-merge-msg.c index 3906eda877..ef8b254ef2 100644 --- a/builtin/fmt-merge-msg.c +++ b/builtin/fmt-merge-msg.c @@ -230,12 +230,14 @@ static void add_branch_desc(struct strbuf *out, const char *name) static void record_person(int which, struct string_list *people, struct commit *commit) { + const char *buffer; char *name_buf, *name, *name_end; struct string_list_item *elem; const char *field; field = (which == 'a') ? "\nauthor " : "\ncommitter "; - name = strstr(commit->buffer, field); + buffer = get_commit_buffer(commit, NULL); + name = strstr(buffer, field); if (!name) return; name += strlen(field); @@ -247,6 +249,7 @@ static void record_person(int which, struct string_list *people, if (name_end < name) return; name_buf = xmemdupz(name, name_end - name + 1); + unuse_commit_buffer(commit, buffer); elem = string_list_lookup(people, name_buf); if (!elem) { diff --git a/builtin/for-each-ref.c b/builtin/for-each-ref.c index 3e1d5c3334..4135980f20 100644 --- a/builtin/for-each-ref.c +++ b/builtin/for-each-ref.c @@ -193,7 +193,7 @@ static int verify_format(const char *format) at = parse_atom(sp + 2, ep); cp = ep + 1; - if (!memcmp(used_atom[at], "color:", 6)) + if (starts_with(used_atom[at], "color:")) need_color_reset_at_eol = !!strcmp(used_atom[at], color_reset); } return 0; diff --git a/builtin/fsck.c b/builtin/fsck.c index fc150c8821..8aadca160e 100644 --- a/builtin/fsck.c +++ b/builtin/fsck.c @@ -310,8 +310,7 @@ static int fsck_obj(struct object *obj) if (obj->type == OBJ_COMMIT) { struct commit *commit = (struct commit *) obj; - free(commit->buffer); - commit->buffer = NULL; + free_commit_buffer(commit); if (!commit->parents && show_root) printf("root %s\n", sha1_to_hex(commit->object.sha1)); diff --git a/builtin/gc.c b/builtin/gc.c index 85f5c2bc62..8d219d8c42 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -26,6 +26,7 @@ static const char * const builtin_gc_usage[] = { }; static int pack_refs = 1; +static int prune_reflogs = 1; static int aggressive_depth = 250; static int aggressive_window = 250; static int gc_auto_threshold = 6700; @@ -258,6 +259,19 @@ static const char *lock_repo_for_gc(int force, pid_t* ret_pid) return NULL; } +static int gc_before_repack(void) +{ + if (pack_refs && run_command_v_opt(pack_refs_cmd.argv, RUN_GIT_CMD)) + return error(FAILED_RUN, pack_refs_cmd.argv[0]); + + if (prune_reflogs && run_command_v_opt(reflog.argv, RUN_GIT_CMD)) + return error(FAILED_RUN, reflog.argv[0]); + + pack_refs = 0; + prune_reflogs = 0; + return 0; +} + int cmd_gc(int argc, const char **argv, const char *prefix) { int aggressive = 0; @@ -320,12 +334,15 @@ int cmd_gc(int argc, const char **argv, const char *prefix) fprintf(stderr, _("Auto packing the repository for optimum performance.\n")); fprintf(stderr, _("See \"git help gc\" for manual housekeeping.\n")); } - if (detach_auto) + if (detach_auto) { + if (gc_before_repack()) + return -1; /* * failure to daemonize is ok, we'll continue * in foreground */ daemonize(); + } } else add_repack_all_option(); @@ -337,11 +354,8 @@ int cmd_gc(int argc, const char **argv, const char *prefix) name, (uintmax_t)pid); } - if (pack_refs && run_command_v_opt(pack_refs_cmd.argv, RUN_GIT_CMD)) - return error(FAILED_RUN, pack_refs_cmd.argv[0]); - - if (run_command_v_opt(reflog.argv, RUN_GIT_CMD)) - return error(FAILED_RUN, reflog.argv[0]); + if (gc_before_repack()) + return -1; if (run_command_v_opt(repack.argv, RUN_GIT_CMD)) return error(FAILED_RUN, repack.argv[0]); diff --git a/builtin/grep.c b/builtin/grep.c index 69ac2d8797..c86a142f30 100644 --- a/builtin/grep.c +++ b/builtin/grep.c @@ -361,9 +361,7 @@ static void run_pager(struct grep_opt *opt, const char *prefix) argv[i] = path_list->items[i].string; argv[path_list->nr] = NULL; - if (prefix && chdir(prefix)) - die(_("Failed to chdir: %s"), prefix); - status = run_command_v_opt(argv, RUN_USING_SHELL); + status = run_command_v_opt_cd_env(argv, RUN_USING_SHELL, prefix, NULL); if (status) exit(status); free(argv); @@ -874,6 +872,9 @@ int cmd_grep(int argc, const char **argv, const char *prefix) if (len > 4 && is_dir_sep(pager[len - 5])) pager += len - 4; + if (opt.ignore_case && !strcmp("less", pager)) + string_list_append(&path_list, "-I"); + if (!strcmp("less", pager) || !strcmp("vi", pager)) { struct strbuf buf = STRBUF_INIT; strbuf_addf(&buf, "+/%s%s", diff --git a/builtin/index-pack.c b/builtin/index-pack.c index 87d8dd81cc..8b3bd29dbc 100644 --- a/builtin/index-pack.c +++ b/builtin/index-pack.c @@ -207,8 +207,13 @@ static unsigned check_object(struct object *obj) if (!(obj->flags & FLAG_CHECKED)) { unsigned long size; int type = sha1_object_info(obj->sha1, &size); - if (type != obj->type || type <= 0) - die(_("object of unexpected type")); + if (type <= 0) + die(_("did not receive expected object %s"), + sha1_to_hex(obj->sha1)); + if (type != obj->type) + die(_("object %s: expected type %s, found %s"), + sha1_to_hex(obj->sha1), + typename(obj->type), typename(type)); obj->flags |= FLAG_CHECKED; return 1; } @@ -781,7 +786,8 @@ static void sha1_object(const void *data, struct object_entry *obj_entry, } if (obj->type == OBJ_COMMIT) { struct commit *commit = (struct commit *) obj; - commit->buffer = NULL; + if (detach_commit_buffer(commit, NULL) != data) + die("BUG: parse_object_buffer transmogrified our buffer"); } obj->flags |= FLAG_CHECKED; } diff --git a/builtin/log.c b/builtin/log.c index 39e8836352..92063dfc48 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -63,6 +63,8 @@ static int parse_decoration_style(const char *var, const char *value) return DECORATE_FULL_REFS; else if (!strcmp(value, "short")) return DECORATE_SHORT_REFS; + else if (!strcmp(value, "auto")) + return (isatty(1) || pager_in_use()) ? DECORATE_SHORT_REFS : 0; return -1; } @@ -158,13 +160,9 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix, if (rev->show_notes) init_display_notes(&rev->notes_opt); - if (rev->diffopt.pickaxe || rev->diffopt.filter) + if (rev->diffopt.pickaxe || rev->diffopt.filter || + DIFF_OPT_TST(&rev->diffopt, FOLLOW_RENAMES)) rev->always_show_header = 0; - if (DIFF_OPT_TST(&rev->diffopt, FOLLOW_RENAMES)) { - rev->always_show_header = 0; - if (rev->diffopt.pathspec.nr != 1) - usage("git logs can only follow renames on one pathname at a time"); - } if (source) rev->show_source = 1; @@ -349,8 +347,7 @@ static int cmd_log_walk(struct rev_info *rev) rev->max_count++; if (!rev->reflog_info) { /* we allow cycles in reflog ancestry */ - free(commit->buffer); - commit->buffer = NULL; + free_commit_buffer(commit); } free_commit_list(commit->parents); commit->parents = NULL; @@ -673,6 +670,7 @@ static void add_header(const char *value) static int thread; static int do_signoff; static const char *signature = git_version_string; +static const char *signature_file; static int config_cover_letter; enum { @@ -742,6 +740,8 @@ static int git_format_config(const char *var, const char *value, void *cb) } if (!strcmp(var, "format.signature")) return git_config_string(&signature, var, value); + if (!strcmp(var, "format.signaturefile")) + return git_config_pathname(&signature_file, var, value); if (!strcmp(var, "format.coverletter")) { if (value && !strcasecmp(value, "auto")) { config_cover_letter = COVER_AUTO; @@ -844,8 +844,13 @@ static void gen_message_id(struct rev_info *info, char *base) static void print_signature(void) { - if (signature && *signature) - printf("-- \n%s\n\n", signature); + if (!signature || !*signature) + return; + + printf("-- \n%s", signature); + if (signature[strlen(signature)-1] != '\n') + putchar('\n'); + putchar('\n'); } static void add_branch_description(struct strbuf *buf, const char *branch_name) @@ -919,9 +924,12 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout, log_write_email_headers(rev, head, &pp.subject, &pp.after_subject, &need_8bit_cte); - for (i = 0; !need_8bit_cte && i < nr; i++) - if (has_non_ascii(list[i]->buffer)) + for (i = 0; !need_8bit_cte && i < nr; i++) { + const char *buf = get_commit_buffer(list[i], NULL); + if (has_non_ascii(buf)) need_8bit_cte = 1; + unuse_commit_buffer(list[i], buf); + } if (!branch_name) branch_name = find_branch_name(rev); @@ -1230,6 +1238,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix) PARSE_OPT_OPTARG, thread_callback }, OPT_STRING(0, "signature", &signature, N_("signature"), N_("add a signature")), + OPT_FILENAME(0, "signature-file", &signature_file, + N_("add a signature from a file")), OPT__QUIET(&quiet, N_("don't print the patch filenames")), OPT_END() }; @@ -1447,6 +1457,18 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix) cover_letter = (config_cover_letter == COVER_ON); } + if (!signature) { + ; /* --no-signature inhibits all signatures */ + } else if (signature && signature != git_version_string) { + ; /* non-default signature already set */ + } else if (signature_file) { + struct strbuf buf = STRBUF_INIT; + + if (strbuf_read_file(&buf, signature_file, 128) < 0) + die_errno(_("unable to read signature file '%s'"), signature_file); + signature = strbuf_detach(&buf, NULL); + } + if (in_reply_to || thread || cover_letter) rev.ref_message_ids = xcalloc(1, sizeof(struct string_list)); if (in_reply_to) { @@ -1508,8 +1530,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix) reopen_stdout(rev.numbered_files ? NULL : commit, NULL, &rev, quiet)) die(_("Failed to create output files")); shown = log_tree_commit(&rev, commit); - free(commit->buffer); - commit->buffer = NULL; + free_commit_buffer(commit); /* We put one extra blank line between formatted * patches and this flag is used by log-tree code diff --git a/builtin/ls-remote.c b/builtin/ls-remote.c index 3e9eefb091..b2a4b92992 100644 --- a/builtin/ls-remote.c +++ b/builtin/ls-remote.c @@ -92,7 +92,7 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix) if (argv[i]) { int j; - pattern = xcalloc(sizeof(const char *), argc - i + 1); + pattern = xcalloc(argc - i + 1, sizeof(const char *)); for (j = i; j < argc; j++) { int len = strlen(argv[j]); char *p = xmalloc(len + 3); diff --git a/builtin/mailinfo.c b/builtin/mailinfo.c index 2c3cd8eab7..cf11c8d607 100644 --- a/builtin/mailinfo.c +++ b/builtin/mailinfo.c @@ -334,7 +334,7 @@ static int check_header(const struct strbuf *line, } if (starts_with(line->buf, "[PATCH]") && isspace(line->buf[7])) { for (i = 0; header[i]; i++) { - if (!memcmp("Subject", header[i], 7)) { + if (!strcmp("Subject", header[i])) { handle_header(&hdr_data[i], line); ret = 1; goto check_header_out; @@ -929,13 +929,13 @@ static void handle_info(void) else continue; - if (!memcmp(header[i], "Subject", 7)) { + if (!strcmp(header[i], "Subject")) { if (!keep_subject) { cleanup_subject(hdr); cleanup_space(hdr); } output_header_lines(fout, "Subject", hdr); - } else if (!memcmp(header[i], "From", 4)) { + } else if (!strcmp(header[i], "From")) { cleanup_space(hdr); handle_from(hdr); fprintf(fout, "Author: %s\n", name.buf); diff --git a/builtin/merge.c b/builtin/merge.c index 428ca247bd..b49c310866 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -852,8 +852,8 @@ static int merge_trivial(struct commit *head, struct commit_list *remoteheads) parent->next->item = remoteheads->item; parent->next->next = NULL; prepare_to_commit(remoteheads); - if (commit_tree(&merge_msg, result_tree, parent, result_commit, NULL, - sign_commit)) + if (commit_tree(merge_msg.buf, merge_msg.len, result_tree, parent, + result_commit, NULL, sign_commit)) die(_("failed to write commit object")); finish(head, remoteheads, result_commit, "In-index merge"); drop_save(); @@ -877,8 +877,8 @@ static int finish_automerge(struct commit *head, commit_list_insert(head, &parents); strbuf_addch(&merge_msg, '\n'); prepare_to_commit(remoteheads); - if (commit_tree(&merge_msg, result_tree, parents, result_commit, - NULL, sign_commit)) + if (commit_tree(merge_msg.buf, merge_msg.len, result_tree, parents, + result_commit, NULL, sign_commit)) die(_("failed to write commit object")); strbuf_addf(&buf, "Merge made by the '%s' strategy.", wt_strategy); finish(head, remoteheads, result_commit, buf.buf); diff --git a/builtin/mv.c b/builtin/mv.c index 2a7243f52e..180ef99127 100644 --- a/builtin/mv.c +++ b/builtin/mv.c @@ -203,7 +203,8 @@ int cmd_mv(int argc, const char **argv, const char *prefix) } } else if (cache_name_pos(src, length) < 0) bad = _("not under version control"); - else if (lstat(dst, &st) == 0) { + else if (lstat(dst, &st) == 0 && + (!ignore_case || strcasecmp(src, dst))) { bad = _("destination exists"); if (force) { /* diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c index de36c60ca1..238b5021eb 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -2214,10 +2214,6 @@ static int git_pack_config(const char *k, const char *v, void *cb) cache_max_small_delta_size = git_config_int(k, v); return 0; } - if (!strcmp(k, "pack.writebitmaps")) { - write_bitmap_index = git_config_bool(k, v); - return 0; - } if (!strcmp(k, "pack.writebitmaphashcache")) { if (git_config_bool(k, v)) write_bitmap_options |= BITMAP_OPT_HASH_CACHE; diff --git a/builtin/patch-id.c b/builtin/patch-id.c index 3cfe02d5a5..77db8739b5 100644 --- a/builtin/patch-id.c +++ b/builtin/patch-id.c @@ -1,17 +1,14 @@ #include "builtin.h" -static void flush_current_id(int patchlen, unsigned char *id, git_SHA_CTX *c) +static void flush_current_id(int patchlen, unsigned char *id, unsigned char *result) { - unsigned char result[20]; char name[50]; if (!patchlen) return; - git_SHA1_Final(result, c); memcpy(name, sha1_to_hex(id), 41); printf("%s %s\n", sha1_to_hex(result), name); - git_SHA1_Init(c); } static int remove_space(char *line) @@ -56,10 +53,31 @@ static int scan_hunk_header(const char *p, int *p_before, int *p_after) return 1; } -static int get_one_patchid(unsigned char *next_sha1, git_SHA_CTX *ctx, struct strbuf *line_buf) +static void flush_one_hunk(unsigned char *result, git_SHA_CTX *ctx) +{ + unsigned char hash[20]; + unsigned short carry = 0; + int i; + + git_SHA1_Final(hash, ctx); + git_SHA1_Init(ctx); + /* 20-byte sum, with carry */ + for (i = 0; i < 20; ++i) { + carry += result[i] + hash[i]; + result[i] = carry; + carry >>= 8; + } +} + +static int get_one_patchid(unsigned char *next_sha1, unsigned char *result, + struct strbuf *line_buf, int stable) { int patchlen = 0, found_next = 0; int before = -1, after = -1; + git_SHA_CTX ctx; + + git_SHA1_Init(&ctx); + hashclr(result); while (strbuf_getwholeline(line_buf, stdin, '\n') != EOF) { char *line = line_buf->buf; @@ -107,6 +125,8 @@ static int get_one_patchid(unsigned char *next_sha1, git_SHA_CTX *ctx, struct st break; /* Else we're parsing another header. */ + if (stable) + flush_one_hunk(result, &ctx); before = after = -1; } @@ -119,39 +139,63 @@ static int get_one_patchid(unsigned char *next_sha1, git_SHA_CTX *ctx, struct st /* Compute the sha without whitespace */ len = remove_space(line); patchlen += len; - git_SHA1_Update(ctx, line, len); + git_SHA1_Update(&ctx, line, len); } if (!found_next) hashclr(next_sha1); + flush_one_hunk(result, &ctx); + return patchlen; } -static void generate_id_list(void) +static void generate_id_list(int stable) { - unsigned char sha1[20], n[20]; - git_SHA_CTX ctx; + unsigned char sha1[20], n[20], result[20]; int patchlen; struct strbuf line_buf = STRBUF_INIT; - git_SHA1_Init(&ctx); hashclr(sha1); while (!feof(stdin)) { - patchlen = get_one_patchid(n, &ctx, &line_buf); - flush_current_id(patchlen, sha1, &ctx); + patchlen = get_one_patchid(n, result, &line_buf, stable); + flush_current_id(patchlen, sha1, result); hashcpy(sha1, n); } strbuf_release(&line_buf); } -static const char patch_id_usage[] = "git patch-id < patch"; +static const char patch_id_usage[] = "git patch-id [--stable | --unstable] < patch"; + +static int git_patch_id_config(const char *var, const char *value, void *cb) +{ + int *stable = cb; + + if (!strcmp(var, "patchid.stable")) { + *stable = git_config_bool(var, value); + return 0; + } + + return git_default_config(var, value, cb); +} int cmd_patch_id(int argc, const char **argv, const char *prefix) { - if (argc != 1) + int stable = -1; + + git_config(git_patch_id_config, &stable); + + /* If nothing is set, default to unstable. */ + if (stable < 0) + stable = 0; + + if (argc == 2 && !strcmp(argv[1], "--stable")) + stable = 1; + else if (argc == 2 && !strcmp(argv[1], "--unstable")) + stable = 0; + else if (argc != 1) usage(patch_id_usage); - generate_id_list(); + generate_id_list(stable); return 0; } diff --git a/builtin/reflog.c b/builtin/reflog.c index c12a9784e6..e8a8fb13b9 100644 --- a/builtin/reflog.c +++ b/builtin/reflog.c @@ -369,7 +369,7 @@ static int expire_reflog(const char *ref, const unsigned char *sha1, int unused, if (!lock) return error("cannot lock ref '%s'", ref); log_file = git_pathdup("logs/%s", ref); - if (!file_exists(log_file)) + if (!reflog_exists(ref)) goto finish; if (!cmd->dry_run) { newlog_path = git_pathdup("logs/%s.lock", ref); diff --git a/builtin/remote.c b/builtin/remote.c index b3ab4cf8f6..c9102e8fe9 100644 --- a/builtin/remote.c +++ b/builtin/remote.c @@ -282,7 +282,7 @@ static int config_read_branches(const char *key, const char *value, void *cb) item = string_list_insert(&branch_list, name); if (!item->util) - item->util = xcalloc(sizeof(struct branch_info), 1); + item->util = xcalloc(1, sizeof(struct branch_info)); info = item->util; if (type == REMOTE) { if (info->remote_name) @@ -398,7 +398,7 @@ static int get_push_ref_states(const struct ref *remote_refs, item = string_list_append(&states->push, abbrev_branch(ref->peer_ref->name)); - item->util = xcalloc(sizeof(struct push_info), 1); + item->util = xcalloc(1, sizeof(struct push_info)); info = item->util; info->forced = ref->force; info->dest = xstrdup(abbrev_branch(ref->name)); @@ -433,7 +433,7 @@ static int get_push_ref_states_noquery(struct ref_states *states) states->push.strdup_strings = 1; if (!remote->push_refspec_nr) { item = string_list_append(&states->push, _("(matching)")); - info = item->util = xcalloc(sizeof(struct push_info), 1); + info = item->util = xcalloc(1, sizeof(struct push_info)); info->status = PUSH_STATUS_NOTQUERIED; info->dest = xstrdup(item->string); } @@ -446,7 +446,7 @@ static int get_push_ref_states_noquery(struct ref_states *states) else item = string_list_append(&states->push, _("(delete)")); - info = item->util = xcalloc(sizeof(struct push_info), 1); + info = item->util = xcalloc(1, sizeof(struct push_info)); info->forced = spec->force; info->status = PUSH_STATUS_NOTQUERIED; info->dest = xstrdup(spec->dst ? spec->dst : item->string); @@ -749,15 +749,23 @@ static int mv(int argc, const char **argv) static int remove_branches(struct string_list *branches) { + const char **branch_names; int i, result = 0; + + branch_names = xmalloc(branches->nr * sizeof(*branch_names)); + for (i = 0; i < branches->nr; i++) + branch_names[i] = branches->items[i].string; + result |= repack_without_refs(branch_names, branches->nr); + free(branch_names); + for (i = 0; i < branches->nr; i++) { struct string_list_item *item = branches->items + i; const char *refname = item->string; - unsigned char *sha1 = item->util; - if (delete_ref(refname, sha1, 0)) + if (delete_ref(refname, NULL, 0)) result |= error(_("Could not remove branch %s"), refname); } + return result; } @@ -789,10 +797,6 @@ static int rm(int argc, const char **argv) known_remotes.to_delete = remote; for_each_remote(add_known_remote, &known_remotes); - strbuf_addf(&buf, "remote.%s", remote->name); - if (git_config_rename_section(buf.buf, NULL) < 1) - return error(_("Could not remove config section '%s'"), buf.buf); - read_branches(); for (i = 0; i < branch_list.nr; i++) { struct string_list_item *item = branch_list.items + i; @@ -837,6 +841,12 @@ static int rm(int argc, const char **argv) } string_list_clear(&skipped, 0); + if (!result) { + strbuf_addf(&buf, "remote.%s", remote->name); + if (git_config_rename_section(buf.buf, NULL) < 1) + return error(_("Could not remove config section '%s'"), buf.buf); + } + return result; } @@ -1303,6 +1313,8 @@ static int prune_remote(const char *remote, int dry_run) { int result = 0, i; struct ref_states states; + struct string_list delete_refs_list = STRING_LIST_INIT_NODUP; + const char **delete_refs; const char *dangling_msg = dry_run ? _(" %s will become dangling!") : _(" %s has become dangling!"); @@ -1316,11 +1328,20 @@ static int prune_remote(const char *remote, int dry_run) states.remote->url_nr ? states.remote->url[0] : _("(no URL)")); + + delete_refs = xmalloc(states.stale.nr * sizeof(*delete_refs)); + for (i = 0; i < states.stale.nr; i++) + delete_refs[i] = states.stale.items[i].util; + if (!dry_run) + result |= repack_without_refs(delete_refs, states.stale.nr); + free(delete_refs); } for (i = 0; i < states.stale.nr; i++) { const char *refname = states.stale.items[i].util; + string_list_insert(&delete_refs_list, refname); + if (!dry_run) result |= delete_ref(refname, NULL, 0); @@ -1330,9 +1351,11 @@ static int prune_remote(const char *remote, int dry_run) else printf_ln(_(" * [pruned] %s"), abbrev_ref(refname, "refs/remotes/")); - warn_dangling_symref(stdout, dangling_msg, refname); } + warn_dangling_symrefs(stdout, dangling_msg, &delete_refs_list); + string_list_clear(&delete_refs_list, 0); + free_remote_ref_states(&states); return result; } diff --git a/builtin/repack.c b/builtin/repack.c index 6b0b62dcb2..ff2216a7aa 100644 --- a/builtin/repack.c +++ b/builtin/repack.c @@ -10,6 +10,7 @@ static int delta_base_offset = 1; static int pack_kept_objects = -1; +static int write_bitmaps; static char *packdir, *packtmp; static const char *const git_repack_usage[] = { @@ -27,6 +28,11 @@ static int repack_config(const char *var, const char *value, void *cb) pack_kept_objects = git_config_bool(var, value); return 0; } + if (!strcmp(var, "repack.writebitmaps") || + !strcmp(var, "pack.writebitmaps")) { + write_bitmaps = git_config_bool(var, value); + return 0; + } return git_default_config(var, value, cb); } @@ -149,7 +155,6 @@ int cmd_repack(int argc, const char **argv, const char *prefix) int no_update_server_info = 0; int quiet = 0; int local = 0; - int write_bitmap = -1; struct option builtin_repack_options[] = { OPT_BIT('a', NULL, &pack_everything, @@ -168,7 +173,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix) OPT__QUIET(&quiet, N_("be quiet")), OPT_BOOL('l', "local", &local, N_("pass --local to git-pack-objects")), - OPT_BOOL('b', "write-bitmap-index", &write_bitmap, + OPT_BOOL('b', "write-bitmap-index", &write_bitmaps, N_("write bitmap index")), OPT_STRING(0, "unpack-unreachable", &unpack_unreachable, N_("approxidate"), N_("with -A, do not loosen objects older than this")), @@ -191,7 +196,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix) git_repack_usage, 0); if (pack_kept_objects < 0) - pack_kept_objects = write_bitmap; + pack_kept_objects = write_bitmaps; packdir = mkpathdup("%s/pack", get_object_directory()); packtmp = mkpathdup("%s/.tmp-%d-pack", packdir, (int)getpid()); @@ -217,9 +222,8 @@ int cmd_repack(int argc, const char **argv, const char *prefix) argv_array_pushf(&cmd_args, "--no-reuse-delta"); if (no_reuse_object) argv_array_pushf(&cmd_args, "--no-reuse-object"); - if (write_bitmap >= 0) - argv_array_pushf(&cmd_args, "--%swrite-bitmap-index", - write_bitmap ? "" : "no-"); + if (write_bitmaps) + argv_array_push(&cmd_args, "--write-bitmap-index"); if (pack_everything & ALL_INTO_ONE) { get_non_kept_pack_filenames(&existing_packs); diff --git a/builtin/replace.c b/builtin/replace.c index b62420a01a..1bb491d3c4 100644 --- a/builtin/replace.c +++ b/builtin/replace.c @@ -12,9 +12,11 @@ #include "builtin.h" #include "refs.h" #include "parse-options.h" +#include "run-command.h" static const char * const git_replace_usage[] = { N_("git replace [-f] <object> <replacement>"), + N_("git replace [-f] --edit <object>"), N_("git replace -d <object>..."), N_("git replace [--format=<format>] [-l [<pattern>]]"), NULL @@ -123,26 +125,36 @@ static int delete_replace_ref(const char *name, const char *ref, return 0; } -static int replace_object(const char *object_ref, const char *replace_ref, - int force) +static void check_ref_valid(unsigned char object[20], + unsigned char prev[20], + char *ref, + int ref_size, + int force) { - unsigned char object[20], prev[20], repl[20]; - enum object_type obj_type, repl_type; - char ref[PATH_MAX]; - struct ref_lock *lock; - - if (get_sha1(object_ref, object)) - die("Failed to resolve '%s' as a valid ref.", object_ref); - if (get_sha1(replace_ref, repl)) - die("Failed to resolve '%s' as a valid ref.", replace_ref); - - if (snprintf(ref, sizeof(ref), + if (snprintf(ref, ref_size, "refs/replace/%s", - sha1_to_hex(object)) > sizeof(ref) - 1) + sha1_to_hex(object)) > ref_size - 1) die("replace ref name too long: %.*s...", 50, ref); if (check_refname_format(ref, 0)) die("'%s' is not a valid ref name.", ref); + if (read_ref(ref, prev)) + hashclr(prev); + else if (!force) + die("replace ref '%s' already exists", ref); +} + +static int replace_object_sha1(const char *object_ref, + unsigned char object[20], + const char *replace_ref, + unsigned char repl[20], + int force) +{ + unsigned char prev[20]; + enum object_type obj_type, repl_type; + char ref[PATH_MAX]; + struct ref_lock *lock; + obj_type = sha1_object_info(object, NULL); repl_type = sha1_object_info(repl, NULL); if (!force && obj_type != repl_type) @@ -152,10 +164,7 @@ static int replace_object(const char *object_ref, const char *replace_ref, object_ref, typename(obj_type), replace_ref, typename(repl_type)); - if (read_ref(ref, prev)) - hashclr(prev); - else if (!force) - die("replace ref '%s' already exists", ref); + check_ref_valid(object, prev, ref, sizeof(ref), force); lock = lock_any_ref_for_update(ref, prev, 0, NULL); if (!lock) @@ -166,13 +175,140 @@ static int replace_object(const char *object_ref, const char *replace_ref, return 0; } +static int replace_object(const char *object_ref, const char *replace_ref, int force) +{ + unsigned char object[20], repl[20]; + + if (get_sha1(object_ref, object)) + die("Failed to resolve '%s' as a valid ref.", object_ref); + if (get_sha1(replace_ref, repl)) + die("Failed to resolve '%s' as a valid ref.", replace_ref); + + return replace_object_sha1(object_ref, object, replace_ref, repl, force); +} + +/* + * Write the contents of the object named by "sha1" to the file "filename", + * pretty-printed for human editing based on its type. + */ +static void export_object(const unsigned char *sha1, const char *filename) +{ + const char *argv[] = { "--no-replace-objects", "cat-file", "-p", NULL, NULL }; + struct child_process cmd = { argv }; + int fd; + + fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0666); + if (fd < 0) + die_errno("unable to open %s for writing", filename); + + argv[3] = sha1_to_hex(sha1); + cmd.git_cmd = 1; + cmd.out = fd; + + if (run_command(&cmd)) + die("cat-file reported failure"); + + close(fd); +} + +/* + * Read a previously-exported (and possibly edited) object back from "filename", + * interpreting it as "type", and writing the result to the object database. + * The sha1 of the written object is returned via sha1. + */ +static void import_object(unsigned char *sha1, enum object_type type, + const char *filename) +{ + int fd; + + fd = open(filename, O_RDONLY); + if (fd < 0) + die_errno("unable to open %s for reading", filename); + + if (type == OBJ_TREE) { + const char *argv[] = { "mktree", NULL }; + struct child_process cmd = { argv }; + struct strbuf result = STRBUF_INIT; + + cmd.argv = argv; + cmd.git_cmd = 1; + cmd.in = fd; + cmd.out = -1; + + if (start_command(&cmd)) + die("unable to spawn mktree"); + + if (strbuf_read(&result, cmd.out, 41) < 0) + die_errno("unable to read from mktree"); + close(cmd.out); + + if (finish_command(&cmd)) + die("mktree reported failure"); + if (get_sha1_hex(result.buf, sha1) < 0) + die("mktree did not return an object name"); + + strbuf_release(&result); + } else { + struct stat st; + int flags = HASH_FORMAT_CHECK | HASH_WRITE_OBJECT; + + if (fstat(fd, &st) < 0) + die_errno("unable to fstat %s", filename); + if (index_fd(sha1, fd, &st, type, NULL, flags) < 0) + die("unable to write object to database"); + /* index_fd close()s fd for us */ + } + + /* + * No need to close(fd) here; both run-command and index-fd + * will have done it for us. + */ +} + +static int edit_and_replace(const char *object_ref, int force) +{ + char *tmpfile = git_pathdup("REPLACE_EDITOBJ"); + enum object_type type; + unsigned char old[20], new[20], prev[20]; + char ref[PATH_MAX]; + + if (get_sha1(object_ref, old) < 0) + die("Not a valid object name: '%s'", object_ref); + + type = sha1_object_info(old, NULL); + if (type < 0) + die("unable to get object type for %s", sha1_to_hex(old)); + + check_ref_valid(old, prev, ref, sizeof(ref), force); + + export_object(old, tmpfile); + if (launch_editor(tmpfile, NULL, NULL) < 0) + die("editing object file failed"); + import_object(new, type, tmpfile); + + free(tmpfile); + + if (!hashcmp(old, new)) + return error("new object is the same as the old one: '%s'", sha1_to_hex(old)); + + return replace_object_sha1(object_ref, old, "replacement", new, force); +} + int cmd_replace(int argc, const char **argv, const char *prefix) { - int list = 0, delete = 0, force = 0; + int force = 0; const char *format = NULL; + enum { + MODE_UNSPECIFIED = 0, + MODE_LIST, + MODE_DELETE, + MODE_EDIT, + MODE_REPLACE + } cmdmode = MODE_UNSPECIFIED; struct option options[] = { - OPT_BOOL('l', "list", &list, N_("list replace refs")), - OPT_BOOL('d', "delete", &delete, N_("delete replace refs")), + OPT_CMDMODE('l', "list", &cmdmode, N_("list replace refs"), MODE_LIST), + OPT_CMDMODE('d', "delete", &cmdmode, N_("delete replace refs"), MODE_DELETE), + OPT_CMDMODE('e', "edit", &cmdmode, N_("edit existing object"), MODE_EDIT), OPT_BOOL('f', "force", &force, N_("replace the ref if it exists")), OPT_STRING(0, "format", &format, N_("format"), N_("use this format")), OPT_END() @@ -182,44 +318,43 @@ int cmd_replace(int argc, const char **argv, const char *prefix) argc = parse_options(argc, argv, prefix, options, git_replace_usage, 0); - if (list && delete) - usage_msg_opt("-l and -d cannot be used together", - git_replace_usage, options); + if (!cmdmode) + cmdmode = argc ? MODE_REPLACE : MODE_LIST; - if (format && delete) - usage_msg_opt("--format and -d cannot be used together", + if (format && cmdmode != MODE_LIST) + usage_msg_opt("--format cannot be used when not listing", git_replace_usage, options); - if (force && (list || delete)) - usage_msg_opt("-f cannot be used with -d or -l", + if (force && cmdmode != MODE_REPLACE && cmdmode != MODE_EDIT) + usage_msg_opt("-f only makes sense when writing a replacement", git_replace_usage, options); - /* Delete refs */ - if (delete) { + switch (cmdmode) { + case MODE_DELETE: if (argc < 1) usage_msg_opt("-d needs at least one argument", git_replace_usage, options); return for_each_replace_name(argv, delete_replace_ref); - } - /* Replace object */ - if (!list && argc) { + case MODE_REPLACE: if (argc != 2) usage_msg_opt("bad number of arguments", git_replace_usage, options); - if (format) - usage_msg_opt("--format cannot be used when not listing", - git_replace_usage, options); return replace_object(argv[0], argv[1], force); - } - /* List refs, even if "list" is not set */ - if (argc > 1) - usage_msg_opt("only one pattern can be given with -l", - git_replace_usage, options); - if (force) - usage_msg_opt("-f needs some arguments", - git_replace_usage, options); + case MODE_EDIT: + if (argc != 1) + usage_msg_opt("-e needs exactly one argument", + git_replace_usage, options); + return edit_and_replace(argv[0], force); + + case MODE_LIST: + if (argc > 1) + usage_msg_opt("only one pattern can be given with -l", + git_replace_usage, options); + return list_replace_refs(argv[0], format); - return list_replace_refs(argv[0], format); + default: + die("BUG: invalid cmdmode %d", (int)cmdmode); + } } diff --git a/builtin/reset.c b/builtin/reset.c index f368266762..850d53229a 100644 --- a/builtin/reset.c +++ b/builtin/reset.c @@ -93,7 +93,7 @@ static int reset_index(const unsigned char *sha1, int reset_type, int quiet) static void print_new_head_line(struct commit *commit) { const char *hex, *body; - char *msg; + const char *msg; hex = find_unique_abbrev(commit->object.sha1, DEFAULT_ABBREV); printf(_("HEAD is now at %s"), hex); @@ -109,7 +109,7 @@ static void print_new_head_line(struct commit *commit) } else printf("\n"); - logmsg_free(msg, commit); + unuse_commit_buffer(commit, msg); } static void update_index_from_diff(struct diff_queue_struct *q, diff --git a/builtin/rev-list.c b/builtin/rev-list.c index 9f92905379..ff84a825ff 100644 --- a/builtin/rev-list.c +++ b/builtin/rev-list.c @@ -106,7 +106,7 @@ static void show_commit(struct commit *commit, void *data) else putchar('\n'); - if (revs->verbose_header && commit->buffer) { + if (revs->verbose_header && get_cached_commit_buffer(commit, NULL)) { struct strbuf buf = STRBUF_INIT; struct pretty_print_context ctx = {0}; ctx.abbrev = revs->abbrev; @@ -173,8 +173,7 @@ static void finish_commit(struct commit *commit, void *data) free_commit_list(commit->parents); commit->parents = NULL; } - free(commit->buffer); - commit->buffer = NULL; + free_commit_buffer(commit); } static void finish_object(struct object *obj, diff --git a/builtin/tag.c b/builtin/tag.c index f3440023ab..ef76556338 100644 --- a/builtin/tag.c +++ b/builtin/tag.c @@ -83,7 +83,7 @@ static int in_commit_list(const struct commit_list *want, struct commit *c) enum contains_result { CONTAINS_UNKNOWN = -1, CONTAINS_NO = 0, - CONTAINS_YES = 1, + CONTAINS_YES = 1 }; /* @@ -338,11 +338,11 @@ static int do_sign(struct strbuf *buffer) } static const char tag_template[] = - N_("\nWrite a tag message\n" + N_("\nWrite a message for tag:\n %s\n" "Lines starting with '%c' will be ignored.\n"); static const char tag_template_nocleanup[] = - N_("\nWrite a tag message\n" + N_("\nWrite a message for tag:\n %s\n" "Lines starting with '%c' will be kept; you may remove them" " yourself if you want to.\n"); @@ -438,9 +438,9 @@ static void create_tag(const unsigned char *object, const char *tag, struct strbuf buf = STRBUF_INIT; strbuf_addch(&buf, '\n'); if (opt->cleanup_mode == CLEANUP_ALL) - strbuf_commented_addf(&buf, _(tag_template), comment_line_char); + strbuf_commented_addf(&buf, _(tag_template), tag, comment_line_char); else - strbuf_commented_addf(&buf, _(tag_template_nocleanup), comment_line_char); + strbuf_commented_addf(&buf, _(tag_template_nocleanup), tag, comment_line_char); write_or_die(fd, buf.buf, buf.len); strbuf_release(&buf); } diff --git a/builtin/update-index.c b/builtin/update-index.c index ba54e19cd5..ebea285e1b 100644 --- a/builtin/update-index.c +++ b/builtin/update-index.c @@ -637,6 +637,9 @@ static int parse_new_style_cacheinfo(const char *arg, unsigned long ul; char *endp; + if (!arg) + return -1; + errno = 0; ul = strtoul(arg, &endp, 8); if (errno || endp == arg || *endp != ',' || (unsigned int) ul != ul) @@ -618,6 +618,7 @@ extern int precomposed_unicode; * that is subject to stripspace. */ extern char comment_line_char; +extern int auto_comment_line_char; enum branch_track { BRANCH_TRACK_UNSPECIFIED = -1, @@ -825,7 +826,6 @@ int normalize_path_copy(char *dst, const char *src); int longest_ancestor_length(const char *path, struct string_list *prefixes); char *strip_path_suffix(const char *path, const char *suffix); int daemon_avoid_alias(const char *path); -int offset_1st_component(const char *path); /* object replacement */ #define LOOKUP_REPLACE_OBJECT 1 @@ -999,7 +999,7 @@ extern int validate_headref(const char *ref); extern int base_name_compare(const char *name1, int len1, int mode1, const char *name2, int len2, int mode2); extern int df_name_compare(const char *name1, int len1, int mode1, const char *name2, int len2, int mode2); -extern int cache_name_compare(const char *name1, int len1, const char *name2, int len2); +extern int name_compare(const char *name1, size_t len1, const char *name2, size_t len2); extern int cache_name_stage_compare(const char *name1, int len1, int stage1, const char *name2, int len2, int stage2); extern void *read_object_with_reference(const unsigned char *sha1, @@ -1294,8 +1294,8 @@ extern int check_repository_format_version(const char *var, const char *value, v extern int git_env_bool(const char *, int); extern int git_config_system(void); extern int config_error_nonbool(const char *); -#if defined(__GNUC__) && ! defined(__clang__) -#define config_error_nonbool(s) (config_error_nonbool(s), -1) +#if defined(__GNUC__) +#define config_error_nonbool(s) (config_error_nonbool(s), const_error()) #endif extern const char *get_log_output_encoding(void); extern const char *get_commit_output_encoding(void); diff --git a/check_bindir b/check_bindir index a1c4c3e8d8..623eadcbb7 100755 --- a/check_bindir +++ b/check_bindir @@ -2,7 +2,7 @@ bindir="$1" gitexecdir="$2" gitcmd="$3" -if test "$bindir" != "$gitexecdir" -a -x "$gitcmd" +if test "$bindir" != "$gitexecdir" && test -x "$gitcmd" then echo echo "!! You have installed git-* commands to new gitexecdir." @@ -370,46 +370,29 @@ static struct child_process column_process; int run_column_filter(int colopts, const struct column_options *opts) { - const char *av[10]; - int ret, ac = 0; - struct strbuf sb_colopt = STRBUF_INIT; - struct strbuf sb_width = STRBUF_INIT; - struct strbuf sb_padding = STRBUF_INIT; + struct argv_array *argv; if (fd_out != -1) return -1; - av[ac++] = "column"; - strbuf_addf(&sb_colopt, "--raw-mode=%d", colopts); - av[ac++] = sb_colopt.buf; - if (opts && opts->width) { - strbuf_addf(&sb_width, "--width=%d", opts->width); - av[ac++] = sb_width.buf; - } - if (opts && opts->indent) { - av[ac++] = "--indent"; - av[ac++] = opts->indent; - } - if (opts && opts->padding) { - strbuf_addf(&sb_padding, "--padding=%d", opts->padding); - av[ac++] = sb_padding.buf; - } - av[ac] = NULL; + memset(&column_process, 0, sizeof(column_process)); + argv = &column_process.args; + + argv_array_push(argv, "column"); + argv_array_pushf(argv, "--raw-mode=%d", colopts); + if (opts && opts->width) + argv_array_pushf(argv, "--width=%d", opts->width); + if (opts && opts->indent) + argv_array_pushf(argv, "--indent=%s", opts->indent); + if (opts && opts->padding) + argv_array_pushf(argv, "--padding=%d", opts->padding); fflush(stdout); - memset(&column_process, 0, sizeof(column_process)); column_process.in = -1; column_process.out = dup(1); column_process.git_cmd = 1; - column_process.argv = av; - - ret = start_command(&column_process); - - strbuf_release(&sb_colopt); - strbuf_release(&sb_width); - strbuf_release(&sb_padding); - if (ret) + if (start_command(&column_process)) return -2; fd_out = dup(1); diff --git a/combine-diff.c b/combine-diff.c index 12764fb733..f9975d2c2e 100644 --- a/combine-diff.c +++ b/combine-diff.c @@ -1396,7 +1396,8 @@ void diff_tree_combined(const unsigned char *sha1, if (show_log_first) { show_log(rev); - if (rev->verbose_header && opt->output_format) + if (rev->verbose_header && opt->output_format && + opt->output_format != DIFF_FORMAT_NO_OUTPUT) printf("%s%c", diff_line_prefix(opt), opt->line_termination); } diff --git a/commit-slab.h b/commit-slab.h index cc114b53b0..375c9c751a 100644 --- a/commit-slab.h +++ b/commit-slab.h @@ -117,4 +117,16 @@ static int stat_ ##slabname## realloc * catch because GCC silently parses it by default. */ +/* + * Statically initialize a commit slab named "var". Note that this + * evaluates "stride" multiple times! Example: + * + * struct indegree indegrees = COMMIT_SLAB_INIT(1, indegrees); + * + */ +#define COMMIT_SLAB_INIT(stride, var) { \ + COMMIT_SLAB_SIZE / sizeof(**((var).slab)) / (stride), \ + (stride), 0, NULL \ +} + #endif /* COMMIT_SLAB_H */ @@ -17,7 +17,6 @@ static struct commit_extra_header *read_commit_extra_header_lines(const char *bu int save_commit_buffer = 1; const char *commit_type = "commit"; -static int commit_count; static struct commit *check_commit(struct object *obj, const unsigned char *sha1, @@ -64,7 +63,6 @@ struct commit *lookup_commit(const unsigned char *sha1) struct object *obj = lookup_object(sha1); if (!obj) { struct commit *c = alloc_commit_node(); - c->index = commit_count++; return create_object(sha1, OBJ_COMMIT, c); } if (!obj->type) @@ -247,6 +245,76 @@ int unregister_shallow(const unsigned char *sha1) return 0; } +struct commit_buffer { + void *buffer; + unsigned long size; +}; +define_commit_slab(buffer_slab, struct commit_buffer); +static struct buffer_slab buffer_slab = COMMIT_SLAB_INIT(1, buffer_slab); + +void set_commit_buffer(struct commit *commit, void *buffer, unsigned long size) +{ + struct commit_buffer *v = buffer_slab_at(&buffer_slab, commit); + v->buffer = buffer; + v->size = size; +} + +const void *get_cached_commit_buffer(const struct commit *commit, unsigned long *sizep) +{ + struct commit_buffer *v = buffer_slab_at(&buffer_slab, commit); + if (sizep) + *sizep = v->size; + return v->buffer; +} + +const void *get_commit_buffer(const struct commit *commit, unsigned long *sizep) +{ + const void *ret = get_cached_commit_buffer(commit, sizep); + if (!ret) { + enum object_type type; + unsigned long size; + ret = read_sha1_file(commit->object.sha1, &type, &size); + if (!ret) + die("cannot read commit object %s", + sha1_to_hex(commit->object.sha1)); + if (type != OBJ_COMMIT) + die("expected commit for %s, got %s", + sha1_to_hex(commit->object.sha1), typename(type)); + if (sizep) + *sizep = size; + } + return ret; +} + +void unuse_commit_buffer(const struct commit *commit, const void *buffer) +{ + struct commit_buffer *v = buffer_slab_at(&buffer_slab, commit); + if (v->buffer != buffer) + free((void *)buffer); +} + +void free_commit_buffer(struct commit *commit) +{ + struct commit_buffer *v = buffer_slab_at(&buffer_slab, commit); + free(v->buffer); + v->buffer = NULL; + v->size = 0; +} + +const void *detach_commit_buffer(struct commit *commit, unsigned long *sizep) +{ + struct commit_buffer *v = buffer_slab_at(&buffer_slab, commit); + void *ret; + + ret = v->buffer; + if (sizep) + *sizep = v->size; + + v->buffer = NULL; + v->size = 0; + return ret; +} + int parse_commit_buffer(struct commit *item, const void *buffer, unsigned long size) { const char *tail = buffer; @@ -324,7 +392,7 @@ int parse_commit(struct commit *item) } ret = parse_commit_buffer(item, buffer, size); if (save_commit_buffer && !ret) { - item->buffer = buffer; + set_commit_buffer(item, buffer, size); return 0; } free(buffer); @@ -539,22 +607,12 @@ static void record_author_date(struct author_date_slab *author_date, struct commit *commit) { const char *buf, *line_end, *ident_line; - char *buffer = NULL; + const char *buffer = get_commit_buffer(commit, NULL); struct ident_split ident; char *date_end; unsigned long date; - if (!commit->buffer) { - unsigned long size; - enum object_type type; - buffer = read_sha1_file(commit->object.sha1, &type, &size); - if (!buffer) - return; - } - - for (buf = commit->buffer ? commit->buffer : buffer; - buf; - buf = line_end + 1) { + for (buf = buffer; buf; buf = line_end + 1) { line_end = strchrnul(buf, '\n'); ident_line = skip_prefix(buf, "author "); if (!ident_line) { @@ -575,7 +633,7 @@ static void record_author_date(struct author_date_slab *author_date, *(author_date_slab_at(author_date, commit)) = date; fail_exit: - free(buffer); + unuse_commit_buffer(commit, buffer); } static int compare_commits_by_author_date(const void *a_, const void *b_, @@ -1031,7 +1089,7 @@ struct commit_list *reduce_heads(struct commit_list *heads) p->item->object.flags |= STALE; num_head++; } - array = xcalloc(sizeof(*array), num_head); + array = xcalloc(num_head, sizeof(*array)); for (p = heads, i = 0; p; p = p->next) { if (p->item->object.flags & STALE) { array[i++] = p->item; @@ -1080,17 +1138,14 @@ static int do_sign_commit(struct strbuf *buf, const char *keyid) return 0; } -int parse_signed_commit(const unsigned char *sha1, +int parse_signed_commit(const struct commit *commit, struct strbuf *payload, struct strbuf *signature) { + unsigned long size; - enum object_type type; - char *buffer = read_sha1_file(sha1, &type, &size); + const char *buffer = get_commit_buffer(commit, &size); int in_signature, saw_signature = -1; - char *line, *tail; - - if (!buffer || type != OBJ_COMMIT) - goto cleanup; + const char *line, *tail; line = buffer; tail = buffer + size; @@ -1098,7 +1153,7 @@ int parse_signed_commit(const unsigned char *sha1, saw_signature = 0; while (line < tail) { const char *sig = NULL; - char *next = memchr(line, '\n', tail - line); + const char *next = memchr(line, '\n', tail - line); next = next ? next + 1 : tail; if (in_signature && line[0] == ' ') @@ -1119,8 +1174,7 @@ int parse_signed_commit(const unsigned char *sha1, } line = next; } - cleanup: - free(buffer); + unuse_commit_buffer(commit, buffer); return saw_signature; } @@ -1211,8 +1265,7 @@ void check_commit_signature(const struct commit* commit, struct signature_check sigc->result = 'N'; - if (parse_signed_commit(commit->object.sha1, - &payload, &signature) <= 0) + if (parse_signed_commit(commit, &payload, &signature) <= 0) goto out; status = verify_signed_buffer(payload.buf, payload.len, signature.buf, signature.len, @@ -1257,11 +1310,9 @@ struct commit_extra_header *read_commit_extra_headers(struct commit *commit, { struct commit_extra_header *extra = NULL; unsigned long size; - enum object_type type; - char *buffer = read_sha1_file(commit->object.sha1, &type, &size); - if (buffer && type == OBJ_COMMIT) - extra = read_commit_extra_header_lines(buffer, size, exclude); - free(buffer); + const char *buffer = get_commit_buffer(commit, &size); + extra = read_commit_extra_header_lines(buffer, size, exclude); + unuse_commit_buffer(commit, buffer); return extra; } @@ -1344,7 +1395,8 @@ void free_commit_extra_headers(struct commit_extra_header *extra) } } -int commit_tree(const struct strbuf *msg, const unsigned char *tree, +int commit_tree(const char *msg, size_t msg_len, + const unsigned char *tree, struct commit_list *parents, unsigned char *ret, const char *author, const char *sign_commit) { @@ -1352,7 +1404,7 @@ int commit_tree(const struct strbuf *msg, const unsigned char *tree, int result; append_merge_tag_headers(parents, &tail); - result = commit_tree_extended(msg, tree, parents, ret, + result = commit_tree_extended(msg, msg_len, tree, parents, ret, author, sign_commit, extra); free_commit_extra_headers(extra); return result; @@ -1473,7 +1525,8 @@ static const char commit_utf8_warn[] = "You may want to amend it after fixing the message, or set the config\n" "variable i18n.commitencoding to the encoding your project uses.\n"; -int commit_tree_extended(const struct strbuf *msg, const unsigned char *tree, +int commit_tree_extended(const char *msg, size_t msg_len, + const unsigned char *tree, struct commit_list *parents, unsigned char *ret, const char *author, const char *sign_commit, struct commit_extra_header *extra) @@ -1484,7 +1537,7 @@ int commit_tree_extended(const struct strbuf *msg, const unsigned char *tree, assert_sha1_type(tree, OBJ_TREE); - if (memchr(msg->buf, '\0', msg->len)) + if (memchr(msg, '\0', msg_len)) return error("a NUL byte in commit log message not allowed."); /* Not having i18n.commitencoding is the same as having utf-8 */ @@ -1523,7 +1576,7 @@ int commit_tree_extended(const struct strbuf *msg, const unsigned char *tree, strbuf_addch(&buffer, '\n'); /* And add the comment */ - strbuf_addbuf(&buffer, msg); + strbuf_add(&buffer, msg, msg_len); /* And check the encoding */ if (encoding_is_utf8 && !verify_utf8(&buffer)) @@ -20,7 +20,6 @@ struct commit { unsigned long date; struct commit_list *parents; struct tree *tree; - char *buffer; }; extern int save_commit_buffer; @@ -51,6 +50,44 @@ int parse_commit_buffer(struct commit *item, const void *buffer, unsigned long s int parse_commit(struct commit *item); void parse_commit_or_die(struct commit *item); +/* + * Associate an object buffer with the commit. The ownership of the + * memory is handed over to the commit, and must be free()-able. + */ +void set_commit_buffer(struct commit *, void *buffer, unsigned long size); + +/* + * Get any cached object buffer associated with the commit. Returns NULL + * if none. The resulting memory should not be freed. + */ +const void *get_cached_commit_buffer(const struct commit *, unsigned long *size); + +/* + * Get the commit's object contents, either from cache or by reading the object + * from disk. The resulting memory should not be modified, and must be given + * to unuse_commit_buffer when the caller is done. + */ +const void *get_commit_buffer(const struct commit *, unsigned long *size); + +/* + * Tell the commit subsytem that we are done with a particular commit buffer. + * The commit and buffer should be the input and return value, respectively, + * from an earlier call to get_commit_buffer. The buffer may or may not be + * freed by this call; callers should not access the memory afterwards. + */ +void unuse_commit_buffer(const struct commit *, const void *buffer); + +/* + * Free any cached object buffer associated with the commit. + */ +void free_commit_buffer(struct commit *); + +/* + * Disassociate any cached object buffer from the commit, but do not free it. + * The buffer (or NULL, if none) is returned. + */ +const void *detach_commit_buffer(struct commit *, unsigned long *sizep); + /* Find beginning and length of commit subject. */ int find_commit_subject(const char *commit_buffer, const char **subject); @@ -115,10 +152,9 @@ struct userformat_want { extern int has_non_ascii(const char *text); struct rev_info; /* in revision.h, it circularly uses enum cmit_fmt */ -extern char *logmsg_reencode(const struct commit *commit, - char **commit_encoding, - const char *output_encoding); -extern void logmsg_free(char *msg, const struct commit *commit); +extern const char *logmsg_reencode(const struct commit *commit, + char **commit_encoding, + const char *output_encoding); extern void get_commit_format(const char *arg, struct rev_info *); extern const char *format_subject(struct strbuf *sb, const char *msg, const char *line_separator); @@ -261,11 +297,13 @@ struct commit_extra_header { extern void append_merge_tag_headers(struct commit_list *parents, struct commit_extra_header ***tail); -extern int commit_tree(const struct strbuf *msg, const unsigned char *tree, +extern int commit_tree(const char *msg, size_t msg_len, + const unsigned char *tree, struct commit_list *parents, unsigned char *ret, const char *author, const char *sign_commit); -extern int commit_tree_extended(const struct strbuf *msg, const unsigned char *tree, +extern int commit_tree_extended(const char *msg, size_t msg_len, + const unsigned char *tree, struct commit_list *parents, unsigned char *ret, const char *author, const char *sign_commit, struct commit_extra_header *); @@ -287,7 +325,7 @@ struct merge_remote_desc { */ struct commit *get_merge_parent(const char *name); -extern int parse_signed_commit(const unsigned char *sha1, +extern int parse_signed_commit(const struct commit *commit, struct strbuf *message, struct strbuf *signature); extern void print_commit_list(struct commit_list *list, const char *format_cur, diff --git a/compat/bswap.h b/compat/bswap.h index 120c6c1d37..f6fd9a6a6c 100644 --- a/compat/bswap.h +++ b/compat/bswap.h @@ -101,19 +101,34 @@ static inline uint64_t git_bswap64(uint64_t x) #undef ntohll #undef htonll -#if !defined(__BYTE_ORDER) -# if defined(BYTE_ORDER) && defined(LITTLE_ENDIAN) && defined(BIG_ENDIAN) -# define __BYTE_ORDER BYTE_ORDER -# define __LITTLE_ENDIAN LITTLE_ENDIAN -# define __BIG_ENDIAN BIG_ENDIAN +#if defined(__BYTE_ORDER) && defined(__LITTLE_ENDIAN) && defined(__BIG_ENDIAN) + +# define GIT_BYTE_ORDER __BYTE_ORDER +# define GIT_LITTLE_ENDIAN __LITTLE_ENDIAN +# define GIT_BIG_ENDIAN __BIG_ENDIAN + +#elif defined(BYTE_ORDER) && defined(LITTLE_ENDIAN) && defined(BIG_ENDIAN) + +# define GIT_BYTE_ORDER BYTE_ORDER +# define GIT_LITTLE_ENDIAN LITTLE_ENDIAN +# define GIT_BIG_ENDIAN BIG_ENDIAN + +#else + +# define GIT_BIG_ENDIAN 4321 +# define GIT_LITTLE_ENDIAN 1234 + +# if defined(_BIG_ENDIAN) && !defined(_LITTLE_ENDIAN) +# define GIT_BYTE_ORDER GIT_BIG_ENDIAN +# elif defined(_LITTLE_ENDIAN) && !defined(_BIG_ENDIAN) +# define GIT_BYTE_ORDER GIT_LITTLE_ENDIAN +# else +# error "Cannot determine endianness" # endif -#endif -#if !defined(__BYTE_ORDER) -# error "Cannot determine endianness" #endif -#if __BYTE_ORDER == __BIG_ENDIAN +#if GIT_BYTE_ORDER == GIT_BIG_ENDIAN # define ntohll(n) (n) # define htonll(n) (n) #else diff --git a/compat/mingw.c b/compat/mingw.c index e9892f8ee4..a0e13bc862 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -1823,3 +1823,27 @@ pid_t waitpid(pid_t pid, int *status, int options) errno = EINVAL; return -1; } + +int mingw_offset_1st_component(const char *path) +{ + int offset = 0; + if (has_dos_drive_prefix(path)) + offset = 2; + + /* unc paths */ + else if (is_dir_sep(path[0]) && is_dir_sep(path[1])) { + + /* skip server name */ + char *pos = strpbrk(path + 2, "\\/"); + if (!pos) + return 0; /* Error: malformed unc path */ + + do { + pos++; + } while (*pos && !is_dir_sep(*pos)); + + offset = pos - path; + } + + return offset + is_dir_sep(path[offset]); +} diff --git a/compat/mingw.h b/compat/mingw.h index e033e720c9..3eaf822e28 100644 --- a/compat/mingw.h +++ b/compat/mingw.h @@ -339,6 +339,8 @@ static inline char *mingw_find_last_dir_sep(const char *path) return ret; } #define find_last_dir_sep mingw_find_last_dir_sep +int mingw_offset_1st_component(const char *path); +#define offset_1st_component mingw_offset_1st_component #define PATH_SEP ';' #define PRIuMAX "I64u" #define PRId64 "I64d" diff --git a/compat/poll/poll.c b/compat/poll/poll.c index 31163f2ae7..a9b41d89f4 100644 --- a/compat/poll/poll.c +++ b/compat/poll/poll.c @@ -605,7 +605,7 @@ restart: if (!rc && timeout == INFTIM) { - SwitchToThread(); + SleepEx (1, TRUE); goto restart; } @@ -147,12 +147,6 @@ int git_config_include(const char *var, const char *value, void *data) return ret; } -static void lowercase(char *p) -{ - for (; *p; p++) - *p = tolower(*p); -} - void git_config_push_parameter(const char *text) { struct strbuf env = STRBUF_INIT; @@ -180,7 +174,7 @@ int git_config_parse_parameter(const char *text, strbuf_list_free(pair); return error("bogus config parameter: %s", text); } - lowercase(pair[0]->buf); + strbuf_tolower(pair[0]); if (fn(pair[0]->buf, pair[1] ? pair[1]->buf : NULL, data) < 0) { strbuf_list_free(pair); return -1; @@ -826,9 +820,16 @@ static int git_default_core_config(const char *var, const char *value) if (!strcmp(var, "core.commentchar")) { const char *comment; int ret = git_config_string(&comment, var, value); - if (!ret) + if (ret) + return ret; + else if (!strcasecmp(comment, "auto")) + auto_comment_line_char = 1; + else if (comment[0] && !comment[1]) { comment_line_char = comment[0]; - return ret; + auto_comment_line_char = 0; + } else + return error("core.commentChar should only be one character"); + return 0; } if (!strcmp(var, "core.askpass")) @@ -952,7 +953,7 @@ static int git_default_push_config(const char *var, const char *value) static int git_default_mailmap_config(const char *var, const char *value) { if (!strcmp(var, "mailmap.file")) - return git_config_string(&git_mailmap_file, var, value); + return git_config_pathname(&git_mailmap_file, var, value); if (!strcmp(var, "mailmap.blob")) return git_config_string(&git_mailmap_blob, var, value); @@ -1538,7 +1539,7 @@ int git_config_set_multivar_in_file(const char *config_filename, * The lock serves a purpose in addition to locking: the new * contents of .git/config will be written into it. */ - lock = xcalloc(sizeof(struct lock_file), 1); + lock = xcalloc(1, sizeof(struct lock_file)); fd = hold_lock_file_for_update(lock, config_filename, 0); if (fd < 0) { error("could not lock config file %s: %s", config_filename, strerror(errno)); @@ -1801,7 +1802,7 @@ int git_config_rename_section_in_file(const char *config_filename, if (!config_filename) config_filename = filename_buf = git_pathdup("config"); - lock = xcalloc(sizeof(struct lock_file), 1); + lock = xcalloc(1, sizeof(struct lock_file)); out_fd = hold_lock_file_for_update(lock, config_filename, 0); if (out_fd < 0) { ret = error("could not lock config file %s", config_filename); @@ -534,22 +534,18 @@ static int git_use_proxy(const char *host) static struct child_process *git_proxy_connect(int fd[2], char *host) { const char *port = STR(DEFAULT_GIT_PORT); - const char **argv; struct child_process *proxy; get_host_and_port(&host, &port); - argv = xmalloc(sizeof(*argv) * 4); - argv[0] = git_proxy_command; - argv[1] = host; - argv[2] = port; - argv[3] = NULL; proxy = xcalloc(1, sizeof(*proxy)); - proxy->argv = argv; + argv_array_push(&proxy->args, git_proxy_command); + argv_array_push(&proxy->args, host); + argv_array_push(&proxy->args, port); proxy->in = -1; proxy->out = -1; if (start_command(proxy)) - die("cannot start proxy %s", argv[0]); + die("cannot start proxy %s", git_proxy_command); fd[0] = proxy->out; /* read from proxy stdout */ fd[1] = proxy->in; /* write to proxy stdin */ return proxy; @@ -663,7 +659,6 @@ struct child_process *git_connect(int fd[2], const char *url, char *hostandport, *path; struct child_process *conn = &no_fork; enum protocol protocol; - const char **arg; struct strbuf cmd = STRBUF_INIT; /* Without this we cannot rely on waitpid() to tell @@ -707,7 +702,6 @@ struct child_process *git_connect(int fd[2], const char *url, sq_quote_buf(&cmd, path); conn->in = conn->out = -1; - conn->argv = arg = xcalloc(7, sizeof(*arg)); if (protocol == PROTO_SSH) { const char *ssh = getenv("GIT_SSH"); int putty = ssh && strcasestr(ssh, "plink"); @@ -718,22 +712,21 @@ struct child_process *git_connect(int fd[2], const char *url, if (!ssh) ssh = "ssh"; - *arg++ = ssh; + argv_array_push(&conn->args, ssh); if (putty && !strcasestr(ssh, "tortoiseplink")) - *arg++ = "-batch"; + argv_array_push(&conn->args, "-batch"); if (port) { /* P is for PuTTY, p is for OpenSSH */ - *arg++ = putty ? "-P" : "-p"; - *arg++ = port; + argv_array_push(&conn->args, putty ? "-P" : "-p"); + argv_array_push(&conn->args, port); } - *arg++ = ssh_host; + argv_array_push(&conn->args, ssh_host); } else { /* remove repo-local variables from the environment */ conn->env = local_repo_env; conn->use_shell = 1; } - *arg++ = cmd.buf; - *arg = NULL; + argv_array_push(&conn->args, cmd.buf); if (start_command(conn)) die("unable to fork"); @@ -759,7 +752,6 @@ int finish_connect(struct child_process *conn) return 0; code = finish_command(conn); - free(conn->argv); free(conn); return code; } diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 2c59a76bc2..7a6e1d797a 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -21,6 +21,12 @@ # source ~/.git-completion.sh # 3) Consider changing your PS1 to also show the current branch, # see git-prompt.sh for details. +# +# If you use complex aliases of form '!f() { ... }; f', you can use the null +# command ':' as the first command in the function body to declare the desired +# completion style. For example '!f() { : git commit ; ... }; f' will +# tell the completion to use commit completion. This also works with aliases +# of form "!sh -c '...'". For example, "!sh -c ': git commit ; ... '". case "$COMP_WORDBREAKS" in *:*) : great ;; @@ -781,6 +787,10 @@ __git_aliased_command () -*) : option ;; *=*) : setting env ;; git) : git itself ;; + \(\)) : skip parens of shell function definition ;; + {) : skip start of shell helper function ;; + :) : skip null command ;; + \'*) : skip opening quote after sh -c ;; *) echo "$word" return @@ -1472,9 +1482,12 @@ _git_log () __git_complete_revlist } +# Common merge options shared by git-merge(1) and git-pull(1). __git_merge_options=" --no-commit --no-stat --log --no-log --squash --strategy --commit --stat --no-squash --ff --no-ff --ff-only --edit --no-edit + --verify-signatures --no-verify-signatures --gpg-sign + --quiet --verbose --progress --no-progress " _git_merge () @@ -1483,7 +1496,8 @@ _git_merge () case "$cur" in --*) - __gitcomp "$__git_merge_options" + __gitcomp "$__git_merge_options + --rerere-autoupdate --no-rerere-autoupdate --abort" return esac __gitcomp_nl "$(__git_refs)" diff --git a/contrib/credential/wincred/Makefile b/contrib/credential/wincred/Makefile index bad45ca47a..6e992c0866 100644 --- a/contrib/credential/wincred/Makefile +++ b/contrib/credential/wincred/Makefile @@ -1,14 +1,22 @@ all: git-credential-wincred.exe -CC = gcc -RM = rm -f -CFLAGS = -O2 -Wall - -include ../../../config.mak.autogen -include ../../../config.mak +CC ?= gcc +RM ?= rm -f +CFLAGS ?= -O2 -Wall + +prefix ?= /usr/local +libexecdir ?= $(prefix)/libexec/git-core + +INSTALL ?= install + git-credential-wincred.exe : git-credential-wincred.c $(LINK.c) $^ $(LOADLIBES) $(LDLIBS) -o $@ +install: git-credential-wincred.exe + $(INSTALL) -m 755 $^ $(libexecdir) + clean: $(RM) git-credential-wincred.exe diff --git a/contrib/diffall/README b/contrib/diffall/README deleted file mode 100644 index 507f17dcd6..0000000000 --- a/contrib/diffall/README +++ /dev/null @@ -1,31 +0,0 @@ -The git-diffall script provides a directory based diff mechanism -for git. - -To determine what diff viewer is used, the script requires either -the 'diff.tool' or 'merge.tool' configuration option to be set. - -This script is compatible with most common forms used to specify a -range of revisions to diff: - - 1. git diffall: shows diff between working tree and staged changes - 2. git diffall --cached [<commit>]: shows diff between staged - changes and HEAD (or other named commit) - 3. git diffall <commit>: shows diff between working tree and named - commit - 4. git diffall <commit> <commit>: show diff between two named commits - 5. git diffall <commit>..<commit>: same as above - 6. git diffall <commit>...<commit>: show the changes on the branch - containing and up to the second, starting at a common ancestor - of both <commit> - -Note: all forms take an optional path limiter [-- <path>*] - -The '--extcmd=<command>' option allows the user to specify a custom -command for viewing diffs. When given, configured defaults are -ignored and the script runs $command $LOCAL $REMOTE. Additionally, -$BASE is set in the environment. - -This script is based on an example provided by Thomas Rast on the -Git list [1]: - -[1] http://thread.gmane.org/gmane.comp.version-control.git/124807 diff --git a/contrib/diffall/git-diffall b/contrib/diffall/git-diffall deleted file mode 100755 index 84f2b654d7..0000000000 --- a/contrib/diffall/git-diffall +++ /dev/null @@ -1,257 +0,0 @@ -#!/bin/sh -# Copyright 2010 - 2012, Tim Henigan <tim.henigan@gmail.com> -# -# Perform a directory diff between commits in the repository using -# the external diff or merge tool specified in the user's config. - -USAGE='[--cached] [--copy-back] [-x|--extcmd=<command>] <commit>{0,2} [-- <path>*] - - --cached Compare to the index rather than the working tree. - - --copy-back Copy files back to the working tree when the diff - tool exits (in case they were modified by the - user). This option is only valid if the diff - compared with the working tree. - - -x=<command> - --extcmd=<command> Specify a custom command for viewing diffs. - git-diffall ignores the configured defaults and - runs $command $LOCAL $REMOTE when this option is - specified. Additionally, $BASE is set in the - environment. -' - -SUBDIRECTORY_OK=1 -. "$(git --exec-path)/git-sh-setup" - -TOOL_MODE=diff -. "$(git --exec-path)/git-mergetool--lib" - -merge_tool="$(get_merge_tool)" -if test -z "$merge_tool" -then - echo "Error: Either the 'diff.tool' or 'merge.tool' option must be set." - usage -fi - -start_dir=$(pwd) - -# All the file paths returned by the diff command are relative to the root -# of the working copy. So if the script is called from a subdirectory, it -# must switch to the root of working copy before trying to use those paths. -cdup=$(git rev-parse --show-cdup) && -cd "$cdup" || { - echo >&2 "Cannot chdir to $cdup, the toplevel of the working tree" - exit 1 -} - -# set up temp dir -tmp=$(perl -e 'use File::Temp qw(tempdir); - $t=tempdir("/tmp/git-diffall.XXXXX") or exit(1); - print $t') || exit 1 -trap 'rm -rf "$tmp"' EXIT - -left= -right= -paths= -dashdash_seen= -compare_staged= -merge_base= -left_dir= -right_dir= -diff_tool= -copy_back= - -while test $# != 0 -do - case "$1" in - -h|--h|--he|--hel|--help) - usage - ;; - --cached) - compare_staged=1 - ;; - --copy-back) - copy_back=1 - ;; - -x|--e|--ex|--ext|--extc|--extcm|--extcmd) - if test $# = 1 - then - echo You must specify the tool for use with --extcmd - usage - else - diff_tool=$2 - shift - fi - ;; - --) - dashdash_seen=1 - ;; - -*) - echo Invalid option: "$1" - usage - ;; - *) - # could be commit, commit range or path limiter - case "$1" in - *...*) - left=${1%...*} - right=${1#*...} - merge_base=1 - ;; - *..*) - left=${1%..*} - right=${1#*..} - ;; - *) - if test -n "$dashdash_seen" - then - paths="$paths$1 " - elif test -z "$left" - then - left=$1 - elif test -z "$right" - then - right=$1 - else - paths="$paths$1 " - fi - ;; - esac - ;; - esac - shift -done - -# Determine the set of files which changed -if test -n "$left" && test -n "$right" -then - left_dir="cmt-$(git rev-parse --short $left)" - right_dir="cmt-$(git rev-parse --short $right)" - - if test -n "$compare_staged" - then - usage - elif test -n "$merge_base" - then - git diff --name-only "$left"..."$right" -- $paths >"$tmp/filelist" - else - git diff --name-only "$left" "$right" -- $paths >"$tmp/filelist" - fi -elif test -n "$left" -then - left_dir="cmt-$(git rev-parse --short $left)" - - if test -n "$compare_staged" - then - right_dir="staged" - git diff --name-only --cached "$left" -- $paths >"$tmp/filelist" - else - right_dir="working_tree" - git diff --name-only "$left" -- $paths >"$tmp/filelist" - fi -else - left_dir="HEAD" - - if test -n "$compare_staged" - then - right_dir="staged" - git diff --name-only --cached -- $paths >"$tmp/filelist" - else - right_dir="working_tree" - git diff --name-only -- $paths >"$tmp/filelist" - fi -fi - -# Exit immediately if there are no diffs -if test ! -s "$tmp/filelist" -then - exit 0 -fi - -if test -n "$copy_back" && test "$right_dir" != "working_tree" -then - echo "--copy-back is only valid when diff includes the working tree." - exit 1 -fi - -# Create the named tmp directories that will hold the files to be compared -mkdir -p "$tmp/$left_dir" "$tmp/$right_dir" - -# Populate the tmp/right_dir directory with the files to be compared -while read name -do - if test -n "$right" - then - ls_list=$(git ls-tree $right "$name") - if test -n "$ls_list" - then - mkdir -p "$tmp/$right_dir/$(dirname "$name")" - git show "$right":"$name" >"$tmp/$right_dir/$name" || true - fi - elif test -n "$compare_staged" - then - ls_list=$(git ls-files -- "$name") - if test -n "$ls_list" - then - mkdir -p "$tmp/$right_dir/$(dirname "$name")" - git show :"$name" >"$tmp/$right_dir/$name" - fi - else - if test -e "$name" - then - mkdir -p "$tmp/$right_dir/$(dirname "$name")" - cp "$name" "$tmp/$right_dir/$name" - fi - fi -done < "$tmp/filelist" - -# Populate the tmp/left_dir directory with the files to be compared -while read name -do - if test -n "$left" - then - ls_list=$(git ls-tree $left "$name") - if test -n "$ls_list" - then - mkdir -p "$tmp/$left_dir/$(dirname "$name")" - git show "$left":"$name" >"$tmp/$left_dir/$name" || true - fi - else - if test -n "$compare_staged" - then - ls_list=$(git ls-tree HEAD "$name") - if test -n "$ls_list" - then - mkdir -p "$tmp/$left_dir/$(dirname "$name")" - git show HEAD:"$name" >"$tmp/$left_dir/$name" - fi - else - mkdir -p "$tmp/$left_dir/$(dirname "$name")" - git show :"$name" >"$tmp/$left_dir/$name" - fi - fi -done < "$tmp/filelist" - -LOCAL="$tmp/$left_dir" -REMOTE="$tmp/$right_dir" - -if test -n "$diff_tool" -then - export BASE - eval $diff_tool '"$LOCAL"' '"$REMOTE"' -else - run_merge_tool "$merge_tool" false -fi - -# Copy files back to the working dir, if requested -if test -n "$copy_back" && test "$right_dir" = "working_tree" -then - cd "$start_dir" - git_top_dir=$(git rev-parse --show-toplevel) - find "$tmp/$right_dir" -type f | - while read file - do - cp "$file" "$git_top_dir/${file#$tmp/$right_dir/}" - done -fi diff --git a/contrib/examples/git-clone.sh b/contrib/examples/git-clone.sh index b4c9376a2c..08cf246bbb 100755 --- a/contrib/examples/git-clone.sh +++ b/contrib/examples/git-clone.sh @@ -516,7 +516,7 @@ then case "$no_checkout" in '') - test "z$quiet" = z -a "z$no_progress" = z && v=-v || v= + test "z$quiet" = z && test "z$no_progress" = z && v=-v || v= git read-tree -m -u $v HEAD HEAD esac fi diff --git a/contrib/examples/git-commit.sh b/contrib/examples/git-commit.sh index 5cafe2eb77..934505bab9 100755 --- a/contrib/examples/git-commit.sh +++ b/contrib/examples/git-commit.sh @@ -51,7 +51,7 @@ run_status () { export GIT_INDEX_FILE fi - if test "$status_only" = "t" -o "$use_status_color" = "t"; then + if test "$status_only" = "t" || test "$use_status_color" = "t"; then color= else color=--nocolor @@ -296,7 +296,7 @@ t,,,[1-9]*) die "No paths with -i does not make sense." ;; esac -if test ! -z "$templatefile" -a -z "$log_given" +if test ! -z "$templatefile" && test -z "$log_given" then if test ! -f "$templatefile" then diff --git a/contrib/examples/git-merge.sh b/contrib/examples/git-merge.sh index 7e40f40c78..52f2aafb9d 100755 --- a/contrib/examples/git-merge.sh +++ b/contrib/examples/git-merge.sh @@ -161,7 +161,7 @@ merge_name () { return fi fi - if test "$remote" = "FETCH_HEAD" -a -r "$GIT_DIR/FETCH_HEAD" + if test "$remote" = "FETCH_HEAD" && test -r "$GIT_DIR/FETCH_HEAD" then sed -e 's/ not-for-merge / /' -e 1q \ "$GIT_DIR/FETCH_HEAD" @@ -527,7 +527,7 @@ do git diff-files --name-only git ls-files --unmerged } | wc -l` - if test $best_cnt -le 0 -o $cnt -le $best_cnt + if test $best_cnt -le 0 || test $cnt -le $best_cnt then best_strategy=$strategy best_cnt=$cnt diff --git a/contrib/examples/git-repack.sh b/contrib/examples/git-repack.sh index f312405a25..96e3fed326 100755 --- a/contrib/examples/git-repack.sh +++ b/contrib/examples/git-repack.sh @@ -76,8 +76,8 @@ case ",$all_into_one," in existing="$existing $e" fi done - if test -n "$existing" -a -n "$unpack_unreachable" -a \ - -n "$remove_redundant" + if test -n "$existing" && test -n "$unpack_unreachable" && \ + test -n "$remove_redundant" then # This may have arbitrary user arguments, so we # have to protect it against whitespace splitting diff --git a/contrib/examples/git-resolve.sh b/contrib/examples/git-resolve.sh index 48d0fc971f..70fdc27b72 100755 --- a/contrib/examples/git-resolve.sh +++ b/contrib/examples/git-resolve.sh @@ -76,7 +76,7 @@ case "$common" in 2>/dev/null || continue # Count the paths that are unmerged. cnt=$(GIT_INDEX_FILE=$G git ls-files --unmerged | wc -l) - if test $best_cnt -le 0 -o $cnt -le $best_cnt + if test $best_cnt -le 0 || test $cnt -le $best_cnt then best=$c best_cnt=$cnt diff --git a/contrib/subtree/Makefile b/contrib/subtree/Makefile index 4030a16898..d888d45161 100644 --- a/contrib/subtree/Makefile +++ b/contrib/subtree/Makefile @@ -3,17 +3,23 @@ prefix ?= /usr/local mandir ?= $(prefix)/share/man -libexecdir ?= $(prefix)/libexec/git-core -gitdir ?= $(shell git --exec-path) +gitexecdir ?= $(prefix)/libexec/git-core man1dir ?= $(mandir)/man1 -gitver ?= $(word 3,$(shell git --version)) +../../GIT-VERSION-FILE: FORCE + $(MAKE) -C ../../ GIT-VERSION-FILE + +-include ../../GIT-VERSION-FILE # this should be set to a 'standard' bsd-type install program -INSTALL ?= install +INSTALL ?= install +RM ?= rm -f + +ASCIIDOC = asciidoc +XMLTO = xmlto -ASCIIDOC_CONF = ../../Documentation/asciidoc.conf -MANPAGE_NORMAL_XSL = ../../Documentation/manpage-normal.xsl +ASCIIDOC_CONF = ../../Documentation/asciidoc.conf +MANPAGE_XSL = ../../Documentation/manpage-normal.xsl GIT_SUBTREE_SH := git-subtree.sh GIT_SUBTREE := git-subtree @@ -31,8 +37,8 @@ $(GIT_SUBTREE): $(GIT_SUBTREE_SH) doc: $(GIT_SUBTREE_DOC) $(GIT_SUBTREE_HTML) install: $(GIT_SUBTREE) - $(INSTALL) -d -m 755 $(DESTDIR)$(libexecdir) - $(INSTALL) -m 755 $(GIT_SUBTREE) $(DESTDIR)$(libexecdir) + $(INSTALL) -d -m 755 $(DESTDIR)$(gitexecdir) + $(INSTALL) -m 755 $(GIT_SUBTREE) $(DESTDIR)$(gitexecdir) install-doc: install-man @@ -41,19 +47,21 @@ install-man: $(GIT_SUBTREE_DOC) $(INSTALL) -m 644 $^ $(DESTDIR)$(man1dir) $(GIT_SUBTREE_DOC): $(GIT_SUBTREE_XML) - xmlto -m $(MANPAGE_NORMAL_XSL) man $^ + $(XMLTO) -m $(MANPAGE_XSL) man $^ $(GIT_SUBTREE_XML): $(GIT_SUBTREE_TXT) - asciidoc -b docbook -d manpage -f $(ASCIIDOC_CONF) \ - -agit_version=$(gitver) $^ + $(ASCIIDOC) -b docbook -d manpage -f $(ASCIIDOC_CONF) \ + -agit_version=$(GIT_VERSION) $^ $(GIT_SUBTREE_HTML): $(GIT_SUBTREE_TXT) - asciidoc -b xhtml11 -d manpage -f $(ASCIIDOC_CONF) \ - -agit_version=$(gitver) $^ + $(ASCIIDOC) -b xhtml11 -d manpage -f $(ASCIIDOC_CONF) \ + -agit_version=$(GIT_VERSION) $^ test: $(MAKE) -C t/ test clean: - rm -f *~ *.xml *.html *.1 - rm -rf subproj mainline + $(RM) $(GIT_SUBTREE) + $(RM) *.xml *.html *.1 + +.PHONY: FORCE diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh index db925ca769..fa1a5839af 100755 --- a/contrib/subtree/git-subtree.sh +++ b/contrib/subtree/git-subtree.sh @@ -558,8 +558,9 @@ cmd_add_commit() commit=$(add_squashed_msg "$rev" "$dir" | git commit-tree $tree $headp -p "$rev") || exit $? else + revp=$(peel_committish "$rev") && commit=$(add_msg "$dir" "$headrev" "$rev" | - git commit-tree $tree $headp -p "$rev") || exit $? + git commit-tree $tree $headp -p "$revp") || exit $? fi git reset "$commit" || exit $? diff --git a/contrib/subtree/t/t7900-subtree.sh b/contrib/subtree/t/t7900-subtree.sh index b22b710c26..6309d124ca 100755 --- a/contrib/subtree/t/t7900-subtree.sh +++ b/contrib/subtree/t/t7900-subtree.sh @@ -8,7 +8,8 @@ This test verifies the basic operation of the merge, pull, add and split subcommands of git subtree. ' -export TEST_DIRECTORY=$(pwd)/../../../t +TEST_DIRECTORY=$(pwd)/../../../t +export TEST_DIRECTORY . ../../../t/test-lib.sh diff --git a/contrib/svn-fe/svnrdump_sim.py b/contrib/svn-fe/svnrdump_sim.py index 4e78a1c3cd..11ac6f6927 100755 --- a/contrib/svn-fe/svnrdump_sim.py +++ b/contrib/svn-fe/svnrdump_sim.py @@ -5,53 +5,64 @@ of the specified revision range. To simulate incremental imports the environment variable SVNRMAX can be set to the highest revision that should be available. """ -import sys, os +import sys +import os if sys.hexversion < 0x02040000: - # The limiter is the ValueError() calls. This may be too conservative - sys.stderr.write("svnrdump-sim.py: requires Python 2.4 or later.\n") - sys.exit(1) + # The limiter is the ValueError() calls. This may be too conservative + sys.stderr.write("svnrdump-sim.py: requires Python 2.4 or later.\n") + sys.exit(1) + def getrevlimit(): - var = 'SVNRMAX' - if var in os.environ: - return os.environ[var] - return None + var = 'SVNRMAX' + if var in os.environ: + return os.environ[var] + return None + def writedump(url, lower, upper): - if url.startswith('sim://'): - filename = url[6:] - if filename[-1] == '/': filename = filename[:-1] #remove terminating slash - else: - raise ValueError('sim:// url required') - f = open(filename, 'r'); - state = 'header' - wroterev = False - while(True): - l = f.readline() - if l == '': break - if state == 'header' and l.startswith('Revision-number: '): - state = 'prefix' - if state == 'prefix' and l == 'Revision-number: %s\n' % lower: - state = 'selection' - if not upper == 'HEAD' and state == 'selection' and l == 'Revision-number: %s\n' % upper: - break; + if url.startswith('sim://'): + filename = url[6:] + if filename[-1] == '/': + filename = filename[:-1] # remove terminating slash + else: + raise ValueError('sim:// url required') + f = open(filename, 'r') + state = 'header' + wroterev = False + while(True): + l = f.readline() + if l == '': + break + if state == 'header' and l.startswith('Revision-number: '): + state = 'prefix' + if state == 'prefix' and l == 'Revision-number: %s\n' % lower: + state = 'selection' + if not upper == 'HEAD' and state == 'selection' and \ + l == 'Revision-number: %s\n' % upper: + break - if state == 'header' or state == 'selection': - if state == 'selection': wroterev = True - sys.stdout.write(l) - return wroterev + if state == 'header' or state == 'selection': + if state == 'selection': + wroterev = True + sys.stdout.write(l) + return wroterev if __name__ == "__main__": - if not (len(sys.argv) in (3, 4, 5)): - print("usage: %s dump URL -rLOWER:UPPER") - sys.exit(1) - if not sys.argv[1] == 'dump': raise NotImplementedError('only "dump" is suppported.') - url = sys.argv[2] - r = ('0', 'HEAD') - if len(sys.argv) == 4 and sys.argv[3][0:2] == '-r': - r = sys.argv[3][2:].lstrip().split(':') - if not getrevlimit() is None: r[1] = getrevlimit() - if writedump(url, r[0], r[1]): ret = 0 - else: ret = 1 - sys.exit(ret) + if not (len(sys.argv) in (3, 4, 5)): + print("usage: %s dump URL -rLOWER:UPPER") + sys.exit(1) + if not sys.argv[1] == 'dump': + raise NotImplementedError('only "dump" is suppported.') + url = sys.argv[2] + r = ('0', 'HEAD') + if len(sys.argv) == 4 and sys.argv[3][0:2] == '-r': + r = sys.argv[3][2:].lstrip().split(':') + if not getrevlimit() is None: + r[1] = getrevlimit() + if writedump(url, r[0], r[1]): + ret = 0 + else: + ret = 1 + sys.exit(ret) diff --git a/contrib/vim/README b/contrib/vim/README deleted file mode 100644 index 8f16d06972..0000000000 --- a/contrib/vim/README +++ /dev/null @@ -1,22 +0,0 @@ -Syntax highlighting for git commit messages, config files, etc. is -included with the vim distribution as of vim 7.2, and should work -automatically. - -If you have an older version of vim, you can get the latest syntax -files from the vim project: - - http://ftp.vim.org/pub/vim/runtime/syntax/git.vim - http://ftp.vim.org/pub/vim/runtime/syntax/gitcommit.vim - http://ftp.vim.org/pub/vim/runtime/syntax/gitconfig.vim - http://ftp.vim.org/pub/vim/runtime/syntax/gitrebase.vim - http://ftp.vim.org/pub/vim/runtime/syntax/gitsendemail.vim - -These files are also available via FTP at the same location. - -To install: - - 1. Copy these files to vim's syntax directory $HOME/.vim/syntax - 2. To auto-detect the editing of various git-related filetypes: - - $ curl http://ftp.vim.org/pub/vim/runtime/filetype.vim | - sed -ne '/^" Git$/, /^$/ p' >>$HOME/.vim/filetype.vim @@ -475,14 +475,6 @@ static void make_service_overridable(const char *name, int ena) die("No such service %s", name); } -static char *xstrdup_tolower(const char *str) -{ - char *p, *dup = xstrdup(str); - for (p = dup; *p; p++) - *p = tolower(*p); - return dup; -} - static void parse_host_and_port(char *hostport, char **host, char **port) { diff --git a/diff-lib.c b/diff-lib.c index 044872935c..875aff8643 100644 --- a/diff-lib.c +++ b/diff-lib.c @@ -97,7 +97,6 @@ int run_diff_files(struct rev_info *revs, unsigned int option) diff_unmerged_stage = 2; entries = active_nr; for (i = 0; i < entries; i++) { - struct stat st; unsigned int oldmode, newmode; struct cache_entry *ce = active_cache[i]; int changed; @@ -115,6 +114,7 @@ int run_diff_files(struct rev_info *revs, unsigned int option) unsigned int wt_mode = 0; int num_compare_stages = 0; size_t path_len; + struct stat st; path_len = ce_namelen(ce); @@ -195,26 +195,35 @@ int run_diff_files(struct rev_info *revs, unsigned int option) continue; /* If CE_VALID is set, don't look at workdir for file removal */ - changed = (ce->ce_flags & CE_VALID) ? 0 : check_removed(ce, &st); - if (changed) { - if (changed < 0) { - perror(ce->name); + if (ce->ce_flags & CE_VALID) { + changed = 0; + newmode = ce->ce_mode; + } else { + struct stat st; + + changed = check_removed(ce, &st); + if (changed) { + if (changed < 0) { + perror(ce->name); + continue; + } + diff_addremove(&revs->diffopt, '-', ce->ce_mode, + ce->sha1, !is_null_sha1(ce->sha1), + ce->name, 0); continue; } - diff_addremove(&revs->diffopt, '-', ce->ce_mode, - ce->sha1, !is_null_sha1(ce->sha1), - ce->name, 0); - continue; + + changed = match_stat_with_submodule(&revs->diffopt, ce, &st, + ce_option, &dirty_submodule); + newmode = ce_mode_from_stat(ce, st.st_mode); } - changed = match_stat_with_submodule(&revs->diffopt, ce, &st, - ce_option, &dirty_submodule); + if (!changed && !dirty_submodule) { ce_mark_uptodate(ce); if (!DIFF_OPT_TST(&revs->diffopt, FIND_COPIES_HARDER)) continue; } oldmode = ce->ce_mode; - newmode = ce_mode_from_stat(ce, st.st_mode); diff_change(&revs->diffopt, oldmode, newmode, ce->sha1, (changed ? null_sha1 : ce->sha1), !is_null_sha1(ce->sha1), (changed ? 0 : !is_null_sha1(ce->sha1)), @@ -1361,7 +1361,7 @@ static struct diffstat_file *diffstat_add(struct diffstat_t *diffstat, const char *name_b) { struct diffstat_file *x; - x = xcalloc(sizeof (*x), 1); + x = xcalloc(1, sizeof(*x)); ALLOC_GROW(diffstat->files, diffstat->nr + 1, diffstat->alloc); diffstat->files[diffstat->nr++] = x; if (name_b) { @@ -3320,6 +3320,9 @@ void diff_setup_done(struct diff_options *options) } options->diff_path_counter = 0; + + if (DIFF_OPT_TST(options, FOLLOW_RENAMES) && options->pathspec.nr != 1) + die(_("--follow requires exactly one pathspec")); } static int opt_arg(const char *arg, int arg_short, const char *arg_long, int *val) @@ -508,21 +508,25 @@ void clear_exclude_list(struct exclude_list *el) static void trim_trailing_spaces(char *buf) { - int i, last_space = -1, nr_spaces, len = strlen(buf); - for (i = 0; i < len; i++) - if (buf[i] == '\\') - i++; - else if (buf[i] == ' ') { - if (last_space == -1) { - last_space = i; - nr_spaces = 1; - } else - nr_spaces++; - } else - last_space = -1; - - if (last_space != -1 && last_space + nr_spaces == len) - buf[last_space] = '\0'; + char *p, *last_space = NULL; + + for (p = buf; *p; p++) + switch (*p) { + case ' ': + if (!last_space) + last_space = p; + break; + case '\\': + p++; + if (!*p) + return; + /* fallthrough */ + default: + last_space = NULL; + } + + if (last_space) + *last_space = '\0'; } int add_excludes_from_file_to_list(const char *fname, @@ -1350,8 +1354,7 @@ static int cmp_name(const void *p1, const void *p2) const struct dir_entry *e1 = *(const struct dir_entry **)p1; const struct dir_entry *e2 = *(const struct dir_entry **)p2; - return cache_name_compare(e1->name, e1->len, - e2->name, e2->len); + return name_compare(e1->name, e1->len, e2->name, e2->len); } static struct path_simplify *create_simplify(const char **pathspec) diff --git a/environment.c b/environment.c index 5c4815dbe1..4dac5e9edd 100644 --- a/environment.c +++ b/environment.c @@ -37,7 +37,7 @@ int core_compression_seen; int fsync_object_files; size_t packed_git_window_size = DEFAULT_PACKED_GIT_WINDOW_SIZE; size_t packed_git_limit = DEFAULT_PACKED_GIT_LIMIT; -size_t delta_base_cache_limit = 16 * 1024 * 1024; +size_t delta_base_cache_limit = 96 * 1024 * 1024; unsigned long big_file_threshold = 512 * 1024 * 1024; const char *pager_program; int pager_use_color = 1; @@ -69,9 +69,10 @@ unsigned long pack_size_limit_cfg; * that is subject to stripspace. */ char comment_line_char = '#'; +int auto_comment_line_char; /* Parallel index stat data preload? */ -int core_preload_index = 0; +int core_preload_index = 1; /* This is set by setup_git_dir_gently() and/or git_default_config() */ char *git_work_tree_cfg; diff --git a/fast-import.c b/fast-import.c index fb4738d373..6707a66471 100644 --- a/fast-import.c +++ b/fast-import.c @@ -248,6 +248,7 @@ struct branch { uintmax_t last_commit; uintmax_t num_notes; unsigned active : 1; + unsigned delete : 1; unsigned pack_id : PACK_ID_BITS; unsigned char sha1[20]; }; @@ -1681,10 +1682,13 @@ static int update_branch(struct branch *b) struct ref_lock *lock; unsigned char old_sha1[20]; - if (is_null_sha1(b->sha1)) - return 0; if (read_ref(b->name, old_sha1)) hashclr(old_sha1); + if (is_null_sha1(b->sha1)) { + if (b->delete) + delete_ref(b->name, old_sha1, 0); + return 0; + } lock = lock_any_ref_for_update(b->name, old_sha1, 0, NULL); if (!lock) return error("Unable to lock %s", b->name); @@ -2611,8 +2615,11 @@ static int parse_from(struct branch *b) free(buf); } else parse_from_existing(b); - } else if (!get_sha1(from, b->sha1)) + } else if (!get_sha1(from, b->sha1)) { parse_from_existing(b); + if (is_null_sha1(b->sha1)) + b->delete = 1; + } else die("Invalid ref name or SHA1 expression: %s", from); diff --git a/fetch-pack.c b/fetch-pack.c index eeee2bb7e0..b12bd4c59a 100644 --- a/fetch-pack.c +++ b/fetch-pack.c @@ -507,7 +507,7 @@ static void filter_refs(struct fetch_pack_args *args, int keep = 0; next = ref->next; - if (!memcmp(ref->name, "refs/", 5) && + if (starts_with(ref->name, "refs/") && check_refname_format(ref->name, 0)) ; /* trash */ else { @@ -276,9 +276,10 @@ static int fsck_ident(const char **ident, struct object *obj, fsck_error error_f return 0; } -static int fsck_commit(struct commit *commit, fsck_error error_func) +static int fsck_commit_buffer(struct commit *commit, const char *buffer, + fsck_error error_func) { - const char *buffer = commit->buffer, *tmp; + const char *tmp; unsigned char tree_sha1[20], sha1[20]; struct commit_graft *graft; int parents = 0; @@ -336,6 +337,14 @@ static int fsck_commit(struct commit *commit, fsck_error error_func) return 0; } +static int fsck_commit(struct commit *commit, fsck_error error_func) +{ + const char *buffer = get_commit_buffer(commit, NULL); + int ret = fsck_commit_buffer(commit, buffer, error_func); + unuse_commit_buffer(commit, buffer); + return ret; +} + static int fsck_tag(struct tag *tag, fsck_error error_func) { struct object *tagged = tag->tagged; diff --git a/git-bisect.sh b/git-bisect.sh index af4d04c3be..1e0d602f4b 100755 --- a/git-bisect.sh +++ b/git-bisect.sh @@ -408,7 +408,7 @@ bisect_replay () { bisect_reset while read git bisect command rev do - test "$git $bisect" = "git bisect" -o "$git" = "git-bisect" || continue + test "$git $bisect" = "git bisect" || test "$git" = "git-bisect" || continue if test "$git" = "git-bisect" then rev="$command" diff --git a/git-compat-util.h b/git-compat-util.h index 086fd374bb..96f55547a3 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -267,6 +267,10 @@ extern char *gitbasename(char *); #define has_dos_drive_prefix(path) 0 #endif +#ifndef offset_1st_component +#define offset_1st_component(path) (is_dir_sep((path)[0])) +#endif + #ifndef is_dir_sep #define is_dir_sep(c) ((c) == '/') #endif @@ -330,8 +334,12 @@ extern void warning(const char *err, ...) __attribute__((format (printf, 1, 2))) * trying to help gcc, anyway, it's OK; other compilers will fall back to * using the function as usual. */ -#if defined(__GNUC__) && ! defined(__clang__) -#define error(...) (error(__VA_ARGS__), -1) +#if defined(__GNUC__) +static inline int const_error(void) +{ + return -1; +} +#define error(...) (error(__VA_ARGS__), const_error()) #endif extern void set_die_routine(NORETURN_PTR void (*routine)(const char *err, va_list params)); diff --git a/git-gui/git-gui.sh b/git-gui/git-gui.sh index 6a8907e7b3..b186329d28 100755 --- a/git-gui/git-gui.sh +++ b/git-gui/git-gui.sh @@ -1558,7 +1558,11 @@ proc rescan_stage2 {fd after} { set rescan_active 2 ui_status [mc "Scanning for modified files ..."] - set fd_di [git_read diff-index --cached -z [PARENT]] + if {[git-version >= "1.7.2"]} { + set fd_di [git_read diff-index --cached --ignore-submodules=dirty -z [PARENT]] + } else { + set fd_di [git_read diff-index --cached -z [PARENT]] + } set fd_df [git_read diff-files -z] fconfigure $fd_di -blocking 0 -translation binary -encoding binary diff --git a/git-gui/lib/diff.tcl b/git-gui/lib/diff.tcl index 30d9a79776..b0a5180af7 100644 --- a/git-gui/lib/diff.tcl +++ b/git-gui/lib/diff.tcl @@ -287,6 +287,9 @@ proc start_show_diff {cont_info {add_opts {}}} { if {$w eq $ui_index} { lappend cmd diff-index lappend cmd --cached + if {[git-version >= "1.7.2"]} { + lappend cmd --ignore-submodules=dirty + } } elseif {$w eq $ui_workdir} { if {[string first {U} $m] >= 0} { lappend cmd diff diff --git a/git-instaweb.sh b/git-instaweb.sh index 4aa3eb80fd..513efa662e 100755 --- a/git-instaweb.sh +++ b/git-instaweb.sh @@ -345,7 +345,17 @@ PidFile "$fqgitdir/pid" Listen $bind$port EOF - for mod in mime dir env log_config + for mod in mpm_event mpm_prefork mpm_worker + do + if test -e $module_path/mod_${mod}.so + then + echo "LoadModule ${mod}_module " \ + "$module_path/mod_${mod}.so" >> "$conf" + # only one mpm module permitted + break + fi + done + for mod in mime dir env log_config authz_core do if test -e $module_path/mod_${mod}.so then diff --git a/git-mergetool.sh b/git-mergetool.sh index d08dc92589..9a046b75d1 100755 --- a/git-mergetool.sh +++ b/git-mergetool.sh @@ -205,7 +205,7 @@ checkout_staged_file () { "$(git checkout-index --temp --stage="$1" "$2" 2>/dev/null)" \ : '\([^ ]*\) ') - if test $? -eq 0 -a -n "$tmpfile" + if test $? -eq 0 && test -n "$tmpfile" then mv -- "$(git rev-parse --show-cdup)$tmpfile" "$3" else @@ -256,7 +256,7 @@ merge_file () { checkout_staged_file 2 "$MERGED" "$LOCAL" checkout_staged_file 3 "$MERGED" "$REMOTE" - if test -z "$local_mode" -o -z "$remote_mode" + if test -z "$local_mode" || test -z "$remote_mode" then echo "Deleted merge conflict for '$MERGED':" describe_file "$local_mode" "local" "$LOCAL" @@ -1238,6 +1238,28 @@ class P4Submit(Command, P4UserMap): if response == 'n': return False + def get_diff_description(self, editedFiles, filesToAdd): + # diff + if os.environ.has_key("P4DIFF"): + del(os.environ["P4DIFF"]) + diff = "" + for editedFile in editedFiles: + diff += p4_read_pipe(['diff', '-du', + wildcard_encode(editedFile)]) + + # new file diff + newdiff = "" + for newFile in filesToAdd: + newdiff += "==== new file ====\n" + newdiff += "--- /dev/null\n" + newdiff += "+++ %s\n" % newFile + f = open(newFile, "r") + for line in f.readlines(): + newdiff += "+" + line + f.close() + + return (diff + newdiff).replace('\r\n', '\n') + def applyCommit(self, id): """Apply one commit, return True if it succeeded.""" @@ -1398,34 +1420,15 @@ class P4Submit(Command, P4UserMap): submitTemplate += "######## Variable git-p4.skipUserNameCheck hides this message.\n" separatorLine = "######## everything below this line is just the diff #######\n" + if not self.prepare_p4_only: + submitTemplate += separatorLine + submitTemplate += self.get_diff_description(editedFiles, filesToAdd) - # diff - if os.environ.has_key("P4DIFF"): - del(os.environ["P4DIFF"]) - diff = "" - for editedFile in editedFiles: - diff += p4_read_pipe(['diff', '-du', - wildcard_encode(editedFile)]) - - # new file diff - newdiff = "" - for newFile in filesToAdd: - newdiff += "==== new file ====\n" - newdiff += "--- /dev/null\n" - newdiff += "+++ %s\n" % newFile - f = open(newFile, "r") - for line in f.readlines(): - newdiff += "+" + line - f.close() - - # change description file: submitTemplate, separatorLine, diff, newdiff (handle, fileName) = tempfile.mkstemp() - tmpFile = os.fdopen(handle, "w+") + tmpFile = os.fdopen(handle, "w+b") if self.isWindows: submitTemplate = submitTemplate.replace("\n", "\r\n") - separatorLine = separatorLine.replace("\n", "\r\n") - newdiff = newdiff.replace("\n", "\r\n") - tmpFile.write(submitTemplate + separatorLine + diff + newdiff) + tmpFile.write(submitTemplate) tmpFile.close() if self.prepare_p4_only: @@ -1472,9 +1475,9 @@ class P4Submit(Command, P4UserMap): tmpFile = open(fileName, "rb") message = tmpFile.read() tmpFile.close() - submitTemplate = message[:message.index(separatorLine)] if self.isWindows: - submitTemplate = submitTemplate.replace("\r\n", "\n") + message = message.replace("\r\n", "\n") + submitTemplate = message[:message.index(separatorLine)] p4_write_pipe(['submit', '-i'], submitTemplate) if self.preserveUser: diff --git a/git-pull.sh b/git-pull.sh index cfc589dc15..18a394fcc4 100755 --- a/git-pull.sh +++ b/git-pull.sh @@ -58,11 +58,9 @@ pull_ff=$(git config pull.ff) case "$pull_ff" in false) no_ff=--no-ff - break ;; only) ff_only=--ff-only - break ;; esac diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh index 6ec9d3cb40..7e1eda0088 100644 --- a/git-rebase--interactive.sh +++ b/git-rebase--interactive.sh @@ -1013,7 +1013,7 @@ then git rev-list $revisions | while read rev do - if test -f "$rewritten"/$rev -a "$(sane_grep "$rev" "$state_dir"/not-cherry-picks)" = "" + if test -f "$rewritten"/$rev && test "$(sane_grep "$rev" "$state_dir"/not-cherry-picks)" = "" then # Use -f2 because if rev-list is telling us this commit is # not worthwhile, we don't want to track its multiple heads, @@ -1049,14 +1049,14 @@ fi has_action "$todo" || - die_abort "Nothing to do" + return 2 cp "$todo" "$todo".backup git_sequence_editor "$todo" || die_abort "Could not execute editor" has_action "$todo" || - die_abort "Nothing to do" + return 2 expand_todo_ids diff --git a/git-rebase--merge.sh b/git-rebase--merge.sh index 6d77b3ca91..d3fb67d75b 100644 --- a/git-rebase--merge.sh +++ b/git-rebase--merge.sh @@ -53,11 +53,12 @@ continue_merge () { } call_merge () { - cmt="$(cat "$state_dir/cmt.$1")" + msgnum="$1" + echo "$msgnum" >"$state_dir/msgnum" + cmt="$(cat "$state_dir/cmt.$msgnum")" echo "$cmt" > "$state_dir/current" hd=$(git rev-parse --verify HEAD) cmt_name=$(git symbolic-ref HEAD 2> /dev/null || echo HEAD) - msgnum=$(cat "$state_dir/msgnum") eval GITHEAD_$cmt='"${cmt_name##refs/heads/}~$(($end - $msgnum))"' eval GITHEAD_$hd='$onto_name' export GITHEAD_$cmt GITHEAD_$hd diff --git a/git-rebase.sh b/git-rebase.sh index 5c7a0a1a58..06c810b64f 100755 --- a/git-rebase.sh +++ b/git-rebase.sh @@ -155,7 +155,7 @@ move_to_original_branch () { esac } -finish_rebase () { +apply_autostash () { if test -f "$state_dir/autostash" then stash_sha1=$(cat "$state_dir/autostash") @@ -171,6 +171,10 @@ You can run "git stash pop" or "git stash drop" at any time. ' fi fi +} + +finish_rebase () { + apply_autostash && git gc --auto && rm -rf "$state_dir" } @@ -186,6 +190,11 @@ run_specific_rebase () { if test $ret -eq 0 then finish_rebase + elif test $ret -eq 2 # special exit status for rebase -i + then + apply_autostash && + rm -rf "$state_dir" && + die "Nothing to do" fi exit $ret } diff --git a/git-remote-testgit.sh b/git-remote-testgit.sh index 1c006a0518..a9c75a2360 100755 --- a/git-remote-testgit.sh +++ b/git-remote-testgit.sh @@ -13,7 +13,8 @@ refspec="${GIT_REMOTE_TESTGIT_REFSPEC-$default_refspec}" test -z "$refspec" && prefix="refs" -export GIT_DIR="$url/.git" +GIT_DIR="$url/.git" +export GIT_DIR force= diff --git a/git-send-email.perl b/git-send-email.perl index abd62b484c..9949db01e1 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -80,6 +80,8 @@ git send-email [options] <file | directory | rev-list options > --to-cmd <str> * Email To: via `<str> \$patch_path` --cc-cmd <str> * Email Cc: via `<str> \$patch_path` --suppress-cc <str> * author, self, sob, cc, cccmd, body, bodycc, all. + --[no-]cc-cover * Email Cc: addresses in the cover letter. + --[no-]to-cover * Email To: addresses in the cover letter. --[no-]signed-off-by-cc * Send to Signed-off-by: addresses. Default on. --[no-]suppress-from * Send to self. Default off. --[no-]chain-reply-to * Chain In-Reply-To: fields. Default off. @@ -195,6 +197,7 @@ sub do_edit { # Variables with corresponding config settings my ($thread, $chain_reply_to, $suppress_from, $signed_off_by_cc); +my ($cover_cc, $cover_to); my ($to_cmd, $cc_cmd); my ($smtp_server, $smtp_server_port, @smtp_server_options); my ($smtp_authuser, $smtp_encryption, $smtp_ssl_cert_path); @@ -211,6 +214,8 @@ my %config_bool_settings = ( "chainreplyto" => [\$chain_reply_to, 0], "suppressfrom" => [\$suppress_from, undef], "signedoffbycc" => [\$signed_off_by_cc, undef], + "cccover" => [\$cover_cc, undef], + "tocover" => [\$cover_to, undef], "signedoffcc" => [\$signed_off_by_cc, undef], # Deprecated "validate" => [\$validate, 1], "multiedit" => [\$multiedit, undef], @@ -302,6 +307,8 @@ my $rc = GetOptions("h" => \$help, "suppress-from!" => \$suppress_from, "suppress-cc=s" => \@suppress_cc, "signed-off-cc|signed-off-by-cc!" => \$signed_off_by_cc, + "cc-cover|cc-cover!" => \$cover_cc, + "to-cover|to-cover!" => \$cover_to, "confirm=s" => \$confirm, "dry-run" => \$dry_run, "envelope-sender=s" => \$envelope_sender, @@ -1481,6 +1488,15 @@ foreach my $t (@files) { @to = (@initial_to, @to); @cc = (@initial_cc, @cc); + if ($message_num == 1) { + if (defined $cover_cc and $cover_cc) { + @initial_cc = @cc; + } + if (defined $cover_to and $cover_to) { + @initial_to = @to; + } + } + my $message_was_sent = send_message(); # set up for the next message diff --git a/git-sh-setup.sh b/git-sh-setup.sh index 5f28b32dc7..9447980330 100644 --- a/git-sh-setup.sh +++ b/git-sh-setup.sh @@ -160,7 +160,7 @@ git_pager() { else GIT_PAGER=cat fi - : ${LESS=-FRSX} + : ${LESS=-FRX} : ${LV=-c} export LESS LV diff --git a/git-stash.sh b/git-stash.sh index af549c7317..bcc757b390 100755 --- a/git-stash.sh +++ b/git-stash.sh @@ -94,7 +94,8 @@ create_stash () { # ease of unpacking later. u_commit=$( untracked_files | ( - export GIT_INDEX_FILE="$TMPindex" + GIT_INDEX_FILE="$TMPindex" && + export GIT_INDEX_FILE && rm -f "$TMPindex" && git update-index -z --add --remove --stdin && u_tree=$(git write-tree) && diff --git a/git-submodule.sh b/git-submodule.sh index b55d83ac46..9245abfd42 100755 --- a/git-submodule.sh +++ b/git-submodule.sh @@ -235,7 +235,7 @@ module_name() sed -n -e 's|^submodule\.\(.*\)\.path '"$re"'$|\1|p' ) test -z "$name" && die "$(eval_gettext "No submodule mapping found in .gitmodules for path '\$sm_path'")" - echo "$name" + printf '%s\n' "$name" } # @@ -291,9 +291,6 @@ module_clone() # resolve any symlinks that might be present in $PWD a=$(cd_to_toplevel && cd "$gitdir" && pwd)/ b=$(cd_to_toplevel && cd "$sm_path" && pwd)/ - # normalize Windows-style absolute paths to POSIX-style absolute paths - case $a in [a-zA-Z]:/*) a=/${a%%:*}${a#*:} ;; esac - case $b in [a-zA-Z]:/*) b=/${b%%:*}${b#*:} ;; esac # Remove all common leading directories after a sanity check if test "${a#$b}" != "$a" || test "${b#$a}" != "$b"; then die "$(eval_gettext "Gitdir '\$a' is part of the submodule path '\$b' or vice versa")" @@ -308,10 +305,10 @@ module_clone() b=${b%/} # Turn each leading "*/" component into "../" - rel=$(echo $b | sed -e 's|[^/][^/]*|..|g') - echo "gitdir: $rel/$a" >"$sm_path/.git" + rel=$(printf '%s\n' "$b" | sed -e 's|[^/][^/]*|..|g') + printf '%s\n' "gitdir: $rel/$a" >"$sm_path/.git" - rel=$(echo $a | sed -e 's|[^/][^/]*|..|g') + rel=$(printf '%s\n' "$a" | sed -e 's|[^/][^/]*|..|g') (clear_local_git_env; cd "$sm_path" && GIT_WORK_TREE=. git config core.worktree "$rel/$b") } @@ -392,11 +389,11 @@ cmd_add() sm_path=$2 if test -z "$sm_path"; then - sm_path=$(echo "$repo" | + sm_path=$(printf '%s\n' "$repo" | sed -e 's|/$||' -e 's|:*/*\.git$||' -e 's|.*[/:]||g') fi - if test -z "$repo" -o -z "$sm_path"; then + if test -z "$repo" || test -z "$sm_path"; then usage fi @@ -453,7 +450,7 @@ Use -f if you really want to add it." >&2 # perhaps the path exists and is already a git repo, else clone it if test -e "$sm_path" then - if test -d "$sm_path"/.git -o -f "$sm_path"/.git + if test -d "$sm_path"/.git || test -f "$sm_path"/.git then eval_gettextln "Adding existing repo at '\$sm_path' to the index" else @@ -835,7 +832,7 @@ Maybe you want to use 'update --init'?")" continue fi - if ! test -d "$sm_path"/.git -o -f "$sm_path"/.git + if ! test -d "$sm_path"/.git && ! test -f "$sm_path"/.git then module_clone "$sm_path" "$name" "$url" "$reference" "$depth" || exit cloned_modules="$cloned_modules;$name" @@ -860,11 +857,11 @@ Maybe you want to use 'update --init'?")" die "$(eval_gettext "Unable to find current ${remote_name}/${branch} revision in submodule path '\$sm_path'")" fi - if test "$subsha1" != "$sha1" -o -n "$force" + if test "$subsha1" != "$sha1" || test -n "$force" then subforce=$force # If we don't already have a -f flag and the submodule has never been checked out - if test -z "$subsha1" -a -z "$force" + if test -z "$subsha1" && test -z "$force" then subforce="-f" fi @@ -1034,7 +1031,7 @@ cmd_summary() { then head=$rev test $# = 0 || shift - elif test -z "$1" -o "$1" = "HEAD" + elif test -z "$1" || test "$1" = "HEAD" then # before the first commit: compare with an empty tree head=$(git hash-object -w -t tree --stdin </dev/null) @@ -1059,17 +1056,21 @@ cmd_summary() { while read mod_src mod_dst sha1_src sha1_dst status sm_path do # Always show modules deleted or type-changed (blob<->module) - test $status = D -o $status = T && echo "$sm_path" && continue + if test "$status" = D || test "$status" = T + then + printf '%s\n' "$sm_path" + continue + fi # Respect the ignore setting for --for-status. if test -n "$for_status" then name=$(module_name "$sm_path") ignore_config=$(get_submodule_config "$name" ignore none) - test $status != A -a $ignore_config = all && continue + test $status != A && test $ignore_config = all && continue fi # Also show added or modified modules which are checked out GIT_DIR="$sm_path/.git" git-rev-parse --git-dir >/dev/null 2>&1 && - echo "$sm_path" + printf '%s\n' "$sm_path" done ) @@ -1125,7 +1126,7 @@ cmd_summary() { *) errmsg= total_commits=$( - if test $mod_src = 160000 -a $mod_dst = 160000 + if test $mod_src = 160000 && test $mod_dst = 160000 then range="$sha1_src...$sha1_dst" elif test $mod_src = 160000 @@ -1162,7 +1163,7 @@ cmd_summary() { # i.e. deleted or changed to blob test $mod_dst = 160000 && echo "$errmsg" else - if test $mod_src = 160000 -a $mod_dst = 160000 + if test $mod_src = 160000 && test $mod_dst = 160000 then limit= test $summary_limit -gt 0 && limit="-$summary_limit" @@ -1233,7 +1234,11 @@ cmd_status() say "U$sha1 $displaypath" continue fi - if test -z "$url" || ! test -d "$sm_path"/.git -o -f "$sm_path"/.git + if test -z "$url" || + { + ! test -d "$sm_path"/.git && + ! test -f "$sm_path"/.git + } then say "-$sha1 $displaypath" continue; @@ -1306,7 +1311,7 @@ cmd_sync() ./*|../*) # rewrite foo/bar as ../.. to find path from # submodule work tree to superproject work tree - up_path="$(echo "$sm_path" | sed "s/[^/][^/]*/../g")" && + up_path="$(printf '%s\n' "$sm_path" | sed "s/[^/][^/]*/../g")" && # guarantee a trailing / up_path=${up_path%/}/ && # path from submodule work tree to submodule origin repo @@ -1402,7 +1407,7 @@ then fi # "--cached" is accepted only by "status" and "summary" -if test -n "$cached" && test "$command" != status -a "$command" != summary +if test -n "$cached" && test "$command" != status && test "$command" != summary then usage fi @@ -20,6 +20,43 @@ const char git_more_info_string[] = static struct startup_info git_startup_info; static int use_pager = -1; +static char orig_cwd[PATH_MAX]; +static const char *env_names[] = { + GIT_DIR_ENVIRONMENT, + GIT_WORK_TREE_ENVIRONMENT, + GIT_IMPLICIT_WORK_TREE_ENVIRONMENT, + GIT_PREFIX_ENVIRONMENT +}; +static char *orig_env[4]; +static int saved_environment; + +static void save_env(void) +{ + int i; + if (saved_environment) + return; + saved_environment = 1; + if (!getcwd(orig_cwd, sizeof(orig_cwd))) + die_errno("cannot getcwd"); + for (i = 0; i < ARRAY_SIZE(env_names); i++) { + orig_env[i] = getenv(env_names[i]); + if (orig_env[i]) + orig_env[i] = xstrdup(orig_env[i]); + } +} + +static void restore_env(void) +{ + int i; + if (*orig_cwd && chdir(orig_cwd)) + die_errno("could not move to %s", orig_cwd); + for (i = 0; i < ARRAY_SIZE(env_names); i++) { + if (orig_env[i]) + setenv(env_names[i], orig_env[i], 1); + else + unsetenv(env_names[i]); + } +} static void commit_pager_choice(void) { switch (use_pager) { @@ -272,6 +309,7 @@ static int handle_alias(int *argcp, const char ***argv) * RUN_SETUP for reading from the configuration file. */ #define NEED_WORK_TREE (1<<3) +#define NO_SETUP (1<<4) struct cmd_struct { const char *cmd; @@ -352,7 +390,7 @@ static struct cmd_struct commands[] = { { "cherry", cmd_cherry, RUN_SETUP }, { "cherry-pick", cmd_cherry_pick, RUN_SETUP | NEED_WORK_TREE }, { "clean", cmd_clean, RUN_SETUP | NEED_WORK_TREE }, - { "clone", cmd_clone }, + { "clone", cmd_clone, NO_SETUP }, { "column", cmd_column, RUN_SETUP_GENTLY }, { "commit", cmd_commit, RUN_SETUP | NEED_WORK_TREE }, { "commit-tree", cmd_commit_tree, RUN_SETUP }, @@ -378,8 +416,8 @@ static struct cmd_struct commands[] = { { "hash-object", cmd_hash_object }, { "help", cmd_help }, { "index-pack", cmd_index_pack, RUN_SETUP_GENTLY }, - { "init", cmd_init_db }, - { "init-db", cmd_init_db }, + { "init", cmd_init_db, NO_SETUP }, + { "init-db", cmd_init_db, NO_SETUP }, { "log", cmd_log, RUN_SETUP }, { "ls-files", cmd_ls_files, RUN_SETUP }, { "ls-remote", cmd_ls_remote, RUN_SETUP_GENTLY }, @@ -484,6 +522,10 @@ static void handle_builtin(int argc, const char **argv) struct cmd_struct *p = commands+i; if (strcmp(p->cmd, cmd)) continue; + if (saved_environment && (p->option & NO_SETUP)) { + restore_env(); + break; + } exit(run_builtin(p, argc, argv)); } } @@ -539,7 +581,10 @@ static int run_argv(int *argcp, const char ***argv) * of overriding "git log" with "git show" by having * alias.log = show */ - if (done_alias || !handle_alias(argcp, argv)) + if (done_alias) + break; + save_env(); + if (!handle_alias(argcp, argv)) break; done_alias = 1; } diff --git a/gitk-git/gitk b/gitk-git/gitk index 90764e8948..c8df35dee5 100755 --- a/gitk-git/gitk +++ b/gitk-git/gitk @@ -2585,6 +2585,7 @@ proc makewindow {} { bind $fstring <Key-Return> {dofind 1 1} bind $sha1entry <Key-Return> {gotocommit; break} bind $sha1entry <<PasteSelection>> clearsha1 + bind $sha1entry <<Paste>> clearsha1 bind $cflist <1> {sel_flist %W %x %y; break} bind $cflist <B1-Motion> {sel_flist %W %x %y; break} bind $cflist <ButtonRelease-1> {treeclick %W %x %y} @@ -2786,7 +2787,7 @@ proc savestuff {w} { global mainheadcirclecolor workingfilescirclecolor indexcirclecolor global linkfgcolor circleoutlinecolor global autoselect autosellen extdifftool perfile_attrs markbgcolor use_ttk - global hideremotes want_ttk maxrefs + global hideremotes want_ttk maxrefs visiblerefs global config_file config_file_tmp if {$stuffsaved} return @@ -2812,6 +2813,7 @@ proc savestuff {w} { puts $f [list set autosellen $autosellen] puts $f [list set showneartags $showneartags] puts $f [list set maxrefs $maxrefs] + puts $f [list set visiblerefs $visiblerefs] puts $f [list set hideremotes $hideremotes] puts $f [list set showlocalchanges $showlocalchanges] puts $f [list set datetimeformat $datetimeformat] @@ -3492,10 +3494,20 @@ proc flist_hl {only} { } proc gitknewtmpdir {} { - global diffnum gitktmpdir gitdir + global diffnum gitktmpdir gitdir env if {![info exists gitktmpdir]} { - set gitktmpdir [file join $gitdir [format ".gitk-tmp.%s" [pid]]] + if {[info exists env(GITK_TMPDIR)]} { + set tmpdir $env(GITK_TMPDIR) + } elseif {[info exists env(TMPDIR)]} { + set tmpdir $env(TMPDIR) + } else { + set tmpdir $gitdir + } + set gitktmpformat [file join $tmpdir ".gitk-tmp.XXXXXX"] + if {[catch {set gitktmpdir [exec mktemp -d $gitktmpformat]}]} { + set gitktmpdir [file join $gitdir [format ".gitk-tmp.%s" [pid]]] + } if {[catch {file mkdir $gitktmpdir} err]} { error_popup "[mc "Error creating temporary directory %s:" $gitktmpdir] $err" unset gitktmpdir @@ -3870,7 +3882,7 @@ proc read_line_source {fd inst} { set id $nullid2 } if {[commitinview $id $curview]} { - selectline [rowofcommit $id] 1 [list $fname $lnum] + selectline [rowofcommit $id] 1 [list $fname $lnum] 1 } else { error_popup [mc "That line comes from commit %s, \ which is not in this view" [shortids $id]] @@ -5205,11 +5217,15 @@ proc dohidelocalchanges {} { # spawn off a process to do git diff-index --cached HEAD proc dodiffindex {} { global lserial showlocalchanges vfilelimit curview - global hasworktree + global hasworktree git_version if {!$showlocalchanges || !$hasworktree} return incr lserial - set cmd "|git diff-index --cached HEAD" + if {[package vcompare $git_version "1.7.2"] >= 0} { + set cmd "|git diff-index --cached --ignore-submodules=dirty HEAD" + } else { + set cmd "|git diff-index --cached HEAD" + } if {$vfilelimit($curview) ne {}} { set cmd [concat $cmd -- $vfilelimit($curview)] } @@ -7020,7 +7036,7 @@ proc viewnextline {dir} { # add a list of tag or branch names at position pos # returns the number of names inserted proc appendrefs {pos ids var} { - global ctext linknum curview $var maxrefs mainheadid + global ctext linknum curview $var maxrefs visiblerefs mainheadid if {[catch {$ctext index $pos}]} { return 0 @@ -7041,14 +7057,14 @@ proc appendrefs {pos ids var} { if {[llength $tags] > $maxrefs} { # If we are displaying heads, and there are too many, # see if there are some important heads to display. - # Currently this means "master" and the current head. + # Currently that are the current head and heads listed in $visiblerefs option set itags {} if {$var eq "idheads"} { set utags {} foreach ti $tags { set hname [lindex $ti 0] set id [lindex $ti 1] - if {($hname eq "master" || $id eq $mainheadid) && + if {([lsearch -exact $visiblerefs $hname] != -1 || $id eq $mainheadid) && [llength $itags] < $maxrefs} { lappend itags $ti } else { @@ -7161,7 +7177,7 @@ proc make_idmark {id} { $canv raise $t } -proc selectline {l isnew {desired_loc {}}} { +proc selectline {l isnew {desired_loc {}} {switch_to_patch 0}} { global canv ctext commitinfo selectedline global canvy0 linespc parents children curview global currentid sha1entry @@ -7187,6 +7203,10 @@ proc selectline {l isnew {desired_loc {}}} { setcanvscroll } + if {$cmitmode ne "patch" && $switch_to_patch} { + set cmitmode "patch" + } + set y [expr {$canvy0 + $l * $linespc}] set ymax [lindex [$canv cget -scrollregion] 3] set ytop [expr {$y - $linespc - 1}] @@ -7705,7 +7725,7 @@ proc addtocflist {ids} { } proc diffcmd {ids flags} { - global log_showroot nullid nullid2 + global log_showroot nullid nullid2 git_version set i [lsearch -exact $ids $nullid] set j [lsearch -exact $ids $nullid2] @@ -7726,6 +7746,9 @@ proc diffcmd {ids flags} { } } } elseif {$j >= 0} { + if {[package vcompare $git_version "1.7.2"] >= 0} { + set flags "$flags --ignore-submodules=dirty" + } set cmd [concat | git diff-index --cached $flags] if {[llength $ids] > 1} { # comparing index with specific revision @@ -11575,7 +11598,29 @@ proc prefsok {} { proc formatdate {d} { global datetimeformat if {$d ne {}} { - set d [clock format [lindex $d 0] -format $datetimeformat] + # If $datetimeformat includes a timezone, display in the + # timezone of the argument. Otherwise, display in local time. + if {[string match {*%[zZ]*} $datetimeformat]} { + if {[catch {set d [clock format [lindex $d 0] -timezone [lindex $d 1] -format $datetimeformat]}]} { + # Tcl < 8.5 does not support -timezone. Emulate it by + # setting TZ (e.g. TZ=<-0430>+04:30). + global env + if {[info exists env(TZ)]} { + set savedTZ $env(TZ) + } + set zone [lindex $d 1] + set sign [string map {+ - - +} [string index $zone 0]] + set env(TZ) <$zone>$sign[string range $zone 1 2]:[string range $zone 3 4] + set d [clock format [lindex $d 0] -format $datetimeformat] + if {[info exists savedTZ]} { + set env(TZ) $savedTZ + } else { + unset env(TZ) + } + } + } else { + set d [clock format [lindex $d 0] -format $datetimeformat] + } } return $d } @@ -12001,6 +12046,7 @@ set wrapcomment "none" set showneartags 1 set hideremotes 0 set maxrefs 20 +set visiblerefs {"master"} set maxlinelen 200 set showlocalchanges 1 set limitdiffs 1 diff --git a/gitk-git/po/vi.po b/gitk-git/po/vi.po new file mode 100644 index 0000000000..4dfe125a69 --- /dev/null +++ b/gitk-git/po/vi.po @@ -0,0 +1,1351 @@ +# Vietnamese translations for gitk package. +# Bản dịch tiếng Việt cho gói gitk. +# This file is distributed under the same license as the gitk package. +# Trần Ngọc Quân <vnwildman@gmail.com>, 2013. +# +msgid "" +msgstr "" +"Project-Id-Version: gitk @@GIT_VERSION@@\n" +"Report-Msgid-Bugs-To: Paul Mackerras <paulus@samba.org>\n" +"POT-Creation-Date: 2013-12-14 09:24+0700\n" +"PO-Revision-Date: 2013-12-14 14:40+0700\n" +"Last-Translator: Trần Ngọc Quân <vnwildman@gmail.com>\n" +"Language-Team: Vietnamese <translation-team-vi@lists.sourceforge.net>\n" +"Language: vi\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=1; plural=0;\n" + +#: gitk:140 +msgid "Couldn't get list of unmerged files:" +msgstr "Không thể lấy danh sách các tập-tin chưa được hòa trộn:" + +#: gitk:212 gitk:2353 +msgid "Color words" +msgstr "Tô màu chữ" + +#: gitk:217 gitk:2353 gitk:8103 gitk:8136 +msgid "Markup words" +msgstr "Đánh dấu chữ" + +#: gitk:322 +msgid "Error parsing revisions:" +msgstr "Gặp lỗi khi phân tích điểm xét duyệt:" + +#: gitk:378 +msgid "Error executing --argscmd command:" +msgstr "Gặp lỗi khi thực hiện lệnh --argscmd:" + +#: gitk:391 +msgid "No files selected: --merge specified but no files are unmerged." +msgstr "" +"Chưa chọn tập tin: --merge đã chỉ định nhưng không có tập tin chưa hòa trộn." + +#: gitk:394 +msgid "" +"No files selected: --merge specified but no unmerged files are within file " +"limit." +msgstr "" +"Chưa chọn tập tin: --merge đã chỉ định nhưng không có tập tin chưa hòa trộn " +"trong giới hạn tập tin." + +#: gitk:416 gitk:564 +msgid "Error executing git log:" +msgstr "Gặp lỗi khi thực hiện lệnh git log:" + +#: gitk:434 gitk:580 +msgid "Reading" +msgstr "Đang đọc" + +#: gitk:494 gitk:4429 +msgid "Reading commits..." +msgstr "Đang đọc các lần chuyển giao..." + +#: gitk:497 gitk:1635 gitk:4432 +msgid "No commits selected" +msgstr "Chưa chọn các lần chuyển giao" + +#: gitk:1509 +msgid "Can't parse git log output:" +msgstr "Không thể phân tích kết xuất từ lệnh git log:" + +#: gitk:1738 +msgid "No commit information available" +msgstr "Không có thông tin về lần chuyển giao nào" + +#: gitk:1895 +msgid "mc" +msgstr "mc" + +#: gitk:1930 gitk:4222 gitk:9552 gitk:11122 gitk:11401 +msgid "OK" +msgstr "Đồng ý" + +#: gitk:1932 gitk:4224 gitk:9079 gitk:9158 gitk:9274 gitk:9323 gitk:9554 +#: gitk:11123 gitk:11402 +msgid "Cancel" +msgstr "Thôi" + +#: gitk:2067 +msgid "Update" +msgstr "Cập nhật" + +#: gitk:2068 +msgid "Reload" +msgstr "Tải lại" + +#: gitk:2069 +msgid "Reread references" +msgstr "Đọc lại tham chiếu" + +#: gitk:2070 +msgid "List references" +msgstr "Liệt kê các tham chiếu" + +#: gitk:2072 +msgid "Start git gui" +msgstr "Khởi chạy git gui" + +#: gitk:2074 +msgid "Quit" +msgstr "Thoát" + +#: gitk:2066 +msgid "File" +msgstr "Chính" + +#: gitk:2078 +msgid "Preferences" +msgstr "Cá nhân hóa" + +#: gitk:2077 +msgid "Edit" +msgstr "Chỉnh sửa" + +#: gitk:2082 +msgid "New view..." +msgstr "Thêm trình bày mới..." + +#: gitk:2083 +msgid "Edit view..." +msgstr "Sửa cách trình bày..." + +#: gitk:2084 +msgid "Delete view" +msgstr "Xóa cách trình bày" + +#: gitk:2086 +msgid "All files" +msgstr "Mọi tập tin" + +#: gitk:2081 gitk:3975 +msgid "View" +msgstr "Trình bày" + +#: gitk:2091 gitk:2101 gitk:2945 +msgid "About gitk" +msgstr "Giới thiệu về gitk" + +#: gitk:2092 gitk:2106 +msgid "Key bindings" +msgstr "Tổ hợp phím" + +#: gitk:2090 gitk:2105 +msgid "Help" +msgstr "Trợ giúp" + +#: gitk:2183 gitk:8535 +msgid "SHA1 ID:" +msgstr "SHA1 ID:" + +#: gitk:2227 +msgid "Row" +msgstr "Hàng" + +#: gitk:2265 +msgid "Find" +msgstr "Tìm" + +#: gitk:2266 +msgid "next" +msgstr "tiếp" + +#: gitk:2267 +msgid "prev" +msgstr "trước" + +#: gitk:2268 +msgid "commit" +msgstr "lần chuyển giao" + +#: gitk:2271 gitk:2273 gitk:4590 gitk:4613 gitk:4637 gitk:6653 gitk:6725 +#: gitk:6810 +msgid "containing:" +msgstr "có chứa:" + +#: gitk:2274 gitk:3457 gitk:3462 gitk:4666 +msgid "touching paths:" +msgstr "đang chạm đường dẫn:" + +#: gitk:2275 gitk:4680 +msgid "adding/removing string:" +msgstr "thêm/gỡ bỏ chuỗi:" + +#: gitk:2276 gitk:4682 +msgid "changing lines matching:" +msgstr "những dòng thay đổi khớp mẫu:" + +#: gitk:2285 gitk:2287 gitk:4669 +msgid "Exact" +msgstr "Chính xác" + +#: gitk:2287 gitk:4757 gitk:6621 +msgid "IgnCase" +msgstr "BquaHt" + +#: gitk:2287 gitk:4639 gitk:4755 gitk:6617 +msgid "Regexp" +msgstr "BTCQ" + +#: gitk:2289 gitk:2290 gitk:4777 gitk:4807 gitk:4814 gitk:6746 gitk:6814 +msgid "All fields" +msgstr "Mọi trường" + +#: gitk:2290 gitk:4774 gitk:4807 gitk:6684 +msgid "Headline" +msgstr "Nội dung chính" + +#: gitk:2291 gitk:4774 gitk:6684 gitk:6814 gitk:7283 +msgid "Comments" +msgstr "Ghi chú" + +#: gitk:2291 gitk:4774 gitk:4779 gitk:4814 gitk:6684 gitk:7218 gitk:8713 +#: gitk:8728 +msgid "Author" +msgstr "Tác giả" + +#: gitk:2291 gitk:4774 gitk:6684 gitk:7220 +msgid "Committer" +msgstr "Người chuyển giao" + +#: gitk:2322 +msgid "Search" +msgstr "Tìm kiếm" + +#: gitk:2330 +msgid "Diff" +msgstr "So sánh" + +#: gitk:2332 +msgid "Old version" +msgstr "Phiên bản cũ" + +#: gitk:2334 +msgid "New version" +msgstr "Phiên bản mới" + +#: gitk:2336 +msgid "Lines of context" +msgstr "Các dòng của nội dung" + +#: gitk:2346 +msgid "Ignore space change" +msgstr "Không xét đến thay đổi do khoảng trắng" + +#: gitk:2350 gitk:2352 gitk:7842 gitk:8089 +msgid "Line diff" +msgstr "Khác biệt theo dòng" + +#: gitk:2417 +msgid "Patch" +msgstr "Vá" + +#: gitk:2419 +msgid "Tree" +msgstr "Cây" + +#: gitk:2577 gitk:2597 +msgid "Diff this -> selected" +msgstr "So sánh cái này -> cái đã chọn" + +#: gitk:2578 gitk:2598 +msgid "Diff selected -> this" +msgstr "So sánh cái đã chọn -> cái này" + +#: gitk:2579 gitk:2599 +msgid "Make patch" +msgstr "Tạo miếng vá" + +#: gitk:2580 gitk:9137 +msgid "Create tag" +msgstr "Tạo thẻ" + +#: gitk:2581 gitk:9254 +msgid "Write commit to file" +msgstr "Ghi lần chuyển giao ra tập tin" + +#: gitk:2582 gitk:9311 +msgid "Create new branch" +msgstr "Tạo nhánh mới" + +#: gitk:2583 +msgid "Cherry-pick this commit" +msgstr "Cherry-pick lần chuyển giao này" + +#: gitk:2584 +msgid "Reset HEAD branch to here" +msgstr "Đặt lại HEAD của nhánh vào đây" + +#: gitk:2585 +msgid "Mark this commit" +msgstr "Đánh dấu lần chuyển giao này" + +#: gitk:2586 +msgid "Return to mark" +msgstr "Quay lại vị trí dấu" + +#: gitk:2587 +msgid "Find descendant of this and mark" +msgstr "Tìm con cháu của cái này và cái đã đánh dấu" + +#: gitk:2588 +msgid "Compare with marked commit" +msgstr "So sánh với lần chuyển giao đã đánh dấu" + +#: gitk:2589 gitk:2600 +msgid "Diff this -> marked commit" +msgstr "So sánh cái này -> lần chuyển giao đã đánh dấu" + +#: gitk:2590 gitk:2601 +msgid "Diff marked commit -> this" +msgstr "So sánh lần chuyển giao đã đánh dấu -> cái này" + +#: gitk:2591 +msgid "Revert this commit" +msgstr "Hoàn lại lần chuyển giao này" + +#: gitk:2607 +msgid "Check out this branch" +msgstr "Checkout nhánh này" + +#: gitk:2608 +msgid "Remove this branch" +msgstr "Gỡ bỏ nhánh này" + +#: gitk:2615 +msgid "Highlight this too" +msgstr "Cũng tô sáng nó" + +#: gitk:2616 +msgid "Highlight this only" +msgstr "Chỉ tô sáng cái này" + +#: gitk:2617 +msgid "External diff" +msgstr "diff từ bên ngoài" + +#: gitk:2618 +msgid "Blame parent commit" +msgstr "Xem công trạng lần chuyển giao cha mẹ" + +#: gitk:2625 +msgid "Show origin of this line" +msgstr "Hiển thị nguyên gốc của dòng này" + +#: gitk:2626 +msgid "Run git gui blame on this line" +msgstr "Chạy lệnh git gui blame cho dòng này" + +#: gitk:2947 +msgid "" +"\n" +"Gitk - a commit viewer for git\n" +"\n" +"Copyright © 2005-2011 Paul Mackerras\n" +"\n" +"Use and redistribute under the terms of the GNU General Public License" +msgstr "" +"\n" +"Gitk - phần mềm xem các lần chuyển giao dành cho git\n" +"\n" +"Bản quyền © 2005-2011 Paul Mackerras\n" +"\n" +"Dùng và phân phối lại phần mềm này theo các điều khoản của Giấy Phép Công GNU" + +#: gitk:2955 gitk:3020 gitk:9738 +msgid "Close" +msgstr "Đóng" + +#: gitk:2976 +msgid "Gitk key bindings" +msgstr "Tổ hợp phím gitk" + +#: gitk:2979 +msgid "Gitk key bindings:" +msgstr "Tổ hợp phím gitk:" + +#: gitk:2981 +#, tcl-format +msgid "<%s-Q>\t\tQuit" +msgstr "<%s-Q>\t\tThoát" + +#: gitk:2982 +#, tcl-format +msgid "<%s-W>\t\tClose window" +msgstr "<%s-W>\t\tĐóng cửa sổ" + +#: gitk:2983 +msgid "<Home>\t\tMove to first commit" +msgstr "<Home>\t\tChuyển đến lần chuyển giao đầu tiên" + +#: gitk:2984 +msgid "<End>\t\tMove to last commit" +msgstr "<End>\t\tChuyển đến lần chuyển giao cuối" + +#: gitk:2985 +msgid "<Up>, p, k\tMove up one commit" +msgstr "<Up>, p, k\tDi chuyển lên một lần chuyển giao" + +#: gitk:2986 +msgid "<Down>, n, j\tMove down one commit" +msgstr "<Down>, n, j\tDi chuyển xuống một lần chuyển giao" + +#: gitk:2987 +msgid "<Left>, z, h\tGo back in history list" +msgstr "<Left>, z, h\tQuay trở lại danh sách lịch sử" + +#: gitk:2988 +msgid "<Right>, x, l\tGo forward in history list" +msgstr "<Right>, x, l\tDi chuyển tiếp trong danh sách lịch sử" + +#: gitk:2989 +msgid "<PageUp>\tMove up one page in commit list" +msgstr "<PageUp>\tDi chuyển lên một trang trong danh sách lần chuyển giao" + +#: gitk:2990 +msgid "<PageDown>\tMove down one page in commit list" +msgstr "<PageDown>\tDi chuyển xuống một trang trong danh sách lần chuyển giao" + +#: gitk:2991 +#, tcl-format +msgid "<%s-Home>\tScroll to top of commit list" +msgstr "<%s-Home>\tCuộn lên trên cùng của danh sách lần chuyển giao" + +#: gitk:2992 +#, tcl-format +msgid "<%s-End>\tScroll to bottom of commit list" +msgstr "<%s-End>\tCuộn xuống dưới cùng của danh sách lần chuyển giao" + +#: gitk:2993 +#, tcl-format +msgid "<%s-Up>\tScroll commit list up one line" +msgstr "<%s-Up>\tCuộn danh sách lần chuyển giao lên một dòng" + +#: gitk:2994 +#, tcl-format +msgid "<%s-Down>\tScroll commit list down one line" +msgstr "<%s-Down>\tCuộn danh sách lần chuyển giao xuống một dòng" + +#: gitk:2995 +#, tcl-format +msgid "<%s-PageUp>\tScroll commit list up one page" +msgstr "<%s-PageUp>\tCuộn danh sách lần chuyển giao lên một trang" + +#: gitk:2996 +#, tcl-format +msgid "<%s-PageDown>\tScroll commit list down one page" +msgstr "<%s-PageDown>\tCuộn danh sách lần chuyển giao xuống một trang" + +#: gitk:2997 +msgid "<Shift-Up>\tFind backwards (upwards, later commits)" +msgstr "<Shift-Up>\tTìm về phía sau (hướng lên trên, lần chuyển giao sau này)" + +#: gitk:2998 +msgid "<Shift-Down>\tFind forwards (downwards, earlier commits)" +msgstr "" +"<Shift-Down>\tTìm về phía trước (hướng xuống dưới, lần chuyển giao trước đây)" + +#: gitk:2999 +msgid "<Delete>, b\tScroll diff view up one page" +msgstr "<Delete>, b\tCuộn phần trình bày diff lên một trang" + +#: gitk:3000 +msgid "<Backspace>\tScroll diff view up one page" +msgstr "<Backspace>\tCuộn phần trình bày diff lên một trang" + +#: gitk:3001 +msgid "<Space>\t\tScroll diff view down one page" +msgstr "<Space>\t\tCuộn phần trình bày diff xuống một trang" + +#: gitk:3002 +msgid "u\t\tScroll diff view up 18 lines" +msgstr "u\t\tCuộn phần trình bày diff lên 18 dòng" + +#: gitk:3003 +msgid "d\t\tScroll diff view down 18 lines" +msgstr "d\t\tCuộn phần trình bày diff xuống 18 dòng" + +#: gitk:3004 +#, tcl-format +msgid "<%s-F>\t\tFind" +msgstr "<%s-F>\t\tTìm kiếm" + +#: gitk:3005 +#, tcl-format +msgid "<%s-G>\t\tMove to next find hit" +msgstr "<%s-G>\t\tDi chuyển đến chỗ gặp kế tiếp" + +#: gitk:3006 +msgid "<Return>\tMove to next find hit" +msgstr "<Return>\t\tDi chuyển đến chỗ gặp kế tiếp" + +#: gitk:3007 +msgid "/\t\tFocus the search box" +msgstr "/\t\tĐưa con trỏ chuột vào ô tìm kiếm" + +#: gitk:3008 +msgid "?\t\tMove to previous find hit" +msgstr "?\t\tDi chuyển đến chỗ gặp kế trước" + +#: gitk:3009 +msgid "f\t\tScroll diff view to next file" +msgstr "f\t\tCuộn phần trình bày diff sang tập-tin kế" + +#: gitk:3010 +#, tcl-format +msgid "<%s-S>\t\tSearch for next hit in diff view" +msgstr "<%s-S>\t\tTìm đến chỗ khác biệt kế tiếp" + +#: gitk:3011 +#, tcl-format +msgid "<%s-R>\t\tSearch for previous hit in diff view" +msgstr "<%s-R>\t\tTìm đến chỗ khác biệt kế trước" + +#: gitk:3012 +#, tcl-format +msgid "<%s-KP+>\tIncrease font size" +msgstr "<%s-KP+>\tTăng cỡ chữ" + +#: gitk:3013 +#, tcl-format +msgid "<%s-plus>\tIncrease font size" +msgstr "<%s-plus>\tTăng cỡ chữ" + +#: gitk:3014 +#, tcl-format +msgid "<%s-KP->\tDecrease font size" +msgstr "<%s-KP->\tGiảm cỡ chữ" + +#: gitk:3015 +#, tcl-format +msgid "<%s-minus>\tDecrease font size" +msgstr "<%s-minus>\tGiảm cỡ chữ" + +#: gitk:3016 +msgid "<F5>\t\tUpdate" +msgstr "<F5>\t\tCập nhật" + +#: gitk:3471 gitk:3480 +#, tcl-format +msgid "Error creating temporary directory %s:" +msgstr "Gặp lỗi khi tạo thư mục tạm %s:" + +#: gitk:3493 +#, tcl-format +msgid "Error getting \"%s\" from %s:" +msgstr "Lỗi chào hỏi \"%s\" từ %s:" + +#: gitk:3556 +msgid "command failed:" +msgstr "lệnh gặp lỗi:" + +#: gitk:3705 +msgid "No such commit" +msgstr "Không có lần chuyển giao như vậy" + +#: gitk:3719 +msgid "git gui blame: command failed:" +msgstr "git gui blame: lệnh gặp lỗi:" + +#: gitk:3750 +#, tcl-format +msgid "Couldn't read merge head: %s" +msgstr "Không thể độc đầu của hòa trộn: %s" + +# tcl-format +#: gitk:3758 +#, tcl-format +msgid "Error reading index: %s" +msgstr "Gặp lỗi khi đọc chỉ mục: %s" + +#: gitk:3783 +#, tcl-format +msgid "Couldn't start git blame: %s" +msgstr "Không thể khởi chạy git blame: %s" + +#: gitk:3786 gitk:6652 +msgid "Searching" +msgstr "Đang tìm kiếm" + +#: gitk:3818 +#, tcl-format +msgid "Error running git blame: %s" +msgstr "Gặp lỗi khi chạy git blame: %s" + +#: gitk:3846 +#, tcl-format +msgid "That line comes from commit %s, which is not in this view" +msgstr "Dòng đến từ lần chuyển giao %s, cái mà không trong trình bày này" + +#: gitk:3860 +msgid "External diff viewer failed:" +msgstr "Bộ trình bày diff từ bên ngoài gặp lỗi:" + +#: gitk:3978 +msgid "Gitk view definition" +msgstr "Định nghĩa cách trình bày gitk" + +#: gitk:3982 +msgid "Remember this view" +msgstr "Nhớ cách trình bày này" + +#: gitk:3983 +msgid "References (space separated list):" +msgstr "Tham chiếu (danh sách ngăn cách bằng dấu cách):" + +#: gitk:3984 +msgid "Branches & tags:" +msgstr "Nhánh & thẻ:" + +#: gitk:3985 +msgid "All refs" +msgstr "Mọi tham chiếu" + +#: gitk:3986 +msgid "All (local) branches" +msgstr "Mọi nhánh (nội bộ)" + +#: gitk:3987 +msgid "All tags" +msgstr "Mọi thẻ" + +#: gitk:3988 +msgid "All remote-tracking branches" +msgstr "Mọi nhánh remote-tracking" + +#: gitk:3989 +msgid "Commit Info (regular expressions):" +msgstr "Thông tin chuyển giao (biểu thức chính quy):" + +#: gitk:3990 +msgid "Author:" +msgstr "Tác giả:" + +#: gitk:3991 +msgid "Committer:" +msgstr "Người chuyển giao:" + +#: gitk:3992 +msgid "Commit Message:" +msgstr "Chú thích của lần chuyển giao:" + +#: gitk:3993 +msgid "Matches all Commit Info criteria" +msgstr "Khớp mọi điều kiện Thông tin Chuyển giao" + +#: gitk:3994 +msgid "Changes to Files:" +msgstr "Đổi thành Tập tin:" + +#: gitk:3995 +msgid "Fixed String" +msgstr "Chuỗi cố định" + +#: gitk:3996 +msgid "Regular Expression" +msgstr "Biểu thức chính quy" + +#: gitk:3997 +msgid "Search string:" +msgstr "Chuỗi tìm kiếm:" + +#: gitk:3998 +msgid "" +"Commit Dates (\"2 weeks ago\", \"2009-03-17 15:27:38\", \"March 17, 2009 " +"15:27:38\"):" +msgstr "" +"Ngày chuyển giao (\"2 weeks ago\", \"2009-03-17 15:27:38\", \"March 17, 2009 " +"15:27:38\"):" + +#: gitk:3999 +msgid "Since:" +msgstr "Kể từ:" + +#: gitk:4000 +msgid "Until:" +msgstr "Đến:" + +#: gitk:4001 +msgid "Limit and/or skip a number of revisions (positive integer):" +msgstr "Giới hạn và/hoặc bỏ số của điểm xét (số nguyên âm):" + +#: gitk:4002 +msgid "Number to show:" +msgstr "Số lượng hiển thị:" + +#: gitk:4003 +msgid "Number to skip:" +msgstr "Số lượng sẽ bỏ qua:" + +#: gitk:4004 +msgid "Miscellaneous options:" +msgstr "Tuỳ chọn hỗn hợp:" + +#: gitk:4005 +msgid "Strictly sort by date" +msgstr "Sắp xếp chặt chẽ theo ngày" + +#: gitk:4006 +msgid "Mark branch sides" +msgstr "Đánh dấu các cạnh nhánh" + +#: gitk:4007 +msgid "Limit to first parent" +msgstr "Giới hạn thành cha mẹ đầu tiên" + +#: gitk:4008 +msgid "Simple history" +msgstr "Lịch sử dạng đơn giản" + +#: gitk:4009 +msgid "Additional arguments to git log:" +msgstr "Đối số bổ xung cho lệnh git log:" + +#: gitk:4010 +msgid "Enter files and directories to include, one per line:" +msgstr "Nhập vào các tập tin và thư mục bao gồm, mỗi dòng một cái:" + +#: gitk:4011 +msgid "Command to generate more commits to include:" +msgstr "Lệnh tạo ra nhiều lần chuyển giao hơn bao gồm:" + +#: gitk:4135 +msgid "Gitk: edit view" +msgstr "Gitk: sửa cách trình bày" + +#: gitk:4143 +msgid "-- criteria for selecting revisions" +msgstr "-- tiêu chuẩn chọn điểm xét duyệt" + +#: gitk:4148 +msgid "View Name" +msgstr "Tên cách trình bày" + +#: gitk:4223 +msgid "Apply (F5)" +msgstr "Áp dụng (F5)" + +#: gitk:4261 +msgid "Error in commit selection arguments:" +msgstr "Lỗi trong các đối số chọn chuyển giao:" + +#: gitk:4314 gitk:4366 gitk:4827 gitk:4841 gitk:6107 gitk:12184 gitk:12185 +msgid "None" +msgstr "Không" + +#: gitk:4924 gitk:4929 +msgid "Descendant" +msgstr "Con cháu" + +#: gitk:4925 +msgid "Not descendant" +msgstr "Không có con cháu" + +#: gitk:4932 gitk:4937 +msgid "Ancestor" +msgstr "Tổ tiên chung" + +#: gitk:4933 +msgid "Not ancestor" +msgstr "Không có chung tổ tiên" + +#: gitk:5223 +msgid "Local changes checked in to index but not committed" +msgstr "" +"Có thay đổi nội bộ đã được đưa vào bảng mục lục, nhưng chưa được chuyển giao" + +#: gitk:5259 +msgid "Local uncommitted changes, not checked in to index" +msgstr "Có thay đổi nội bộ, nhưng chưa được đưa vào bảng mục lục" + +#: gitk:7032 +msgid "and many more" +msgstr "và nhiều nữa" + +#: gitk:7035 +msgid "many" +msgstr "nhiều" + +#: gitk:7222 +msgid "Tags:" +msgstr "Thẻ:" + +#: gitk:7239 gitk:7245 gitk:8708 +msgid "Parent" +msgstr "Cha" + +#: gitk:7250 +msgid "Child" +msgstr "Con" + +#: gitk:7259 +msgid "Branch" +msgstr "Nhánh" + +#: gitk:7262 +msgid "Follows" +msgstr "Đứng sau" + +#: gitk:7265 +msgid "Precedes" +msgstr "Đứng trước" + +# tcl-format +#: gitk:7849 +#, tcl-format +msgid "Error getting diffs: %s" +msgstr "Lỗi lấy diff: %s" + +#: gitk:8533 +msgid "Goto:" +msgstr "Nhảy tới:" + +#: gitk:8554 +#, tcl-format +msgid "Short SHA1 id %s is ambiguous" +msgstr "Định danh SHA1 dạng ngắn %s là chưa đủ rõ ràng" + +#: gitk:8561 +#, tcl-format +msgid "Revision %s is not known" +msgstr "Không hiểu điểm xét duyệt %s" + +#: gitk:8571 +#, tcl-format +msgid "SHA1 id %s is not known" +msgstr "Không hiểu định danh SHA1 %s" + +#: gitk:8573 +#, tcl-format +msgid "Revision %s is not in the current view" +msgstr "Điểm %s không ở trong phần hiển thị hiện tại" + +#: gitk:8715 gitk:8730 +msgid "Date" +msgstr "Ngày" + +#: gitk:8718 +msgid "Children" +msgstr "Con cháu" + +#: gitk:8781 +#, tcl-format +msgid "Reset %s branch to here" +msgstr "Đặt lại nhánh %s tại đây" + +#: gitk:8783 +msgid "Detached head: can't reset" +msgstr "Head đã bị tách rời: không thể đặt lại" + +#: gitk:8888 gitk:8894 +msgid "Skipping merge commit " +msgstr "Bỏ qua lần chuyển giao hòa trộn " + +#: gitk:8903 gitk:8908 +msgid "Error getting patch ID for " +msgstr "Gặp lỗi khi lấy ID miếng vá cho " + +#: gitk:8904 gitk:8909 +msgid " - stopping\n" +msgstr " - dừng\n" + +#: gitk:8914 gitk:8917 gitk:8925 gitk:8939 gitk:8948 +msgid "Commit " +msgstr "Commit " + +#: gitk:8918 +msgid "" +" is the same patch as\n" +" " +msgstr "" +" là cùng một miếng vá với\n" +" " + +#: gitk:8926 +msgid "" +" differs from\n" +" " +msgstr "" +" khác biệt từ\n" +" " + +#: gitk:8928 +msgid "" +"Diff of commits:\n" +"\n" +msgstr "" +"Khác biệt của lần chuyển giao (commit):\n" +"\n" + +#: gitk:8940 gitk:8949 +#, tcl-format +msgid " has %s children - stopping\n" +msgstr " có %s con - dừng\n" + +#: gitk:8968 +#, tcl-format +msgid "Error writing commit to file: %s" +msgstr "Gặp lỗi trong quá trình ghi lần chuyển giao vào tập tin: %s" + +#: gitk:8974 +#, tcl-format +msgid "Error diffing commits: %s" +msgstr "Gặp lỗi khi so sánh sự khác biệt giữa các lần chuyển giao: %s" + +#: gitk:9020 +msgid "Top" +msgstr "Đỉnh" + +#: gitk:9021 +msgid "From" +msgstr "Từ" + +#: gitk:9026 +msgid "To" +msgstr "Đến" + +#: gitk:9050 +msgid "Generate patch" +msgstr "Tạo miếng vá" + +#: gitk:9052 +msgid "From:" +msgstr "Từ:" + +#: gitk:9061 +msgid "To:" +msgstr "Đến:" + +#: gitk:9070 +msgid "Reverse" +msgstr "Đảo ngược" + +#: gitk:9072 gitk:9268 +msgid "Output file:" +msgstr "Tập tin kết xuất:" + +#: gitk:9078 +msgid "Generate" +msgstr "Tạo" + +#: gitk:9116 +msgid "Error creating patch:" +msgstr "Gặp lỗi khi tạo miếng vá:" + +#: gitk:9139 gitk:9256 gitk:9313 +msgid "ID:" +msgstr "ID:" + +#: gitk:9148 +msgid "Tag name:" +msgstr "Tên thẻ:" + +#: gitk:9151 +msgid "Tag message is optional" +msgstr "Ghi chú thẻ chỉ là tùy chọn" + +#: gitk:9153 +msgid "Tag message:" +msgstr "Ghi chú cho thẻ:" + +#: gitk:9157 gitk:9322 +msgid "Create" +msgstr "Tạo" + +#: gitk:9175 +msgid "No tag name specified" +msgstr "Chưa chỉ ra tên của thẻ" + +#: gitk:9179 +#, tcl-format +msgid "Tag \"%s\" already exists" +msgstr "Thẻ “%s” đã có sẵn rồi" + +#: gitk:9189 +msgid "Error creating tag:" +msgstr "Gặp lỗi khi tạo thẻ:" + +#: gitk:9265 +msgid "Command:" +msgstr "Lệnh:" + +#: gitk:9273 +msgid "Write" +msgstr "Ghi" + +#: gitk:9291 +msgid "Error writing commit:" +msgstr "Gặp lỗi trong quá trình ghi chuyển giao:" + +#: gitk:9318 +msgid "Name:" +msgstr "Tên:" + +#: gitk:9341 +msgid "Please specify a name for the new branch" +msgstr "Vui lòng chỉ định tên cho nhánh mới" + +#: gitk:9346 +#, tcl-format +msgid "Branch '%s' already exists. Overwrite?" +msgstr "Nhánh “%s” đã có từ trước rồi. Ghi đè?" + +#: gitk:9413 +#, tcl-format +msgid "Commit %s is already included in branch %s -- really re-apply it?" +msgstr "" +"Lần chuyển giao %s đã sẵn được bao gồm trong nhánh %s -- bạn có thực sự muốn " +"áp dụng lại nó không?" + +#: gitk:9418 +msgid "Cherry-picking" +msgstr "Đang cherry-pick" + +#: gitk:9427 +#, tcl-format +msgid "" +"Cherry-pick failed because of local changes to file '%s'.\n" +"Please commit, reset or stash your changes and try again." +msgstr "" +"Cherry-pick gặp lỗi bởi vì các thay đổi nội bộ tập tin “%s”.\n" +"Xin hãy chuyển giao, reset hay stash các thay đổi của bạn sau đó thử lại." + +#: gitk:9433 +msgid "" +"Cherry-pick failed because of merge conflict.\n" +"Do you wish to run git citool to resolve it?" +msgstr "" +"Cherry-pick gặp lỗi bởi vì xung đột trong hòa trộn.\n" +"Bạn có muốn chạy lệnh “git citool” để giải quyết vấn đề này không?" + +#: gitk:9449 gitk:9507 +msgid "No changes committed" +msgstr "Không có thay đổi nào cần chuyển giao" + +#: gitk:9476 +#, tcl-format +msgid "Commit %s is not included in branch %s -- really revert it?" +msgstr "" +"Lần chuyển giao %s không được bao gồm trong nhánh %s -- bạn có thực sự muốn " +"“revert” nó không?" + +#: gitk:9481 +msgid "Reverting" +msgstr "Đang hoàn tác" + +#: gitk:9489 +#, tcl-format +msgid "" +"Revert failed because of local changes to the following files:%s Please " +"commit, reset or stash your changes and try again." +msgstr "" +"Revert gặp lỗi bởi vì tập tin sau đã được thay đổi nội bộ:%s\n" +"Xin hãy chạy lệnh “commit”, “reset” hoặc “stash” rồi thử lại." + +#: gitk:9493 +msgid "" +"Revert failed because of merge conflict.\n" +" Do you wish to run git citool to resolve it?" +msgstr "" +"Revert gặp lỗi bởi vì xung đột hòa trộn.\n" +" Bạn có muốn chạy lệnh “git citool” để phân giải nó không?" + +#: gitk:9536 +msgid "Confirm reset" +msgstr "Xác nhật đặt lại" + +#: gitk:9538 +#, tcl-format +msgid "Reset branch %s to %s?" +msgstr "Đặt lại nhánh “%s” thành “%s”?" + +#: gitk:9540 +msgid "Reset type:" +msgstr "Kiểu đặt lại:" + +#: gitk:9543 +msgid "Soft: Leave working tree and index untouched" +msgstr "Mềm: Không động đến thư mục làm việc và bảng mục lục" + +#: gitk:9546 +msgid "Mixed: Leave working tree untouched, reset index" +msgstr "" +"Pha trộn: Không động chạm đến thư mục làm việc nhưng đặt lại bảng mục lục" + +#: gitk:9549 +msgid "" +"Hard: Reset working tree and index\n" +"(discard ALL local changes)" +msgstr "" +"Hard: Đặt lại cây làm việc và mục lục\n" +"(hủy bỏ MỌI thay đổi nội bộ)" + +#: gitk:9566 +msgid "Resetting" +msgstr "Đang đặt lại" + +#: gitk:9626 +msgid "Checking out" +msgstr "Đang checkout" + +#: gitk:9679 +msgid "Cannot delete the currently checked-out branch" +msgstr "Không thể xóa nhánh hiện tại đang được lấy ra" + +#: gitk:9685 +#, tcl-format +msgid "" +"The commits on branch %s aren't on any other branch.\n" +"Really delete branch %s?" +msgstr "" +"Các lần chuyển giao trên nhánh %s không ở trên nhánh khác.\n" +"Thực sự muốn xóa nhánh %s?" + +#: gitk:9716 +#, tcl-format +msgid "Tags and heads: %s" +msgstr "Thẻ và Đầu: %s" + +#: gitk:9731 +msgid "Filter" +msgstr "Bộ lọc" + +#: gitk:10027 +msgid "" +"Error reading commit topology information; branch and preceding/following " +"tag information will be incomplete." +msgstr "" +"Gặp lỗi khi đọc thông tin hình học lần chuyển giao; thông tin nhánh và thẻ " +"trước/sau sẽ không hoàn thiện." + +#: gitk:11004 +msgid "Tag" +msgstr "Thẻ" + +#: gitk:11008 +msgid "Id" +msgstr "Id" + +#: gitk:11091 +msgid "Gitk font chooser" +msgstr "Hộp thoại chọn phông Gitk" + +#: gitk:11108 +msgid "B" +msgstr "B" + +#: gitk:11111 +msgid "I" +msgstr "I" + +#: gitk:11229 +msgid "Commit list display options" +msgstr "Các tùy chọn về hiển thị danh sách lần chuyển giao" + +#: gitk:11232 +msgid "Maximum graph width (lines)" +msgstr "Độ rộng biểu đồ tối đa (dòng)" + +#: gitk:11235 +#, tcl-format +msgid "Maximum graph width (% of pane)" +msgstr "Độ rộng biểu đồ tối đa (% của bảng)" + +#: gitk:11238 +msgid "Show local changes" +msgstr "Hiển thị các thay đổi nội bộ" + +#: gitk:11241 +msgid "Auto-select SHA1 (length)" +msgstr "Tự chọn SHA1 (độ dài)" + +#: gitk:11245 +msgid "Hide remote refs" +msgstr "Ẩn tham chiếu đến máy chủ" + +#: gitk:11249 +msgid "Diff display options" +msgstr "Các tùy chọn trình bày các khác biệt" + +#: gitk:11251 +msgid "Tab spacing" +msgstr "Khoảng cách tab" + +#: gitk:11254 +msgid "Display nearby tags/heads" +msgstr "Hiển thị các thẻ/đầu xung quanh" + +#: gitk:11257 +msgid "Maximum # tags/heads to show" +msgstr "Số lượng thẻ/đầu tối đa sẽ hiển thị" + +#: gitk:11260 +msgid "Limit diffs to listed paths" +msgstr "Giới hạn các khác biệt cho đường dẫn đã liệt kê" + +#: gitk:11263 +msgid "Support per-file encodings" +msgstr "Hỗ trợ mã hóa mỗi-dòng" + +#: gitk:11269 gitk:11416 +msgid "External diff tool" +msgstr "Công cụ so sánh từ bên ngoài" + +#: gitk:11270 +msgid "Choose..." +msgstr "Chọn..." + +#: gitk:11275 +msgid "General options" +msgstr "Các tùy chọn chung" + +#: gitk:11278 +msgid "Use themed widgets" +msgstr "Dùng các widget chủ đề" + +#: gitk:11280 +msgid "(change requires restart)" +msgstr "(để thay đổi cần khởi động lại)" + +#: gitk:11282 +msgid "(currently unavailable)" +msgstr "(hiện tại không sẵn sàng)" + +#: gitk:11293 +msgid "Colors: press to choose" +msgstr "Màu sắc: bấm vào nút phía dưới để chọn màu" + +#: gitk:11296 +msgid "Interface" +msgstr "Giao diện" + +#: gitk:11297 +msgid "interface" +msgstr "giao diện" + +#: gitk:11300 +msgid "Background" +msgstr "Nền" + +#: gitk:11301 gitk:11331 +msgid "background" +msgstr "nền" + +#: gitk:11304 +msgid "Foreground" +msgstr "Tiền cảnh" + +#: gitk:11305 +msgid "foreground" +msgstr "tiền cảnh" + +#: gitk:11308 +msgid "Diff: old lines" +msgstr "So sánh: dòng cũ" + +#: gitk:11309 +msgid "diff old lines" +msgstr "diff dòng cũ" + +#: gitk:11313 +msgid "Diff: new lines" +msgstr "So sánh: dòng mới" + +#: gitk:11314 +msgid "diff new lines" +msgstr "màu dòng mới" + +#: gitk:11318 +msgid "Diff: hunk header" +msgstr "So sánh: phần đầu của đoạn" + +#: gitk:11320 +msgid "diff hunk header" +msgstr "màu của phần đầu của đoạn khi so sánh" + +#: gitk:11324 +msgid "Marked line bg" +msgstr "Nền dòng đánh dấu" + +#: gitk:11326 +msgid "marked line background" +msgstr "nền dòng được đánh dấu" + +#: gitk:11330 +msgid "Select bg" +msgstr "Màu nền" + +#: gitk:11339 +msgid "Fonts: press to choose" +msgstr "Phông chữ: bấm vào các nút ở dưới để chọn" + +#: gitk:11341 +msgid "Main font" +msgstr "Phông chữ chính" + +#: gitk:11342 +msgid "Diff display font" +msgstr "Phông chữ dùng khi so sánh" + +#: gitk:11343 +msgid "User interface font" +msgstr "Phông chữ giao diện" + +#: gitk:11365 +msgid "Gitk preferences" +msgstr "Cá nhân hóa các cài đặt cho Gitk" + +#: gitk:11374 +msgid "General" +msgstr "Chung" + +#: gitk:11375 +msgid "Colors" +msgstr "Màu sắc" + +#: gitk:11376 +msgid "Fonts" +msgstr "Phông chữ" + +#: gitk:11426 +#, tcl-format +msgid "Gitk: choose color for %s" +msgstr "Gitk: chọn màu cho %s" + +#: gitk:12080 +msgid "Cannot find a git repository here." +msgstr "Không thể tìm thấy kho git ở đây." + +#: gitk:12127 +#, tcl-format +msgid "Ambiguous argument '%s': both revision and filename" +msgstr "Đối số “%s” chưa rõ ràng: vừa là điểm xét duyệt vừa là tên tập tin" + +#: gitk:12139 +msgid "Bad arguments to gitk:" +msgstr "Đối số không hợp lệ cho gitk:" + +#: gitk:12242 +msgid "Command line" +msgstr "Dòng lệnh" diff --git a/http-push.c b/http-push.c index f2c56c8454..de00d1693a 100644 --- a/http-push.c +++ b/http-push.c @@ -1732,7 +1732,7 @@ int main(int argc, char **argv) git_extract_argv0_path(argv[0]); - repo = xcalloc(sizeof(*repo), 1); + repo = xcalloc(1, sizeof(*repo)); argv++; for (i = 1; i < argc; i++, argv++) { @@ -906,6 +906,83 @@ static CURLcode curlinfo_strbuf(CURL *curl, CURLINFO info, struct strbuf *buf) return ret; } +/* + * Check for and extract a content-type parameter. "raw" + * should be positioned at the start of the potential + * parameter, with any whitespace already removed. + * + * "name" is the name of the parameter. The value is appended + * to "out". + */ +static int extract_param(const char *raw, const char *name, + struct strbuf *out) +{ + size_t len = strlen(name); + + if (strncasecmp(raw, name, len)) + return -1; + raw += len; + + if (*raw != '=') + return -1; + raw++; + + while (*raw && !isspace(*raw) && *raw != ';') + strbuf_addch(out, *raw++); + return 0; +} + +/* + * Extract a normalized version of the content type, with any + * spaces suppressed, all letters lowercased, and no trailing ";" + * or parameters. + * + * Note that we will silently remove even invalid whitespace. For + * example, "text / plain" is specifically forbidden by RFC 2616, + * but "text/plain" is the only reasonable output, and this keeps + * our code simple. + * + * If the "charset" argument is not NULL, store the value of any + * charset parameter there. + * + * Example: + * "TEXT/PLAIN; charset=utf-8" -> "text/plain", "utf-8" + * "text / plain" -> "text/plain" + */ +static void extract_content_type(struct strbuf *raw, struct strbuf *type, + struct strbuf *charset) +{ + const char *p; + + strbuf_reset(type); + strbuf_grow(type, raw->len); + for (p = raw->buf; *p; p++) { + if (isspace(*p)) + continue; + if (*p == ';') { + p++; + break; + } + strbuf_addch(type, tolower(*p)); + } + + if (!charset) + return; + + strbuf_reset(charset); + while (*p) { + while (isspace(*p) || *p == ';') + p++; + if (!extract_param(p, "charset", charset)) + return; + while (*p && !isspace(*p)) + p++; + } + + if (!charset->len && starts_with(type->buf, "text/")) + strbuf_addstr(charset, "ISO-8859-1"); +} + /* http_request() targets */ #define HTTP_REQUEST_STRBUF 0 #define HTTP_REQUEST_FILE 1 @@ -957,9 +1034,13 @@ static int http_request(const char *url, ret = run_one_slot(slot, &results); - if (options && options->content_type) - curlinfo_strbuf(slot->curl, CURLINFO_CONTENT_TYPE, - options->content_type); + if (options && options->content_type) { + struct strbuf raw = STRBUF_INIT; + curlinfo_strbuf(slot->curl, CURLINFO_CONTENT_TYPE, &raw); + extract_content_type(&raw, options->content_type, + options->charset); + strbuf_release(&raw); + } if (options && options->effective_url) curlinfo_strbuf(slot->curl, CURLINFO_EFFECTIVE_URL, @@ -144,6 +144,13 @@ struct http_get_options { struct strbuf *content_type; /* + * If non-NULL, and content_type above is non-NULL, returns + * the charset parameter from the content-type. If none is + * present, returns an empty string. + */ + struct strbuf *charset; + + /* * If non-NULL, returns the URL we ended up at, including any * redirects we followed. */ diff --git a/imap-send.c b/imap-send.c index 0bc6f7fae1..83a6ed2ac3 100644 --- a/imap-send.c +++ b/imap-send.c @@ -23,9 +23,9 @@ */ #include "cache.h" +#include "credential.h" #include "exec_cmd.h" #include "run-command.h" -#include "prompt.h" #ifdef NO_OPENSSL typedef void *SSL; #endif @@ -946,12 +946,13 @@ static int auth_cram_md5(struct imap_store *ctx, struct imap_cmd *cmd, const cha static struct imap_store *imap_open_store(struct imap_server_conf *srvc) { + struct credential cred = CREDENTIAL_INIT; struct imap_store *ctx; struct imap *imap; char *arg, *rsp; int s = -1, preauth; - ctx = xcalloc(sizeof(*ctx), 1); + ctx = xcalloc(1, sizeof(*ctx)); ctx->imap = imap = xcalloc(sizeof(*imap), 1); imap->buf.sock.fd[0] = imap->buf.sock.fd[1] = -1; @@ -1096,25 +1097,23 @@ static struct imap_store *imap_open_store(struct imap_server_conf *srvc) } #endif imap_info("Logging in...\n"); - if (!srvc->user) { - fprintf(stderr, "Skipping server %s, no user\n", srvc->host); - goto bail; - } - if (!srvc->pass) { - struct strbuf prompt = STRBUF_INIT; - strbuf_addf(&prompt, "Password (%s@%s): ", srvc->user, srvc->host); - arg = git_getpass(prompt.buf); - strbuf_release(&prompt); - if (!*arg) { - fprintf(stderr, "Skipping account %s@%s, no password\n", srvc->user, srvc->host); - goto bail; - } - /* - * getpass() returns a pointer to a static buffer. make a copy - * for long term storage. - */ - srvc->pass = xstrdup(arg); + if (!srvc->user || !srvc->pass) { + cred.protocol = xstrdup(srvc->use_ssl ? "imaps" : "imap"); + cred.host = xstrdup(srvc->host); + + if (srvc->user) + cred.username = xstrdup(srvc->user); + if (srvc->pass) + cred.password = xstrdup(srvc->pass); + + credential_fill(&cred); + + if (!srvc->user) + srvc->user = xstrdup(cred.username); + if (!srvc->pass) + srvc->pass = xstrdup(cred.password); } + if (CAP(NOLOGIN)) { fprintf(stderr, "Skipping account %s@%s, server forbids LOGIN\n", srvc->user, srvc->host); goto bail; @@ -1153,10 +1152,18 @@ static struct imap_store *imap_open_store(struct imap_server_conf *srvc) } } /* !preauth */ + if (cred.username) + credential_approve(&cred); + credential_clear(&cred); + ctx->prefix = ""; return ctx; bail: + if (cred.username) + credential_reject(&cred); + credential_clear(&cred); + imap_close_store(ctx); return NULL; } diff --git a/log-tree.c b/log-tree.c index cf2f86c866..10e68442b3 100644 --- a/log-tree.c +++ b/log-tree.c @@ -376,7 +376,7 @@ static void show_signature(struct rev_info *opt, struct commit *commit) struct strbuf gpg_output = STRBUF_INIT; int status; - if (parse_signed_commit(commit->object.sha1, &payload, &signature) <= 0) + if (parse_signed_commit(commit, &payload, &signature) <= 0) goto out; status = verify_signed_buffer(payload.buf, payload.len, @@ -588,7 +588,7 @@ void show_log(struct rev_info *opt) show_mergetag(opt, commit); } - if (!commit->buffer) + if (!get_cached_commit_buffer(commit, NULL)) return; if (opt->show_notes) { diff --git a/merge-recursive.c b/merge-recursive.c index 4177092942..d38a3b2eb5 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -40,7 +40,7 @@ static struct tree *shift_tree_object(struct tree *one, struct tree *two, static struct commit *make_virtual_commit(struct tree *tree, const char *comment) { - struct commit *commit = xcalloc(1, sizeof(struct commit)); + struct commit *commit = alloc_commit_node(); struct merge_remote_desc *desc = xmalloc(sizeof(*desc)); desc->name = comment; @@ -190,9 +190,11 @@ static void output_commit_title(struct merge_options *o, struct commit *commit) printf(_("(bad commit)\n")); else { const char *title; - int len = find_commit_subject(commit->buffer, &title); + const char *msg = get_commit_buffer(commit, NULL); + int len = find_commit_subject(msg, &title); if (len) printf("%.*s\n", len, title); + unuse_commit_buffer(commit, msg); } } } @@ -589,6 +591,12 @@ static int remove_file(struct merge_options *o, int clean, return -1; } if (update_working_directory) { + if (ignore_case) { + struct cache_entry *ce; + ce = cache_file_exists(path, strlen(path), ignore_case); + if (ce && ce_stage(ce) == 0) + return 0; + } if (remove_path(path)) return -1; } diff --git a/name-hash.c b/name-hash.c index 97444d0201..49fd508317 100644 --- a/name-hash.c +++ b/name-hash.c @@ -179,7 +179,7 @@ static int same_name(const struct cache_entry *ce, const char *name, int namelen * Always do exact compare, even if we want a case-ignoring comparison; * we do the quick exact one first, because it will be the common case. */ - if (len == namelen && !cache_name_compare(name, namelen, ce->name, len)) + if (len == namelen && !memcmp(name, ce->name, len)) return 1; if (!icase) diff --git a/notes-cache.c b/notes-cache.c index 97dfd63c9b..c4e9bb7f6c 100644 --- a/notes-cache.c +++ b/notes-cache.c @@ -48,7 +48,6 @@ int notes_cache_write(struct notes_cache *c) { unsigned char tree_sha1[20]; unsigned char commit_sha1[20]; - struct strbuf msg = STRBUF_INIT; if (!c || !c->tree.initialized || !c->tree.ref || !*c->tree.ref) return -1; @@ -57,9 +56,8 @@ int notes_cache_write(struct notes_cache *c) if (write_notes_tree(&c->tree, tree_sha1)) return -1; - strbuf_attach(&msg, c->validity, - strlen(c->validity), strlen(c->validity) + 1); - if (commit_tree(&msg, tree_sha1, NULL, commit_sha1, NULL, NULL) < 0) + if (commit_tree(c->validity, strlen(c->validity), tree_sha1, NULL, + commit_sha1, NULL, NULL) < 0) return -1; if (update_ref("update notes cache", c->tree.ref, commit_sha1, NULL, 0, UPDATE_REFS_QUIET_ON_ERR) < 0) diff --git a/notes-merge.c b/notes-merge.c index 94a1a8ae46..fd5fae255d 100644 --- a/notes-merge.c +++ b/notes-merge.c @@ -644,7 +644,8 @@ int notes_merge(struct notes_merge_options *o, struct commit_list *parents = NULL; commit_list_insert(remote, &parents); /* LIFO order */ commit_list_insert(local, &parents); - create_notes_commit(local_tree, parents, &o->commit_msg, + create_notes_commit(local_tree, parents, + o->commit_msg.buf, o->commit_msg.len, result_sha1); } @@ -671,8 +672,8 @@ int notes_merge_commit(struct notes_merge_options *o, DIR *dir; struct dirent *e; struct strbuf path = STRBUF_INIT; - char *msg = strstr(partial_commit->buffer, "\n\n"); - struct strbuf sb_msg = STRBUF_INIT; + const char *buffer = get_commit_buffer(partial_commit, NULL); + const char *msg = strstr(buffer, "\n\n"); int baselen; strbuf_addstr(&path, git_path(NOTES_MERGE_WORKTREE)); @@ -719,9 +720,9 @@ int notes_merge_commit(struct notes_merge_options *o, strbuf_setlen(&path, baselen); } - strbuf_attach(&sb_msg, msg, strlen(msg), strlen(msg) + 1); - create_notes_commit(partial_tree, partial_commit->parents, &sb_msg, - result_sha1); + create_notes_commit(partial_tree, partial_commit->parents, + msg, strlen(msg), result_sha1); + unuse_commit_buffer(partial_commit, buffer); if (o->verbosity >= 4) printf("Finalized notes merge commit: %s\n", sha1_to_hex(result_sha1)); diff --git a/notes-utils.c b/notes-utils.c index a0b1d7be98..b64dc1b021 100644 --- a/notes-utils.c +++ b/notes-utils.c @@ -4,7 +4,8 @@ #include "notes-utils.h" void create_notes_commit(struct notes_tree *t, struct commit_list *parents, - const struct strbuf *msg, unsigned char *result_sha1) + const char *msg, size_t msg_len, + unsigned char *result_sha1) { unsigned char tree_sha1[20]; @@ -25,7 +26,7 @@ void create_notes_commit(struct notes_tree *t, struct commit_list *parents, /* else: t->ref points to nothing, assume root/orphan commit */ } - if (commit_tree(msg, tree_sha1, parents, result_sha1, NULL, NULL)) + if (commit_tree(msg, msg_len, tree_sha1, parents, result_sha1, NULL, NULL)) die("Failed to commit notes tree to database"); } @@ -46,7 +47,7 @@ void commit_notes(struct notes_tree *t, const char *msg) if (buf.buf[buf.len - 1] != '\n') strbuf_addch(&buf, '\n'); /* Make sure msg ends with newline */ - create_notes_commit(t, NULL, &buf, commit_sha1); + create_notes_commit(t, NULL, buf.buf, buf.len, commit_sha1); strbuf_insert(&buf, 0, "notes: ", 7); /* commit message starts at index 7 */ update_ref(buf.buf, t->ref, commit_sha1, NULL, 0, UPDATE_REFS_DIE_ON_ERR); diff --git a/notes-utils.h b/notes-utils.h index 564e30cccd..890ddb33e1 100644 --- a/notes-utils.h +++ b/notes-utils.h @@ -15,7 +15,7 @@ * The resulting commit SHA1 is stored in result_sha1. */ void create_notes_commit(struct notes_tree *t, struct commit_list *parents, - const struct strbuf *msg, unsigned char *result_sha1); + const char *msg, size_t msg_len, unsigned char *result_sha1); void commit_notes(struct notes_tree *t, const char *msg); @@ -303,7 +303,7 @@ static int note_tree_insert(struct notes_tree *t, struct int_node *tree, free(entry); return 0; } - new_node = (struct int_node *) xcalloc(sizeof(struct int_node), 1); + new_node = (struct int_node *) xcalloc(1, sizeof(struct int_node)); ret = note_tree_insert(t, new_node, n + 1, l, GET_PTR_TYPE(*p), combine_notes); if (ret) @@ -443,7 +443,7 @@ static void load_subtree(struct notes_tree *t, struct leaf_node *subtree, if (len <= 20) { type = PTR_TYPE_NOTE; l = (struct leaf_node *) - xcalloc(sizeof(struct leaf_node), 1); + xcalloc(1, sizeof(struct leaf_node)); hashcpy(l->key_sha1, object_sha1); hashcpy(l->val_sha1, entry.sha1); if (len < 20) { @@ -1003,7 +1003,7 @@ void init_notes(struct notes_tree *t, const char *notes_ref, if (!combine_notes) combine_notes = combine_notes_concatenate; - t->root = (struct int_node *) xcalloc(sizeof(struct int_node), 1); + t->root = (struct int_node *) xcalloc(1, sizeof(struct int_node)); t->first_non_note = NULL; t->prev_non_note = NULL; t->ref = notes_ref ? xstrdup(notes_ref) : NULL; @@ -197,8 +197,8 @@ struct object *parse_object_buffer(const unsigned char *sha1, enum object_type t if (commit) { if (parse_commit_buffer(commit, buffer, size)) return NULL; - if (!commit->buffer) { - commit->buffer = buffer; + if (!get_cached_commit_buffer(commit, NULL)) { + set_commit_buffer(commit, buffer, size); *eaten_p = 1; } obj = &commit->object; diff --git a/pack-objects.c b/pack-objects.c index d01d851ce9..4f36c32045 100644 --- a/pack-objects.c +++ b/pack-objects.c @@ -47,8 +47,8 @@ static void rehash_objects(struct packing_data *pdata) if (pdata->index_size < 1024) pdata->index_size = 1024; - pdata->index = xrealloc(pdata->index, sizeof(uint32_t) * pdata->index_size); - memset(pdata->index, 0, sizeof(int) * pdata->index_size); + free(pdata->index); + pdata->index = xcalloc(pdata->index_size, sizeof(*pdata->index)); entry = pdata->objects; diff --git a/pack-revindex.c b/pack-revindex.c index 5bd7c61980..5c8376e978 100644 --- a/pack-revindex.c +++ b/pack-revindex.c @@ -45,7 +45,7 @@ static void init_pack_revindex(void) if (!num) return; pack_revindex_hashsz = num * 11; - pack_revindex = xcalloc(sizeof(*pack_revindex), pack_revindex_hashsz); + pack_revindex = xcalloc(pack_revindex_hashsz, sizeof(*pack_revindex)); for (p = packed_git; p; p = p->next) { num = pack_revindex_ix(p); num = - 1 - num; @@ -64,7 +64,7 @@ void setup_pager(void) { const char *pager = git_pager(isatty(1)); - if (!pager || pager_in_use()) + if (!pager) return; /* @@ -85,7 +85,7 @@ void setup_pager(void) int i = 0; if (!getenv("LESS")) - env[i++] = "LESS=FRSX"; + env[i++] = "LESS=FRX"; if (!getenv("LV")) env[i++] = "LV=-c"; env[i] = NULL; diff --git a/parse-options.h b/parse-options.h index 3189676695..7940bc71af 100644 --- a/parse-options.h +++ b/parse-options.h @@ -176,8 +176,8 @@ extern NORETURN void usage_msg_opt(const char *msg, extern int optbug(const struct option *opt, const char *reason); extern int opterror(const struct option *opt, const char *reason, int flags); -#if defined(__GNUC__) && ! defined(__clang__) -#define opterror(o,r,f) (opterror((o),(r),(f)), -1) +#if defined(__GNUC__) +#define opterror(o,r,f) (opterror((o),(r),(f)), const_error()) #endif /*----- incremental advanced APIs -----*/ @@ -823,10 +823,3 @@ int daemon_avoid_alias(const char *p) } } } - -int offset_1st_component(const char *path) -{ - if (has_dos_drive_prefix(path)) - return 2 + is_dir_sep(path[2]); - return is_dir_sep(path[0]); -} diff --git a/perl/Git/SVN/Log.pm b/perl/Git/SVN/Log.pm index 34f2869ab5..664105357c 100644 --- a/perl/Git/SVN/Log.pm +++ b/perl/Git/SVN/Log.pm @@ -116,7 +116,7 @@ sub run_pager { return; } open STDIN, '<&', $rfd or fatal "Can't redirect stdin: $!"; - $ENV{LESS} ||= 'FRSX'; + $ENV{LESS} ||= 'FRX'; $ENV{LV} ||= '-c'; exec $pager or fatal "Can't run pager: $! ($pager)"; } @@ -274,7 +274,7 @@ static void add_rfc822_quoted(struct strbuf *out, const char *s, int len) enum rfc2047_type { RFC2047_SUBJECT, - RFC2047_ADDRESS, + RFC2047_ADDRESS }; static int is_rfc2047_special(char ch, enum rfc2047_type type) @@ -606,29 +606,16 @@ static char *replace_encoding_header(char *buf, const char *encoding) return strbuf_detach(&tmp, NULL); } -char *logmsg_reencode(const struct commit *commit, - char **commit_encoding, - const char *output_encoding) +const char *logmsg_reencode(const struct commit *commit, + char **commit_encoding, + const char *output_encoding) { static const char *utf8 = "UTF-8"; const char *use_encoding; char *encoding; - char *msg = commit->buffer; + const char *msg = get_commit_buffer(commit, NULL); char *out; - if (!msg) { - enum object_type type; - unsigned long size; - - msg = read_sha1_file(commit->object.sha1, &type, &size); - if (!msg) - die("Cannot read commit object %s", - sha1_to_hex(commit->object.sha1)); - if (type != OBJ_COMMIT) - die("Expected commit for '%s', got %s", - sha1_to_hex(commit->object.sha1), typename(type)); - } - if (!output_encoding || !*output_encoding) { if (commit_encoding) *commit_encoding = @@ -652,12 +639,13 @@ char *logmsg_reencode(const struct commit *commit, * Otherwise, we still want to munge the encoding header in the * result, which will be done by modifying the buffer. If we * are using a fresh copy, we can reuse it. But if we are using - * the cached copy from commit->buffer, we need to duplicate it - * to avoid munging commit->buffer. + * the cached copy from get_commit_buffer, we need to duplicate it + * to avoid munging the cached copy. */ - out = msg; - if (out == commit->buffer) - out = xstrdup(out); + if (msg == get_cached_commit_buffer(commit, NULL)) + out = xstrdup(msg); + else + out = (char *)msg; } else { /* @@ -667,8 +655,8 @@ char *logmsg_reencode(const struct commit *commit, * copy, we can free it. */ out = reencode_string(msg, output_encoding, use_encoding); - if (out && msg != commit->buffer) - free(msg); + if (out) + unuse_commit_buffer(commit, msg); } /* @@ -687,12 +675,6 @@ char *logmsg_reencode(const struct commit *commit, return out ? out : msg; } -void logmsg_free(char *msg, const struct commit *commit) -{ - if (msg != commit->buffer) - free(msg); -} - static int mailmap_name(const char **email, size_t *email_len, const char **name, size_t *name_len) { @@ -796,7 +778,7 @@ struct format_commit_context { struct signature_check signature_check; enum flush_type flush_type; enum trunc_type truncate; - char *message; + const char *message; char *commit_encoding; size_t width, indent1, indent2; int auto_color; @@ -1506,13 +1488,18 @@ void format_commit_message(const struct commit *commit, context.commit = commit; context.pretty_ctx = pretty_ctx; context.wrap_start = sb->len; + /* + * convert a commit message to UTF-8 first + * as far as 'format_commit_item' assumes it in UTF-8 + */ context.message = logmsg_reencode(commit, &context.commit_encoding, - output_enc); + utf8); strbuf_expand(sb, format, format_commit_item, &context); rewrap_message_tail(sb, &context, 0, 0, 0); + /* then convert a commit message to an actual output encoding */ if (output_enc) { if (same_encoding(utf8, output_enc)) output_enc = NULL; @@ -1531,7 +1518,7 @@ void format_commit_message(const struct commit *commit, } free(context.commit_encoding); - logmsg_free(context.message, commit); + unuse_commit_buffer(commit, context.message); free(context.signature_check.gpg_output); free(context.signature_check.signer); } @@ -1700,7 +1687,7 @@ void pretty_print_commit(struct pretty_print_context *pp, unsigned long beginning_of_body; int indent = 4; const char *msg; - char *reencoded; + const char *reencoded; const char *encoding; int need_8bit_cte = pp->need_8bit_cte; @@ -1767,7 +1754,7 @@ void pretty_print_commit(struct pretty_print_context *pp, if (pp->fmt == CMIT_FMT_EMAIL && sb->len <= beginning_of_body) strbuf_addch(sb, '\n'); - logmsg_free(reencoded, commit); + unuse_commit_buffer(commit, reencoded); } void pp_commit_easy(enum cmit_fmt fmt, const struct commit *commit, diff --git a/read-cache.c b/read-cache.c index 7f5645e745..6a45966ec4 100644 --- a/read-cache.c +++ b/read-cache.c @@ -422,18 +422,26 @@ int df_name_compare(const char *name1, int len1, int mode1, return c1 - c2; } -int cache_name_stage_compare(const char *name1, int len1, int stage1, const char *name2, int len2, int stage2) +int name_compare(const char *name1, size_t len1, const char *name2, size_t len2) { - int len = len1 < len2 ? len1 : len2; - int cmp; - - cmp = memcmp(name1, name2, len); + size_t min_len = (len1 < len2) ? len1 : len2; + int cmp = memcmp(name1, name2, min_len); if (cmp) return cmp; if (len1 < len2) return -1; if (len1 > len2) return 1; + return 0; +} + +int cache_name_stage_compare(const char *name1, int len1, int stage1, const char *name2, int len2, int stage2) +{ + int cmp; + + cmp = name_compare(name1, len1, name2, len2); + if (cmp) + return cmp; if (stage1 < stage2) return -1; @@ -442,11 +450,6 @@ int cache_name_stage_compare(const char *name1, int len1, int stage1, const char return 0; } -int cache_name_compare(const char *name1, int len1, const char *name2, int len2) -{ - return cache_name_stage_compare(name1, len1, 0, name2, len2, 0); -} - static int index_name_stage_pos(const struct index_state *istate, const char *name, int namelen, int stage) { int first, last; diff --git a/reflog-walk.c b/reflog-walk.c index 0dd5084fe5..9ce8b53ccc 100644 --- a/reflog-walk.c +++ b/reflog-walk.c @@ -41,7 +41,7 @@ static int read_one_reflog(unsigned char *osha1, unsigned char *nsha1, static struct complete_reflogs *read_complete_reflog(const char *ref) { struct complete_reflogs *reflogs = - xcalloc(sizeof(struct complete_reflogs), 1); + xcalloc(1, sizeof(struct complete_reflogs)); reflogs->ref = xstrdup(ref); for_each_reflog_ent(ref, read_one_reflog, reflogs); if (reflogs->nr == 0) { @@ -135,7 +135,7 @@ struct reflog_walk_info { void init_reflog_walk(struct reflog_walk_info** info) { - *info = xcalloc(sizeof(struct reflog_walk_info), 1); + *info = xcalloc(1, sizeof(struct reflog_walk_info)); } int add_reflog_for_walk(struct reflog_walk_info *info, @@ -199,7 +199,7 @@ int add_reflog_for_walk(struct reflog_walk_info *info, = reflogs; } - commit_reflog = xcalloc(sizeof(struct commit_reflog), 1); + commit_reflog = xcalloc(1, sizeof(struct commit_reflog)); if (recno < 0) { commit_reflog->recno = get_reflog_recno_by_time(reflogs, timestamp); if (commit_reflog->recno < 0) { @@ -242,7 +242,7 @@ void fake_reflog_parent(struct reflog_walk_info *info, struct commit *commit) return; } - commit->parents = xcalloc(sizeof(struct commit_list), 1); + commit->parents = xcalloc(1, sizeof(struct commit_list)); commit->parents->item = commit_info->commit; } @@ -1820,6 +1820,7 @@ int peel_ref(const char *refname, unsigned char *sha1) struct warn_if_dangling_data { FILE *fp; const char *refname; + const struct string_list *refnames; const char *msg_fmt; }; @@ -1834,8 +1835,12 @@ static int warn_if_dangling_symref(const char *refname, const unsigned char *sha return 0; resolves_to = resolve_ref_unsafe(refname, junk, 0, NULL); - if (!resolves_to || strcmp(resolves_to, d->refname)) + if (!resolves_to + || (d->refname + ? strcmp(resolves_to, d->refname) + : !string_list_has_string(d->refnames, resolves_to))) { return 0; + } fprintf(d->fp, d->msg_fmt, refname); fputc('\n', d->fp); @@ -1848,6 +1853,18 @@ void warn_dangling_symref(FILE *fp, const char *msg_fmt, const char *refname) data.fp = fp; data.refname = refname; + data.refnames = NULL; + data.msg_fmt = msg_fmt; + for_each_rawref(warn_if_dangling_symref, &data); +} + +void warn_dangling_symrefs(FILE *fp, const char *msg_fmt, const struct string_list *refnames) +{ + struct warn_if_dangling_data data; + + data.fp = fp; + data.refname = NULL; + data.refnames = refnames; data.msg_fmt = msg_fmt; for_each_rawref(warn_if_dangling_symref, &data); } @@ -2208,7 +2225,6 @@ int dwim_log(const char *str, int len, unsigned char *sha1, char **log) *log = NULL; for (p = ref_rev_parse_rules; *p; p++) { - struct stat st; unsigned char hash[20]; char path[PATH_MAX]; const char *ref, *it; @@ -2217,12 +2233,9 @@ int dwim_log(const char *str, int len, unsigned char *sha1, char **log) ref = resolve_ref_unsafe(path, hash, 1, NULL); if (!ref) continue; - if (!stat(git_path("logs/%s", path), &st) && - S_ISREG(st.st_mode)) + if (reflog_exists(path)) it = path; - else if (strcmp(ref, path) && - !stat(git_path("logs/%s", ref), &st) && - S_ISREG(st.st_mode)) + else if (strcmp(ref, path) && reflog_exists(ref)) it = ref; else continue; @@ -2640,7 +2653,7 @@ static int curate_packed_ref_fn(struct ref_entry *entry, void *cb_data) return 0; } -static int repack_without_refs(const char **refnames, int n) +int repack_without_refs(const char **refnames, int n) { struct ref_dir *packed; struct string_list refs_to_delete = STRING_LIST_INIT_DUP; @@ -3139,122 +3152,133 @@ int create_symref(const char *ref_target, const char *refs_heads_master, return 0; } -static char *ref_msg(const char *line, const char *endp) -{ - const char *ep; - line += 82; - ep = memchr(line, '\n', endp - line); - if (!ep) - ep = endp; - return xmemdupz(line, ep - line); +struct read_ref_at_cb { + const char *refname; + unsigned long at_time; + int cnt; + int reccnt; + unsigned char *sha1; + int found_it; + + unsigned char osha1[20]; + unsigned char nsha1[20]; + int tz; + unsigned long date; + char **msg; + unsigned long *cutoff_time; + int *cutoff_tz; + int *cutoff_cnt; +}; + +static int read_ref_at_ent(unsigned char *osha1, unsigned char *nsha1, + const char *email, unsigned long timestamp, int tz, + const char *message, void *cb_data) +{ + struct read_ref_at_cb *cb = cb_data; + + cb->reccnt++; + cb->tz = tz; + cb->date = timestamp; + + if (timestamp <= cb->at_time || cb->cnt == 0) { + if (cb->msg) + *cb->msg = xstrdup(message); + if (cb->cutoff_time) + *cb->cutoff_time = timestamp; + if (cb->cutoff_tz) + *cb->cutoff_tz = tz; + if (cb->cutoff_cnt) + *cb->cutoff_cnt = cb->reccnt - 1; + /* + * we have not yet updated cb->[n|o]sha1 so they still + * hold the values for the previous record. + */ + if (!is_null_sha1(cb->osha1)) { + hashcpy(cb->sha1, nsha1); + if (hashcmp(cb->osha1, nsha1)) + warning("Log for ref %s has gap after %s.", + cb->refname, show_date(cb->date, cb->tz, DATE_RFC2822)); + } + else if (cb->date == cb->at_time) + hashcpy(cb->sha1, nsha1); + else if (hashcmp(nsha1, cb->sha1)) + warning("Log for ref %s unexpectedly ended on %s.", + cb->refname, show_date(cb->date, cb->tz, + DATE_RFC2822)); + hashcpy(cb->osha1, osha1); + hashcpy(cb->nsha1, nsha1); + cb->found_it = 1; + return 1; + } + hashcpy(cb->osha1, osha1); + hashcpy(cb->nsha1, nsha1); + if (cb->cnt > 0) + cb->cnt--; + return 0; +} + +static int read_ref_at_ent_oldest(unsigned char *osha1, unsigned char *nsha1, + const char *email, unsigned long timestamp, + int tz, const char *message, void *cb_data) +{ + struct read_ref_at_cb *cb = cb_data; + + if (cb->msg) + *cb->msg = xstrdup(message); + if (cb->cutoff_time) + *cb->cutoff_time = timestamp; + if (cb->cutoff_tz) + *cb->cutoff_tz = tz; + if (cb->cutoff_cnt) + *cb->cutoff_cnt = cb->reccnt; + hashcpy(cb->sha1, osha1); + if (is_null_sha1(cb->sha1)) + hashcpy(cb->sha1, nsha1); + /* We just want the first entry */ + return 1; } int read_ref_at(const char *refname, unsigned long at_time, int cnt, unsigned char *sha1, char **msg, unsigned long *cutoff_time, int *cutoff_tz, int *cutoff_cnt) { - const char *logfile, *logdata, *logend, *rec, *lastgt, *lastrec; - char *tz_c; - int logfd, tz, reccnt = 0; - struct stat st; - unsigned long date; - unsigned char logged_sha1[20]; - void *log_mapped; - size_t mapsz; + struct read_ref_at_cb cb; - logfile = git_path("logs/%s", refname); - logfd = open(logfile, O_RDONLY, 0); - if (logfd < 0) - die_errno("Unable to read log '%s'", logfile); - fstat(logfd, &st); - if (!st.st_size) - die("Log %s is empty.", logfile); - mapsz = xsize_t(st.st_size); - log_mapped = xmmap(NULL, mapsz, PROT_READ, MAP_PRIVATE, logfd, 0); - logdata = log_mapped; - close(logfd); + memset(&cb, 0, sizeof(cb)); + cb.refname = refname; + cb.at_time = at_time; + cb.cnt = cnt; + cb.msg = msg; + cb.cutoff_time = cutoff_time; + cb.cutoff_tz = cutoff_tz; + cb.cutoff_cnt = cutoff_cnt; + cb.sha1 = sha1; + + for_each_reflog_ent_reverse(refname, read_ref_at_ent, &cb); + + if (!cb.reccnt) + die("Log for %s is empty.", refname); + if (cb.found_it) + return 0; + + for_each_reflog_ent(refname, read_ref_at_ent_oldest, &cb); - lastrec = NULL; - rec = logend = logdata + st.st_size; - while (logdata < rec) { - reccnt++; - if (logdata < rec && *(rec-1) == '\n') - rec--; - lastgt = NULL; - while (logdata < rec && *(rec-1) != '\n') { - rec--; - if (*rec == '>') - lastgt = rec; - } - if (!lastgt) - die("Log %s is corrupt.", logfile); - date = strtoul(lastgt + 1, &tz_c, 10); - if (date <= at_time || cnt == 0) { - tz = strtoul(tz_c, NULL, 10); - if (msg) - *msg = ref_msg(rec, logend); - if (cutoff_time) - *cutoff_time = date; - if (cutoff_tz) - *cutoff_tz = tz; - if (cutoff_cnt) - *cutoff_cnt = reccnt - 1; - if (lastrec) { - if (get_sha1_hex(lastrec, logged_sha1)) - die("Log %s is corrupt.", logfile); - if (get_sha1_hex(rec + 41, sha1)) - die("Log %s is corrupt.", logfile); - if (hashcmp(logged_sha1, sha1)) { - warning("Log %s has gap after %s.", - logfile, show_date(date, tz, DATE_RFC2822)); - } - } - else if (date == at_time) { - if (get_sha1_hex(rec + 41, sha1)) - die("Log %s is corrupt.", logfile); - } - else { - if (get_sha1_hex(rec + 41, logged_sha1)) - die("Log %s is corrupt.", logfile); - if (hashcmp(logged_sha1, sha1)) { - warning("Log %s unexpectedly ended on %s.", - logfile, show_date(date, tz, DATE_RFC2822)); - } - } - munmap(log_mapped, mapsz); - return 0; - } - lastrec = rec; - if (cnt > 0) - cnt--; - } - - rec = logdata; - while (rec < logend && *rec != '>' && *rec != '\n') - rec++; - if (rec == logend || *rec == '\n') - die("Log %s is corrupt.", logfile); - date = strtoul(rec + 1, &tz_c, 10); - tz = strtoul(tz_c, NULL, 10); - if (get_sha1_hex(logdata, sha1)) - die("Log %s is corrupt.", logfile); - if (is_null_sha1(sha1)) { - if (get_sha1_hex(logdata + 41, sha1)) - die("Log %s is corrupt.", logfile); - } - if (msg) - *msg = ref_msg(logdata, logend); - munmap(log_mapped, mapsz); - - if (cutoff_time) - *cutoff_time = date; - if (cutoff_tz) - *cutoff_tz = tz; - if (cutoff_cnt) - *cutoff_cnt = reccnt; return 1; } +int reflog_exists(const char *refname) +{ + struct stat st; + + return !lstat(git_path("logs/%s", refname), &st) && + S_ISREG(st.st_mode); +} + +int delete_reflog(const char *refname) +{ + return remove_path(git_path("logs/%s", refname)); +} + static int show_one_reflog_ent(struct strbuf *sb, each_reflog_ent_fn fn, void *cb_data) { unsigned char osha1[20], nsha1[20]; @@ -77,6 +77,7 @@ static inline const char *has_glob_specials(const char *pattern) extern int for_each_rawref(each_ref_fn, void *); extern void warn_dangling_symref(FILE *fp, const char *msg_fmt, const char *refname); +extern void warn_dangling_symrefs(FILE *fp, const char *msg_fmt, const struct string_list* refnames); /* * Lock the packed-refs file for writing. Flags is passed to @@ -120,6 +121,8 @@ extern void rollback_packed_refs(void); */ int pack_refs(unsigned int flags); +extern int repack_without_refs(const char **refnames, int n); + extern int ref_exists(const char *); /* @@ -161,6 +164,12 @@ extern int read_ref_at(const char *refname, unsigned long at_time, int cnt, unsigned char *sha1, char **msg, unsigned long *cutoff_time, int *cutoff_tz, int *cutoff_cnt); +/** Check if a particular reflog exists */ +extern int reflog_exists(const char *refname); + +/** Delete a reflog */ +extern int delete_reflog(const char *refname); + /* iterate over reflog entries */ typedef int each_reflog_ent_fn(unsigned char *osha1, unsigned char *nsha1, const char *, unsigned long, int, const char *, void *); int for_each_reflog_ent(const char *refname, each_reflog_ent_fn fn, void *cb_data); diff --git a/remote-curl.c b/remote-curl.c index 52c2d96ce6..4493b389de 100644 --- a/remote-curl.c +++ b/remote-curl.c @@ -194,19 +194,19 @@ static void free_discovery(struct discovery *d) } } -static int show_http_message(struct strbuf *type, struct strbuf *msg) +static int show_http_message(struct strbuf *type, struct strbuf *charset, + struct strbuf *msg) { const char *p, *eol; /* * We only show text/plain parts, as other types are likely * to be ugly to look at on the user's terminal. - * - * TODO should handle "; charset=XXX", and re-encode into - * logoutputencoding */ - if (strcasecmp(type->buf, "text/plain")) + if (strcmp(type->buf, "text/plain")) return -1; + if (charset->len) + strbuf_reencode(msg, charset->buf, get_log_output_encoding()); strbuf_trim(msg); if (!msg->len) @@ -225,6 +225,7 @@ static struct discovery* discover_refs(const char *service, int for_push) { struct strbuf exp = STRBUF_INIT; struct strbuf type = STRBUF_INIT; + struct strbuf charset = STRBUF_INIT; struct strbuf buffer = STRBUF_INIT; struct strbuf refs_url = STRBUF_INIT; struct strbuf effective_url = STRBUF_INIT; @@ -249,6 +250,7 @@ static struct discovery* discover_refs(const char *service, int for_push) memset(&options, 0, sizeof(options)); options.content_type = &type; + options.charset = &charset; options.effective_url = &effective_url; options.base_url = &url; options.no_cache = 1; @@ -259,13 +261,13 @@ static struct discovery* discover_refs(const char *service, int for_push) case HTTP_OK: break; case HTTP_MISSING_TARGET: - show_http_message(&type, &buffer); + show_http_message(&type, &charset, &buffer); die("repository '%s' not found", url.buf); case HTTP_NOAUTH: - show_http_message(&type, &buffer); + show_http_message(&type, &charset, &buffer); die("Authentication failed for '%s'", url.buf); default: - show_http_message(&type, &buffer); + show_http_message(&type, &charset, &buffer); die("unable to access '%s': %s", url.buf, curl_errorstr); } @@ -310,6 +312,7 @@ static struct discovery* discover_refs(const char *service, int for_push) strbuf_release(&refs_url); strbuf_release(&exp); strbuf_release(&type); + strbuf_release(&charset); strbuf_release(&effective_url); strbuf_release(&buffer); last_discovery = last; @@ -523,7 +523,7 @@ static void free_refspecs(struct refspec *refspec, int nr_refspec) static struct refspec *parse_refspec_internal(int nr_refspec, const char **refspec, int fetch, int verify) { int i; - struct refspec *rs = xcalloc(sizeof(*rs), nr_refspec); + struct refspec *rs = xcalloc(nr_refspec, sizeof(*rs)); for (i = 0; i < nr_refspec; i++) { size_t llen; @@ -1194,7 +1194,7 @@ static int match_explicit(struct ref *src, struct ref *dst, case 1: break; case 0: - if (!memcmp(dst_value, "refs/", 5)) + if (starts_with(dst_value, "refs/")) matched_dst = make_linked_ref(dst_value, dst_tail); else if (is_null_sha1(matched_src->new_sha1)) error("unable to delete '%s': remote ref does not exist", diff --git a/revision.c b/revision.c index 71e2337423..2571ada6bf 100644 --- a/revision.c +++ b/revision.c @@ -1633,6 +1633,7 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg !strcmp(arg, "--reflog") || !strcmp(arg, "--not") || !strcmp(arg, "--no-walk") || !strcmp(arg, "--do-walk") || !strcmp(arg, "--bisect") || starts_with(arg, "--glob=") || + starts_with(arg, "--exclude=") || starts_with(arg, "--branches=") || starts_with(arg, "--tags=") || starts_with(arg, "--remotes=") || starts_with(arg, "--no-walk=")) { @@ -1648,8 +1649,10 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg revs->skip_count = atoi(optarg); return argcount; } else if ((*arg == '-') && isdigit(arg[1])) { - /* accept -<digit>, like traditional "head" */ - revs->max_count = atoi(arg + 1); + /* accept -<digit>, like traditional "head" */ + if (strtol_i(arg + 1, 10, &revs->max_count) < 0 || + revs->max_count < 0) + die("'%s': not a non-negative integer", arg + 1); revs->no_walk = 0; } else if (!strcmp(arg, "-n")) { if (argc <= 1) @@ -2788,7 +2791,7 @@ static int commit_match(struct commit *commit, struct rev_info *opt) { int retval; const char *encoding; - char *message; + const char *message; struct strbuf buf = STRBUF_INIT; if (!opt->grep_filter.pattern_list && !opt->grep_filter.header_list) @@ -2830,14 +2833,21 @@ static int commit_match(struct commit *commit, struct rev_info *opt) format_display_notes(commit->object.sha1, &buf, encoding, 1); } - /* Find either in the original commit message, or in the temporary */ + /* + * Find either in the original commit message, or in the temporary. + * Note that we cast away the constness of "message" here. It is + * const because it may come from the cached commit buffer. That's OK, + * because we know that it is modifiable heap memory, and that while + * grep_buffer may modify it for speed, it will restore any + * changes before returning. + */ if (buf.len) retval = grep_buffer(&opt->grep_filter, buf.buf, buf.len); else retval = grep_buffer(&opt->grep_filter, - message, strlen(message)); + (char *)message, strlen(message)); strbuf_release(&buf); - logmsg_free(message, commit); + unuse_commit_buffer(commit, message); return retval; } diff --git a/run-command.c b/run-command.c index 75abc478c6..be07d4ad33 100644 --- a/run-command.c +++ b/run-command.c @@ -279,6 +279,9 @@ int start_command(struct child_process *cmd) int failed_errno; char *str; + if (!cmd->argv) + cmd->argv = cmd->args.argv; + /* * In case of errors we must keep the promise to close FDs * that have been passed in via ->in and ->out. @@ -328,6 +331,7 @@ int start_command(struct child_process *cmd) fail_pipe: error("cannot create %s pipe for %s: %s", str, cmd->argv[0], strerror(failed_errno)); + argv_array_clear(&cmd->args); errno = failed_errno; return -1; } @@ -519,6 +523,7 @@ fail_pipe: close_pair(fderr); else if (cmd->err) close(cmd->err); + argv_array_clear(&cmd->args); errno = failed_errno; return -1; } @@ -543,7 +548,9 @@ fail_pipe: int finish_command(struct child_process *cmd) { - return wait_or_whine(cmd->pid, cmd->argv[0]); + int ret = wait_or_whine(cmd->pid, cmd->argv[0]); + argv_array_clear(&cmd->args); + return ret; } int run_command(struct child_process *cmd) diff --git a/run-command.h b/run-command.h index 3653bfa6e1..ea73de309b 100644 --- a/run-command.h +++ b/run-command.h @@ -5,8 +5,11 @@ #include <pthread.h> #endif +#include "argv-array.h" + struct child_process { const char **argv; + struct argv_array args; pid_t pid; /* * Using .in, .out, .err: diff --git a/sequencer.c b/sequencer.c index 0a80c58d11..c513d7eeb4 100644 --- a/sequencer.c +++ b/sequencer.c @@ -116,39 +116,23 @@ static const char *action_name(const struct replay_opts *opts) return opts->action == REPLAY_REVERT ? "revert" : "cherry-pick"; } -static char *get_encoding(const char *message); - struct commit_message { char *parent_label; const char *label; const char *subject; - char *reencoded_message; const char *message; }; static int get_message(struct commit *commit, struct commit_message *out) { - const char *encoding; const char *abbrev, *subject; int abbrev_len, subject_len; char *q; - if (!commit->buffer) - return -1; - encoding = get_encoding(commit->buffer); - if (!encoding) - encoding = "UTF-8"; if (!git_commit_encoding) git_commit_encoding = "UTF-8"; - out->reencoded_message = NULL; - out->message = commit->buffer; - if (same_encoding(encoding, git_commit_encoding)) - out->reencoded_message = reencode_string(commit->buffer, - git_commit_encoding, encoding); - if (out->reencoded_message) - out->message = out->reencoded_message; - + out->message = logmsg_reencode(commit, NULL, git_commit_encoding); abbrev = find_unique_abbrev(commit->object.sha1, DEFAULT_ABBREV); abbrev_len = strlen(abbrev); @@ -167,29 +151,10 @@ static int get_message(struct commit *commit, struct commit_message *out) return 0; } -static void free_message(struct commit_message *msg) +static void free_message(struct commit *commit, struct commit_message *msg) { free(msg->parent_label); - free(msg->reencoded_message); -} - -static char *get_encoding(const char *message) -{ - const char *p = message, *eol; - - while (*p && *p != '\n') { - for (eol = p + 1; *eol && *eol != '\n'; eol++) - ; /* do nothing */ - if (starts_with(p, "encoding ")) { - char *result = xmalloc(eol - 8 - p); - strlcpy(result, p + 9, eol - 8 - p); - return result; - } - p = eol; - if (*p == '\n') - p++; - } - return NULL; + unuse_commit_buffer(commit, msg->message); } static void write_cherry_pick_head(struct commit *commit, const char *pseudoref) @@ -278,7 +243,7 @@ static int fast_forward_to(const unsigned char *to, const unsigned char *from, read_cache(); if (checkout_fast_forward(from, to, 1)) - exit(1); /* the callee should have complained already */ + exit(128); /* the callee should have complained already */ ref_lock = lock_any_ref_for_update("HEAD", unborn ? null_sha1 : from, 0, NULL); if (!ref_lock) @@ -489,7 +454,7 @@ static int do_pick_commit(struct commit *commit, struct replay_opts *opts) unsigned char head[20]; struct commit *base, *next, *parent; const char *base_label, *next_label; - struct commit_message msg = { NULL, NULL, NULL, NULL, NULL }; + struct commit_message msg = { NULL, NULL, NULL, NULL }; char *defmsg = NULL; struct strbuf msgbuf = STRBUF_INIT; int res, unborn = 0, allow; @@ -654,7 +619,7 @@ static int do_pick_commit(struct commit *commit, struct replay_opts *opts) res = run_git_commit(defmsg, opts, allow); leave: - free_message(&msg); + free_message(commit, &msg); free(defmsg); return res; @@ -701,10 +666,12 @@ static int format_todo(struct strbuf *buf, struct commit_list *todo_list, int subject_len; for (cur = todo_list; cur; cur = cur->next) { + const char *commit_buffer = get_commit_buffer(cur->item, NULL); sha1_abbrev = find_unique_abbrev(cur->item->object.sha1, DEFAULT_ABBREV); - subject_len = find_commit_subject(cur->item->buffer, &subject); + subject_len = find_commit_subject(commit_buffer, &subject); strbuf_addf(buf, "%s %s %.*s\n", action_str, sha1_abbrev, subject_len, subject); + unuse_commit_buffer(cur->item, commit_buffer); } return 0; } diff --git a/sha1_file.c b/sha1_file.c index 3e9f55f1bb..34d527f670 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -1437,19 +1437,23 @@ static int open_sha1_file(const unsigned char *sha1) { int fd; struct alternate_object_database *alt; + int most_interesting_errno; fd = git_open_noatime(sha1_file_name(sha1)); if (fd >= 0) return fd; + most_interesting_errno = errno; prepare_alt_odb(); - errno = ENOENT; for (alt = alt_odb_list; alt; alt = alt->next) { fill_sha1_path(alt->name, sha1); fd = git_open_noatime(alt->base); if (fd >= 0) return fd; + if (most_interesting_errno == ENOENT) + most_interesting_errno = errno; } + errno = most_interesting_errno; return -1; } diff --git a/sha1_name.c b/sha1_name.c index 2b6322fad0..c2c938c4e1 100644 --- a/sha1_name.c +++ b/sha1_name.c @@ -862,27 +862,17 @@ static int get_sha1_oneline(const char *prefix, unsigned char *sha1, commit_list_insert(l->item, &backup); } while (list) { - char *p, *to_free = NULL; + const char *p, *buf; struct commit *commit; - enum object_type type; - unsigned long size; int matches; commit = pop_most_recent_commit(&list, ONELINE_SEEN); if (!parse_object(commit->object.sha1)) continue; - if (commit->buffer) - p = commit->buffer; - else { - p = read_sha1_file(commit->object.sha1, &type, &size); - if (!p) - continue; - to_free = p; - } - - p = strstr(p, "\n\n"); + buf = get_commit_buffer(commit, NULL); + p = strstr(buf, "\n\n"); matches = p && !regexec(®ex, p + 2, 0, NULL, 0); - free(to_free); + unuse_commit_buffer(commit, buf); if (matches) { hashcpy(sha1, commit->object.sha1); diff --git a/sideband.c b/sideband.c index d1125f5c52..7f9dc229fb 100644 --- a/sideband.c +++ b/sideband.c @@ -30,7 +30,7 @@ int recv_sideband(const char *me, int in_stream, int out) memcpy(buf, PREFIX, pf); term = getenv("TERM"); - if (term && strcmp(term, "dumb")) + if (isatty(2) && term && strcmp(term, "dumb")) suffix = ANSI_SUFFIX; else suffix = DUMB_SUFFIX; @@ -1,5 +1,6 @@ #include "cache.h" #include "refs.h" +#include "utf8.h" int starts_with(const char *str, const char *prefix) { @@ -99,6 +100,29 @@ void strbuf_ltrim(struct strbuf *sb) sb->buf[sb->len] = '\0'; } +int strbuf_reencode(struct strbuf *sb, const char *from, const char *to) +{ + char *out; + int len; + + if (same_encoding(from, to)) + return 0; + + out = reencode_string_len(sb->buf, sb->len, to, from, &len); + if (!out) + return -1; + + strbuf_attach(sb, out, len, len); + return 0; +} + +void strbuf_tolower(struct strbuf *sb) +{ + char *p = sb->buf, *end = sb->buf + sb->len; + for (; p < end; p++) + *p = tolower(*p); +} + struct strbuf **strbuf_split_buf(const char *str, size_t slen, int terminator, int max) { @@ -563,3 +587,16 @@ int fprintf_ln(FILE *fp, const char *fmt, ...) return -1; return ret + 1; } + +char *xstrdup_tolower(const char *string) +{ + char *result; + size_t len, i; + + len = strlen(string); + result = xmalloc(len + 1); + for (i = 0; i < len; i++) + result[i] = tolower(string[i]); + result[i] = '\0'; + return result; +} @@ -45,6 +45,8 @@ static inline void strbuf_setlen(struct strbuf *sb, size_t len) extern void strbuf_trim(struct strbuf *); extern void strbuf_rtrim(struct strbuf *); extern void strbuf_ltrim(struct strbuf *); +extern int strbuf_reencode(struct strbuf *sb, const char *from, const char *to); +extern void strbuf_tolower(struct strbuf *sb); extern int strbuf_cmp(const struct strbuf *, const struct strbuf *); /* @@ -183,4 +185,6 @@ extern int printf_ln(const char *fmt, ...); __attribute__((format (printf,2,3))) extern int fprintf_ln(FILE *fp, const char *fmt, ...); +char *xstrdup_tolower(const char *); + #endif /* STRBUF_H */ diff --git a/string-list.h b/string-list.h index de6769c92d..dd5e294465 100644 --- a/string-list.h +++ b/string-list.h @@ -15,8 +15,8 @@ struct string_list { compare_strings_fn cmp; /* NULL uses strcmp() */ }; -#define STRING_LIST_INIT_NODUP { NULL, 0, 0, 0 } -#define STRING_LIST_INIT_DUP { NULL, 0, 0, 1 } +#define STRING_LIST_INIT_NODUP { NULL, 0, 0, 0, NULL } +#define STRING_LIST_INIT_DUP { NULL, 0, 0, 1, NULL } void print_string_list(const struct string_list *p, const char *text); void string_list_clear(struct string_list *list, int free_util); @@ -71,6 +71,7 @@ You can pass --verbose (or -v), --debug (or -d), and --immediate (or -i) command line argument to the test, or by setting GIT_TEST_OPTS appropriately before running "make". +-v:: --verbose:: This makes the test more verbose. Specifically, the command being run and their output if any are also @@ -81,6 +82,7 @@ appropriately before running "make". numbers matching <pattern>. The number matched against is simply the running count of the test within the file. +-d:: --debug:: This may help the person who is developing a new test. It causes the command defined with test_debug to run. @@ -89,6 +91,7 @@ appropriately before running "make". failed tests so that you can inspect its contents after the test finished. +-i:: --immediate:: This causes the test to immediately exit upon the first failed test. Cleanup commands requested with @@ -96,10 +99,17 @@ appropriately before running "make". in order to keep the state for inspection by the tester to diagnose the bug. +-l:: --long-tests:: This causes additional long-running tests to be run (where available), for more exhaustive testing. +-r:: +--run=<test-selector>:: + Run only the subset of tests indicated by + <test-selector>. See section "Skipping Tests" below for + <test-selector> syntax. + --valgrind=<tool>:: Execute all Git binaries under valgrind tool <tool> and exit with status 126 on errors (just like regular tests, this will @@ -187,10 +197,77 @@ and either can match the "t[0-9]{4}" part to skip the whole test, or t[0-9]{4} followed by ".$number" to say which particular test to skip. -Note that some tests in the existing test suite rely on previous -test item, so you cannot arbitrarily disable one and expect the -remainder of test to check what the test originally was intended -to check. +For an individual test suite --run could be used to specify that +only some tests should be run or that some tests should be +excluded from a run. + +The argument for --run is a list of individual test numbers or +ranges with an optional negation prefix that define what tests in +a test suite to include in the run. A range is two numbers +separated with a dash and matches a range of tests with both ends +been included. You may omit the first or the second number to +mean "from the first test" or "up to the very last test" +respectively. + +Optional prefix of '!' means that the test or a range of tests +should be excluded from the run. + +If --run starts with an unprefixed number or range the initial +set of tests to run is empty. If the first item starts with '!' +all the tests are added to the initial set. After initial set is +determined every test number or range is added or excluded from +the set one by one, from left to right. + +Individual numbers or ranges could be separated either by a space +or a comma. + +For example, to run only tests up to a specific test (21), one +could do this: + + $ sh ./t9200-git-cvsexport-commit.sh --run='1-21' + +or this: + + $ sh ./t9200-git-cvsexport-commit.sh --run='-21' + +Common case is to run several setup tests (1, 2, 3) and then a +specific test (21) that relies on that setup: + + $ sh ./t9200-git-cvsexport-commit.sh --run='1 2 3 21' + +or: + + $ sh ./t9200-git-cvsexport-commit.sh --run=1,2,3,21 + +or: + + $ sh ./t9200-git-cvsexport-commit.sh --run='-3 21' + +As noted above, the test set is built going though items left to +right, so this: + + $ sh ./t9200-git-cvsexport-commit.sh --run='1-4 !3' + +will run tests 1, 2, and 4. Items that comes later have higher +precendence. It means that this: + + $ sh ./t9200-git-cvsexport-commit.sh --run='!3 1-4' + +would just run tests from 1 to 4, including 3. + +You may use negation with ranges. The following will run all +test in the test suite except from 7 up to 11: + + $ sh ./t9200-git-cvsexport-commit.sh --run='!7-11' + +Some tests in a test suite rely on the previous tests performing +certain actions, specifically some tests are designated as +"setup" test, so you cannot _arbitrarily_ disable one test and +expect the rest to function correctly. + +--run is mostly useful when you want to focus on a specific test +and know what setup is needed for it. Or when you want to run +everything up to a certain test. Naming Tests @@ -596,6 +673,27 @@ library for your script to use. ... ' + - test_write_lines <lines> + + Write <lines> on standard output, one line per argument. + Useful to prepare multi-line files in a compact form. + + Example: + + test_write_lines a b c d e f g >foo + + Is a more compact equivalent of: + cat >foo <<-EOF + a + b + c + d + e + f + g + EOF + + - test_pause This command is useful for writing and debugging tests and must be diff --git a/t/check-non-portable-shell.pl b/t/check-non-portable-shell.pl index 45971f43b7..b170cbc045 100755 --- a/t/check-non-portable-shell.pl +++ b/t/check-non-portable-shell.pl @@ -16,12 +16,12 @@ sub err { while (<>) { chomp; - /^\s*sed\s+-i/ and err 'sed -i is not portable'; - /^\s*echo\s+-n/ and err 'echo -n is not portable (please use printf)'; + /\bsed\s+-i/ and err 'sed -i is not portable'; + /\becho\s+-n/ and err 'echo -n is not portable (please use printf)'; /^\s*declare\s+/ and err 'arrays/declare not portable'; /^\s*[^#]\s*which\s/ and err 'which is not portable (please use type)'; - /test\s+[^=]*==/ and err '"test a == b" is not portable (please use =)'; - /^\s*export\s+[^=]*=/ and err '"export FOO=bar" is not portable (please use FOO=bar && export FOO)'; + /\btest\s+[^=]*==/ and err '"test a == b" is not portable (please use =)'; + /\bexport\s+[A-Za-z0-9_]*=/ and err '"export FOO=bar" is not portable (please use FOO=bar && export FOO)'; # this resets our $. for each file close ARGV if eof; } diff --git a/t/lib-httpd.sh b/t/lib-httpd.sh index 252cbf163b..fd53b57187 100644 --- a/t/lib-httpd.sh +++ b/t/lib-httpd.sh @@ -37,6 +37,11 @@ then test_done fi +if ! test_have_prereq SANITY; then + test_skip_or_die $GIT_TEST_HTTPD \ + "Cannot run httpd tests as root" +fi + HTTPD_PARA="" for DEFAULT_HTTPD_PATH in '/usr/sbin/httpd' '/usr/sbin/apache2' @@ -105,10 +110,15 @@ else "Could not identify web server at '$LIB_HTTPD_PATH'" fi +install_script () { + write_script "$HTTPD_ROOT_PATH/$1" <"$TEST_PATH/$1" +} + prepare_httpd() { mkdir -p "$HTTPD_DOCUMENT_ROOT_PATH" cp "$TEST_PATH"/passwd "$HTTPD_ROOT_PATH" - cp "$TEST_PATH"/broken-smart-http.sh "$HTTPD_ROOT_PATH" + install_script broken-smart-http.sh + install_script error.sh ln -s "$LIB_HTTPD_MODULE_PATH" "$HTTPD_ROOT_PATH/modules" @@ -132,7 +142,7 @@ prepare_httpd() { HTTPD_URL_USER=$HTTPD_PROTO://user%40host@$HTTPD_DEST HTTPD_URL_USER_PASS=$HTTPD_PROTO://user%40host:pass%40host@$HTTPD_DEST - if test -n "$LIB_HTTPD_DAV" -o -n "$LIB_HTTPD_SVN" + if test -n "$LIB_HTTPD_DAV" || test -n "$LIB_HTTPD_SVN" then HTTPD_PARA="$HTTPD_PARA -DDAV" diff --git a/t/lib-httpd/apache.conf b/t/lib-httpd/apache.conf index 3a03e8263d..b384d79935 100644 --- a/t/lib-httpd/apache.conf +++ b/t/lib-httpd/apache.conf @@ -97,12 +97,16 @@ Alias /auth/dumb/ www/auth/dumb/ </LocationMatch> ScriptAliasMatch /smart_*[^/]*/(.*) ${GIT_EXEC_PATH}/git-http-backend/$1 ScriptAlias /broken_smart/ broken-smart-http.sh/ +ScriptAlias /error/ error.sh/ <Directory ${GIT_EXEC_PATH}> Options FollowSymlinks </Directory> <Files broken-smart-http.sh> Options ExecCGI </Files> +<Files error.sh> + Options ExecCGI +</Files> <Files ${GIT_EXEC_PATH}/git-http-backend> Options ExecCGI </Files> diff --git a/t/lib-httpd/broken-smart-http.sh b/t/lib-httpd/broken-smart-http.sh index f7ebfffa80..82cc610b0a 100755..100644 --- a/t/lib-httpd/broken-smart-http.sh +++ b/t/lib-httpd/broken-smart-http.sh @@ -1,4 +1,3 @@ -#!/bin/sh printf "Content-Type: text/%s\n" "html" echo printf "%s\n" "001e# service=git-upload-pack" diff --git a/t/lib-httpd/error.sh b/t/lib-httpd/error.sh new file mode 100755 index 0000000000..a77b8e5469 --- /dev/null +++ b/t/lib-httpd/error.sh @@ -0,0 +1,31 @@ +#!/bin/sh + +printf "Status: 500 Intentional Breakage\n" + +printf "Content-Type: " +charset=iso-8859-1 +case "$PATH_INFO" in +*html*) + printf "text/html" + ;; +*text*) + printf "text/plain" + ;; +*charset*) + printf "text/plain; charset=utf-8" + charset=utf-8 + ;; +*utf16*) + printf "text/plain; charset=utf-16" + charset=utf-16 + ;; +*odd-spacing*) + printf "text/plain; foo=bar ;charset=utf-16; other=nonsense" + charset=utf-16 + ;; +esac +printf "\n" + +printf "\n" +printf "this is the error message\n" | +iconv -f us-ascii -t $charset diff --git a/t/perf/p5310-pack-bitmaps.sh b/t/perf/p5310-pack-bitmaps.sh index 685d46f8b7..f8ed8573b7 100755 --- a/t/perf/p5310-pack-bitmaps.sh +++ b/t/perf/p5310-pack-bitmaps.sh @@ -8,6 +8,9 @@ test_perf_large_repo # note that we do everything through config, # since we want to be able to compare bitmap-aware # git versus non-bitmap git +# +# We intentionally use the deprecated pack.writebitmaps +# config so that we can test against older versions of git. test_expect_success 'setup bitmap config' ' git config pack.writebitmaps true && git config pack.writebitmaphashcache true diff --git a/t/t0000-basic.sh b/t/t0000-basic.sh index a2bb63ce8e..f10ba4a01e 100755 --- a/t/t0000-basic.sh +++ b/t/t0000-basic.sh @@ -42,9 +42,9 @@ test_expect_success 'success is reported like this' ' : ' -run_sub_test_lib_test () { - name="$1" descr="$2" # stdin is the body of the test code - shift 2 +_run_sub_test_lib_test_common () { + neg="$1" name="$2" descr="$3" # stdin is the body of the test code + shift 3 mkdir "$name" && ( # Pretend we're not running under a test harness, whether we @@ -70,10 +70,23 @@ run_sub_test_lib_test () { export TEST_DIRECTORY && TEST_OUTPUT_DIRECTORY=$(pwd) && export TEST_OUTPUT_DIRECTORY && - ./"$name.sh" "$@" >out 2>err + if test -z "$neg" + then + ./"$name.sh" "$@" >out 2>err + else + ! ./"$name.sh" "$@" >out 2>err + fi ) } +run_sub_test_lib_test () { + _run_sub_test_lib_test_common '' "$@" +} + +run_sub_test_lib_test_err () { + _run_sub_test_lib_test_common '!' "$@" +} + check_sub_test_lib_test () { name="$1" # stdin is the expected output from the test ( @@ -84,6 +97,18 @@ check_sub_test_lib_test () { ) } +check_sub_test_lib_test_err () { + name="$1" # stdin is the expected output output from the test + # expected error output is in descriptior 3 + ( + cd "$name" && + sed -e 's/^> //' -e 's/Z$//' >expect.out && + test_cmp expect.out out && + sed -e 's/^> //' -e 's/Z$//' <&3 >expect.err && + test_cmp expect.err err + ) +} + test_expect_success 'pretend we have a fully passing test suite' " run_sub_test_lib_test full-pass '3 passing tests' <<-\\EOF && for i in 1 2 3 @@ -270,6 +295,398 @@ test_expect_success 'test --verbose-only' ' EOF ' +test_expect_success 'GIT_SKIP_TESTS' " + ( + GIT_SKIP_TESTS='git.2' && export GIT_SKIP_TESTS && + run_sub_test_lib_test git-skip-tests-basic \ + 'GIT_SKIP_TESTS' <<-\\EOF && + for i in 1 2 3 + do + test_expect_success \"passing test #\$i\" 'true' + done + test_done + EOF + check_sub_test_lib_test git-skip-tests-basic <<-\\EOF + > ok 1 - passing test #1 + > ok 2 # skip passing test #2 (GIT_SKIP_TESTS) + > ok 3 - passing test #3 + > # passed all 3 test(s) + > 1..3 + EOF + ) +" + +test_expect_success 'GIT_SKIP_TESTS several tests' " + ( + GIT_SKIP_TESTS='git.2 git.5' && export GIT_SKIP_TESTS && + run_sub_test_lib_test git-skip-tests-several \ + 'GIT_SKIP_TESTS several tests' <<-\\EOF && + for i in 1 2 3 4 5 6 + do + test_expect_success \"passing test #\$i\" 'true' + done + test_done + EOF + check_sub_test_lib_test git-skip-tests-several <<-\\EOF + > ok 1 - passing test #1 + > ok 2 # skip passing test #2 (GIT_SKIP_TESTS) + > ok 3 - passing test #3 + > ok 4 - passing test #4 + > ok 5 # skip passing test #5 (GIT_SKIP_TESTS) + > ok 6 - passing test #6 + > # passed all 6 test(s) + > 1..6 + EOF + ) +" + +test_expect_success 'GIT_SKIP_TESTS sh pattern' " + ( + GIT_SKIP_TESTS='git.[2-5]' && export GIT_SKIP_TESTS && + run_sub_test_lib_test git-skip-tests-sh-pattern \ + 'GIT_SKIP_TESTS sh pattern' <<-\\EOF && + for i in 1 2 3 4 5 6 + do + test_expect_success \"passing test #\$i\" 'true' + done + test_done + EOF + check_sub_test_lib_test git-skip-tests-sh-pattern <<-\\EOF + > ok 1 - passing test #1 + > ok 2 # skip passing test #2 (GIT_SKIP_TESTS) + > ok 3 # skip passing test #3 (GIT_SKIP_TESTS) + > ok 4 # skip passing test #4 (GIT_SKIP_TESTS) + > ok 5 # skip passing test #5 (GIT_SKIP_TESTS) + > ok 6 - passing test #6 + > # passed all 6 test(s) + > 1..6 + EOF + ) +" + +test_expect_success '--run basic' " + run_sub_test_lib_test run-basic \ + '--run basic' --run='1 3 5' <<-\\EOF && + for i in 1 2 3 4 5 6 + do + test_expect_success \"passing test #\$i\" 'true' + done + test_done + EOF + check_sub_test_lib_test run-basic <<-\\EOF + > ok 1 - passing test #1 + > ok 2 # skip passing test #2 (--run) + > ok 3 - passing test #3 + > ok 4 # skip passing test #4 (--run) + > ok 5 - passing test #5 + > ok 6 # skip passing test #6 (--run) + > # passed all 6 test(s) + > 1..6 + EOF +" + +test_expect_success '--run with a range' " + run_sub_test_lib_test run-range \ + '--run with a range' --run='1-3' <<-\\EOF && + for i in 1 2 3 4 5 6 + do + test_expect_success \"passing test #\$i\" 'true' + done + test_done + EOF + check_sub_test_lib_test run-range <<-\\EOF + > ok 1 - passing test #1 + > ok 2 - passing test #2 + > ok 3 - passing test #3 + > ok 4 # skip passing test #4 (--run) + > ok 5 # skip passing test #5 (--run) + > ok 6 # skip passing test #6 (--run) + > # passed all 6 test(s) + > 1..6 + EOF +" + +test_expect_success '--run with two ranges' " + run_sub_test_lib_test run-two-ranges \ + '--run with two ranges' --run='1-2 5-6' <<-\\EOF && + for i in 1 2 3 4 5 6 + do + test_expect_success \"passing test #\$i\" 'true' + done + test_done + EOF + check_sub_test_lib_test run-two-ranges <<-\\EOF + > ok 1 - passing test #1 + > ok 2 - passing test #2 + > ok 3 # skip passing test #3 (--run) + > ok 4 # skip passing test #4 (--run) + > ok 5 - passing test #5 + > ok 6 - passing test #6 + > # passed all 6 test(s) + > 1..6 + EOF +" + +test_expect_success '--run with a left open range' " + run_sub_test_lib_test run-left-open-range \ + '--run with a left open range' --run='-3' <<-\\EOF && + for i in 1 2 3 4 5 6 + do + test_expect_success \"passing test #\$i\" 'true' + done + test_done + EOF + check_sub_test_lib_test run-left-open-range <<-\\EOF + > ok 1 - passing test #1 + > ok 2 - passing test #2 + > ok 3 - passing test #3 + > ok 4 # skip passing test #4 (--run) + > ok 5 # skip passing test #5 (--run) + > ok 6 # skip passing test #6 (--run) + > # passed all 6 test(s) + > 1..6 + EOF +" + +test_expect_success '--run with a right open range' " + run_sub_test_lib_test run-right-open-range \ + '--run with a right open range' --run='4-' <<-\\EOF && + for i in 1 2 3 4 5 6 + do + test_expect_success \"passing test #\$i\" 'true' + done + test_done + EOF + check_sub_test_lib_test run-right-open-range <<-\\EOF + > ok 1 # skip passing test #1 (--run) + > ok 2 # skip passing test #2 (--run) + > ok 3 # skip passing test #3 (--run) + > ok 4 - passing test #4 + > ok 5 - passing test #5 + > ok 6 - passing test #6 + > # passed all 6 test(s) + > 1..6 + EOF +" + +test_expect_success '--run with basic negation' " + run_sub_test_lib_test run-basic-neg \ + '--run with basic negation' --run='"'!3'"' <<-\\EOF && + for i in 1 2 3 4 5 6 + do + test_expect_success \"passing test #\$i\" 'true' + done + test_done + EOF + check_sub_test_lib_test run-basic-neg <<-\\EOF + > ok 1 - passing test #1 + > ok 2 - passing test #2 + > ok 3 # skip passing test #3 (--run) + > ok 4 - passing test #4 + > ok 5 - passing test #5 + > ok 6 - passing test #6 + > # passed all 6 test(s) + > 1..6 + EOF +" + +test_expect_success '--run with two negations' " + run_sub_test_lib_test run-two-neg \ + '--run with two negations' --run='"'!3 !6'"' <<-\\EOF && + for i in 1 2 3 4 5 6 + do + test_expect_success \"passing test #\$i\" 'true' + done + test_done + EOF + check_sub_test_lib_test run-two-neg <<-\\EOF + > ok 1 - passing test #1 + > ok 2 - passing test #2 + > ok 3 # skip passing test #3 (--run) + > ok 4 - passing test #4 + > ok 5 - passing test #5 + > ok 6 # skip passing test #6 (--run) + > # passed all 6 test(s) + > 1..6 + EOF +" + +test_expect_success '--run a range and negation' " + run_sub_test_lib_test run-range-and-neg \ + '--run a range and negation' --run='"'-4 !2'"' <<-\\EOF && + for i in 1 2 3 4 5 6 + do + test_expect_success \"passing test #\$i\" 'true' + done + test_done + EOF + check_sub_test_lib_test run-range-and-neg <<-\\EOF + > ok 1 - passing test #1 + > ok 2 # skip passing test #2 (--run) + > ok 3 - passing test #3 + > ok 4 - passing test #4 + > ok 5 # skip passing test #5 (--run) + > ok 6 # skip passing test #6 (--run) + > # passed all 6 test(s) + > 1..6 + EOF +" + +test_expect_success '--run range negation' " + run_sub_test_lib_test run-range-neg \ + '--run range negation' --run='"'!1-3'"' <<-\\EOF && + for i in 1 2 3 4 5 6 + do + test_expect_success \"passing test #\$i\" 'true' + done + test_done + EOF + check_sub_test_lib_test run-range-neg <<-\\EOF + > ok 1 # skip passing test #1 (--run) + > ok 2 # skip passing test #2 (--run) + > ok 3 # skip passing test #3 (--run) + > ok 4 - passing test #4 + > ok 5 - passing test #5 + > ok 6 - passing test #6 + > # passed all 6 test(s) + > 1..6 + EOF +" + +test_expect_success '--run include, exclude and include' " + run_sub_test_lib_test run-inc-neg-inc \ + '--run include, exclude and include' \ + --run='"'1-5 !1-3 2'"' <<-\\EOF && + for i in 1 2 3 4 5 6 + do + test_expect_success \"passing test #\$i\" 'true' + done + test_done + EOF + check_sub_test_lib_test run-inc-neg-inc <<-\\EOF + > ok 1 # skip passing test #1 (--run) + > ok 2 - passing test #2 + > ok 3 # skip passing test #3 (--run) + > ok 4 - passing test #4 + > ok 5 - passing test #5 + > ok 6 # skip passing test #6 (--run) + > # passed all 6 test(s) + > 1..6 + EOF +" + +test_expect_success '--run include, exclude and include, comma separated' " + run_sub_test_lib_test run-inc-neg-inc-comma \ + '--run include, exclude and include, comma separated' \ + --run=1-5,\!1-3,2 <<-\\EOF && + for i in 1 2 3 4 5 6 + do + test_expect_success \"passing test #\$i\" 'true' + done + test_done + EOF + check_sub_test_lib_test run-inc-neg-inc-comma <<-\\EOF + > ok 1 # skip passing test #1 (--run) + > ok 2 - passing test #2 + > ok 3 # skip passing test #3 (--run) + > ok 4 - passing test #4 + > ok 5 - passing test #5 + > ok 6 # skip passing test #6 (--run) + > # passed all 6 test(s) + > 1..6 + EOF +" + +test_expect_success '--run exclude and include' " + run_sub_test_lib_test run-neg-inc \ + '--run exclude and include' \ + --run='"'!3- 5'"' <<-\\EOF && + for i in 1 2 3 4 5 6 + do + test_expect_success \"passing test #\$i\" 'true' + done + test_done + EOF + check_sub_test_lib_test run-neg-inc <<-\\EOF + > ok 1 - passing test #1 + > ok 2 - passing test #2 + > ok 3 # skip passing test #3 (--run) + > ok 4 # skip passing test #4 (--run) + > ok 5 - passing test #5 + > ok 6 # skip passing test #6 (--run) + > # passed all 6 test(s) + > 1..6 + EOF +" + +test_expect_success '--run empty selectors' " + run_sub_test_lib_test run-empty-sel \ + '--run empty selectors' \ + --run='1,,3,,,5' <<-\\EOF && + for i in 1 2 3 4 5 6 + do + test_expect_success \"passing test #\$i\" 'true' + done + test_done + EOF + check_sub_test_lib_test run-empty-sel <<-\\EOF + > ok 1 - passing test #1 + > ok 2 # skip passing test #2 (--run) + > ok 3 - passing test #3 + > ok 4 # skip passing test #4 (--run) + > ok 5 - passing test #5 + > ok 6 # skip passing test #6 (--run) + > # passed all 6 test(s) + > 1..6 + EOF +" + +test_expect_success '--run invalid range start' " + run_sub_test_lib_test_err run-inv-range-start \ + '--run invalid range start' \ + --run='a-5' <<-\\EOF && + test_expect_success \"passing test #1\" 'true' + test_done + EOF + check_sub_test_lib_test_err run-inv-range-start \ + <<-\\EOF_OUT 3<<-\\EOF_ERR + > FATAL: Unexpected exit with code 1 + EOF_OUT + > error: --run: invalid non-numeric in range start: 'a-5' + EOF_ERR +" + +test_expect_success '--run invalid range end' " + run_sub_test_lib_test_err run-inv-range-end \ + '--run invalid range end' \ + --run='1-z' <<-\\EOF && + test_expect_success \"passing test #1\" 'true' + test_done + EOF + check_sub_test_lib_test_err run-inv-range-end \ + <<-\\EOF_OUT 3<<-\\EOF_ERR + > FATAL: Unexpected exit with code 1 + EOF_OUT + > error: --run: invalid non-numeric in range end: '1-z' + EOF_ERR +" + +test_expect_success '--run invalid selector' " + run_sub_test_lib_test_err run-inv-selector \ + '--run invalid selector' \ + --run='1?' <<-\\EOF && + test_expect_success \"passing test #1\" 'true' + test_done + EOF + check_sub_test_lib_test_err run-inv-selector \ + <<-\\EOF_OUT 3<<-\\EOF_ERR + > FATAL: Unexpected exit with code 1 + EOF_OUT + > error: --run: invalid non-numeric in test selector: '1?' + EOF_ERR +" + + test_set_prereq HAVEIT haveit=no test_expect_success HAVEIT 'test runs if prerequisite is satisfied' ' diff --git a/t/t0001-init.sh b/t/t0001-init.sh index 2f3020342a..e62c0ffbc2 100755 --- a/t/t0001-init.sh +++ b/t/t0001-init.sh @@ -56,7 +56,7 @@ test_expect_success 'plain through aliased command, outside any git repo' ' check_config plain-aliased/.git false unset ' -test_expect_failure 'plain nested through aliased command' ' +test_expect_success 'plain nested through aliased command' ' ( git init plain-ancestor-aliased && cd plain-ancestor-aliased && @@ -68,7 +68,7 @@ test_expect_failure 'plain nested through aliased command' ' check_config plain-ancestor-aliased/plain-nested/.git false unset ' -test_expect_failure 'plain nested in bare through aliased command' ' +test_expect_success 'plain nested in bare through aliased command' ' ( git init --bare bare-ancestor-aliased.git && cd bare-ancestor-aliased.git && diff --git a/t/t0008-ignores.sh b/t/t0008-ignores.sh index 63beb99828..39e55a13c8 100755 --- a/t/t0008-ignores.sh +++ b/t/t0008-ignores.sh @@ -806,4 +806,29 @@ test_expect_success !MINGW 'quoting allows trailing whitespace' ' test_cmp err.expect err ' +test_expect_success NOT_MINGW,NOT_CYGWIN 'correct handling of backslashes' ' + rm -rf whitespace && + mkdir whitespace && + >"whitespace/trailing 1 " && + >"whitespace/trailing 2 \\\\" && + >"whitespace/trailing 3 \\\\" && + >"whitespace/trailing 4 \\ " && + >"whitespace/trailing 5 \\ \\ " && + >"whitespace/trailing 6 \\a\\" && + >whitespace/untracked && + sed -e "s/Z$//" >ignore <<-\EOF && + whitespace/trailing 1 \ Z + whitespace/trailing 2 \\\\Z + whitespace/trailing 3 \\\\ Z + whitespace/trailing 4 \\\ Z + whitespace/trailing 5 \\ \\\ Z + whitespace/trailing 6 \\a\\Z + EOF + echo whitespace/untracked >expect && + >err.expect && + git ls-files -o -X ignore whitespace >actual 2>err && + test_cmp expect actual && + test_cmp err.expect err +' + test_done diff --git a/t/t0021-conversion.sh b/t/t0021-conversion.sh index b92e6cb046..f890c54d13 100755 --- a/t/t0021-conversion.sh +++ b/t/t0021-conversion.sh @@ -190,8 +190,6 @@ test_expect_success 'required filter clean failure' ' test_must_fail git add test.fc ' -test -n "$GIT_TEST_LONG" && test_set_prereq EXPENSIVE - test_expect_success EXPENSIVE 'filter large file' ' git config filter.largefile.smudge cat && git config filter.largefile.clean cat && diff --git a/t/t0025-crlf-auto.sh b/t/t0025-crlf-auto.sh index b0e5694ebd..28102de1a0 100755 --- a/t/t0025-crlf-auto.sh +++ b/t/t0025-crlf-auto.sh @@ -36,7 +36,7 @@ test_expect_success 'default settings cause no changes' ' onediff=$(git diff one) && twodiff=$(git diff two) && threediff=$(git diff three) && - test -z "$onediff" -a -z "$twodiff" -a -z "$threediff" + test -z "$onediff" && test -z "$twodiff" && test -z "$threediff" ' test_expect_success 'crlf=true causes a CRLF file to be normalized' ' @@ -111,7 +111,7 @@ test_expect_success 'autocrlf=true does not normalize CRLF files' ' onediff=$(git diff one) && twodiff=$(git diff two) && threediff=$(git diff three) && - test -z "$onediff" -a -z "$twodiff" -a -z "$threediff" + test -z "$onediff" && test -z "$twodiff" && test -z "$threediff" ' test_expect_success 'text=auto, autocrlf=true _does_ normalize CRLF files' ' @@ -126,7 +126,7 @@ test_expect_success 'text=auto, autocrlf=true _does_ normalize CRLF files' ' onediff=$(git diff one) && twodiff=$(git diff two) && threediff=$(git diff three) && - test -z "$onediff" -a -n "$twodiff" -a -z "$threediff" + test -z "$onediff" && test -n "$twodiff" && test -z "$threediff" ' test_expect_success 'text=auto, autocrlf=true does not normalize binary files' ' diff --git a/t/t0026-eol-config.sh b/t/t0026-eol-config.sh index e1126aa7cc..4807b0f015 100755 --- a/t/t0026-eol-config.sh +++ b/t/t0026-eol-config.sh @@ -36,7 +36,7 @@ test_expect_success 'eol=lf puts LFs in normalized file' ' ! has_cr two && onediff=$(git diff one) && twodiff=$(git diff two) && - test -z "$onediff" -a -z "$twodiff" + test -z "$onediff" && test -z "$twodiff" ' test_expect_success 'eol=crlf puts CRLFs in normalized file' ' @@ -49,7 +49,7 @@ test_expect_success 'eol=crlf puts CRLFs in normalized file' ' ! has_cr two && onediff=$(git diff one) && twodiff=$(git diff two) && - test -z "$onediff" -a -z "$twodiff" + test -z "$onediff" && test -z "$twodiff" ' test_expect_success 'autocrlf=true overrides eol=lf' ' @@ -63,7 +63,7 @@ test_expect_success 'autocrlf=true overrides eol=lf' ' has_cr two && onediff=$(git diff one) && twodiff=$(git diff two) && - test -z "$onediff" -a -z "$twodiff" + test -z "$onediff" && test -z "$twodiff" ' test_expect_success 'autocrlf=true overrides unset eol' ' @@ -77,7 +77,7 @@ test_expect_success 'autocrlf=true overrides unset eol' ' has_cr two && onediff=$(git diff one) && twodiff=$(git diff two) && - test -z "$onediff" -a -z "$twodiff" + test -z "$onediff" && test -z "$twodiff" ' test_done diff --git a/t/t1400-update-ref.sh b/t/t1400-update-ref.sh index 4e2459afc5..0218e96366 100755 --- a/t/t1400-update-ref.sh +++ b/t/t1400-update-ref.sh @@ -235,7 +235,7 @@ test_expect_success \ 'rm -f o e && git rev-parse --verify "master@{2005-05-26 23:33:01}" >o 2>e && test '"$B"' = $(cat o) && - test "warning: Log .git/logs/'"$m has gap after $gd"'." = "$(cat e)"' + test "warning: Log for ref '"$m has gap after $gd"'." = "$(cat e)"' test_expect_success \ 'Query "master@{2005-05-26 23:38:00}" (middle of history)' \ 'rm -f o e && @@ -253,7 +253,7 @@ test_expect_success \ 'rm -f o e && git rev-parse --verify "master@{2005-05-28}" >o 2>e && test '"$D"' = $(cat o) && - test "warning: Log .git/logs/'"$m unexpectedly ended on $ld"'." = "$(cat e)"' + test "warning: Log for ref '"$m unexpectedly ended on $ld"'." = "$(cat e)"' rm -f .git/$m .git/logs/$m expect diff --git a/t/t1410-reflog.sh b/t/t1410-reflog.sh index 236b13a3ab..8cab06f90a 100755 --- a/t/t1410-reflog.sh +++ b/t/t1410-reflog.sh @@ -245,4 +245,12 @@ test_expect_success 'gc.reflogexpire=false' ' ' +test_expect_success 'checkout should not delete log for packed ref' ' + test $(git reflog master | wc -l) = 4 && + git branch foo && + git pack-refs --all && + git checkout foo && + test $(git reflog master | wc -l) = 4 +' + test_done diff --git a/t/t1507-rev-parse-upstream.sh b/t/t1507-rev-parse-upstream.sh index 178694ee63..1978947c41 100755 --- a/t/t1507-rev-parse-upstream.sh +++ b/t/t1507-rev-parse-upstream.sh @@ -121,7 +121,7 @@ test_expect_success 'merge my-side@{u} records the correct name' ' git branch -D new ;# can fail but is ok git branch -t new my-side@{u} && git merge -s ours new@{u} && - git show -s --pretty=format:%s >actual && + git show -s --pretty=tformat:%s >actual && echo "Merge remote-tracking branch ${sq}origin/side${sq}" >expect && test_cmp expect actual ) diff --git a/t/t2107-update-index-basic.sh b/t/t2107-update-index-basic.sh index fe2fb17102..1bafb9098c 100755 --- a/t/t2107-update-index-basic.sh +++ b/t/t2107-update-index-basic.sh @@ -29,6 +29,10 @@ test_expect_success 'update-index -h with corrupt index' ' test_i18ngrep "[Uu]sage: git update-index" broken/usage ' +test_expect_success '--cacheinfo complains of missing arguments' ' + test_must_fail git update-index --cacheinfo +' + test_expect_success '--cacheinfo does not accept blob null sha1' ' echo content >file && git add file && diff --git a/t/t3032-merge-recursive-options.sh b/t/t3032-merge-recursive-options.sh index 5fd7bbb652..4029c9c8c0 100755 --- a/t/t3032-merge-recursive-options.sh +++ b/t/t3032-merge-recursive-options.sh @@ -14,7 +14,11 @@ test_description='merge-recursive options . ./test-lib.sh test_have_prereq SED_STRIPS_CR && SED_OPTIONS=-b -test_have_prereq GREP_STRIPS_CR && export GREP_OPTIONS=-U +if test_have_prereq GREP_STRIPS_CR +then + GREP_OPTIONS=-U + export GREP_OPTIONS +fi test_expect_success 'setup' ' conflict_hunks () { diff --git a/t/t3302-notes-index-expensive.sh b/t/t3302-notes-index-expensive.sh index e35d7811ac..8d44e04354 100755 --- a/t/t3302-notes-index-expensive.sh +++ b/t/t3302-notes-index-expensive.sh @@ -7,9 +7,7 @@ test_description='Test commit notes index (expensive!)' . ./test-lib.sh -test_set_prereq NOT_EXPENSIVE test -n "$GIT_NOTES_TIMING_TESTS" && test_set_prereq EXPENSIVE -test -x /usr/bin/time && test_set_prereq USR_BIN_TIME create_repo () { number_of_commits=$1 @@ -17,43 +15,43 @@ create_repo () { test -d .git || { git init && ( - while [ $nr -lt $number_of_commits ]; do + while test $nr -lt $number_of_commits + do nr=$(($nr+1)) mark=$(($nr+$nr)) notemark=$(($mark+1)) test_tick && - cat <<INPUT_END && -commit refs/heads/master -mark :$mark -committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE -data <<COMMIT -commit #$nr -COMMIT - -M 644 inline file -data <<EOF -file in commit #$nr -EOF - -blob -mark :$notemark -data <<EOF -note for commit #$nr -EOF - -INPUT_END - - echo "N :$notemark :$mark" >> note_commit + cat <<-INPUT_END && + commit refs/heads/master + mark :$mark + committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE + data <<COMMIT + commit #$nr + COMMIT + + M 644 inline file + data <<EOF + file in commit #$nr + EOF + + blob + mark :$notemark + data <<EOF + note for commit #$nr + EOF + + INPUT_END + echo "N :$notemark :$mark" >>note_commit done && test_tick && - cat <<INPUT_END && -commit refs/notes/commits -committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE -data <<COMMIT -notes -COMMIT + cat <<-INPUT_END && + commit refs/notes/commits + committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE + data <<COMMIT + notes + COMMIT -INPUT_END + INPUT_END cat note_commit ) | @@ -65,62 +63,74 @@ INPUT_END test_notes () { count=$1 && git config core.notesRef refs/notes/commits && - git log | grep "^ " > output && + git log | grep "^ " >output && i=$count && - while [ $i -gt 0 ]; do + while test $i -gt 0 + do echo " commit #$i" && echo " note for commit #$i" && - i=$(($i-1)); - done > expect && + i=$(($i-1)) + done >expect && test_cmp expect output } -cat > time_notes << \EOF +write_script time_notes <<\EOF mode=$1 i=1 - while [ $i -lt $2 ]; do + while test $i -lt $2 + do case $1 in no-notes) - GIT_NOTES_REF=non-existing; export GIT_NOTES_REF - ;; + GIT_NOTES_REF=non-existing + export GIT_NOTES_REF + ;; notes) unset GIT_NOTES_REF - ;; + ;; esac - git log >/dev/null + git log i=$(($i+1)) - done + done >/dev/null EOF time_notes () { for mode in no-notes notes do echo $mode - /usr/bin/time "$SHELL_PATH" ../time_notes $mode $1 + /usr/bin/time ../time_notes $mode $1 done } do_tests () { - pr=$1 - count=$2 - - test_expect_success $pr 'setup / mkdir' ' - mkdir $count && - cd $count + count=$1 pr=${2-} + + test_expect_success $pr "setup $count" ' + mkdir "$count" && + ( + cd "$count" && + create_repo "$count" + ) ' - test_expect_success $pr "setup $count" "create_repo $count" - - test_expect_success $pr 'notes work' "test_notes $count" - - test_expect_success USR_BIN_TIME,$pr 'notes timing with /usr/bin/time' "time_notes 100" + test_expect_success $pr 'notes work' ' + ( + cd "$count" && + test_notes "$count" + ) + ' - test_expect_success $pr 'teardown / cd ..' 'cd ..' + test_expect_success "USR_BIN_TIME${pr:+,$pr}" 'notes timing with /usr/bin/time' ' + ( + cd "$count" && + time_notes 100 + ) + ' } -do_tests NOT_EXPENSIVE 10 -for count in 100 1000 10000; do - do_tests EXPENSIVE $count +do_tests 10 +for count in 100 1000 10000 +do + do_tests "$count" EXPENSIVE done test_done diff --git a/t/t3402-rebase-merge.sh b/t/t3402-rebase-merge.sh index be8c1d5ef9..5a27ec9b5e 100755 --- a/t/t3402-rebase-merge.sh +++ b/t/t3402-rebase-merge.sh @@ -33,6 +33,7 @@ test_expect_success setup ' tr "[a-z]" "[A-Z]" <original >newfile && git add newfile && git commit -a -m"side edits further." && + git branch second-side && tr "[a-m]" "[A-M]" <original >newfile && rm -f original && @@ -41,6 +42,7 @@ test_expect_success setup ' git branch test-rebase side && git branch test-rebase-pick side && git branch test-reference-pick side && + git branch test-conflicts side && git checkout -b test-merge side ' @@ -138,4 +140,17 @@ test_expect_success 'rebase -s funny -Xopt' ' test -f funny.was.run ' +test_expect_success 'rebase --skip works with two conflicts in a row' ' + git checkout second-side && + tr "[A-Z]" "[a-z]" <newfile >tmp && + mv tmp newfile && + git commit -a -m"edit conflicting with side" && + tr "[d-f]" "[D-F]" <newfile >tmp && + mv tmp newfile && + git commit -a -m"another edit conflicting with side" && + test_must_fail git rebase --merge test-conflicts && + test_must_fail git rebase --skip && + git rebase --skip +' + test_done diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh index c0023a5b4f..8197ed29a9 100755 --- a/t/t3404-rebase-interactive.sh +++ b/t/t3404-rebase-interactive.sh @@ -67,6 +67,14 @@ test_expect_success 'setup' ' SHELL= export SHELL +test_expect_success 'rebase --keep-empty' ' + git checkout -b emptybranch master && + git commit --allow-empty -m "empty" && + git rebase --keep-empty -i HEAD~2 && + git log --oneline >actual && + test_line_count = 6 actual +' + test_expect_success 'rebase -i with the exec command' ' git checkout master && ( diff --git a/t/t3419-rebase-patch-id.sh b/t/t3419-rebase-patch-id.sh index e70ac10a0c..9292b499f3 100755 --- a/t/t3419-rebase-patch-id.sh +++ b/t/t3419-rebase-patch-id.sh @@ -4,12 +4,9 @@ test_description='git rebase - test patch id computation' . ./test-lib.sh -test_set_prereq NOT_EXPENSIVE test -n "$GIT_PATCHID_TIMING_TESTS" && test_set_prereq EXPENSIVE -test -x /usr/bin/time && test_set_prereq USR_BIN_TIME -count() -{ +count () { i=0 while test $i -lt $1 do @@ -18,8 +15,7 @@ count() done } -scramble() -{ +scramble () { i=0 while read x do @@ -28,12 +24,11 @@ scramble() echo "$x" fi i=$((($i+1) % 10)) - done < "$1" > "$1.new" + done <"$1" >"$1.new" mv -f "$1.new" "$1" } -run() -{ +run () { echo \$ "$@" /usr/bin/time "$@" >/dev/null } @@ -43,10 +38,8 @@ test_expect_success 'setup' ' git tag root ' -do_tests() -{ - pr=$1 - nlines=$2 +do_tests () { + nlines=$1 pr=${2-} test_expect_success $pr "setup: $nlines lines" " rm -f .gitattributes && @@ -103,7 +96,7 @@ do_tests() " } -do_tests NOT_EXPENSIVE 500 -do_tests EXPENSIVE 50000 +do_tests 500 +do_tests 50000 EXPENSIVE test_done diff --git a/t/t3420-rebase-autostash.sh b/t/t3420-rebase-autostash.sh index 90eb26493c..d783f03d3f 100755 --- a/t/t3420-rebase-autostash.sh +++ b/t/t3420-rebase-autostash.sh @@ -167,4 +167,19 @@ testrebase "" .git/rebase-apply testrebase " --merge" .git/rebase-merge testrebase " --interactive" .git/rebase-merge +test_expect_success 'abort rebase -i with --autostash' ' + test_when_finished "git reset --hard" && + echo uncommited-content >file0 && + ( + write_script abort-editor.sh <<-\EOF && + echo >"$1" + EOF + test_set_editor "$(pwd)/abort-editor.sh" && + test_must_fail git rebase -i --autostash HEAD^ && + rm -f abort-editor.sh + ) && + echo uncommited-content >expected && + test_cmp expected file0 +' + test_done diff --git a/t/t3910-mac-os-precompose.sh b/t/t3910-mac-os-precompose.sh index 96941e94cc..831935665e 100755 --- a/t/t3910-mac-os-precompose.sh +++ b/t/t3910-mac-os-precompose.sh @@ -140,6 +140,16 @@ test_expect_success "Add long precomposed filename" ' git add * && git commit -m "Long filename" ' + +test_expect_failure 'handle existing decomposed filenames' ' + echo content >"verbatim.$Adiarnfd" && + git -c core.precomposeunicode=false add "verbatim.$Adiarnfd" && + git commit -m "existing decomposed file" && + >expect && + git ls-files --exclude-standard -o "verbatim*" >untracked && + test_cmp expect untracked +' + # Test if the global core.precomposeunicode stops autosensing # Must be the last test case test_expect_success "respect git config --global core.precomposeunicode" ' diff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh index 282bee4a54..256affce89 100755 --- a/t/t4014-format-patch.sh +++ b/t/t4014-format-patch.sh @@ -762,6 +762,67 @@ test_expect_success 'format-patch --signature="" suppresses signatures' ' ! grep "^-- \$" output ' +test_expect_success 'prepare mail-signature input' ' + cat >mail-signature <<-\EOF + + Test User <test.email@kernel.org> + http://git.kernel.org/cgit/git/git.git + + git.kernel.org/?p=git/git.git;a=summary + + EOF +' + +test_expect_success '--signature-file=file works' ' + git format-patch --stdout --signature-file=mail-signature -1 >output && + check_patch output && + sed -e "1,/^-- \$/d" <output >actual && + { + cat mail-signature && echo + } >expect && + test_cmp expect actual +' + +test_expect_success 'format.signaturefile works' ' + test_config format.signaturefile mail-signature && + git format-patch --stdout -1 >output && + check_patch output && + sed -e "1,/^-- \$/d" <output >actual && + { + cat mail-signature && echo + } >expect && + test_cmp expect actual +' + +test_expect_success '--no-signature suppresses format.signaturefile ' ' + test_config format.signaturefile mail-signature && + git format-patch --stdout --no-signature -1 >output && + check_patch output && + ! grep "^-- \$" output +' + +test_expect_success '--signature-file overrides format.signaturefile' ' + cat >other-mail-signature <<-\EOF + Use this other signature instead of mail-signature. + EOF + test_config format.signaturefile mail-signature && + git format-patch --stdout \ + --signature-file=other-mail-signature -1 >output && + check_patch output && + sed -e "1,/^-- \$/d" <output >actual && + { + cat other-mail-signature && echo + } >expect && + test_cmp expect actual +' + +test_expect_success '--signature overrides format.signaturefile' ' + test_config format.signaturefile mail-signature && + git format-patch --stdout --signature="my sig" -1 >output && + check_patch output && + grep "my sig" output +' + test_expect_success TTY 'format-patch --stdout paginates' ' rm -f pager_used && test_terminal env GIT_PAGER="wc >pager_used" git format-patch --stdout --all && diff --git a/t/t4039-diff-assume-unchanged.sh b/t/t4039-diff-assume-unchanged.sh index 9d9498bd95..23c0e357a7 100755 --- a/t/t4039-diff-assume-unchanged.sh +++ b/t/t4039-diff-assume-unchanged.sh @@ -28,4 +28,15 @@ test_expect_success 'diff-files does not examine assume-unchanged entries' ' test -z "$(git diff-files -- one)" ' +test_expect_success POSIXPERM 'find-copies-harder is not confused by mode bits' ' + echo content >exec && + chmod +x exec && + git add exec && + git commit -m exec && + git update-index --assume-unchanged exec && + >expect && + git diff-files --find-copies-harder -- exec >actual && + test_cmp expect actual +' + test_done diff --git a/t/t4041-diff-submodule-option.sh b/t/t4041-diff-submodule-option.sh index 1751c83307..463d63bde0 100755 --- a/t/t4041-diff-submodule-option.sh +++ b/t/t4041-diff-submodule-option.sh @@ -11,6 +11,9 @@ This test tries to verify the sanity of the --submodule option of git diff. . ./test-lib.sh +# Tested non-UTF-8 encoding +test_encoding="ISO8859-1" + # String "added" in German (translated with Google Translate), encoded in UTF-8, # used in sample commit log messages in add_file() function below. added=$(printf "hinzugef\303\274gt") @@ -23,8 +26,8 @@ add_file () { echo "$name" >"$name" && git add "$name" && test_tick && - msg_added_iso88591=$(echo "Add $name ($added $name)" | iconv -f utf-8 -t iso8859-1) && - git -c 'i18n.commitEncoding=iso8859-1' commit -m "$msg_added_iso88591" + msg_added_iso88591=$(echo "Add $name ($added $name)" | iconv -f utf-8 -t $test_encoding) && + git -c "i18n.commitEncoding=$test_encoding" commit -m "$msg_added_iso88591" done >/dev/null && git rev-parse --short --verify HEAD ) diff --git a/t/t4102-apply-rename.sh b/t/t4102-apply-rename.sh index 49e2d6c349..fae305979a 100755 --- a/t/t4102-apply-rename.sh +++ b/t/t4102-apply-rename.sh @@ -52,6 +52,6 @@ EOF test_expect_success 'apply copy' \ 'git apply --index --stat --summary --apply test-patch && - test "$(cat bar)" = "This is bar" -a "$(cat foo)" = "This is foo"' + test "$(cat bar)" = "This is bar" && test "$(cat foo)" = "This is foo"' test_done diff --git a/t/t4201-shortlog.sh b/t/t4201-shortlog.sh index 42866992cf..97fcb31d6e 100755 --- a/t/t4201-shortlog.sh +++ b/t/t4201-shortlog.sh @@ -188,4 +188,10 @@ test_expect_success 'shortlog ignores commits with missing authors' ' test_cmp expect actual ' +test_expect_success 'shortlog with revision pseudo options' ' + git shortlog --all && + git shortlog --branches && + git shortlog --exclude=refs/heads/m* --all +' + test_done diff --git a/t/t4204-patch-id.sh b/t/t4204-patch-id.sh index 7940f6f0b9..baa9d3c82e 100755 --- a/t/t4204-patch-id.sh +++ b/t/t4204-patch-id.sh @@ -5,27 +5,44 @@ test_description='git patch-id' . ./test-lib.sh test_expect_success 'setup' ' - test_commit initial foo a && - test_commit first foo b && - git checkout -b same HEAD^ && - test_commit same-msg foo b && - git checkout -b notsame HEAD^ && - test_commit notsame-msg foo c + as="a a a a a a a a" && # eight a + test_write_lines $as >foo && + test_write_lines $as >bar && + git add foo bar && + git commit -a -m initial && + test_write_lines $as b >foo && + test_write_lines $as b >bar && + git commit -a -m first && + git checkout -b same master && + git commit --amend -m same-msg && + git checkout -b notsame master && + echo c >foo && + echo c >bar && + git commit --amend -a -m notsame-msg && + test_write_lines bar foo >bar-then-foo && + test_write_lines foo bar >foo-then-bar ' test_expect_success 'patch-id output is well-formed' ' - git log -p -1 | git patch-id > output && + git log -p -1 | git patch-id >output && grep "^[a-f0-9]\{40\} $(git rev-parse HEAD)$" output ' +#calculate patch id. Make sure output is not empty. calc_patch_id () { - git patch-id | - sed "s# .*##" > patch-id_"$1" + name="$1" + shift + git patch-id "$@" | + sed "s/ .*//" >patch-id_"$name" && + test_line_count -gt 0 patch-id_"$name" +} + +get_top_diff () { + git log -p -1 "$@" -O bar-then-foo -- } get_patch_id () { - git log -p -1 "$1" | git patch-id | - sed "s# .*##" > patch-id_"$1" + get_top_diff "$1" | calc_patch_id "$@" } test_expect_success 'patch-id detects equality' ' @@ -56,6 +73,69 @@ test_expect_success 'whitespace is irrelevant in footer' ' test_cmp patch-id_master patch-id_same ' +cmp_patch_id () { + if + test "$1" = "relevant" + then + ! test_cmp patch-id_"$2" patch-id_"$3" + else + test_cmp patch-id_"$2" patch-id_"$3" + fi +} + +test_patch_id_file_order () { + relevant="$1" + shift + name="order-${1}-$relevant" + shift + get_top_diff "master" | calc_patch_id "$name" "$@" && + git checkout same && + git format-patch -1 --stdout -O foo-then-bar | + calc_patch_id "ordered-$name" "$@" && + cmp_patch_id $relevant "$name" "ordered-$name" + +} + +# combined test for options: add more tests here to make them +# run with all options +test_patch_id () { + test_patch_id_file_order "$@" +} + +# small tests with detailed diagnostic for basic options. +test_expect_success 'file order is irrelevant with --stable' ' + test_patch_id_file_order irrelevant --stable --stable +' + +test_expect_success 'file order is relevant with --unstable' ' + test_patch_id_file_order relevant --unstable --unstable +' + +#Now test various option combinations. +test_expect_success 'default is unstable' ' + test_patch_id relevant default +' + +test_expect_success 'patchid.stable = true is stable' ' + test_config patchid.stable true && + test_patch_id irrelevant patchid.stable=true +' + +test_expect_success 'patchid.stable = false is unstable' ' + test_config patchid.stable false && + test_patch_id relevant patchid.stable=false +' + +test_expect_success '--unstable overrides patchid.stable = true' ' + test_config patchid.stable true && + test_patch_id relevant patchid.stable=true--unstable --unstable +' + +test_expect_success '--stable overrides patchid.stable = false' ' + test_config patchid.stable false && + test_patch_id irrelevant patchid.stable=false--stable --stable +' + test_expect_success 'patch-id supports git-format-patch MIME output' ' get_patch_id master && git checkout same && diff --git a/t/t4205-log-pretty-formats.sh b/t/t4205-log-pretty-formats.sh index 2a6278bb33..c84ec9ae61 100755 --- a/t/t4205-log-pretty-formats.sh +++ b/t/t4205-log-pretty-formats.sh @@ -7,6 +7,9 @@ test_description='Test pretty formats' . ./test-lib.sh +# Tested non-UTF-8 encoding +test_encoding="ISO8859-1" + sample_utf8_part=$(printf "f\303\244ng") commit_msg () { @@ -27,8 +30,8 @@ test_expect_success 'set up basic repos' ' >bar && git add foo && test_tick && - git config i18n.commitEncoding iso8859-1 && - git commit -m "$(commit_msg iso8859-1)" && + git config i18n.commitEncoding $test_encoding && + git commit -m "$(commit_msg $test_encoding)" && git add bar && test_tick && git commit -m "add bar" && @@ -56,8 +59,8 @@ test_expect_success 'alias user-defined format' ' test_cmp expected actual ' -test_expect_success 'alias user-defined tformat with %s (iso8859-1 encoding)' ' - git config i18n.logOutputEncoding iso8859-1 && +test_expect_success 'alias user-defined tformat with %s (ISO8859-1 encoding)' ' + git config i18n.logOutputEncoding $test_encoding && git log --oneline >expected-s && git log --pretty="tformat:%h %s" >actual-s && git config --unset i18n.logOutputEncoding && @@ -141,9 +144,7 @@ test_expect_success 'setup more commits' ' ' test_expect_success 'left alignment formatting' ' - git log --pretty="format:%<(40)%s" >actual && - # complete the incomplete line at the end - echo >>actual && + git log --pretty="tformat:%<(40)%s" >actual && qz_to_tab_space <<EOF >expected && message two Z message one Z @@ -153,10 +154,19 @@ EOF test_cmp expected actual ' +test_expect_success 'left alignment formatting. i18n.logOutputEncoding' ' + git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(40)%s" >actual && + qz_to_tab_space <<EOF | iconv -f utf-8 -t $test_encoding >expected && +message two Z +message one Z +add bar Z +$(commit_msg) Z +EOF + test_cmp expected actual +' + test_expect_success 'left alignment formatting at the nth column' ' - git log --pretty="format:%h %<|(40)%s" >actual && - # complete the incomplete line at the end - echo >>actual && + git log --pretty="tformat:%h %<|(40)%s" >actual && qz_to_tab_space <<EOF >expected && $head1 message two Z $head2 message one Z @@ -166,10 +176,19 @@ EOF test_cmp expected actual ' +test_expect_success 'left alignment formatting at the nth column. i18n.logOutputEncoding' ' + git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%h %<|(40)%s" >actual && + qz_to_tab_space <<EOF | iconv -f utf-8 -t $test_encoding >expected && +$head1 message two Z +$head2 message one Z +$head3 add bar Z +$head4 $(commit_msg) Z +EOF + test_cmp expected actual +' + test_expect_success 'left alignment formatting with no padding' ' - git log --pretty="format:%<(1)%s" >actual && - # complete the incomplete line at the end - echo >>actual && + git log --pretty="tformat:%<(1)%s" >actual && cat <<EOF >expected && message two message one @@ -179,10 +198,19 @@ EOF test_cmp expected actual ' +test_expect_success 'left alignment formatting with no padding. i18n.logOutputEncoding' ' + git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(1)%s" >actual && + cat <<EOF | iconv -f utf-8 -t $test_encoding >expected && +message two +message one +add bar +$(commit_msg) +EOF + test_cmp expected actual +' + test_expect_success 'left alignment formatting with trunc' ' - git log --pretty="format:%<(10,trunc)%s" >actual && - # complete the incomplete line at the end - echo >>actual && + git log --pretty="tformat:%<(10,trunc)%s" >actual && qz_to_tab_space <<EOF >expected && message .. message .. @@ -192,10 +220,19 @@ EOF test_cmp expected actual ' +test_expect_success 'left alignment formatting with trunc. i18n.logOutputEncoding' ' + git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(10,trunc)%s" >actual && + qz_to_tab_space <<EOF | iconv -f utf-8 -t $test_encoding >expected && +message .. +message .. +add bar Z +initial... +EOF + test_cmp expected actual +' + test_expect_success 'left alignment formatting with ltrunc' ' - git log --pretty="format:%<(10,ltrunc)%s" >actual && - # complete the incomplete line at the end - echo >>actual && + git log --pretty="tformat:%<(10,ltrunc)%s" >actual && qz_to_tab_space <<EOF >expected && ..sage two ..sage one @@ -205,10 +242,19 @@ EOF test_cmp expected actual ' +test_expect_success 'left alignment formatting with ltrunc. i18n.logOutputEncoding' ' + git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(10,ltrunc)%s" >actual && + qz_to_tab_space <<EOF | iconv -f utf-8 -t $test_encoding >expected && +..sage two +..sage one +add bar Z +..${sample_utf8_part}lich +EOF + test_cmp expected actual +' + test_expect_success 'left alignment formatting with mtrunc' ' - git log --pretty="format:%<(10,mtrunc)%s" >actual && - # complete the incomplete line at the end - echo >>actual && + git log --pretty="tformat:%<(10,mtrunc)%s" >actual && qz_to_tab_space <<EOF >expected && mess.. two mess.. one @@ -218,10 +264,19 @@ EOF test_cmp expected actual ' +test_expect_success 'left alignment formatting with mtrunc. i18n.logOutputEncoding' ' + git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(10,mtrunc)%s" >actual && + qz_to_tab_space <<EOF | iconv -f utf-8 -t $test_encoding >expected && +mess.. two +mess.. one +add bar Z +init..lich +EOF + test_cmp expected actual +' + test_expect_success 'right alignment formatting' ' - git log --pretty="format:%>(40)%s" >actual && - # complete the incomplete line at the end - echo >>actual && + git log --pretty="tformat:%>(40)%s" >actual && qz_to_tab_space <<EOF >expected && Z message two Z message one @@ -231,10 +286,19 @@ EOF test_cmp expected actual ' +test_expect_success 'right alignment formatting. i18n.logOutputEncoding' ' + git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%>(40)%s" >actual && + qz_to_tab_space <<EOF | iconv -f utf-8 -t $test_encoding >expected && +Z message two +Z message one +Z add bar +Z $(commit_msg) +EOF + test_cmp expected actual +' + test_expect_success 'right alignment formatting at the nth column' ' - git log --pretty="format:%h %>|(40)%s" >actual && - # complete the incomplete line at the end - echo >>actual && + git log --pretty="tformat:%h %>|(40)%s" >actual && qz_to_tab_space <<EOF >expected && $head1 message two $head2 message one @@ -244,10 +308,19 @@ EOF test_cmp expected actual ' +test_expect_success 'right alignment formatting at the nth column. i18n.logOutputEncoding' ' + git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%h %>|(40)%s" >actual && + qz_to_tab_space <<EOF | iconv -f utf-8 -t $test_encoding >expected && +$head1 message two +$head2 message one +$head3 add bar +$head4 $(commit_msg) +EOF + test_cmp expected actual +' + test_expect_success 'right alignment formatting with no padding' ' - git log --pretty="format:%>(1)%s" >actual && - # complete the incomplete line at the end - echo >>actual && + git log --pretty="tformat:%>(1)%s" >actual && cat <<EOF >expected && message two message one @@ -257,10 +330,19 @@ EOF test_cmp expected actual ' +test_expect_success 'right alignment formatting with no padding. i18n.logOutputEncoding' ' + git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%>(1)%s" >actual && + cat <<EOF | iconv -f utf-8 -t $test_encoding >expected && +message two +message one +add bar +$(commit_msg) +EOF + test_cmp expected actual +' + test_expect_success 'center alignment formatting' ' - git log --pretty="format:%><(40)%s" >actual && - # complete the incomplete line at the end - echo >>actual && + git log --pretty="tformat:%><(40)%s" >actual && qz_to_tab_space <<EOF >expected && Z message two Z Z message one Z @@ -270,10 +352,18 @@ EOF test_cmp expected actual ' +test_expect_success 'center alignment formatting. i18n.logOutputEncoding' ' + git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%><(40)%s" >actual && + qz_to_tab_space <<EOF | iconv -f utf-8 -t $test_encoding >expected && +Z message two Z +Z message one Z +Z add bar Z +Z $(commit_msg) Z +EOF + test_cmp expected actual +' test_expect_success 'center alignment formatting at the nth column' ' - git log --pretty="format:%h %><|(40)%s" >actual && - # complete the incomplete line at the end - echo >>actual && + git log --pretty="tformat:%h %><|(40)%s" >actual && qz_to_tab_space <<EOF >expected && $head1 message two Z $head2 message one Z @@ -283,10 +373,19 @@ EOF test_cmp expected actual ' +test_expect_success 'center alignment formatting at the nth column. i18n.logOutputEncoding' ' + git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%h %><|(40)%s" >actual && + qz_to_tab_space <<EOF | iconv -f utf-8 -t $test_encoding >expected && +$head1 message two Z +$head2 message one Z +$head3 add bar Z +$head4 $(commit_msg) Z +EOF + test_cmp expected actual +' + test_expect_success 'center alignment formatting with no padding' ' - git log --pretty="format:%><(1)%s" >actual && - # complete the incomplete line at the end - echo >>actual && + git log --pretty="tformat:%><(1)%s" >actual && cat <<EOF >expected && message two message one @@ -296,11 +395,23 @@ EOF test_cmp expected actual ' +# save HEAD's SHA-1 digest (with no abbreviations) to use it below +# as far as the next test amends HEAD +old_head1=$(git rev-parse --verify HEAD~0) +test_expect_success 'center alignment formatting with no padding. i18n.logOutputEncoding' ' + git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%><(1)%s" >actual && + cat <<EOF | iconv -f utf-8 -t $test_encoding >expected && +message two +message one +add bar +$(commit_msg) +EOF + test_cmp expected actual +' + test_expect_success 'left/right alignment formatting with stealing' ' git commit --amend -m short --author "long long long <long@me.com>" && - git log --pretty="format:%<(10,trunc)%s%>>(10,ltrunc)% an" >actual && - # complete the incomplete line at the end - echo >>actual && + git log --pretty="tformat:%<(10,trunc)%s%>>(10,ltrunc)% an" >actual && cat <<EOF >expected && short long long long message .. A U Thor @@ -309,6 +420,20 @@ initial... A U Thor EOF test_cmp expected actual ' +test_expect_success 'left/right alignment formatting with stealing. i18n.logOutputEncoding' ' + git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(10,trunc)%s%>>(10,ltrunc)% an" >actual && + cat <<EOF | iconv -f utf-8 -t $test_encoding >expected && +short long long long +message .. A U Thor +add bar A U Thor +initial... A U Thor +EOF + test_cmp expected actual +' + +# get new digests (with no abbreviations) +head1=$(git rev-parse --verify HEAD~0) && +head2=$(git rev-parse --verify HEAD~1) && test_expect_success 'log decoration properly follows tag chain' ' git tag -a tag1 -m tag1 && @@ -317,9 +442,9 @@ test_expect_success 'log decoration properly follows tag chain' ' git commit --amend -m shorter && git log --no-walk --tags --pretty="%H %d" --decorate=full >actual && cat <<EOF >expected && -6a908c10688b2503073c39c9ba26322c73902bb5 (tag: refs/tags/tag2) -9f716384d92283fb915a4eee5073f030638e05f9 (tag: refs/tags/message-one) -b87e4cccdb77336ea79d89224737be7ea8e95367 (tag: refs/tags/message-two) +$head1 (tag: refs/tags/tag2) +$head2 (tag: refs/tags/message-one) +$old_head1 (tag: refs/tags/message-two) EOF sort actual >actual1 && test_cmp expected actual1 diff --git a/t/t5000-tar-tree.sh b/t/t5000-tar-tree.sh index 74fc5a88ec..899c1c5bbc 100755 --- a/t/t5000-tar-tree.sh +++ b/t/t5000-tar-tree.sh @@ -72,7 +72,7 @@ check_tar() { for header in *.paxheader do data=${header%.paxheader}.data && - if test -h $data -o -e $data + if test -h $data || test -e $data then path=$(get_pax_header $header path) && if test -n "$path" @@ -164,7 +164,7 @@ check_tar with_olde-prefix olde- test_expect_success 'git archive on large files' ' test_config core.bigfilethreshold 1 && git archive HEAD >b3.tar && - test_cmp b.tar b3.tar + test_cmp_bin b.tar b3.tar ' test_expect_success \ @@ -173,15 +173,15 @@ test_expect_success \ test_expect_success \ 'git archive vs. the same in a bare repo' \ - 'test_cmp b.tar b3.tar' + 'test_cmp_bin b.tar b3.tar' test_expect_success 'git archive with --output' \ 'git archive --output=b4.tar HEAD && - test_cmp b.tar b4.tar' + test_cmp_bin b.tar b4.tar' test_expect_success 'git archive --remote' \ 'git archive --remote=. HEAD >b5.tar && - test_cmp b.tar b5.tar' + test_cmp_bin b.tar b5.tar' test_expect_success \ 'validate file modification time' \ @@ -198,7 +198,7 @@ test_expect_success \ test_expect_success 'git archive with --output, override inferred format' ' git archive --format=tar --output=d4.zip HEAD && - test_cmp b.tar d4.zip + test_cmp_bin b.tar d4.zip ' test_expect_success \ @@ -244,34 +244,34 @@ test_expect_success 'archive --list shows only enabled remote filters' ' test_expect_success 'invoke tar filter by format' ' git archive --format=tar.foo HEAD >config.tar.foo && tr ab ba <config.tar.foo >config.tar && - test_cmp b.tar config.tar && + test_cmp_bin b.tar config.tar && git archive --format=bar HEAD >config.bar && tr ab ba <config.bar >config.tar && - test_cmp b.tar config.tar + test_cmp_bin b.tar config.tar ' test_expect_success 'invoke tar filter by extension' ' git archive -o config-implicit.tar.foo HEAD && - test_cmp config.tar.foo config-implicit.tar.foo && + test_cmp_bin config.tar.foo config-implicit.tar.foo && git archive -o config-implicit.bar HEAD && - test_cmp config.tar.foo config-implicit.bar + test_cmp_bin config.tar.foo config-implicit.bar ' test_expect_success 'default output format remains tar' ' git archive -o config-implicit.baz HEAD && - test_cmp b.tar config-implicit.baz + test_cmp_bin b.tar config-implicit.baz ' test_expect_success 'extension matching requires dot' ' git archive -o config-implicittar.foo HEAD && - test_cmp b.tar config-implicittar.foo + test_cmp_bin b.tar config-implicittar.foo ' test_expect_success 'only enabled filters are available remotely' ' test_must_fail git archive --remote=. --format=tar.foo HEAD \ >remote.tar.foo && git archive --remote=. --format=bar >remote.bar HEAD && - test_cmp remote.bar config.bar + test_cmp_bin remote.bar config.bar ' test_expect_success GZIP 'git archive --format=tgz' ' @@ -280,27 +280,27 @@ test_expect_success GZIP 'git archive --format=tgz' ' test_expect_success GZIP 'git archive --format=tar.gz' ' git archive --format=tar.gz HEAD >j1.tar.gz && - test_cmp j.tgz j1.tar.gz + test_cmp_bin j.tgz j1.tar.gz ' test_expect_success GZIP 'infer tgz from .tgz filename' ' git archive --output=j2.tgz HEAD && - test_cmp j.tgz j2.tgz + test_cmp_bin j.tgz j2.tgz ' test_expect_success GZIP 'infer tgz from .tar.gz filename' ' git archive --output=j3.tar.gz HEAD && - test_cmp j.tgz j3.tar.gz + test_cmp_bin j.tgz j3.tar.gz ' test_expect_success GZIP 'extract tgz file' ' gzip -d -c <j.tgz >j.tar && - test_cmp b.tar j.tar + test_cmp_bin b.tar j.tar ' test_expect_success GZIP 'remote tar.gz is allowed by default' ' git archive --remote=. --format=tar.gz HEAD >remote.tar.gz && - test_cmp j.tgz remote.tar.gz + test_cmp_bin j.tgz remote.tar.gz ' test_expect_success GZIP 'remote tar.gz can be disabled' ' diff --git a/t/t5001-archive-attr.sh b/t/t5001-archive-attr.sh index 51dedab29b..b04d955bfa 100755 --- a/t/t5001-archive-attr.sh +++ b/t/t5001-archive-attr.sh @@ -68,7 +68,7 @@ test_expect_missing worktree2/ignored-by-worktree test_expect_success 'git archive vs. bare' ' (cd bare && git archive HEAD) >bare-archive.tar && - test_cmp archive.tar bare-archive.tar + test_cmp_bin archive.tar bare-archive.tar ' test_expect_success 'git archive with worktree attributes, bare' ' diff --git a/t/t5003-archive-zip.sh b/t/t5003-archive-zip.sh index c72f71eb18..21a5c93f41 100755 --- a/t/t5003-archive-zip.sh +++ b/t/t5003-archive-zip.sh @@ -97,15 +97,15 @@ test_expect_success \ test_expect_success \ 'git archive --format=zip vs. the same in a bare repo' \ - 'test_cmp d.zip d1.zip' + 'test_cmp_bin d.zip d1.zip' test_expect_success 'git archive --format=zip with --output' \ 'git archive --format=zip --output=d2.zip HEAD && - test_cmp d.zip d2.zip' + test_cmp_bin d.zip d2.zip' test_expect_success 'git archive with --output, inferring format' ' git archive --output=d3.zip HEAD && - test_cmp d.zip d3.zip + test_cmp_bin d.zip d3.zip ' test_expect_success \ diff --git a/t/t5004-archive-corner-cases.sh b/t/t5004-archive-corner-cases.sh index 67f3b54bed..305bcac6b7 100755 --- a/t/t5004-archive-corner-cases.sh +++ b/t/t5004-archive-corner-cases.sh @@ -45,7 +45,7 @@ test_expect_success HEADER_ONLY_TAR_OK 'tar archive of commit with empty tree' ' test_expect_success 'tar archive of empty tree is empty' ' git archive --format=tar HEAD: >empty.tar && perl -e "print \"\\0\" x 10240" >10knuls.tar && - test_cmp 10knuls.tar empty.tar + test_cmp_bin 10knuls.tar empty.tar ' test_expect_success 'tar archive of empty tree with prefix' ' diff --git a/t/t5150-request-pull.sh b/t/t5150-request-pull.sh index 93e2c65de6..82c33b88e7 100755 --- a/t/t5150-request-pull.sh +++ b/t/t5150-request-pull.sh @@ -229,7 +229,7 @@ test_expect_success 'pull request format' ' cd local && git request-pull initial "$downstream_url" full ) >request && - grep ' tags/full$' + grep " tags/full\$" request ' test_expect_success 'request-pull ignores OPTIONS_KEEPDASHDASH poison' ' diff --git a/t/t5310-pack-bitmaps.sh b/t/t5310-pack-bitmaps.sh index f4f02ba918..0580258c91 100755 --- a/t/t5310-pack-bitmaps.sh +++ b/t/t5310-pack-bitmaps.sh @@ -18,7 +18,7 @@ test_expect_success 'setup repo with moderate-sized history' ' git checkout master && blob=$(echo tagged-blob | git hash-object -w --stdin) && git tag tagged-blob $blob && - git config pack.writebitmaps true && + git config repack.writebitmaps true && git config pack.writebitmaphashcache true ' diff --git a/t/t5403-post-checkout-hook.sh b/t/t5403-post-checkout-hook.sh index 1753ef2b91..fc898c9eac 100755 --- a/t/t5403-post-checkout-hook.sh +++ b/t/t5403-post-checkout-hook.sh @@ -39,7 +39,7 @@ test_expect_success 'post-checkout receives the right arguments with HEAD unchan old=$(awk "{print \$1}" clone1/.git/post-checkout.args) && new=$(awk "{print \$2}" clone1/.git/post-checkout.args) && flag=$(awk "{print \$3}" clone1/.git/post-checkout.args) && - test $old = $new -a $flag = 1 + test $old = $new && test $flag = 1 ' test_expect_success 'post-checkout runs as expected ' ' @@ -52,7 +52,7 @@ test_expect_success 'post-checkout args are correct with git checkout -b ' ' old=$(awk "{print \$1}" clone1/.git/post-checkout.args) && new=$(awk "{print \$2}" clone1/.git/post-checkout.args) && flag=$(awk "{print \$3}" clone1/.git/post-checkout.args) && - test $old = $new -a $flag = 1 + test $old = $new && test $flag = 1 ' test_expect_success 'post-checkout receives the right args with HEAD changed ' ' @@ -60,7 +60,7 @@ test_expect_success 'post-checkout receives the right args with HEAD changed ' ' old=$(awk "{print \$1}" clone2/.git/post-checkout.args) && new=$(awk "{print \$2}" clone2/.git/post-checkout.args) && flag=$(awk "{print \$3}" clone2/.git/post-checkout.args) && - test $old != $new -a $flag = 1 + test $old != $new && test $flag = 1 ' test_expect_success 'post-checkout receives the right args when not switching branches ' ' @@ -68,7 +68,7 @@ test_expect_success 'post-checkout receives the right args when not switching br old=$(awk "{print \$1}" clone2/.git/post-checkout.args) && new=$(awk "{print \$2}" clone2/.git/post-checkout.args) && flag=$(awk "{print \$3}" clone2/.git/post-checkout.args) && - test $old = $new -a $flag = 0 + test $old = $new && test $flag = 0 ' if test "$(git config --bool core.filemode)" = true; then diff --git a/t/t5510-fetch.sh b/t/t5510-fetch.sh index 29d59ef9fa..d78f3201f4 100755 --- a/t/t5510-fetch.sh +++ b/t/t5510-fetch.sh @@ -447,6 +447,43 @@ test_expect_success 'explicit pull should update tracking' ' ) ' +test_expect_success 'explicit --refmap is allowed only with command-line refspec' ' + cd "$D" && + ( + cd three && + test_must_fail git fetch --refmap="*:refs/remotes/none/*" + ) +' + +test_expect_success 'explicit --refmap option overrides remote.*.fetch' ' + cd "$D" && + git branch -f side && + ( + cd three && + git update-ref refs/remotes/origin/master base-origin-master && + o=$(git rev-parse --verify refs/remotes/origin/master) && + git fetch --refmap="refs/heads/*:refs/remotes/other/*" origin master && + n=$(git rev-parse --verify refs/remotes/origin/master) && + test "$o" = "$n" && + test_must_fail git rev-parse --verify refs/remotes/origin/side && + git rev-parse --verify refs/remotes/other/master + ) +' + +test_expect_success 'explicitly empty --refmap option disables remote.*.fetch' ' + cd "$D" && + git branch -f side && + ( + cd three && + git update-ref refs/remotes/origin/master base-origin-master && + o=$(git rev-parse --verify refs/remotes/origin/master) && + git fetch --refmap="" origin master && + n=$(git rev-parse --verify refs/remotes/origin/master) && + test "$o" = "$n" && + test_must_fail git rev-parse --verify refs/remotes/origin/side + ) +' + test_expect_success 'configured fetch updates tracking' ' cd "$D" && diff --git a/t/t5538-push-shallow.sh b/t/t5538-push-shallow.sh index 8e54ac5746..ceee95b8a4 100755 --- a/t/t5538-push-shallow.sh +++ b/t/t5538-push-shallow.sh @@ -120,63 +120,4 @@ EOF git cat-file blob `echo 1|git hash-object --stdin` >/dev/null ) ' - -if test -n "$NO_CURL" -o -z "$GIT_TEST_HTTPD"; then - say 'skipping remaining tests, git built without http support' - test_done -fi - -. "$TEST_DIRECTORY"/lib-httpd.sh -start_httpd - -test_expect_success 'push to shallow repo via http' ' - git clone --bare --no-local shallow "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" && - ( - cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" && - git config http.receivepack true - ) && - ( - cd full && - commit 9 && - git push $HTTPD_URL/smart/repo.git +master:refs/remotes/top/master - ) && - ( - cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" && - git fsck && - git log --format=%s top/master >actual && - cat <<EOF >expect && -9 -4 -3 -EOF - test_cmp expect actual - ) -' - -test_expect_success 'push from shallow repo via http' ' - mv "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" shallow-upstream.git && - git clone --bare --no-local full "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" && - ( - cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" && - git config http.receivepack true - ) && - commit 10 && - git push $HTTPD_URL/smart/repo.git +master:refs/remotes/top/master && - ( - cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" && - git fsck && - git log --format=%s top/master >actual && - cat <<EOF >expect && -10 -1 -4 -3 -2 -1 -EOF - test_cmp expect actual - ) -' - -stop_httpd test_done diff --git a/t/t5542-push-http-shallow.sh b/t/t5542-push-http-shallow.sh new file mode 100755 index 0000000000..2a691e09eb --- /dev/null +++ b/t/t5542-push-http-shallow.sh @@ -0,0 +1,100 @@ +#!/bin/sh + +test_description='push from/to a shallow clone over http' + +. ./test-lib.sh + +if test -n "$NO_CURL"; then + say 'skipping test, git built without http support' + test_done +fi + +. "$TEST_DIRECTORY"/lib-httpd.sh +start_httpd + +commit() { + echo "$1" >tracked && + git add tracked && + git commit -m "$1" +} + +test_expect_success 'setup' ' + git config --global transfer.fsckObjects true && + commit 1 && + commit 2 && + commit 3 && + commit 4 && + git clone . full && + ( + git init full-abc && + cd full-abc && + commit a && + commit b && + commit c + ) && + git clone --no-local --depth=2 .git shallow && + git --git-dir=shallow/.git log --format=%s >actual && + cat <<EOF >expect && +4 +3 +EOF + test_cmp expect actual && + git clone --no-local --depth=2 full-abc/.git shallow2 && + git --git-dir=shallow2/.git log --format=%s >actual && + cat <<EOF >expect && +c +b +EOF + test_cmp expect actual +' + +test_expect_success 'push to shallow repo via http' ' + git clone --bare --no-local shallow "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" && + ( + cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" && + git config http.receivepack true + ) && + ( + cd full && + commit 9 && + git push $HTTPD_URL/smart/repo.git +master:refs/remotes/top/master + ) && + ( + cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" && + git fsck && + git log --format=%s top/master >actual && + cat <<EOF >expect && +9 +4 +3 +EOF + test_cmp expect actual + ) +' + +test_expect_success 'push from shallow repo via http' ' + mv "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" shallow-upstream.git && + git clone --bare --no-local full "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" && + ( + cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" && + git config http.receivepack true + ) && + commit 10 && + git push $HTTPD_URL/smart/repo.git +master:refs/remotes/top/master && + ( + cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" && + git fsck && + git log --format=%s top/master >actual && + cat <<EOF >expect && +10 +4 +3 +2 +1 +EOF + test_cmp expect actual + ) +' + +stop_httpd +test_done diff --git a/t/t5550-http-fetch-dumb.sh b/t/t5550-http-fetch-dumb.sh index 1a3a2b6c1a..ac71418a1b 100755 --- a/t/t5550-http-fetch-dumb.sh +++ b/t/t5550-http-fetch-dumb.sh @@ -171,5 +171,30 @@ test_expect_success 'did not use upload-pack service' ' test_cmp exp act ' +test_expect_success 'git client shows text/plain errors' ' + test_must_fail git clone "$HTTPD_URL/error/text" 2>stderr && + grep "this is the error message" stderr +' + +test_expect_success 'git client does not show html errors' ' + test_must_fail git clone "$HTTPD_URL/error/html" 2>stderr && + ! grep "this is the error message" stderr +' + +test_expect_success 'git client shows text/plain with a charset' ' + test_must_fail git clone "$HTTPD_URL/error/charset" 2>stderr && + grep "this is the error message" stderr +' + +test_expect_success 'http error messages are reencoded' ' + test_must_fail git clone "$HTTPD_URL/error/utf16" 2>stderr && + grep "this is the error message" stderr +' + +test_expect_success 'reencoding is robust to whitespace oddities' ' + test_must_fail git clone "$HTTPD_URL/error/odd-spacing" 2>stderr && + grep "this is the error message" stderr +' + stop_httpd test_done diff --git a/t/t5551-http-fetch-smart.sh b/t/t5551-http-fetch-smart.sh index e07eaf35f1..6cbc12d9a7 100755 --- a/t/t5551-http-fetch-smart.sh +++ b/t/t5551-http-fetch-smart.sh @@ -213,8 +213,6 @@ test_expect_success 'cookies stored in http.cookiefile when http.savecookies set test_cmp expect_cookies.txt cookies_tail.txt ' -test -n "$GIT_TEST_LONG" && test_set_prereq EXPENSIVE - test_expect_success EXPENSIVE 'create 50,000 tags in the repo' ' ( cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" && @@ -240,8 +238,7 @@ test_expect_success EXPENSIVE 'create 50,000 tags in the repo' ' ' test_expect_success EXPENSIVE 'clone the 50,000 tag repo to check OS command line overflow' ' - git clone $HTTPD_URL/smart/repo.git too-many-refs 2>err && - test_line_count = 0 err && + git clone $HTTPD_URL/smart/repo.git too-many-refs && ( cd too-many-refs && test $(git for-each-ref refs/tags | wc -l) = 50000 diff --git a/t/t5560-http-backend-noserver.sh b/t/t5560-http-backend-noserver.sh index 5abd11a563..aa73eeaef8 100755 --- a/t/t5560-http-backend-noserver.sh +++ b/t/t5560-http-backend-noserver.sh @@ -5,7 +5,11 @@ test_description='test git-http-backend-noserver' HTTPD_DOCUMENT_ROOT_PATH="$TRASH_DIRECTORY" -test_have_prereq GREP_STRIPS_CR && export GREP_OPTIONS=-U +if test_have_prereq GREP_STRIPS_CR +then + GREP_OPTIONS=-U + export GREP_OPTIONS +fi run_backend() { echo "$2" | diff --git a/t/t5801-remote-helpers.sh b/t/t5801-remote-helpers.sh index a00a660763..2419407546 100755 --- a/t/t5801-remote-helpers.sh +++ b/t/t5801-remote-helpers.sh @@ -87,13 +87,29 @@ test_expect_success 'push new branch by name' ' compare_refs local HEAD server refs/heads/new-name ' -test_expect_failure 'push new branch with old:new refspec' ' +test_expect_success 'push new branch with old:new refspec' ' (cd local && git push origin new-name:new-refspec ) && compare_refs local HEAD server refs/heads/new-refspec ' +test_expect_success 'push new branch with HEAD:new refspec' ' + (cd local && + git checkout new-name + git push origin HEAD:new-refspec-2 + ) && + compare_refs local HEAD server refs/heads/new-refspec-2 +' + +test_expect_success 'push delete branch' ' + (cd local && + git push origin :new-name + ) && + test_must_fail git --git-dir="server/.git" \ + rev-parse --verify refs/heads/new-name +' + test_expect_success 'forced push' ' (cd local && git checkout -b force-test && diff --git a/t/t6006-rev-list-format.sh b/t/t6006-rev-list-format.sh index 9d9d9de08e..c277db64f7 100755 --- a/t/t6006-rev-list-format.sh +++ b/t/t6006-rev-list-format.sh @@ -9,19 +9,32 @@ test_description='git rev-list --pretty=format test' . "$TEST_DIRECTORY"/lib-terminal.sh test_tick +# Tested non-UTF-8 encoding +test_encoding="ISO8859-1" + # String "added" in German # (translated with Google Translate), # encoded in UTF-8, used as a commit log message below. -added=$(printf "added (hinzugef\303\274gt) foo") -added_iso88591=$(echo "$added" | iconv -f utf-8 -t iso8859-1) +added_utf8_part=$(printf "\303\274") +added_utf8_part_iso88591=$(echo "$added_utf8_part" | iconv -f utf-8 -t $test_encoding) +added=$(printf "added (hinzugef${added_utf8_part}gt) foo") +added_iso88591=$(echo "$added" | iconv -f utf-8 -t $test_encoding) # same but "changed" -changed=$(printf "changed (ge\303\244ndert) foo") -changed_iso88591=$(echo "$changed" | iconv -f utf-8 -t iso8859-1) +changed_utf8_part=$(printf "\303\244") +changed_utf8_part_iso88591=$(echo "$changed_utf8_part" | iconv -f utf-8 -t $test_encoding) +changed=$(printf "changed (ge${changed_utf8_part}ndert) foo") +changed_iso88591=$(echo "$changed" | iconv -f utf-8 -t $test_encoding) + +# Count of char to truncate +# Number is chosen so, that non-ACSII characters +# (see $added_utf8_part and $changed_utf8_part) +# fall into truncated parts of appropriate words both from left and right +truncate_count=20 test_expect_success 'setup' ' : >foo && git add foo && - git config i18n.commitEncoding iso8859-1 && + git config i18n.commitEncoding $test_encoding && git commit -m "$added_iso88591" && head1=$(git rev-parse --verify HEAD) && head1_short=$(git rev-parse --verify --short $head1) && @@ -124,9 +137,9 @@ EOF test_format encoding %e <<EOF commit $head2 -iso8859-1 +$test_encoding commit $head1 -iso8859-1 +$test_encoding EOF test_format subject %s <<EOF @@ -136,6 +149,13 @@ commit $head1 $added EOF +test_format subject-truncated "%<($truncate_count,trunc)%s" <<EOF +commit $head2 +changed (ge${changed_utf8_part}ndert).. +commit $head1 +added (hinzugef${added_utf8_part}gt.. +EOF + test_format body %b <<EOF commit $head2 commit $head1 @@ -203,16 +223,16 @@ test_expect_success '%C(auto) respects --color=auto (stdout not tty)' ' ) ' -iconv -f utf-8 -t iso8859-1 > commit-msg <<EOF +iconv -f utf-8 -t $test_encoding > commit-msg <<EOF Test printing of complex bodies This commit message is much longer than the others, -and it will be encoded in iso8859-1. We should therefore -include an iso8859 character: ¡bueno! +and it will be encoded in $test_encoding. We should therefore +include an ISO8859 character: ¡bueno! EOF test_expect_success 'setup complex body' ' - git config i18n.commitencoding iso8859-1 && + git config i18n.commitencoding $test_encoding && echo change2 >foo && git commit -a -F commit-msg && head3=$(git rev-parse --verify HEAD) && head3_short=$(git rev-parse --short $head3) @@ -220,11 +240,11 @@ test_expect_success 'setup complex body' ' test_format complex-encoding %e <<EOF commit $head3 -iso8859-1 +$test_encoding commit $head2 -iso8859-1 +$test_encoding commit $head1 -iso8859-1 +$test_encoding EOF test_format complex-subject %s <<EOF @@ -236,20 +256,47 @@ commit $head1 $added_iso88591 EOF +test_format complex-subject-trunc "%<($truncate_count,trunc)%s" <<EOF +commit $head3 +Test printing of c.. +commit $head2 +changed (ge${changed_utf8_part_iso88591}ndert).. +commit $head1 +added (hinzugef${added_utf8_part_iso88591}gt.. +EOF + +test_format complex-subject-mtrunc "%<($truncate_count,mtrunc)%s" <<EOF +commit $head3 +Test prin..ex bodies +commit $head2 +changed (..dert) foo +commit $head1 +added (hi..f${added_utf8_part_iso88591}gt) foo +EOF + +test_format complex-subject-ltrunc "%<($truncate_count,ltrunc)%s" <<EOF +commit $head3 +.. of complex bodies +commit $head2 +..ged (ge${changed_utf8_part_iso88591}ndert) foo +commit $head1 +.. (hinzugef${added_utf8_part_iso88591}gt) foo +EOF + test_expect_success 'prepare expected messages (for test %b)' ' cat <<-EOF >expected.utf-8 && commit $head3 This commit message is much longer than the others, - and it will be encoded in iso8859-1. We should therefore - include an iso8859 character: ¡bueno! + and it will be encoded in $test_encoding. We should therefore + include an ISO8859 character: ¡bueno! commit $head2 commit $head1 EOF - iconv -f utf-8 -t iso8859-1 expected.utf-8 >expected.iso8859-1 + iconv -f utf-8 -t $test_encoding expected.utf-8 >expected.ISO8859-1 ' -test_format complex-body %b <expected.iso8859-1 +test_format complex-body %b <expected.ISO8859-1 # Git uses i18n.commitEncoding if no i18n.logOutputEncoding set # so unset i18n.commitEncoding to test encoding conversion @@ -264,6 +311,33 @@ commit $head1 $added EOF +test_format complex-subject-commitencoding-unset-trunc "%<($truncate_count,trunc)%s" <<EOF +commit $head3 +Test printing of c.. +commit $head2 +changed (ge${changed_utf8_part}ndert).. +commit $head1 +added (hinzugef${added_utf8_part}gt.. +EOF + +test_format complex-subject-commitencoding-unset-mtrunc "%<($truncate_count,mtrunc)%s" <<EOF +commit $head3 +Test prin..ex bodies +commit $head2 +changed (..dert) foo +commit $head1 +added (hi..f${added_utf8_part}gt) foo +EOF + +test_format complex-subject-commitencoding-unset-ltrunc "%<($truncate_count,ltrunc)%s" <<EOF +commit $head3 +.. of complex bodies +commit $head2 +..ged (ge${changed_utf8_part}ndert) foo +commit $head1 +.. (hinzugef${added_utf8_part}gt) foo +EOF + test_format complex-body-commitencoding-unset %b <expected.utf-8 test_expect_success '%x00 shows NUL' ' diff --git a/t/t6039-merge-ignorecase.sh b/t/t6039-merge-ignorecase.sh new file mode 100755 index 0000000000..a977653147 --- /dev/null +++ b/t/t6039-merge-ignorecase.sh @@ -0,0 +1,53 @@ +#!/bin/sh + +test_description='git-merge with case-changing rename on case-insensitive file system' + +. ./test-lib.sh + +if ! test_have_prereq CASE_INSENSITIVE_FS +then + skip_all='skipping case insensitive tests - case sensitive file system' + test_done +fi + +test_expect_success 'merge with case-changing rename' ' + test $(git config core.ignorecase) = true && + >TestCase && + git add TestCase && + git commit -m "add TestCase" && + git tag baseline + git checkout -b with-camel && + >foo && + git add foo && + git commit -m "intervening commit" && + git checkout master && + git rm TestCase && + >testcase && + git add testcase && + git commit -m "rename to testcase" && + git checkout with-camel && + git merge master -m "merge" && + test_path_is_file testcase +' + +test_expect_success 'merge with case-changing rename on both sides' ' + git checkout master && + git reset --hard baseline && + git branch -D with-camel && + git checkout -b with-camel && + git mv TestCase testcase && + git commit -m "recase on branch" && + >foo && + git add foo && + git commit -m "intervening commit" && + git checkout master && + git rm TestCase && + >testcase && + git add testcase && + git commit -m "rename to testcase" && + git checkout with-camel && + git merge master -m "merge" && + test_path_is_file testcase +' + +test_done diff --git a/t/t6050-replace.sh b/t/t6050-replace.sh index 719a11673b..68b3cb26d9 100755 --- a/t/t6050-replace.sh +++ b/t/t6050-replace.sh @@ -318,6 +318,33 @@ test_expect_success 'test --format long' ' test_cmp expected actual ' +test_expect_success 'setup a fake editor' ' + write_script fakeeditor <<-\EOF + sed -e "s/A U Thor/A fake Thor/" "$1" >"$1.new" + mv "$1.new" "$1" + EOF +' + +test_expect_success '--edit with and without already replaced object' ' + test_must_fail env GIT_EDITOR=./fakeeditor git replace --edit "$PARA3" && + GIT_EDITOR=./fakeeditor git replace --force --edit "$PARA3" && + git replace -l | grep "$PARA3" && + git cat-file commit "$PARA3" | grep "A fake Thor" && + git replace -d "$PARA3" && + GIT_EDITOR=./fakeeditor git replace --edit "$PARA3" && + git replace -l | grep "$PARA3" && + git cat-file commit "$PARA3" | grep "A fake Thor" +' + +test_expect_success '--edit and change nothing or command failed' ' + git replace -d "$PARA3" && + test_must_fail env GIT_EDITOR=true git replace --edit "$PARA3" && + test_must_fail env GIT_EDITOR="./fakeeditor;false" git replace --edit "$PARA3" && + GIT_EDITOR=./fakeeditor git replace --edit "$PARA3" && + git replace -l | grep "$PARA3" && + git cat-file commit "$PARA3" | grep "A fake Thor" +' + test_expect_success 'replace ref cleanup' ' test -n "$(git replace)" && git replace -d $(git replace) && diff --git a/t/t7007-show.sh b/t/t7007-show.sh index e41fa00b80..1b824fe5ed 100755 --- a/t/t7007-show.sh +++ b/t/t7007-show.sh @@ -24,7 +24,8 @@ test_expect_success 'set up a bit of history' ' git tag -m "annotated tag" annotated && git checkout -b side HEAD^^ && test_commit side2 && - test_commit side3 + test_commit side3 && + test_merge merge main3 ' test_expect_success 'showing two commits' ' @@ -109,8 +110,11 @@ test_expect_success 'showing range' ' ' test_expect_success '-s suppresses diff' ' - echo main3 >expect && - git show -s --format=%s main3 >actual && + cat >expect <<-\EOF && + merge + main3 + EOF + git show -s --format=%s merge main3 >actual && test_cmp expect actual ' diff --git a/t/t7102-reset.sh b/t/t7102-reset.sh index 450529404c..ee703bed64 100755 --- a/t/t7102-reset.sh +++ b/t/t7102-reset.sh @@ -22,6 +22,9 @@ commit_msg () { fi } +# Tested non-UTF-8 encoding +test_encoding="ISO8859-1" + test_expect_success 'creating initial files and commits' ' test_tick && echo "1st file" >first && @@ -41,7 +44,7 @@ test_expect_success 'creating initial files and commits' ' echo "1st line 2nd file" >secondfile && echo "2nd line 2nd file" >>secondfile && - git -c "i18n.commitEncoding=iso8859-1" commit -a -m "$(commit_msg iso8859-1)" && + git -c "i18n.commitEncoding=$test_encoding" commit -a -m "$(commit_msg $test_encoding)" && head5=$(git rev-parse --verify HEAD) ' # git log --pretty=oneline # to see those SHA1 involved @@ -64,10 +67,10 @@ test_expect_success 'reset --hard message' ' test_cmp .expected .actual ' -test_expect_success 'reset --hard message (iso8859-1 logoutputencoding)' ' +test_expect_success 'reset --hard message (ISO8859-1 logoutputencoding)' ' hex=$(git log -1 --format="%h") && - git -c "i18n.logOutputEncoding=iso8859-1" reset --hard > .actual && - echo HEAD is now at $hex $(commit_msg iso8859-1) > .expected && + git -c "i18n.logOutputEncoding=$test_encoding" reset --hard > .actual && + echo HEAD is now at $hex $(commit_msg $test_encoding) > .expected && test_cmp .expected .actual ' @@ -331,7 +334,7 @@ test_expect_success 'redoing the last two commits should succeed' ' echo "1st line 2nd file" >secondfile && echo "2nd line 2nd file" >>secondfile && - git -c "i18n.commitEncoding=iso8859-1" commit -a -m "$(commit_msg iso8859-1)" && + git -c "i18n.commitEncoding=$test_encoding" commit -a -m "$(commit_msg $test_encoding)" && check_changes $head5 ' diff --git a/t/t7300-clean.sh b/t/t7300-clean.sh index 74de814aec..04118ad75b 100755 --- a/t/t7300-clean.sh +++ b/t/t7300-clean.sh @@ -426,10 +426,10 @@ test_expect_success SANITY 'removal failure' ' mkdir foo && touch foo/bar && + test_when_finished "chmod 755 foo" && (exec <foo/bar && chmod 0 foo && - test_must_fail git clean -f -d && - chmod 755 foo) + test_must_fail git clean -f -d) ' test_expect_success 'nested git work tree' ' diff --git a/t/t7500-commit.sh b/t/t7500-commit.sh index bdc1f29503..116885a260 100755 --- a/t/t7500-commit.sh +++ b/t/t7500-commit.sh @@ -223,7 +223,8 @@ test_expect_success 'Commit without message is allowed with --allow-empty-messag git add foo && >empty && git commit --allow-empty-message <empty && - commit_msg_is "" + commit_msg_is "" && + git tag empty-message-commit ' test_expect_success 'Commit without message is no-no without --allow-empty-message' ' @@ -240,6 +241,14 @@ test_expect_success 'Commit a message with --allow-empty-message' ' commit_msg_is "hello there" ' +test_expect_success 'commit -C empty respects --allow-empty-message' ' + echo more >>foo && + git add foo && + test_must_fail git commit -C empty-message-commit && + git commit -C empty-message-commit --allow-empty-message && + commit_msg_is "" +' + commit_for_rebase_autosquash_setup () { echo "first content line" >>foo && git add foo && diff --git a/t/t7502-commit.sh b/t/t7502-commit.sh index 6465cd59af..051489ea33 100755 --- a/t/t7502-commit.sh +++ b/t/t7502-commit.sh @@ -570,4 +570,30 @@ test_expect_success 'commit --status with custom comment character' ' test_i18ngrep "^; Changes to be committed:" .git/COMMIT_EDITMSG ' +test_expect_success 'switch core.commentchar' ' + test_commit "#foo" foo && + GIT_EDITOR=.git/FAKE_EDITOR git -c core.commentChar=auto commit --amend && + test_i18ngrep "^; Changes to be committed:" .git/COMMIT_EDITMSG +' + +test_expect_success 'switch core.commentchar but out of options' ' + cat >text <<\EOF && +# 1 +; 2 +@ 3 +! 4 +$ 5 +% 6 +^ 7 +& 8 +| 9 +: 10 +EOF + git commit --amend -F text && + ( + test_set_editor .git/FAKE_EDITOR && + test_must_fail git -c core.commentChar=auto commit --amend + ) +' + test_done diff --git a/t/t7508-status.sh b/t/t7508-status.sh index c987b5ed65..8ed5788808 100755 --- a/t/t7508-status.sh +++ b/t/t7508-status.sh @@ -1350,8 +1350,7 @@ test_expect_success "status (core.commentchar with submodule summary)" ' test_expect_success "status (core.commentchar with two chars with submodule summary)" ' test_config core.commentchar ";;" && - git -c status.displayCommentPrefix=true status >output && - test_i18ncmp expect output + test_must_fail git -c status.displayCommentPrefix=true status ' test_expect_success "--ignore-submodules=all suppresses submodule summary" ' @@ -1380,7 +1379,32 @@ EOF test_i18ncmp expect output ' -test_expect_success '.gitmodules ignore=all suppresses submodule summary' ' +test_expect_success '.gitmodules ignore=all suppresses unstaged submodule summary' ' + cat > expect << EOF && +On branch master +Changes to be committed: + (use "git reset HEAD <file>..." to unstage) + + modified: sm + +Changes not staged for commit: + (use "git add <file>..." to update what will be committed) + (use "git checkout -- <file>..." to discard changes in working directory) + + modified: dir1/modified + +Untracked files: + (use "git add <file>..." to include in what will be committed) + + .gitmodules + dir1/untracked + dir2/modified + dir2/untracked + expect + output + untracked + +EOF git config --add -f .gitmodules submodule.subname.ignore all && git config --add -f .gitmodules submodule.subname.path sm && git status > output && @@ -1388,7 +1412,7 @@ test_expect_success '.gitmodules ignore=all suppresses submodule summary' ' git config -f .gitmodules --remove-section submodule.subname ' -test_expect_success '.git/config ignore=all suppresses submodule summary' ' +test_expect_success '.git/config ignore=all suppresses unstaged submodule summary' ' git config --add -f .gitmodules submodule.subname.ignore none && git config --add -f .gitmodules submodule.subname.path sm && git config --add submodule.subname.ignore all && @@ -1461,4 +1485,49 @@ test_expect_success 'Restore default test environment' ' git config --unset status.showUntrackedFiles ' +test_expect_success 'git commit will commit a staged but ignored submodule' ' + git config --add -f .gitmodules submodule.subname.ignore all && + git config --add -f .gitmodules submodule.subname.path sm && + git config --add submodule.subname.ignore all && + git status -s --ignore-submodules=dirty >output && + test_i18ngrep "^M. sm" output && + GIT_EDITOR="echo hello >>\"\$1\"" && + export GIT_EDITOR && + git commit -uno && + git status -s --ignore-submodules=dirty >output && + test_i18ngrep ! "^M. sm" output +' + +test_expect_success 'git commit --dry-run will show a staged but ignored submodule' ' + git reset HEAD^ && + git add sm && + cat >expect << EOF && +On branch master +Changes to be committed: + (use "git reset HEAD <file>..." to unstage) + + modified: sm + +Changes not staged for commit: + (use "git add <file>..." to update what will be committed) + (use "git checkout -- <file>..." to discard changes in working directory) + + modified: dir1/modified + +Untracked files not listed (use -u option to show untracked files) +EOF + git commit -uno --dry-run >output && + test_i18ncmp expect output && + git status -s --ignore-submodules=dirty >output && + test_i18ngrep "^M. sm" output +' + +test_expect_success 'git commit -m will commit a staged but ignored submodule' ' + git commit -uno -m message && + git status -s --ignore-submodules=dirty >output && + test_i18ngrep ! "^M. sm" output && + git config --remove-section submodule.subname && + git config -f .gitmodules --remove-section submodule.subname +' + test_done diff --git a/t/t7600-merge.sh b/t/t7600-merge.sh index 10aa028017..b16462132f 100755 --- a/t/t7600-merge.sh +++ b/t/t7600-merge.sh @@ -57,11 +57,10 @@ create_merge_msgs () { git log --no-merges ^HEAD c2 c3 } >squash.1-5-9 && : >msg.nologff && - echo >msg.nolognoff && + : >msg.nolognoff && { echo "* tag 'c3':" && - echo " commit 3" && - echo + echo " commit 3" } >msg.log } @@ -71,7 +70,7 @@ verify_merge () { git diff --exit-code && if test -n "$3" then - git show -s --pretty=format:%s HEAD >msg.act && + git show -s --pretty=tformat:%s HEAD >msg.act && test_cmp "$3" msg.act fi } @@ -620,10 +619,10 @@ test_expect_success 'merge early part of c2' ' git tag c6 && git branch -f c5-branch c5 && git merge c5-branch~1 && - git show -s --pretty=format:%s HEAD >actual.branch && + git show -s --pretty=tformat:%s HEAD >actual.branch && git reset --keep HEAD^ && git merge c5~1 && - git show -s --pretty=format:%s HEAD >actual.tag && + git show -s --pretty=tformat:%s HEAD >actual.tag && test_cmp expected.branch actual.branch && test_cmp expected.tag actual.tag ' diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh index 284018e3cd..021c5479bd 100755 --- a/t/t7700-repack.sh +++ b/t/t7700-repack.sh @@ -21,7 +21,7 @@ test_expect_success 'objects in packs marked .keep are not repacked' ' objsha1=$(git verify-pack -v pack-$packsha1.idx | head -n 1 | sed -e "s/^\([0-9a-f]\{40\}\).*/\1/") && mv pack-* .git/objects/pack/ && - git repack --no-pack-kept-objects -A -d -l && + git repack -A -d -l && git prune-packed && for p in .git/objects/pack/*.idx; do idx=$(basename $p) @@ -35,9 +35,25 @@ test_expect_success 'objects in packs marked .keep are not repacked' ' test -z "$found_duplicate_object" ' -test_expect_success 'writing bitmaps can duplicate .keep objects' ' +test_expect_success 'writing bitmaps via command-line can duplicate .keep objects' ' # build on $objsha1, $packsha1, and .keep state from previous - git repack -Adl && + git repack -Adbl && + test_when_finished "found_duplicate_object=" && + for p in .git/objects/pack/*.idx; do + idx=$(basename $p) + test "pack-$packsha1.idx" = "$idx" && continue + if git verify-pack -v $p | egrep "^$objsha1"; then + found_duplicate_object=1 + echo "DUPLICATE OBJECT FOUND" + break + fi + done && + test "$found_duplicate_object" = 1 +' + +test_expect_success 'writing bitmaps via config can duplicate .keep objects' ' + # build on $objsha1, $packsha1, and .keep state from previous + git -c repack.writebitmaps=true repack -Adl && test_when_finished "found_duplicate_object=" && for p in .git/objects/pack/*.idx; do idx=$(basename $p) diff --git a/t/t7810-grep.sh b/t/t7810-grep.sh index 63b3039243..40615debc4 100755 --- a/t/t7810-grep.sh +++ b/t/t7810-grep.sh @@ -1096,11 +1096,6 @@ test_expect_success 'grep -E pattern with grep.patternType=fixed' ' test_cmp expected actual ' -test_config() { - git config "$1" "$2" && - test_when_finished "git config --unset $1" -} - cat >expected <<EOF hello.c<RED>:<RESET>int main(int argc, const char **argv) hello.c<RED>-<RESET>{ diff --git a/t/t8003-blame-corner-cases.sh b/t/t8003-blame-corner-cases.sh index e7cac1db55..2a3469bcbe 100755 --- a/t/t8003-blame-corner-cases.sh +++ b/t/t8003-blame-corner-cases.sh @@ -191,4 +191,13 @@ test_expect_success 'indent of line numbers, ten lines' ' test $(grep -c " " actual) = 9 ' +test_expect_success 'blaming files with CRLF newlines' ' + git config core.autocrlf false && + printf "testcase\r\n" >crlffile && + git add crlffile && + git commit -m testcase && + git -c core.autocrlf=input blame crlffile >actual && + grep "A U Thor" actual +' + test_done diff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh index 1ecdacb6fd..19a3ced600 100755 --- a/t/t9001-send-email.sh +++ b/t/t9001-send-email.sh @@ -1334,6 +1334,51 @@ test_expect_success $PREREQ '--force sends cover letter template anyway' ' test -n "$(ls msgtxt*)" ' +test_cover_addresses () { + header="$1" + shift + clean_fake_sendmail && + rm -fr outdir && + git format-patch --cover-letter -2 -o outdir && + cover=`echo outdir/0000-*.patch` && + mv $cover cover-to-edit.patch && + perl -pe "s/^From:/$header: extra\@address.com\nFrom:/" cover-to-edit.patch >"$cover" && + git send-email \ + --force \ + --from="Example <nobody@example.com>" \ + --no-to --no-cc \ + "$@" \ + --smtp-server="$(pwd)/fake.sendmail" \ + outdir/0000-*.patch \ + outdir/0001-*.patch \ + outdir/0002-*.patch \ + 2>errors >out && + grep "^$header: extra@address.com" msgtxt1 >to1 && + grep "^$header: extra@address.com" msgtxt2 >to2 && + grep "^$header: extra@address.com" msgtxt3 >to3 && + test_line_count = 1 to1 && + test_line_count = 1 to2 && + test_line_count = 1 to3 +} + +test_expect_success $PREREQ 'to-cover adds To to all mail' ' + test_cover_addresses "To" --to-cover +' + +test_expect_success $PREREQ 'cc-cover adds Cc to all mail' ' + test_cover_addresses "Cc" --cc-cover +' + +test_expect_success $PREREQ 'tocover adds To to all mail' ' + test_config sendemail.tocover true && + test_cover_addresses "To" +' + +test_expect_success $PREREQ 'cccover adds Cc to all mail' ' + test_config sendemail.cccover true && + test_cover_addresses "Cc" +' + test_expect_success $PREREQ 'sendemail.aliasfiletype=mailrc' ' clean_fake_sendmail && echo "alias sbd somebody@example.org" >.mailrc && diff --git a/t/t9138-git-svn-authors-prog.sh b/t/t9138-git-svn-authors-prog.sh index 83cc5fc9d1..2937f4c265 100755 --- a/t/t9138-git-svn-authors-prog.sh +++ b/t/t9138-git-svn-authors-prog.sh @@ -7,40 +7,39 @@ test_description='git svn authors prog tests' . ./lib-git-svn.sh -cat > svn-authors-prog <<'EOF' -#!/usr/bin/perl -$_ = shift; -if (s/-sub$//) { - print "$_ <$_\@sub.example.com>\n"; -} -else { - print "$_ <$_\@example.com>\n"; -} +write_script svn-authors-prog "$PERL_PATH" <<-\EOF + $_ = shift; + if (s/-sub$//) { + print "$_ <$_\@sub.example.com>\n"; + } else { + print "$_ <$_\@example.com>\n"; + } EOF -chmod +x svn-authors-prog -cat > svn-authors <<'EOF' -ff = FFFFFFF FFFFFFF <fFf@other.example.com> -EOF +test_expect_success 'svn-authors setup' ' + cat >svn-authors <<-\EOF + ff = FFFFFFF FFFFFFF <fFf@other.example.com> + EOF +' test_expect_success 'setup svnrepo' ' for i in aa bb cc-sub dd-sub ee-foo ff do svn mkdir -m $i --username $i "$svnrepo"/$i done - ' +' test_expect_success 'import authors with prog and file' ' git svn clone --authors-prog=./svn-authors-prog \ --authors-file=svn-authors "$svnrepo" x - ' +' test_expect_success 'imported 6 revisions successfully' ' ( cd x test "`git rev-list refs/remotes/git-svn | wc -l`" -eq 6 ) - ' +' test_expect_success 'authors-prog ran correctly' ' ( @@ -56,7 +55,7 @@ test_expect_success 'authors-prog ran correctly' ' git rev-list -1 --pretty=raw refs/remotes/git-svn~5 | \ grep "^author aa <aa@example\.com> " ) - ' +' test_expect_success 'authors-file overrode authors-prog' ' ( @@ -64,7 +63,7 @@ test_expect_success 'authors-file overrode authors-prog' ' git rev-list -1 --pretty=raw refs/remotes/git-svn | \ grep "^author FFFFFFF FFFFFFF <fFf@other\.example\.com> " ) - ' +' git --git-dir=x/.git config --unset svn.authorsfile git --git-dir=x/.git config --unset svn.authorsprog diff --git a/t/t9300-fast-import.sh b/t/t9300-fast-import.sh index 27263dfb80..5fc9ef262a 100755 --- a/t/t9300-fast-import.sh +++ b/t/t9300-fast-import.sh @@ -2999,4 +2999,22 @@ test_expect_success 'T: ls root tree' ' test_cmp expect actual ' +test_expect_success 'T: delete branch' ' + git branch to-delete && + git fast-import <<-EOF && + reset refs/heads/to-delete + from 0000000000000000000000000000000000000000 + EOF + test_must_fail git rev-parse --verify refs/heads/to-delete +' + +test_expect_success 'T: empty reset doesnt delete branch' ' + git branch not-to-delete && + git fast-import <<-EOF && + reset refs/heads/not-to-delete + EOF + git show-ref && + git rev-parse --verify refs/heads/not-to-delete +' + test_done diff --git a/t/t9350-fast-export.sh b/t/t9350-fast-export.sh index 2312dec8f0..66c8b0a371 100755 --- a/t/t9350-fast-export.sh +++ b/t/t9350-fast-export.sh @@ -504,4 +504,22 @@ test_expect_success 'refs are updated even if no commits need to be exported' ' test_cmp expected actual ' +test_expect_success 'use refspec' ' + git fast-export --refspec refs/heads/master:refs/heads/foobar master | \ + grep "^commit " | sort | uniq > actual && + echo "commit refs/heads/foobar" > expected && + test_cmp expected actual +' + +test_expect_success 'delete refspec' ' + git branch to-delete && + git fast-export --refspec :refs/heads/to-delete to-delete ^to-delete > actual && + cat > expected <<-EOF && + reset refs/heads/to-delete + from 0000000000000000000000000000000000000000 + + EOF + test_cmp expected actual +' + test_done diff --git a/t/t9807-git-p4-submit.sh b/t/t9807-git-p4-submit.sh index 4caf36e006..7fab2ed977 100755 --- a/t/t9807-git-p4-submit.sh +++ b/t/t9807-git-p4-submit.sh @@ -403,7 +403,8 @@ test_expect_success 'submit --prepare-p4-only' ' git commit -m "prep only add" && git p4 submit --prepare-p4-only >out && test_i18ngrep "prepared for submission" out && - test_i18ngrep "must be deleted" out + test_i18ngrep "must be deleted" out && + ! test_i18ngrep "everything below this line is just the diff" out ) && ( cd "$cli" && diff --git a/t/t9814-git-p4-rename.sh b/t/t9814-git-p4-rename.sh index be802e0e16..1fc1f5f2af 100755 --- a/t/t9814-git-p4-rename.sh +++ b/t/t9814-git-p4-rename.sh @@ -177,7 +177,7 @@ test_expect_success 'detect copies' ' level=$(git diff-tree -r -C --find-copies-harder HEAD | sed 1d | cut -f1 | cut -d" " -f5 | sed "s/C0*//") && test -n "$level" && test "$level" -gt 0 && test "$level" -lt 98 && src=$(git diff-tree -r -C --find-copies-harder HEAD | sed 1d | cut -f2) && - test "$src" = file10 -o "$src" = file11 && + test "$src" = file10 || test "$src" = file11 && git config git-p4.detectCopies $(($level + 2)) && git p4 submit && p4 filelog //depot/file12 && @@ -191,7 +191,7 @@ test_expect_success 'detect copies' ' level=$(git diff-tree -r -C --find-copies-harder HEAD | sed 1d | cut -f1 | cut -d" " -f5 | sed "s/C0*//") && test -n "$level" && test "$level" -gt 2 && test "$level" -lt 100 && src=$(git diff-tree -r -C --find-copies-harder HEAD | sed 1d | cut -f2) && - test "$src" = file10 -o "$src" = file11 -o "$src" = file12 && + test "$src" = file10 || test "$src" = file11 || test "$src" = file12 && git config git-p4.detectCopies $(($level - 2)) && git p4 submit && p4 filelog //depot/file13 && diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh index 2d4beb5e50..1d1c1063a3 100755 --- a/t/t9902-completion.sh +++ b/t/t9902-completion.sh @@ -550,6 +550,33 @@ test_expect_success 'complete files' ' test_completion "git add mom" "momified" ' +test_expect_success "completion uses <cmd> completion for alias: !sh -c 'git <cmd> ...'" ' + test_config alias.co "!sh -c '"'"'git checkout ...'"'"'" && + test_completion "git co m" <<-\EOF + master Z + mybranch Z + mytag Z + EOF +' + +test_expect_success 'completion uses <cmd> completion for alias: !f () { VAR=val git <cmd> ... }' ' + test_config alias.co "!f () { VAR=val git checkout ... ; } f" && + test_completion "git co m" <<-\EOF + master Z + mybranch Z + mytag Z + EOF +' + +test_expect_success 'completion used <cmd> completion for alias: !f() { : git <cmd> ; ... }' ' + test_config alias.co "!f() { : git checkout ; if ... } f" && + test_completion "git co m" <<-\EOF + master Z + mybranch Z + mytag Z + EOF +' + test_expect_failure 'complete with tilde expansion' ' git init tmp && cd tmp && test_when_finished "cd .. && rm -rf tmp" && diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh index 158e10a67e..0377d3e296 100644 --- a/t/test-lib-functions.sh +++ b/t/test-lib-functions.sh @@ -542,7 +542,7 @@ test_must_fail () { if test $exit_code = 0; then echo >&2 "test_must_fail: command succeeded: $*" return 1 - elif test $exit_code -gt 129 -a $exit_code -le 192; then + elif test $exit_code -gt 129 && test $exit_code -le 192; then echo >&2 "test_must_fail: died by signal: $*" return 1 elif test $exit_code = 127; then @@ -569,7 +569,7 @@ test_must_fail () { test_might_fail () { "$@" exit_code=$? - if test $exit_code -gt 129 -a $exit_code -le 192; then + if test $exit_code -gt 129 && test $exit_code -le 192; then echo >&2 "test_might_fail: died by signal: $*" return 1 elif test $exit_code = 127; then @@ -617,6 +617,12 @@ test_cmp() { $GIT_TEST_CMP "$@" } +# test_cmp_bin - helper to compare binary files + +test_cmp_bin() { + cmp "$@" +} + # Check if the file expected to be empty is indeed empty, and barfs # otherwise. @@ -717,6 +723,11 @@ test_ln_s_add () { fi } +# This function writes out its parameters, one per line +test_write_lines () { + printf "%s\n" "$@" +} + perl () { command "$PERL_PATH" "$@" } diff --git a/t/test-lib.sh b/t/test-lib.sh index c081668dfe..a4795373a6 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -91,6 +91,7 @@ unset VISUAL EMAIL LANGUAGE COLUMNS $("$PERL_PATH" -e ' VALGRIND UNZIP PERF_ + CURL_VERBOSE )); my @vars = grep(/^GIT_/ && !/^GIT_($ok)/o, @env); print join("\n", @vars); @@ -191,6 +192,14 @@ do immediate=t; shift ;; -l|--l|--lo|--lon|--long|--long-|--long-t|--long-te|--long-tes|--long-test|--long-tests) GIT_TEST_LONG=t; export GIT_TEST_LONG; shift ;; + -r) + shift; test "$#" -ne 0 || { + echo 'error: -r requires an argument' >&2; + exit 1; + } + run_list=$1; shift ;; + --run=*) + run_list=$(expr "z$1" : 'z[^=]*=\(.*\)'); shift ;; -h|--h|--he|--hel|--help) help=t; shift ;; -v|--v|--ve|--ver|--verb|--verbo|--verbos|--verbose) @@ -366,6 +375,99 @@ match_pattern_list () { return 1 } +match_test_selector_list () { + title="$1" + shift + arg="$1" + shift + test -z "$1" && return 0 + + # Both commas and whitespace are accepted as separators. + OLDIFS=$IFS + IFS=' ,' + set -- $1 + IFS=$OLDIFS + + # If the first selector is negative we include by default. + include= + case "$1" in + !*) include=t ;; + esac + + for selector + do + orig_selector=$selector + + positive=t + case "$selector" in + !*) + positive= + selector=${selector##?} + ;; + esac + + test -z "$selector" && continue + + case "$selector" in + *-*) + if expr "z${selector%%-*}" : "z[0-9]*[^0-9]" >/dev/null + then + echo "error: $title: invalid non-numeric in range" \ + "start: '$orig_selector'" >&2 + exit 1 + fi + if expr "z${selector#*-}" : "z[0-9]*[^0-9]" >/dev/null + then + echo "error: $title: invalid non-numeric in range" \ + "end: '$orig_selector'" >&2 + exit 1 + fi + ;; + *) + if expr "z$selector" : "z[0-9]*[^0-9]" >/dev/null + then + echo "error: $title: invalid non-numeric in test" \ + "selector: '$orig_selector'" >&2 + exit 1 + fi + esac + + # Short cut for "obvious" cases + test -z "$include" && test -z "$positive" && continue + test -n "$include" && test -n "$positive" && continue + + case "$selector" in + -*) + if test $arg -le ${selector#-} + then + include=$positive + fi + ;; + *-) + if test $arg -ge ${selector%-} + then + include=$positive + fi + ;; + *-*) + if test ${selector%%-*} -le $arg \ + && test $arg -le ${selector#*-} + then + include=$positive + fi + ;; + *) + if test $arg -eq $selector + then + include=$positive + fi + ;; + esac + done + + test -n "$include" +} + maybe_teardown_verbose () { test -z "$verbose_only" && return exec 4>/dev/null 3>/dev/null @@ -452,25 +554,35 @@ test_finish_ () { test_skip () { to_skip= + skipped_reason= if match_pattern_list $this_test.$test_count $GIT_SKIP_TESTS then to_skip=t + skipped_reason="GIT_SKIP_TESTS" fi if test -z "$to_skip" && test -n "$test_prereq" && ! test_have_prereq "$test_prereq" then to_skip=t - fi - case "$to_skip" in - t) + of_prereq= if test "$missing_prereq" != "$test_prereq" then of_prereq=" of $test_prereq" fi + skipped_reason="missing $missing_prereq${of_prereq}" + fi + if test -z "$to_skip" && test -n "$run_list" && + ! match_test_selector_list '--run' $test_count "$run_list" + then + to_skip=t + skipped_reason="--run" + fi + case "$to_skip" in + t) say_color skip >&3 "skipping test: $@" - say_color skip "ok $test_count # skip $1 (missing $missing_prereq${of_prereq})" + say_color skip "ok $test_count # skip $1 ($skipped_reason)" : true ;; *) @@ -864,6 +976,14 @@ test_lazy_prereq AUTOIDENT ' git var GIT_AUTHOR_IDENT ' +test_lazy_prereq EXPENSIVE ' + test -n "$GIT_TEST_LONG" +' + +test_lazy_prereq USR_BIN_TIME ' + test -x /usr/bin/time +' + # When the tests are run as root, permission tests will report that # things are writable when they shouldn't be. test -w / || test_set_prereq SANITY diff --git a/transport-helper.c b/transport-helper.c index b468e4f88e..84c616f180 100644 --- a/transport-helper.c +++ b/transport-helper.c @@ -101,7 +101,6 @@ static void do_take_over(struct transport *transport) static struct child_process *get_helper(struct transport *transport) { struct helper_data *data = transport->data; - struct argv_array argv = ARGV_ARRAY_INIT; struct strbuf buf = STRBUF_INIT; struct child_process *helper; const char **refspecs = NULL; @@ -123,10 +122,9 @@ static struct child_process *get_helper(struct transport *transport) helper->in = -1; helper->out = -1; helper->err = 0; - argv_array_pushf(&argv, "git-remote-%s", data->name); - argv_array_push(&argv, transport->remote->name); - argv_array_push(&argv, remove_ext_force(transport->url)); - helper->argv = argv_array_detach(&argv, NULL); + argv_array_pushf(&helper->args, "git-remote-%s", data->name); + argv_array_push(&helper->args, transport->remote->name); + argv_array_push(&helper->args, remove_ext_force(transport->url)); helper->git_cmd = 0; helper->silent_exec_failure = 1; @@ -245,7 +243,6 @@ static int disconnect_helper(struct transport *transport) close(data->helper->out); fclose(data->out); res = finish_command(data->helper); - argv_array_free_detached(data->helper->argv); free(data->helper); data->helper = NULL; } @@ -397,18 +394,16 @@ static int get_importer(struct transport *transport, struct child_process *fasti { struct child_process *helper = get_helper(transport); struct helper_data *data = transport->data; - struct argv_array argv = ARGV_ARRAY_INIT; int cat_blob_fd, code; memset(fastimport, 0, sizeof(*fastimport)); fastimport->in = helper->out; - argv_array_push(&argv, "fast-import"); - argv_array_push(&argv, debug ? "--stats" : "--quiet"); + argv_array_push(&fastimport->args, "fast-import"); + argv_array_push(&fastimport->args, debug ? "--stats" : "--quiet"); if (data->bidi_import) { cat_blob_fd = xdup(helper->in); - argv_array_pushf(&argv, "--cat-blob-fd=%d", cat_blob_fd); + argv_array_pushf(&fastimport->args, "--cat-blob-fd=%d", cat_blob_fd); } - fastimport->argv = argv.argv; fastimport->git_cmd = 1; code = start_command(fastimport); @@ -421,30 +416,24 @@ static int get_exporter(struct transport *transport, { struct helper_data *data = transport->data; struct child_process *helper = get_helper(transport); - int argc = 0, i; - struct strbuf tmp = STRBUF_INIT; + int i; memset(fastexport, 0, sizeof(*fastexport)); /* we need to duplicate helper->in because we want to use it after * fastexport is done with it. */ fastexport->out = dup(helper->in); - fastexport->argv = xcalloc(6 + revlist_args->nr, sizeof(*fastexport->argv)); - fastexport->argv[argc++] = "fast-export"; - fastexport->argv[argc++] = "--use-done-feature"; - fastexport->argv[argc++] = data->signed_tags ? - "--signed-tags=verbatim" : "--signed-tags=warn-strip"; - if (data->export_marks) { - strbuf_addf(&tmp, "--export-marks=%s.tmp", data->export_marks); - fastexport->argv[argc++] = strbuf_detach(&tmp, NULL); - } - if (data->import_marks) { - strbuf_addf(&tmp, "--import-marks=%s", data->import_marks); - fastexport->argv[argc++] = strbuf_detach(&tmp, NULL); - } + argv_array_push(&fastexport->args, "fast-export"); + argv_array_push(&fastexport->args, "--use-done-feature"); + argv_array_push(&fastexport->args, data->signed_tags ? + "--signed-tags=verbatim" : "--signed-tags=warn-strip"); + if (data->export_marks) + argv_array_pushf(&fastexport->args, "--export-marks=%s.tmp", data->export_marks); + if (data->import_marks) + argv_array_pushf(&fastexport->args, "--import-marks=%s", data->import_marks); for (i = 0; i < revlist_args->nr; i++) - fastexport->argv[argc++] = revlist_args->items[i].string; + argv_array_push(&fastexport->args, revlist_args->items[i].string); fastexport->git_cmd = 1; return start_command(fastexport); @@ -485,7 +474,6 @@ static int fetch_with_import(struct transport *transport, if (finish_command(&fastimport)) die("Error while running fast-import"); - argv_array_free_detached(fastimport.argv); /* * The fast-import stream of a remote helper that advertises @@ -862,7 +850,7 @@ static int push_refs_with_export(struct transport *transport, struct ref *ref; struct child_process *helper, exporter; struct helper_data *data = transport->data; - struct string_list revlist_args = STRING_LIST_INIT_NODUP; + struct string_list revlist_args = STRING_LIST_INIT_DUP; struct strbuf buf = STRBUF_INIT; if (!data->refspecs) @@ -882,15 +870,10 @@ static int push_refs_with_export(struct transport *transport, write_constant(helper->in, "export\n"); - strbuf_reset(&buf); - for (ref = remote_refs; ref; ref = ref->next) { char *private; unsigned char sha1[20]; - if (ref->deletion) - die("remote-helpers do not support ref deletion"); - private = apply_refspecs(data->refspecs, data->refspec_nr, ref->name); if (private && !get_sha1(private, sha1)) { strbuf_addf(&buf, "^%s", private); @@ -900,15 +883,34 @@ static int push_refs_with_export(struct transport *transport, free(private); if (ref->peer_ref) { - if (strcmp(ref->peer_ref->name, ref->name)) - die("remote-helpers do not support old:new syntax"); - string_list_append(&revlist_args, ref->peer_ref->name); + if (strcmp(ref->name, ref->peer_ref->name)) { + if (!ref->deletion) { + const char *name; + int flag; + + /* Follow symbolic refs (mainly for HEAD). */ + name = resolve_ref_unsafe(ref->peer_ref->name, sha1, 1, &flag); + if (!name || !(flag & REF_ISSYMREF)) + name = ref->peer_ref->name; + + strbuf_addf(&buf, "%s:%s", name, ref->name); + } else + strbuf_addf(&buf, ":%s", ref->name); + + string_list_append(&revlist_args, "--refspec"); + string_list_append(&revlist_args, buf.buf); + strbuf_release(&buf); + } + if (!ref->deletion) + string_list_append(&revlist_args, ref->peer_ref->name); } } if (get_exporter(transport, &exporter, &revlist_args)) die("Couldn't run fast-export"); + string_list_clear(&revlist_args, 1); + if (finish_command(&exporter)) die("Error while running fast-export"); if (push_update_refs_status(data, remote_refs, flags)) @@ -1026,7 +1028,7 @@ static struct ref *get_refs_list(struct transport *transport, int for_push) int transport_helper_init(struct transport *transport, const char *name) { - struct helper_data *data = xcalloc(sizeof(*data), 1); + struct helper_data *data = xcalloc(1, sizeof(*data)); data->name = name; if (getenv("GIT_TRANSPORT_HELPER_DEBUG")) diff --git a/tree-walk.c b/tree-walk.c index 4dc86c7fe5..5dd9a71804 100644 --- a/tree-walk.c +++ b/tree-walk.c @@ -144,16 +144,6 @@ struct tree_desc_x { struct tree_desc_skip *skip; }; -static int name_compare(const char *a, int a_len, - const char *b, int b_len) -{ - int len = (a_len < b_len) ? a_len : b_len; - int cmp = memcmp(a, b, len); - if (cmp) - return cmp; - return (a_len - b_len); -} - static int check_entry_match(const char *a, int a_len, const char *b, int b_len) { /* diff --git a/unicode_width.h b/unicode_width.h new file mode 100644 index 0000000000..47cdd2369d --- /dev/null +++ b/unicode_width.h @@ -0,0 +1,323 @@ +static const struct interval zero_width[] = { +{ 0x0300, 0x036F }, +{ 0x0483, 0x0489 }, +{ 0x0591, 0x05BD }, +{ 0x05BF, 0x05BF }, +{ 0x05C1, 0x05C2 }, +{ 0x05C4, 0x05C5 }, +{ 0x05C7, 0x05C7 }, +{ 0x0600, 0x0605 }, +{ 0x0610, 0x061A }, +{ 0x061C, 0x061C }, +{ 0x064B, 0x065F }, +{ 0x0670, 0x0670 }, +{ 0x06D6, 0x06DD }, +{ 0x06DF, 0x06E4 }, +{ 0x06E7, 0x06E8 }, +{ 0x06EA, 0x06ED }, +{ 0x070F, 0x070F }, +{ 0x0711, 0x0711 }, +{ 0x0730, 0x074A }, +{ 0x07A6, 0x07B0 }, +{ 0x07EB, 0x07F3 }, +{ 0x0816, 0x0819 }, +{ 0x081B, 0x0823 }, +{ 0x0825, 0x0827 }, +{ 0x0829, 0x082D }, +{ 0x0859, 0x085B }, +{ 0x08E4, 0x0902 }, +{ 0x093A, 0x093A }, +{ 0x093C, 0x093C }, +{ 0x0941, 0x0948 }, +{ 0x094D, 0x094D }, +{ 0x0951, 0x0957 }, +{ 0x0962, 0x0963 }, +{ 0x0981, 0x0981 }, +{ 0x09BC, 0x09BC }, +{ 0x09C1, 0x09C4 }, +{ 0x09CD, 0x09CD }, +{ 0x09E2, 0x09E3 }, +{ 0x0A01, 0x0A02 }, +{ 0x0A3C, 0x0A3C }, +{ 0x0A41, 0x0A42 }, +{ 0x0A47, 0x0A48 }, +{ 0x0A4B, 0x0A4D }, +{ 0x0A51, 0x0A51 }, +{ 0x0A70, 0x0A71 }, +{ 0x0A75, 0x0A75 }, +{ 0x0A81, 0x0A82 }, +{ 0x0ABC, 0x0ABC }, +{ 0x0AC1, 0x0AC5 }, +{ 0x0AC7, 0x0AC8 }, +{ 0x0ACD, 0x0ACD }, +{ 0x0AE2, 0x0AE3 }, +{ 0x0B01, 0x0B01 }, +{ 0x0B3C, 0x0B3C }, +{ 0x0B3F, 0x0B3F }, +{ 0x0B41, 0x0B44 }, +{ 0x0B4D, 0x0B4D }, +{ 0x0B56, 0x0B56 }, +{ 0x0B62, 0x0B63 }, +{ 0x0B82, 0x0B82 }, +{ 0x0BC0, 0x0BC0 }, +{ 0x0BCD, 0x0BCD }, +{ 0x0C00, 0x0C00 }, +{ 0x0C3E, 0x0C40 }, +{ 0x0C46, 0x0C48 }, +{ 0x0C4A, 0x0C4D }, +{ 0x0C55, 0x0C56 }, +{ 0x0C62, 0x0C63 }, +{ 0x0C81, 0x0C81 }, +{ 0x0CBC, 0x0CBC }, +{ 0x0CBF, 0x0CBF }, +{ 0x0CC6, 0x0CC6 }, +{ 0x0CCC, 0x0CCD }, +{ 0x0CE2, 0x0CE3 }, +{ 0x0D01, 0x0D01 }, +{ 0x0D41, 0x0D44 }, +{ 0x0D4D, 0x0D4D }, +{ 0x0D62, 0x0D63 }, +{ 0x0DCA, 0x0DCA }, +{ 0x0DD2, 0x0DD4 }, +{ 0x0DD6, 0x0DD6 }, +{ 0x0E31, 0x0E31 }, +{ 0x0E34, 0x0E3A }, +{ 0x0E47, 0x0E4E }, +{ 0x0EB1, 0x0EB1 }, +{ 0x0EB4, 0x0EB9 }, +{ 0x0EBB, 0x0EBC }, +{ 0x0EC8, 0x0ECD }, +{ 0x0F18, 0x0F19 }, +{ 0x0F35, 0x0F35 }, +{ 0x0F37, 0x0F37 }, +{ 0x0F39, 0x0F39 }, +{ 0x0F71, 0x0F7E }, +{ 0x0F80, 0x0F84 }, +{ 0x0F86, 0x0F87 }, +{ 0x0F8D, 0x0F97 }, +{ 0x0F99, 0x0FBC }, +{ 0x0FC6, 0x0FC6 }, +{ 0x102D, 0x1030 }, +{ 0x1032, 0x1037 }, +{ 0x1039, 0x103A }, +{ 0x103D, 0x103E }, +{ 0x1058, 0x1059 }, +{ 0x105E, 0x1060 }, +{ 0x1071, 0x1074 }, +{ 0x1082, 0x1082 }, +{ 0x1085, 0x1086 }, +{ 0x108D, 0x108D }, +{ 0x109D, 0x109D }, +{ 0x1160, 0x11FF }, +{ 0x135D, 0x135F }, +{ 0x1712, 0x1714 }, +{ 0x1732, 0x1734 }, +{ 0x1752, 0x1753 }, +{ 0x1772, 0x1773 }, +{ 0x17B4, 0x17B5 }, +{ 0x17B7, 0x17BD }, +{ 0x17C6, 0x17C6 }, +{ 0x17C9, 0x17D3 }, +{ 0x17DD, 0x17DD }, +{ 0x180B, 0x180E }, +{ 0x18A9, 0x18A9 }, +{ 0x1920, 0x1922 }, +{ 0x1927, 0x1928 }, +{ 0x1932, 0x1932 }, +{ 0x1939, 0x193B }, +{ 0x1A17, 0x1A18 }, +{ 0x1A1B, 0x1A1B }, +{ 0x1A56, 0x1A56 }, +{ 0x1A58, 0x1A5E }, +{ 0x1A60, 0x1A60 }, +{ 0x1A62, 0x1A62 }, +{ 0x1A65, 0x1A6C }, +{ 0x1A73, 0x1A7C }, +{ 0x1A7F, 0x1A7F }, +{ 0x1AB0, 0x1ABE }, +{ 0x1B00, 0x1B03 }, +{ 0x1B34, 0x1B34 }, +{ 0x1B36, 0x1B3A }, +{ 0x1B3C, 0x1B3C }, +{ 0x1B42, 0x1B42 }, +{ 0x1B6B, 0x1B73 }, +{ 0x1B80, 0x1B81 }, +{ 0x1BA2, 0x1BA5 }, +{ 0x1BA8, 0x1BA9 }, +{ 0x1BAB, 0x1BAD }, +{ 0x1BE6, 0x1BE6 }, +{ 0x1BE8, 0x1BE9 }, +{ 0x1BED, 0x1BED }, +{ 0x1BEF, 0x1BF1 }, +{ 0x1C2C, 0x1C33 }, +{ 0x1C36, 0x1C37 }, +{ 0x1CD0, 0x1CD2 }, +{ 0x1CD4, 0x1CE0 }, +{ 0x1CE2, 0x1CE8 }, +{ 0x1CED, 0x1CED }, +{ 0x1CF4, 0x1CF4 }, +{ 0x1CF8, 0x1CF9 }, +{ 0x1DC0, 0x1DF5 }, +{ 0x1DFC, 0x1DFF }, +{ 0x200B, 0x200F }, +{ 0x202A, 0x202E }, +{ 0x2060, 0x2064 }, +{ 0x2066, 0x206F }, +{ 0x20D0, 0x20F0 }, +{ 0x2CEF, 0x2CF1 }, +{ 0x2D7F, 0x2D7F }, +{ 0x2DE0, 0x2DFF }, +{ 0x302A, 0x302D }, +{ 0x3099, 0x309A }, +{ 0xA66F, 0xA672 }, +{ 0xA674, 0xA67D }, +{ 0xA69F, 0xA69F }, +{ 0xA6F0, 0xA6F1 }, +{ 0xA802, 0xA802 }, +{ 0xA806, 0xA806 }, +{ 0xA80B, 0xA80B }, +{ 0xA825, 0xA826 }, +{ 0xA8C4, 0xA8C4 }, +{ 0xA8E0, 0xA8F1 }, +{ 0xA926, 0xA92D }, +{ 0xA947, 0xA951 }, +{ 0xA980, 0xA982 }, +{ 0xA9B3, 0xA9B3 }, +{ 0xA9B6, 0xA9B9 }, +{ 0xA9BC, 0xA9BC }, +{ 0xA9E5, 0xA9E5 }, +{ 0xAA29, 0xAA2E }, +{ 0xAA31, 0xAA32 }, +{ 0xAA35, 0xAA36 }, +{ 0xAA43, 0xAA43 }, +{ 0xAA4C, 0xAA4C }, +{ 0xAA7C, 0xAA7C }, +{ 0xAAB0, 0xAAB0 }, +{ 0xAAB2, 0xAAB4 }, +{ 0xAAB7, 0xAAB8 }, +{ 0xAABE, 0xAABF }, +{ 0xAAC1, 0xAAC1 }, +{ 0xAAEC, 0xAAED }, +{ 0xAAF6, 0xAAF6 }, +{ 0xABE5, 0xABE5 }, +{ 0xABE8, 0xABE8 }, +{ 0xABED, 0xABED }, +{ 0xFB1E, 0xFB1E }, +{ 0xFE00, 0xFE0F }, +{ 0xFE20, 0xFE2D }, +{ 0xFEFF, 0xFEFF }, +{ 0xFFF9, 0xFFFB }, +{ 0x101FD, 0x101FD }, +{ 0x102E0, 0x102E0 }, +{ 0x10376, 0x1037A }, +{ 0x10A01, 0x10A03 }, +{ 0x10A05, 0x10A06 }, +{ 0x10A0C, 0x10A0F }, +{ 0x10A38, 0x10A3A }, +{ 0x10A3F, 0x10A3F }, +{ 0x10AE5, 0x10AE6 }, +{ 0x11001, 0x11001 }, +{ 0x11038, 0x11046 }, +{ 0x1107F, 0x11081 }, +{ 0x110B3, 0x110B6 }, +{ 0x110B9, 0x110BA }, +{ 0x110BD, 0x110BD }, +{ 0x11100, 0x11102 }, +{ 0x11127, 0x1112B }, +{ 0x1112D, 0x11134 }, +{ 0x11173, 0x11173 }, +{ 0x11180, 0x11181 }, +{ 0x111B6, 0x111BE }, +{ 0x1122F, 0x11231 }, +{ 0x11234, 0x11234 }, +{ 0x11236, 0x11237 }, +{ 0x112DF, 0x112DF }, +{ 0x112E3, 0x112EA }, +{ 0x11301, 0x11301 }, +{ 0x1133C, 0x1133C }, +{ 0x11340, 0x11340 }, +{ 0x11366, 0x1136C }, +{ 0x11370, 0x11374 }, +{ 0x114B3, 0x114B8 }, +{ 0x114BA, 0x114BA }, +{ 0x114BF, 0x114C0 }, +{ 0x114C2, 0x114C3 }, +{ 0x115B2, 0x115B5 }, +{ 0x115BC, 0x115BD }, +{ 0x115BF, 0x115C0 }, +{ 0x11633, 0x1163A }, +{ 0x1163D, 0x1163D }, +{ 0x1163F, 0x11640 }, +{ 0x116AB, 0x116AB }, +{ 0x116AD, 0x116AD }, +{ 0x116B0, 0x116B5 }, +{ 0x116B7, 0x116B7 }, +{ 0x16AF0, 0x16AF4 }, +{ 0x16B30, 0x16B36 }, +{ 0x16F8F, 0x16F92 }, +{ 0x1BC9D, 0x1BC9E }, +{ 0x1BCA0, 0x1BCA3 }, +{ 0x1D167, 0x1D169 }, +{ 0x1D173, 0x1D182 }, +{ 0x1D185, 0x1D18B }, +{ 0x1D1AA, 0x1D1AD }, +{ 0x1D242, 0x1D244 }, +{ 0x1E8D0, 0x1E8D6 }, +{ 0xE0001, 0xE0001 }, +{ 0xE0020, 0xE007F }, +{ 0xE0100, 0xE01EF } +}; +static const struct interval double_width[] = { +{ /* plane */ 0x0, 0x1C }, +{ /* plane */ 0x1C, 0x21 }, +{ /* plane */ 0x21, 0x22 }, +{ /* plane */ 0x22, 0x23 }, +{ /* plane */ 0x0, 0x0 }, +{ /* plane */ 0x0, 0x0 }, +{ /* plane */ 0x0, 0x0 }, +{ /* plane */ 0x0, 0x0 }, +{ /* plane */ 0x0, 0x0 }, +{ /* plane */ 0x0, 0x0 }, +{ /* plane */ 0x0, 0x0 }, +{ /* plane */ 0x0, 0x0 }, +{ /* plane */ 0x0, 0x0 }, +{ /* plane */ 0x0, 0x0 }, +{ /* plane */ 0x0, 0x0 }, +{ /* plane */ 0x0, 0x0 }, +{ /* plane */ 0x0, 0x0 }, +{ 0x1100, 0x115F }, +{ 0x2329, 0x232A }, +{ 0x2E80, 0x2E99 }, +{ 0x2E9B, 0x2EF3 }, +{ 0x2F00, 0x2FD5 }, +{ 0x2FF0, 0x2FFB }, +{ 0x3000, 0x303E }, +{ 0x3041, 0x3096 }, +{ 0x3099, 0x30FF }, +{ 0x3105, 0x312D }, +{ 0x3131, 0x318E }, +{ 0x3190, 0x31BA }, +{ 0x31C0, 0x31E3 }, +{ 0x31F0, 0x321E }, +{ 0x3220, 0x3247 }, +{ 0x3250, 0x32FE }, +{ 0x3300, 0x4DBF }, +{ 0x4E00, 0xA48C }, +{ 0xA490, 0xA4C6 }, +{ 0xA960, 0xA97C }, +{ 0xAC00, 0xD7A3 }, +{ 0xF900, 0xFAFF }, +{ 0xFE10, 0xFE19 }, +{ 0xFE30, 0xFE52 }, +{ 0xFE54, 0xFE66 }, +{ 0xFE68, 0xFE6B }, +{ 0xFF01, 0xFF60 }, +{ 0xFFE0, 0xFFE6 }, +{ 0x1B000, 0x1B001 }, +{ 0x1F200, 0x1F202 }, +{ 0x1F210, 0x1F23A }, +{ 0x1F240, 0x1F248 }, +{ 0x1F250, 0x1F251 }, +{ 0x20000, 0x2FFFD }, +{ 0x30000, 0x3FFFD } +}; diff --git a/unpack-trees.c b/unpack-trees.c index 97fc995467..e9a05b9085 100644 --- a/unpack-trees.c +++ b/unpack-trees.c @@ -622,17 +622,6 @@ static int unpack_failed(struct unpack_trees_options *o, const char *message) return -1; } -/* NEEDSWORK: give this a better name and share with tree-walk.c */ -static int name_compare(const char *a, int a_len, - const char *b, int b_len) -{ - int len = (a_len < b_len) ? a_len : b_len; - int cmp = memcmp(a, b, len); - if (cmp) - return cmp; - return (a_len - b_len); -} - /* * The tree traversal is looking at name p. If we have a matching entry, * return it. If name p is a directory in the index, do not return diff --git a/update_unicode.sh b/update_unicode.sh new file mode 100755 index 0000000000..000b937e68 --- /dev/null +++ b/update_unicode.sh @@ -0,0 +1,37 @@ +#!/bin/sh +#See http://www.unicode.org/reports/tr44/ +# +#Me Enclosing_Mark an enclosing combining mark +#Mn Nonspacing_Mark a nonspacing combining mark (zero advance width) +#Cf Format a format control character +# +UNICODEWIDTH_H=../unicode_width.h +if ! test -d unicode; then + mkdir unicode +fi && +( cd unicode && + if ! test -f UnicodeData.txt; then + wget http://www.unicode.org/Public/UCD/latest/ucd/UnicodeData.txt + fi && + if ! test -f EastAsianWidth.txt; then + wget http://www.unicode.org/Public/UCD/latest/ucd/EastAsianWidth.txt + fi && + if ! test -d uniset; then + git clone https://github.com/depp/uniset.git + fi && + ( + cd uniset && + if ! test -x uniset; then + autoreconf -i && + ./configure --enable-warnings=-Werror CFLAGS='-O0 -ggdb' + fi && + make + ) && + echo "static const struct interval zero_width[] = {" >$UNICODEWIDTH_H && + UNICODE_DIR=. ./uniset/uniset --32 cat:Me,Mn,Cf + U+1160..U+11FF - U+00AD | + grep -v plane >>$UNICODEWIDTH_H && + echo "};" >>$UNICODEWIDTH_H && + echo "static const struct interval double_width[] = {" >>$UNICODEWIDTH_H && + UNICODE_DIR=. ./uniset/uniset --32 eaw:F,W >>$UNICODEWIDTH_H && + echo "};" >>$UNICODEWIDTH_H +) @@ -80,52 +80,8 @@ static int git_wcwidth(ucs_char_t ch) { /* * Sorted list of non-overlapping intervals of non-spacing characters, - * generated by - * "uniset +cat=Me +cat=Mn +cat=Cf -00AD +1160-11FF +200B c". */ - static const struct interval combining[] = { - { 0x0300, 0x036F }, { 0x0483, 0x0489 }, { 0x0591, 0x05BD }, - { 0x05BF, 0x05BF }, { 0x05C1, 0x05C2 }, { 0x05C4, 0x05C5 }, - { 0x05C7, 0x05C7 }, { 0x0600, 0x0604 }, { 0x0610, 0x061A }, - { 0x064B, 0x065F }, { 0x0670, 0x0670 }, { 0x06D6, 0x06E4 }, - { 0x06E7, 0x06E8 }, { 0x06EA, 0x06ED }, { 0x070F, 0x070F }, - { 0x0711, 0x0711 }, { 0x0730, 0x074A }, { 0x07A6, 0x07B0 }, - { 0x0901, 0x0902 }, { 0x093C, 0x093C }, { 0x0941, 0x0948 }, - { 0x094D, 0x094D }, { 0x0951, 0x0954 }, { 0x0962, 0x0963 }, - { 0x0981, 0x0981 }, { 0x09BC, 0x09BC }, { 0x09C1, 0x09C4 }, - { 0x09CD, 0x09CD }, { 0x09E2, 0x09E3 }, { 0x0A01, 0x0A02 }, - { 0x0A3C, 0x0A3C }, { 0x0A41, 0x0A42 }, { 0x0A47, 0x0A48 }, - { 0x0A4B, 0x0A4D }, { 0x0A70, 0x0A71 }, { 0x0A81, 0x0A82 }, - { 0x0ABC, 0x0ABC }, { 0x0AC1, 0x0AC5 }, { 0x0AC7, 0x0AC8 }, - { 0x0ACD, 0x0ACD }, { 0x0AE2, 0x0AE3 }, { 0x0B01, 0x0B01 }, - { 0x0B3C, 0x0B3C }, { 0x0B3F, 0x0B3F }, { 0x0B41, 0x0B43 }, - { 0x0B4D, 0x0B4D }, { 0x0B56, 0x0B56 }, { 0x0B82, 0x0B82 }, - { 0x0BC0, 0x0BC0 }, { 0x0BCD, 0x0BCD }, { 0x0C3E, 0x0C40 }, - { 0x0C46, 0x0C48 }, { 0x0C4A, 0x0C4D }, { 0x0C55, 0x0C56 }, - { 0x0CBC, 0x0CBC }, { 0x0CBF, 0x0CBF }, { 0x0CC6, 0x0CC6 }, - { 0x0CCC, 0x0CCD }, { 0x0D41, 0x0D43 }, { 0x0D4D, 0x0D4D }, - { 0x0DCA, 0x0DCA }, { 0x0DD2, 0x0DD4 }, { 0x0DD6, 0x0DD6 }, - { 0x0E31, 0x0E31 }, { 0x0E34, 0x0E3A }, { 0x0E47, 0x0E4E }, - { 0x0EB1, 0x0EB1 }, { 0x0EB4, 0x0EB9 }, { 0x0EBB, 0x0EBC }, - { 0x0EC8, 0x0ECD }, { 0x0F18, 0x0F19 }, { 0x0F35, 0x0F35 }, - { 0x0F37, 0x0F37 }, { 0x0F39, 0x0F39 }, { 0x0F71, 0x0F7E }, - { 0x0F80, 0x0F84 }, { 0x0F86, 0x0F87 }, { 0x0F90, 0x0F97 }, - { 0x0F99, 0x0FBC }, { 0x0FC6, 0x0FC6 }, { 0x102D, 0x1030 }, - { 0x1032, 0x1032 }, { 0x1036, 0x1037 }, { 0x1039, 0x1039 }, - { 0x1058, 0x1059 }, { 0x1160, 0x11FF }, { 0x1712, 0x1714 }, - { 0x1732, 0x1734 }, { 0x1752, 0x1753 }, { 0x1772, 0x1773 }, - { 0x17B4, 0x17B5 }, { 0x17B7, 0x17BD }, { 0x17C6, 0x17C6 }, - { 0x17C9, 0x17D3 }, { 0x17DD, 0x17DD }, { 0x180B, 0x180D }, - { 0x18A9, 0x18A9 }, { 0x1920, 0x1922 }, { 0x1927, 0x1928 }, - { 0x1932, 0x1932 }, { 0x1939, 0x193B }, { 0x200B, 0x200F }, - { 0x202A, 0x202E }, { 0x2060, 0x2063 }, { 0x206A, 0x206F }, - { 0x20D0, 0x20EA }, { 0x302A, 0x302F }, { 0x3099, 0x309A }, - { 0xFB1E, 0xFB1E }, { 0xFE00, 0xFE0F }, { 0xFE20, 0xFE23 }, - { 0xFEFF, 0xFEFF }, { 0xFFF9, 0xFFFB }, { 0x1D167, 0x1D169 }, - { 0x1D173, 0x1D182 }, { 0x1D185, 0x1D18B }, - { 0x1D1AA, 0x1D1AD }, { 0xE0001, 0xE0001 }, - { 0xE0020, 0xE007F }, { 0xE0100, 0xE01EF } - }; +#include "unicode_width.h" /* test for 8-bit control characters */ if (ch == 0) @@ -134,34 +90,16 @@ static int git_wcwidth(ucs_char_t ch) return -1; /* binary search in table of non-spacing characters */ - if (bisearch(ch, combining, sizeof(combining) + if (bisearch(ch, zero_width, sizeof(zero_width) / sizeof(struct interval) - 1)) return 0; - /* - * If we arrive here, ch is neither a combining nor a C0/C1 - * control character. - */ + /* binary search in table of double width characters */ + if (bisearch(ch, double_width, sizeof(double_width) + / sizeof(struct interval) - 1)) + return 2; - return 1 + - (ch >= 0x1100 && - /* Hangul Jamo init. consonants */ - (ch <= 0x115f || - ch == 0x2329 || ch == 0x232a || - /* CJK ... Yi */ - (ch >= 0x2e80 && ch <= 0xa4cf && - ch != 0x303f) || - /* Hangul Syllables */ - (ch >= 0xac00 && ch <= 0xd7a3) || - /* CJK Compatibility Ideographs */ - (ch >= 0xf900 && ch <= 0xfaff) || - /* CJK Compatibility Forms */ - (ch >= 0xfe30 && ch <= 0xfe6f) || - /* Fullwidth Forms */ - (ch >= 0xff00 && ch <= 0xff60) || - (ch >= 0xffe0 && ch <= 0xffe6) || - (ch >= 0x20000 && ch <= 0x2fffd) || - (ch >= 0x30000 && ch <= 0x3fffd))); + return 1; } /* diff --git a/wt-status.c b/wt-status.c index ec7344e508..318a191238 100644 --- a/wt-status.c +++ b/wt-status.c @@ -188,7 +188,7 @@ static void wt_status_print_unmerged_header(struct wt_status *s) } else { status_printf_ln(s, c, _(" (use \"git add/rm <file>...\" as appropriate to mark resolution)")); } - status_printf_ln(s, c, ""); + status_printf_ln(s, c, "%s", ""); } static void wt_status_print_cached_header(struct wt_status *s) @@ -204,7 +204,7 @@ static void wt_status_print_cached_header(struct wt_status *s) status_printf_ln(s, c, _(" (use \"git reset %s <file>...\" to unstage)"), s->reference); else status_printf_ln(s, c, _(" (use \"git rm --cached <file>...\" to unstage)")); - status_printf_ln(s, c, ""); + status_printf_ln(s, c, "%s", ""); } static void wt_status_print_dirty_header(struct wt_status *s, @@ -223,7 +223,7 @@ static void wt_status_print_dirty_header(struct wt_status *s, status_printf_ln(s, c, _(" (use \"git checkout -- <file>...\" to discard changes in working directory)")); if (has_dirty_submodules) status_printf_ln(s, c, _(" (commit or discard the untracked or modified content in submodules)")); - status_printf_ln(s, c, ""); + status_printf_ln(s, c, "%s", ""); } static void wt_status_print_other_header(struct wt_status *s, @@ -235,12 +235,12 @@ static void wt_status_print_other_header(struct wt_status *s, if (!s->hints) return; status_printf_ln(s, c, _(" (use \"git %s <file>...\" to include in what will be committed)"), how); - status_printf_ln(s, c, ""); + status_printf_ln(s, c, "%s", ""); } static void wt_status_print_trailer(struct wt_status *s) { - status_printf_ln(s, color(WT_STATUS_HEADER, s), ""); + status_printf_ln(s, color(WT_STATUS_HEADER, s), "%s", ""); } #define quote_path quote_path_relative @@ -519,9 +519,19 @@ static void wt_status_collect_changes_index(struct wt_status *s) opt.def = s->is_initial ? EMPTY_TREE_SHA1_HEX : s->reference; setup_revisions(0, NULL, &rev, &opt); + DIFF_OPT_SET(&rev.diffopt, OVERRIDE_SUBMODULE_CONFIG); if (s->ignore_submodule_arg) { - DIFF_OPT_SET(&rev.diffopt, OVERRIDE_SUBMODULE_CONFIG); handle_ignore_submodules_arg(&rev.diffopt, s->ignore_submodule_arg); + } else { + /* + * Unless the user did explicitly request a submodule ignore + * mode by passing a command line option we do not ignore any + * changed submodule SHA-1s when comparing index and HEAD, no + * matter what is configured. Otherwise the user won't be + * shown any submodules she manually added (and which are + * staged to be committed), which would be really confusing. + */ + handle_ignore_submodules_arg(&rev.diffopt, "dirty"); } rev.diffopt.output_format |= DIFF_FORMAT_CALLBACK; @@ -826,7 +836,7 @@ static void wt_status_print_other(struct wt_status *s, string_list_clear(&output, 0); strbuf_release(&buf); conclude: - status_printf_ln(s, GIT_COLOR_NORMAL, ""); + status_printf_ln(s, GIT_COLOR_NORMAL, "%s", ""); } void wt_status_truncate_message_at_cut_line(struct strbuf *buf) @@ -913,7 +923,7 @@ static void wt_status_print_tracking(struct wt_status *s) color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), "%c", comment_line_char); else - fprintf_ln(s->fp, ""); + fputs("", s->fp); } static int has_unmerged(struct wt_status *s) @@ -1329,7 +1339,7 @@ void wt_status_print(struct wt_status *s) on_what = _("Not currently on any branch."); } } - status_printf(s, color(WT_STATUS_HEADER, s), ""); + status_printf(s, color(WT_STATUS_HEADER, s), "%s", ""); status_printf_more(s, branch_status_color, "%s", on_what); status_printf_more(s, branch_color, "%s\n", branch_name); if (!s->is_initial) @@ -1342,9 +1352,9 @@ void wt_status_print(struct wt_status *s) free(state.detached_from); if (s->is_initial) { - status_printf_ln(s, color(WT_STATUS_HEADER, s), ""); + status_printf_ln(s, color(WT_STATUS_HEADER, s), "%s", ""); status_printf_ln(s, color(WT_STATUS_HEADER, s), _("Initial commit")); - status_printf_ln(s, color(WT_STATUS_HEADER, s), ""); + status_printf_ln(s, color(WT_STATUS_HEADER, s), "%s", ""); } wt_status_print_updated(s); @@ -1361,7 +1371,7 @@ void wt_status_print(struct wt_status *s) if (s->show_ignored_files) wt_status_print_other(s, &s->ignored, _("Ignored files"), "add -f"); if (advice_status_u_option && 2000 < s->untracked_in_ms) { - status_printf_ln(s, GIT_COLOR_NORMAL, ""); + status_printf_ln(s, GIT_COLOR_NORMAL, "%s", ""); status_printf_ln(s, GIT_COLOR_NORMAL, _("It took %.2f seconds to enumerate untracked files. 'status -uno'\n" "may speed it up, but you have to be careful not to forget to add\n" |