summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Documentation/RelNotes/1.9.4.txt16
-rw-r--r--Documentation/RelNotes/2.0.1.txt115
-rw-r--r--Documentation/RelNotes/2.0.2.txt32
-rw-r--r--Documentation/config.txt8
-rw-r--r--Documentation/git-rev-parse.txt2
-rw-r--r--Documentation/git-submodule.txt2
-rw-r--r--Documentation/git.txt7
-rw-r--r--Documentation/gitmodules.txt4
-rw-r--r--Documentation/glossary-content.txt2
-rw-r--r--Documentation/user-manual.txt15
-rwxr-xr-xGIT-VERSION-GEN2
-rw-r--r--Makefile7
l---------RelNotes2
-rw-r--r--alloc.c23
-rw-r--r--builtin/annotate.c12
-rw-r--r--builtin/apply.c16
-rw-r--r--builtin/blame.c58
-rw-r--r--builtin/clean.c5
-rw-r--r--builtin/clone.c2
-rw-r--r--builtin/commit-tree.c4
-rw-r--r--builtin/commit.c27
-rw-r--r--builtin/fast-export.c5
-rw-r--r--builtin/fmt-merge-msg.c5
-rw-r--r--builtin/fsck.c3
-rw-r--r--builtin/gc.c26
-rw-r--r--builtin/grep.c3
-rw-r--r--builtin/index-pack.c42
-rw-r--r--builtin/log.c21
-rw-r--r--builtin/ls-remote.c2
-rw-r--r--builtin/mailinfo.c6
-rw-r--r--builtin/merge.c8
-rw-r--r--builtin/mv.c3
-rw-r--r--builtin/remote.c45
-rw-r--r--builtin/repack.c14
-rw-r--r--builtin/rerere.c2
-rw-r--r--builtin/reset.c4
-rw-r--r--builtin/rev-list.c5
-rw-r--r--builtin/update-index.c3
-rw-r--r--cache.h3
-rw-r--r--combine-diff.c3
-rw-r--r--commit-slab.h12
-rw-r--r--commit.c131
-rw-r--r--commit.h54
-rw-r--r--compat/bswap.h33
-rw-r--r--compat/mingw.c3
-rw-r--r--compat/mmap.c4
-rw-r--r--config.c6
-rw-r--r--config.mak.uname1
-rw-r--r--connect.c4
-rw-r--r--contrib/completion/git-completion.bash6
-rwxr-xr-xcontrib/subtree/t/t7900-subtree.sh3
-rw-r--r--diff-lib.c33
-rw-r--r--diff.c5
-rw-r--r--dir.c34
-rw-r--r--fsck.c13
-rw-r--r--git-compat-util.h1
-rwxr-xr-xgit-instaweb.sh12
-rwxr-xr-xgit-pull.sh2
-rw-r--r--git-rebase--interactive.sh4
-rw-r--r--git-rebase--merge.sh5
-rwxr-xr-xgit-rebase.sh11
-rwxr-xr-xgit-remote-testgit.sh3
-rwxr-xr-xgit-stash.sh3
-rw-r--r--http-backend.c4
-rw-r--r--http-push.c2
-rw-r--r--imap-send.c2
-rw-r--r--log-tree.c4
-rw-r--r--merge-recursive.c12
-rw-r--r--notes-cache.c6
-rw-r--r--notes-merge.c13
-rw-r--r--notes-utils.c7
-rw-r--r--notes-utils.h2
-rw-r--r--notes.c6
-rw-r--r--object.c4
-rw-r--r--pack-objects.c4
-rw-r--r--pack-revindex.c2
-rw-r--r--pager.c2
-rw-r--r--path.c4
-rw-r--r--pathspec.c3
-rw-r--r--pretty.c61
-rw-r--r--read-cache.c47
-rw-r--r--reflog-walk.c8
-rw-r--r--refs.c21
-rw-r--r--refs.h3
-rw-r--r--remote.c2
-rw-r--r--revision.c22
-rw-r--r--sequencer.c49
-rw-r--r--sh-i18n--envsubst.c4
-rw-r--r--sha1_file.c9
-rw-r--r--sha1_name.c18
-rw-r--r--sideband.c2
-rwxr-xr-xt/t0008-ignores.sh25
-rwxr-xr-xt/t1507-rev-parse-upstream.sh2
-rwxr-xr-xt/t2107-update-index-basic.sh4
-rwxr-xr-xt/t3032-merge-recursive-options.sh6
-rwxr-xr-xt/t3402-rebase-merge.sh15
-rwxr-xr-xt/t3420-rebase-autostash.sh15
-rwxr-xr-xt/t4039-diff-assume-unchanged.sh11
-rwxr-xr-xt/t4041-diff-submodule-option.sh7
-rwxr-xr-xt/t4107-apply-ignore-whitespace.sh12
-rwxr-xr-xt/t4201-shortlog.sh6
-rwxr-xr-xt/t4205-log-pretty-formats.sh217
-rwxr-xr-xt/t5150-request-pull.sh2
-rwxr-xr-xt/t5537-fetch-shallow.sh28
-rwxr-xr-xt/t5538-push-shallow.sh59
-rwxr-xr-xt/t5542-push-http-shallow.sh100
-rwxr-xr-xt/t5560-http-backend-noserver.sh6
-rwxr-xr-xt/t6006-rev-list-format.sh116
-rwxr-xr-xt/t6039-merge-ignorecase.sh53
-rwxr-xr-xt/t7007-show.sh10
-rwxr-xr-xt/t7102-reset.sh13
-rwxr-xr-xt/t7300-clean.sh4
-rwxr-xr-xt/t7500-commit.sh11
-rwxr-xr-xt/t7508-status.sh74
-rwxr-xr-xt/t7510-signed-commit.sh71
-rwxr-xr-xt/t7600-merge.sh11
-rwxr-xr-xt/t7700-repack.sh20
-rwxr-xr-xt/t8003-blame-corner-cases.sh9
-rw-r--r--transport-helper.c2
-rw-r--r--wrapper.c38
-rw-r--r--wt-status.c12
121 files changed, 1628 insertions, 601 deletions
diff --git a/Documentation/RelNotes/1.9.4.txt b/Documentation/RelNotes/1.9.4.txt
new file mode 100644
index 0000000000..e1d1835436
--- /dev/null
+++ b/Documentation/RelNotes/1.9.4.txt
@@ -0,0 +1,16 @@
+Git v1.9.4 Release Notes
+========================
+
+Fixes since v1.9.3
+------------------
+
+ * Commands that take pathspecs on the command line misbehaved when
+ the pathspec is given as an absolute pathname (which is a
+ practice not particularly encouraged) that points at a symbolic
+ link in the working tree.
+
+ * An earlier fix to the shell prompt script (in contrib/) for using
+ the PROMPT_COMMAND interface did not correctly check if the extra
+ code path needs to trigger, causing the branch name not to appear
+ when 'promptvars' option is disabled in bash or PROMPT_SUBST is
+ unset in zsh.
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.0.2.txt b/Documentation/RelNotes/2.0.2.txt
new file mode 100644
index 0000000000..8e8321b2ef
--- /dev/null
+++ b/Documentation/RelNotes/2.0.2.txt
@@ -0,0 +1,32 @@
+Git v2.0.2 Release Notes
+========================
+
+ * Documentation for "git submodule sync" forgot to say that the subcommand
+ can take the "--recursive" option.
+
+ * Mishandling of patterns in .gitignore that has trailing SPs quoted
+ with backslashes (e.g. ones that end with "\ ") have been
+ corrected.
+
+ * Recent updates to "git repack" started to duplicate objects that
+ are in packfiles marked with .keep flag into the new packfile by
+ mistake.
+
+ * "git clone -b brefs/tags/bar" would have mistakenly thought we were
+ following a single tag, even though it was a name of the branch,
+ because it incorrectly used strstr().
+
+ * "%G" (nothing after G) is an invalid pretty format specifier, but
+ the parser did not notice it as garbage.
+
+ * Code to avoid adding the same alternate object store twice was
+ subtly broken for a long time, but nobody seems to have noticed.
+
+ * A handful of code paths had to read the commit object more than
+ once when showing header fields that are usually not parsed. The
+ internal data structure to keep track of the contents of the commit
+ object has been updated to reduce the need for this double-reading,
+ and to allow the caller find the length of the object.
+
+ * During "git rebase --merge", a conflicted patch could not be
+ skipped with "--skip" if the next one also conflicted.
diff --git a/Documentation/config.txt b/Documentation/config.txt
index 1932e9b9a2..c08286e968 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -2293,7 +2293,9 @@ 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
submodule summary' command, which shows a similar output but does
@@ -2324,7 +2326,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 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/git-rev-parse.txt b/Documentation/git-rev-parse.txt
index 987395d22a..54143a0693 100644
--- a/Documentation/git-rev-parse.txt
+++ b/Documentation/git-rev-parse.txt
@@ -102,7 +102,7 @@ eval "set -- $(git rev-parse --sq --prefix "$prefix" "$@")"
+
If you want to make sure that the output actually names an object in
your object database and/or can be used as a specific type of object
-you require, you can add "^{type}" peeling operator to the parameter.
+you require, you can add "\^{type}" peeling operator to the parameter.
For example, `git rev-parse "$VAR^{commit}"` will make sure `$VAR`
names an existing object that is a commit-ish (i.e. a commit, or an
annotated tag that points at a commit). To make sure that `$VAR`
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.txt b/Documentation/git.txt
index c15609face..9d0883d28f 100644
--- a/Documentation/git.txt
+++ b/Documentation/git.txt
@@ -43,14 +43,17 @@ unreleased) version of Git, that is available from '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.2/git.html[documentation for release 2.0.2]
* release notes for
+ link:RelNotes/2.0.2.txt[2.0.2],
+ link:RelNotes/2.0.1.txt[2.0.1],
link:RelNotes/2.0.0.txt[2.0.0].
-* link:v1.9.3/git.html[documentation for release 1.9.3]
+* link:v1.9.4/git.html[documentation for release 1.9.4]
* release notes for
+ link:RelNotes/1.9.4.txt[1.9.4],
link:RelNotes/1.9.3.txt[1.9.3],
link:RelNotes/1.9.2.txt[1.9.2],
link:RelNotes/1.9.1.txt[1.9.1],
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/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/user-manual.txt b/Documentation/user-manual.txt
index 022e74e616..46aa6bc1a6 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.
diff --git a/GIT-VERSION-GEN b/GIT-VERSION-GEN
index 5d6dc5b4c6..b14f852c0c 100755
--- a/GIT-VERSION-GEN
+++ b/GIT-VERSION-GEN
@@ -1,7 +1,7 @@
#!/bin/sh
GVF=GIT-VERSION-FILE
-DEF_VER=v2.0.0
+DEF_VER=v2.0.2
LF='
'
diff --git a/Makefile b/Makefile
index a53f3a8326..e0caec3f67 100644
--- a/Makefile
+++ b/Makefile
@@ -183,9 +183,6 @@ all::
# Define NO_STRUCT_ITIMERVAL if you don't have struct itimerval
# This also implies NO_SETITIMER
#
-# Define NO_THREAD_SAFE_PREAD if your pread() implementation is not
-# thread-safe. (e.g. compat/pread.c or cygwin)
-#
# Define NO_FAST_WORKING_DIRECTORY if accessing objects in pack files is
# generally faster on your platform than accessing the working directory.
#
@@ -1339,10 +1336,6 @@ endif
ifdef NO_PREAD
COMPAT_CFLAGS += -DNO_PREAD
COMPAT_OBJS += compat/pread.o
- NO_THREAD_SAFE_PREAD = YesPlease
-endif
-ifdef NO_THREAD_SAFE_PREAD
- BASIC_CFLAGS += -DNO_THREAD_SAFE_PREAD
endif
ifdef NO_FAST_WORKING_DIRECTORY
BASIC_CFLAGS += -DNO_FAST_WORKING_DIRECTORY
diff --git a/RelNotes b/RelNotes
index e50885caa1..7c4ae86d0f 120000
--- a/RelNotes
+++ b/RelNotes
@@ -1 +1 @@
-Documentation/RelNotes/2.0.0.txt \ No newline at end of file
+Documentation/RelNotes/2.0.2.txt \ No newline at end of file
diff --git a/alloc.c b/alloc.c
index f3ee745695..eb22a45c9d 100644
--- a/alloc.c
+++ b/alloc.c
@@ -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/builtin/annotate.c b/builtin/annotate.c
index fc43eed36b..da413ae0d1 100644
--- a/builtin/annotate.c
+++ b/builtin/annotate.c
@@ -5,20 +5,18 @@
*/
#include "git-compat-util.h"
#include "builtin.h"
+#include "argv-array.h"
int cmd_annotate(int argc, const char **argv, const char *prefix)
{
- const char **nargv;
+ struct argv_array args = ARGV_ARRAY_INIT;
int i;
- nargv = xmalloc(sizeof(char *) * (argc + 2));
- nargv[0] = "annotate";
- nargv[1] = "-c";
+ argv_array_pushl(&args, "annotate", "-c", NULL);
for (i = 1; i < argc; i++) {
- nargv[i+1] = argv[i];
+ argv_array_push(&args, argv[i]);
}
- nargv[argc + 1] = NULL;
- return cmd_blame(argc + 1, nargv, prefix);
+ return cmd_blame(args.argc, args.argv, prefix);
}
diff --git a/builtin/apply.c b/builtin/apply.c
index 87439fad11..622ee1674a 100644
--- a/builtin/apply.c
+++ b/builtin/apply.c
@@ -300,11 +300,13 @@ static int fuzzy_matchlines(const char *s1, size_t n1,
while ((*last2 == '\r') || (*last2 == '\n'))
last2--;
- /* skip leading whitespace */
- while (isspace(*s1) && (s1 <= last1))
- s1++;
- while (isspace(*s2) && (s2 <= last2))
- s2++;
+ /* skip leading whitespaces, if both begin with whitespace */
+ if (s1 <= last1 && s2 <= last2 && isspace(*s1) && isspace(*s2)) {
+ while (isspace(*s1) && (s1 <= last1))
+ s1++;
+ while (isspace(*s2) && (s2 <= last2))
+ s2++;
+ }
/* early return if both lines are empty */
if ((s1 > last1) && (s2 > last2))
return 1;
@@ -2867,9 +2869,7 @@ static int apply_binary_fragment(struct image *img, struct patch *patch)
case BINARY_LITERAL_DEFLATED:
clear_image(img);
img->len = fragment->size;
- img->buf = xmalloc(img->len+1);
- memcpy(img->buf, fragment->patch, img->len);
- img->buf[img->len] = '\0';
+ img->buf = xmemdupz(fragment->patch, img->len);
return 0;
}
return -1;
diff --git a/builtin/blame.c b/builtin/blame.c
index 88cb799727..6a284ce46b 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -1405,7 +1405,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 +1416,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 +1430,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);
}
/*
@@ -1556,22 +1556,29 @@ static void assign_blame(struct scoreboard *sb, int opt)
static const char *format_time(unsigned long time, const char *tz_str,
int show_raw_time)
{
- static char time_buf[128];
+ static struct strbuf time_buf = STRBUF_INIT;
+ strbuf_reset(&time_buf);
if (show_raw_time) {
- snprintf(time_buf, sizeof(time_buf), "%lu %s", time, tz_str);
+ strbuf_addf(&time_buf, "%lu %s", time, tz_str);
}
else {
const char *time_str;
- int time_len;
+ size_t time_width;
int tz;
tz = atoi(tz_str);
time_str = show_date(time, tz, blame_date_mode);
- time_len = strlen(time_str);
- memcpy(time_buf, time_str, time_len);
- memset(time_buf + time_len, ' ', blame_date_width - time_len);
+ strbuf_addstr(&time_buf, time_str);
+ /*
+ * Add space paddings to time_buf to display a fixed width
+ * string, and use time_width for display width calibration.
+ */
+ for (time_width = utf8_strwidth(time_str);
+ time_width < blame_date_width;
+ time_width++)
+ strbuf_addch(&time_buf, ' ');
}
- return time_buf;
+ return time_buf.buf;
}
#define OUTPUT_ANNOTATE_COMPAT 001
@@ -1999,6 +2006,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.
*/
@@ -2019,7 +2038,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;
@@ -2046,7 +2065,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;
@@ -2088,7 +2107,6 @@ 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);
@@ -2331,7 +2349,14 @@ parse_done:
blame_date_width = sizeof("2006-10-19");
break;
case DATE_RELATIVE:
- /* "normal" is used as the fallback for "relative" */
+ /* TRANSLATORS: This string is used to tell us the maximum
+ display width for a relative timestamp in "git blame"
+ output. For C locale, "4 years, 11 months ago", which
+ takes 22 places, is the longest among various forms of
+ relative timestamps, but your language may need more or
+ fewer display columns. */
+ blame_date_width = utf8_strwidth(_("4 years, 11 months ago")) + 1; /* add the null */
+ break;
case DATE_LOCAL:
case DATE_NORMAL:
blame_date_width = sizeof("Thu Oct 19 16:00:04 2006 -0700");
@@ -2433,11 +2458,8 @@ parse_done:
die("revision walk setup failed");
if (is_null_sha1(sb.final->object.sha1)) {
- char *buf;
o = sb.final->util;
- buf = xmalloc(o->file.size + 1);
- memcpy(buf, o->file.ptr, o->file.size + 1);
- sb.final_buf = buf;
+ sb.final_buf = xmemdupz(o->file.ptr, o->file.size);
sb.final_buf_size = o->file.size;
}
else {
diff --git a/builtin/clean.c b/builtin/clean.c
index 9a9151575d..1032563e5f 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
@@ -621,8 +621,7 @@ static int *list_and_choose(struct menu_opts *opts, struct menu_stuff *stuff)
nr += chosen[i];
}
- result = xmalloc(sizeof(int) * (nr + 1));
- memset(result, 0, sizeof(int) * (nr + 1));
+ result = xcalloc(nr + 1, sizeof(int));
for (i = 0; i < stuff->nr && j < nr; i++) {
if (chosen[i])
result[j++] = i;
diff --git a/builtin/clone.c b/builtin/clone.c
index 9b3c04d914..545105a86f 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -695,7 +695,7 @@ static void write_refspec_config(const char* src_ref_prefix,
if (option_mirror || !option_bare) {
if (option_single_branch && !option_mirror) {
if (option_branch) {
- if (strstr(our_head_points_at->name, "refs/tags/"))
+ if (starts_with(our_head_points_at->name, "refs/tags/"))
strbuf_addf(&value, "+%s:%s", our_head_points_at->name,
our_head_points_at->name);
else
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 9cfef6c6cc..39cf8976e3 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -650,9 +650,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) {
@@ -833,8 +832,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);
@@ -1659,8 +1672,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/fast-export.c b/builtin/fast-export.c
index b8d8a3aaf9..05d161f19f 100644
--- a/builtin/fast-export.c
+++ b/builtin/fast-export.c
@@ -279,6 +279,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 +289,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 +337,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);
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/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..b8d440d0e0 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -874,6 +874,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 b9f6e12c0e..9ca0203922 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -40,17 +40,13 @@ struct base_data {
int ofs_first, ofs_last;
};
-#if !defined(NO_PTHREADS) && defined(NO_THREAD_SAFE_PREAD)
-/* pread() emulation is not thread-safe. Disable threading. */
-#define NO_PTHREADS
-#endif
-
struct thread_local {
#ifndef NO_PTHREADS
pthread_t thread;
#endif
struct base_data *base_cache;
size_t base_cache_used;
+ int pack_fd;
};
/*
@@ -91,7 +87,8 @@ static off_t consumed_bytes;
static unsigned deepest_delta;
static git_SHA_CTX input_ctx;
static uint32_t input_crc32;
-static int input_fd, output_fd, pack_fd;
+static int input_fd, output_fd;
+static const char *curr_pack;
#ifndef NO_PTHREADS
@@ -134,6 +131,7 @@ static inline void unlock_mutex(pthread_mutex_t *mutex)
*/
static void init_thread(void)
{
+ int i;
init_recursive_mutex(&read_mutex);
pthread_mutex_init(&counter_mutex, NULL);
pthread_mutex_init(&work_mutex, NULL);
@@ -141,11 +139,18 @@ static void init_thread(void)
pthread_mutex_init(&deepest_delta_mutex, NULL);
pthread_key_create(&key, NULL);
thread_data = xcalloc(nr_threads, sizeof(*thread_data));
+ for (i = 0; i < nr_threads; i++) {
+ thread_data[i].pack_fd = open(curr_pack, O_RDONLY);
+ if (thread_data[i].pack_fd == -1)
+ die_errno(_("unable to open %s"), curr_pack);
+ }
+
threads_active = 1;
}
static void cleanup_thread(void)
{
+ int i;
if (!threads_active)
return;
threads_active = 0;
@@ -154,6 +159,8 @@ static void cleanup_thread(void)
pthread_mutex_destroy(&work_mutex);
if (show_stat)
pthread_mutex_destroy(&deepest_delta_mutex);
+ for (i = 0; i < nr_threads; i++)
+ close(thread_data[i].pack_fd);
pthread_key_delete(key);
free(thread_data);
}
@@ -200,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;
}
@@ -288,13 +300,13 @@ static const char *open_pack_file(const char *pack_name)
output_fd = open(pack_name, O_CREAT|O_EXCL|O_RDWR, 0600);
if (output_fd < 0)
die_errno(_("unable to create '%s'"), pack_name);
- pack_fd = output_fd;
+ nothread_data.pack_fd = output_fd;
} else {
input_fd = open(pack_name, O_RDONLY);
if (input_fd < 0)
die_errno(_("cannot open packfile '%s'"), pack_name);
output_fd = -1;
- pack_fd = input_fd;
+ nothread_data.pack_fd = input_fd;
}
git_SHA1_Init(&input_ctx);
return pack_name;
@@ -350,8 +362,7 @@ static void set_thread_data(struct thread_local *data)
static struct base_data *alloc_base_data(void)
{
- struct base_data *base = xmalloc(sizeof(struct base_data));
- memset(base, 0, sizeof(*base));
+ struct base_data *base = xcalloc(1, sizeof(struct base_data));
base->ref_last = -1;
base->ofs_last = -1;
return base;
@@ -542,7 +553,7 @@ static void *unpack_data(struct object_entry *obj,
do {
ssize_t n = (len < 64*1024) ? len : 64*1024;
- n = pread(pack_fd, inbuf, n, from);
+ n = xpread(get_thread_data()->pack_fd, inbuf, n, from);
if (n < 0)
die_errno(_("cannot pread pack file"));
if (!n)
@@ -774,7 +785,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;
}
@@ -1490,7 +1502,7 @@ static void show_pack_info(int stat_only)
int cmd_index_pack(int argc, const char **argv, const char *prefix)
{
int i, fix_thin_pack = 0, verify = 0, stat_only = 0;
- const char *curr_pack, *curr_index;
+ const char *curr_index;
const char *index_name = NULL, *pack_name = NULL;
const char *keep_name = NULL, *keep_msg = NULL;
char *index_name_buf = NULL, *keep_name_buf = NULL;
diff --git a/builtin/log.c b/builtin/log.c
index 39e8836352..4f678136d1 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -158,13 +158,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 +345,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;
@@ -919,9 +914,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);
@@ -1508,8 +1506,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 66d8843301..8763b2efa2 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/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..36c1cf9c25 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 = -1;
static char *packdir, *packtmp;
static const char *const git_repack_usage[] = {
@@ -27,6 +28,10 @@ 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, "pack.writebitmaps")) {
+ write_bitmaps = git_config_bool(var, value);
+ return 0;
+ }
return git_default_config(var, value, cb);
}
@@ -149,7 +154,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 +172,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 +195,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 > 0;
packdir = mkpathdup("%s/pack", get_object_directory());
packtmp = mkpathdup("%s/.tmp-%d-pack", packdir, (int)getpid());
@@ -217,9 +221,9 @@ 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)
+ if (write_bitmaps >= 0)
argv_array_pushf(&cmd_args, "--%swrite-bitmap-index",
- write_bitmap ? "" : "no-");
+ write_bitmaps ? "" : "no-");
if (pack_everything & ALL_INTO_ONE) {
get_non_kept_pack_filenames(&existing_packs);
diff --git a/builtin/rerere.c b/builtin/rerere.c
index 4e51addb3e..98eb8c5404 100644
--- a/builtin/rerere.c
+++ b/builtin/rerere.c
@@ -60,6 +60,8 @@ int cmd_rerere(int argc, const char **argv, const char *prefix)
argc = parse_options(argc, argv, prefix, options, rerere_usage, 0);
+ git_config(git_xmerge_config, NULL);
+
if (autoupdate == 1)
flags = RERERE_AUTOUPDATE;
if (autoupdate == 0)
diff --git a/builtin/reset.c b/builtin/reset.c
index f4e087596b..6bd6245821 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/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)
diff --git a/cache.h b/cache.h
index 107ac61b68..cc46be4e0f 100644
--- a/cache.h
+++ b/cache.h
@@ -279,6 +279,7 @@ struct index_state {
initialized : 1;
struct hashmap name_hash;
struct hashmap dir_hash;
+ unsigned char sha1[20];
};
extern struct index_state the_index;
@@ -1322,6 +1323,8 @@ extern void fsync_or_die(int fd, const char *);
extern ssize_t read_in_full(int fd, void *buf, size_t count);
extern ssize_t write_in_full(int fd, const void *buf, size_t count);
+extern ssize_t pread_in_full(int fd, void *buf, size_t count, off_t offset);
+
static inline ssize_t write_str_in_full(int fd, const char *str)
{
return write_in_full(fd, str, strlen(str));
diff --git a/combine-diff.c b/combine-diff.c
index 24ca7e2334..fd6d63c703 100644
--- a/combine-diff.c
+++ b/combine-diff.c
@@ -1339,7 +1339,8 @@ void diff_tree_combined(const unsigned char *sha1,
if (show_log_first && i == 0) {
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 */
diff --git a/commit.c b/commit.c
index f4793316a2..4ff8077dbf 100644
--- a/commit.c
+++ b/commit.c
@@ -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))
diff --git a/commit.h b/commit.h
index a9f177ba48..2e1492a6e4 100644
--- a/commit.h
+++ b/commit.h
@@ -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..363a957a1d 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -1226,8 +1226,7 @@ static int WSAAPI getaddrinfo_stub(const char *node, const char *service,
else
ai->ai_canonname = NULL;
- sin = xmalloc(ai->ai_addrlen);
- memset(sin, 0, ai->ai_addrlen);
+ sin = xcalloc(1, ai->ai_addrlen);
sin->sin_family = AF_INET;
/* Note: getaddrinfo is supposed to allow service to be a string,
* which should be looked up using getservbyname. This is
diff --git a/compat/mmap.c b/compat/mmap.c
index c9d46d1742..7f662fef7b 100644
--- a/compat/mmap.c
+++ b/compat/mmap.c
@@ -14,7 +14,7 @@ void *git_mmap(void *start, size_t length, int prot, int flags, int fd, off_t of
}
while (n < length) {
- ssize_t count = pread(fd, (char *)start + n, length - n, offset + n);
+ ssize_t count = xpread(fd, (char *)start + n, length - n, offset + n);
if (count == 0) {
memset((char *)start+n, 0, length-n);
@@ -22,8 +22,6 @@ void *git_mmap(void *start, size_t length, int prot, int flags, int fd, off_t of
}
if (count < 0) {
- if (errno == EAGAIN || errno == EINTR)
- continue;
free(start);
errno = EACCES;
return MAP_FAILED;
diff --git a/config.c b/config.c
index a30cb5c07d..2634457f6b 100644
--- a/config.c
+++ b/config.c
@@ -952,7 +952,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 +1538,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));
@@ -1793,7 +1793,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);
diff --git a/config.mak.uname b/config.mak.uname
index 23a8803656..7846bd7657 100644
--- a/config.mak.uname
+++ b/config.mak.uname
@@ -157,7 +157,6 @@ ifeq ($(uname_O),Cygwin)
NO_SYMLINK_HEAD = YesPlease
NO_IPV6 = YesPlease
OLD_ICONV = UnfortunatelyYes
- NO_THREAD_SAFE_PREAD = YesPlease
# There are conflicting reports about this.
# On some boxes NO_MMAP is needed, and not so elsewhere.
# Try commenting this out if you suspect MMAP is more efficient
diff --git a/connect.c b/connect.c
index a983d061a9..ebc3a5be7d 100644
--- a/connect.c
+++ b/connect.c
@@ -64,9 +64,7 @@ static void parse_one_symref_info(struct string_list *symref, const char *val, i
if (!len)
return; /* just "symref" */
/* e.g. "symref=HEAD:refs/heads/master" */
- sym = xmalloc(len + 1);
- memcpy(sym, val, len);
- sym[len] = '\0';
+ sym = xmemdupz(val, len);
target = strchr(sym, ':');
if (!target)
/* just "symref=something" */
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 2c59a76bc2..019026efcb 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -1472,9 +1472,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 +1486,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/subtree/t/t7900-subtree.sh b/contrib/subtree/t/t7900-subtree.sh
index 66ce4b07c2..8dc6840353 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/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)),
diff --git a/diff.c b/diff.c
index f72769a1c4..3f1f08f9fd 100644
--- a/diff.c
+++ b/diff.c
@@ -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) {
@@ -3325,6 +3325,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)
diff --git a/dir.c b/dir.c
index eb6f581270..797805d6a1 100644
--- a/dir.c
+++ b/dir.c
@@ -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,
diff --git a/fsck.c b/fsck.c
index abed62bac7..a7233c8d0b 100644
--- a/fsck.c
+++ b/fsck.c
@@ -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-compat-util.h b/git-compat-util.h
index f6d3a46622..e6a4159a25 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -531,6 +531,7 @@ extern void *xcalloc(size_t nmemb, size_t size);
extern void *xmmap(void *start, size_t length, int prot, int flags, int fd, off_t offset);
extern ssize_t xread(int fd, void *buf, size_t len);
extern ssize_t xwrite(int fd, const void *buf, size_t len);
+extern ssize_t xpread(int fd, void *buf, size_t len, off_t offset);
extern int xdup(int fd);
extern FILE *xfdopen(int fd, const char *mode);
extern int xmkstemp(char *template);
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-pull.sh b/git-pull.sh
index 6cd8ebc534..7358fac864 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..f267d8b6c3 100644
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -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 71429fd743..66c64d7ef2 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 4543815ffd..47ca3b990b 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-stash.sh b/git-stash.sh
index 4798bcf0e5..4621d81fab 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/http-backend.c b/http-backend.c
index d2c0a625ce..f6b7a5bae1 100644
--- a/http-backend.c
+++ b/http-backend.c
@@ -607,9 +607,7 @@ int main(int argc, char **argv)
cmd = c;
n = out[0].rm_eo - out[0].rm_so;
- cmd_arg = xmalloc(n);
- memcpy(cmd_arg, dir + out[0].rm_so + 1, n-1);
- cmd_arg[n-1] = '\0';
+ cmd_arg = xmemdupz(dir + out[0].rm_so + 1, n - 1);
dir[out[0].rm_so] = 0;
break;
}
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++) {
diff --git a/imap-send.c b/imap-send.c
index 0bc6f7fae1..45230e19cd 100644
--- a/imap-send.c
+++ b/imap-send.c
@@ -951,7 +951,7 @@ static struct imap_store *imap_open_store(struct imap_server_conf *srvc)
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;
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/notes-cache.c b/notes-cache.c
index eabe4a0d9b..25b20aa21f 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, 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 4aa7023903..f6891f7255 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, 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);
diff --git a/notes.c b/notes.c
index 5f07c0b7f2..5fe691dbcd 100644
--- a/notes.c
+++ b/notes.c
@@ -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;
diff --git a/object.c b/object.c
index 57a0890a87..9c31e9a5e0 100644
--- a/object.c
+++ b/object.c
@@ -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;
diff --git a/pager.c b/pager.c
index 0cc75a8eee..53670a63a7 100644
--- a/pager.c
+++ b/pager.c
@@ -64,7 +64,7 @@ void setup_pager(void)
{
const char *pager = git_pager(isatty(1));
- if (!pager || pager_in_use())
+ if (!pager)
return;
/*
diff --git a/path.c b/path.c
index f9c5062427..c36f003930 100644
--- a/path.c
+++ b/path.c
@@ -249,9 +249,7 @@ int validate_headref(const char *path)
static struct passwd *getpw_str(const char *username, size_t len)
{
struct passwd *pw;
- char *username_z = xmalloc(len + 1);
- memcpy(username_z, username, len);
- username_z[len] = '\0';
+ char *username_z = xmemdupz(username, len);
pw = getpwnam(username_z);
free(username_z);
return pw;
diff --git a/pathspec.c b/pathspec.c
index 8043099955..0be5edbd13 100644
--- a/pathspec.c
+++ b/pathspec.c
@@ -389,8 +389,7 @@ void parse_pathspec(struct pathspec *pathspec,
if (!(flags & PATHSPEC_PREFER_CWD))
die("BUG: PATHSPEC_PREFER_CWD requires arguments");
- pathspec->items = item = xmalloc(sizeof(*item));
- memset(item, 0, sizeof(*item));
+ pathspec->items = item = xcalloc(1, sizeof(*item));
item->match = prefix;
item->original = prefix;
item->nowildcard_len = item->len = strlen(prefix);
diff --git a/pretty.c b/pretty.c
index 3c43db558a..f3e8b6c5bc 100644
--- a/pretty.c
+++ b/pretty.c
@@ -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;
@@ -1267,6 +1249,8 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
if (c->signature_check.key)
strbuf_addstr(sb, c->signature_check.key);
break;
+ default:
+ return 0;
}
return 2;
}
@@ -1506,13 +1490,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 +1520,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 +1689,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 +1756,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 ba13353b37..7f5645e745 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -1477,6 +1477,7 @@ int read_index_from(struct index_state *istate, const char *path)
if (verify_hdr(hdr, mmap_size) < 0)
goto unmap;
+ hashcpy(istate->sha1, (unsigned char *)hdr + mmap_size - 20);
istate->version = ntohl(hdr->hdr_version);
istate->cache_nr = ntohl(hdr->hdr_entries);
istate->cache_alloc = alloc_nr(istate->cache_nr);
@@ -1760,6 +1761,50 @@ static int ce_write_entry(git_SHA_CTX *c, int fd, struct cache_entry *ce,
return result;
}
+/*
+ * This function verifies if index_state has the correct sha1 of the
+ * index file. Don't die if we have any other failure, just return 0.
+ */
+static int verify_index_from(const struct index_state *istate, const char *path)
+{
+ int fd;
+ ssize_t n;
+ struct stat st;
+ unsigned char sha1[20];
+
+ if (!istate->initialized)
+ return 0;
+
+ fd = open(path, O_RDONLY);
+ if (fd < 0)
+ return 0;
+
+ if (fstat(fd, &st))
+ goto out;
+
+ if (st.st_size < sizeof(struct cache_header) + 20)
+ goto out;
+
+ n = pread_in_full(fd, sha1, 20, st.st_size - 20);
+ if (n != 20)
+ goto out;
+
+ if (hashcmp(istate->sha1, sha1))
+ goto out;
+
+ close(fd);
+ return 1;
+
+out:
+ close(fd);
+ return 0;
+}
+
+static int verify_index(const struct index_state *istate)
+{
+ return verify_index_from(istate, get_index_file());
+}
+
static int has_racy_timestamp(struct index_state *istate)
{
int entries = istate->cache_nr;
@@ -1779,7 +1824,7 @@ static int has_racy_timestamp(struct index_state *istate)
void update_index_if_able(struct index_state *istate, struct lock_file *lockfile)
{
if ((istate->cache_changed || has_racy_timestamp(istate)) &&
- !write_index(istate, lockfile->fd))
+ verify_index(istate) && !write_index(istate, lockfile->fd))
commit_locked_index(lockfile);
else
rollback_lock_file(lockfile);
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;
}
diff --git a/refs.c b/refs.c
index 28d5eca8ea..59fb70087a 100644
--- a/refs.c
+++ b/refs.c
@@ -1611,6 +1611,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;
};
@@ -1625,8 +1626,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);
@@ -1639,6 +1644,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);
}
@@ -2431,7 +2448,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;
diff --git a/refs.h b/refs.h
index 87a1a79ad6..1440acc06c 100644
--- a/refs.h
+++ b/refs.h
@@ -89,6 +89,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
@@ -132,6 +133,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 *);
/*
diff --git a/remote.c b/remote.c
index eea2c8de45..0e9459cc06 100644
--- a/remote.c
+++ b/remote.c
@@ -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;
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/sequencer.c b/sequencer.c
index bde5f047b0..bbaddcb05a 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)
@@ -485,7 +450,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;
@@ -650,7 +615,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;
@@ -697,10 +662,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/sh-i18n--envsubst.c b/sh-i18n--envsubst.c
index 855d28cf94..6dd03a974a 100644
--- a/sh-i18n--envsubst.c
+++ b/sh-i18n--envsubst.c
@@ -278,9 +278,7 @@ static string_list_ty variables_set;
static void
note_variable (const char *var_ptr, size_t var_len)
{
- char *string = xmalloc (var_len + 1);
- memcpy (string, var_ptr, var_len);
- string[var_len] = '\0';
+ char *string = xmemdupz (var_ptr, var_len);
string_list_append (&variables_set, string);
}
diff --git a/sha1_file.c b/sha1_file.c
index 3e9f55f1bb..a38854ce55 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -315,7 +315,8 @@ static int link_alt_odb_entry(const char *entry, const char *relative_base, int
* thing twice, or object directory itself.
*/
for (alt = alt_odb_list; alt; alt = alt->next) {
- if (!memcmp(ent->base, alt->base, pfxlen)) {
+ if (pfxlen == alt->name - alt->base - 1 &&
+ !memcmp(ent->base, alt->base, pfxlen)) {
free(ent);
return -1;
}
@@ -1437,19 +1438,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(&regex, 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;
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/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/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/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/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/t4107-apply-ignore-whitespace.sh b/t/t4107-apply-ignore-whitespace.sh
index b04fc8fc12..9e29b5262d 100755
--- a/t/t4107-apply-ignore-whitespace.sh
+++ b/t/t4107-apply-ignore-whitespace.sh
@@ -111,7 +111,6 @@ sed -e 's/T/ /g' > main.c.final <<\EOF
#include <stdio.h>
void print_int(int num);
-T/* a comment */
int func(int num);
int main() {
@@ -154,7 +153,8 @@ test_expect_success 'patch2 reverse applies with --ignore-space-change' '
git config apply.ignorewhitespace change
test_expect_success 'patch2 applies (apply.ignorewhitespace = change)' '
- git apply patch2.patch
+ git apply patch2.patch &&
+ test_cmp main.c.final main.c
'
test_expect_success 'patch3 fails (missing string at EOL)' '
@@ -165,12 +165,8 @@ test_expect_success 'patch4 fails (missing EOL at EOF)' '
test_must_fail git apply patch4.patch
'
-test_expect_success 'patch5 applies (leading whitespace)' '
- git apply patch5.patch
-'
-
-test_expect_success 'patches do not mangle whitespace' '
- test_cmp main.c main.c.final
+test_expect_success 'patch5 fails (leading whitespace differences matter)' '
+ test_must_fail git apply patch5.patch
'
test_expect_success 're-create file (with --ignore-whitespace)' '
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/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/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/t5537-fetch-shallow.sh b/t/t5537-fetch-shallow.sh
index be951a4679..a980574682 100755
--- a/t/t5537-fetch-shallow.sh
+++ b/t/t5537-fetch-shallow.sh
@@ -173,33 +173,6 @@ EOF
)
'
-if test -n "$NO_CURL" -o -z "$GIT_TEST_HTTPD"; then
- say 'skipping remaining tests, git built without http support'
- test_done
-fi
-
-LIB_HTTPD_PORT=${LIB_HTTPD_PORT-'5537'}
-. "$TEST_DIRECTORY"/lib-httpd.sh
-start_httpd
-
-test_expect_success 'clone http repository' '
- git clone --bare --no-local shallow "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
- git clone $HTTPD_URL/smart/repo.git clone &&
- (
- cd clone &&
- git fsck &&
- git log --format=%s origin/master >actual &&
- cat <<EOF >expect &&
-7
-6
-5
-4
-3
-EOF
- test_cmp expect actual
- )
-'
-
test_expect_success POSIXPERM,SANITY 'shallow fetch from a read-only repo' '
cp -R .git read-only.git &&
find read-only.git -print | xargs chmod -w &&
@@ -213,5 +186,4 @@ EOF
test_cmp expect actual
'
-stop_httpd
test_done
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/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/t6006-rev-list-format.sh b/t/t6006-rev-list-format.sh
index 9d9d9de08e..88ed3191e8 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' '
@@ -394,4 +468,10 @@ test_expect_success 'single-character name is parsed correctly' '
test_cmp expect actual
'
+test_expect_success 'unused %G placeholders are passed through' '
+ echo "%GX %G" >expect &&
+ git log -1 --format="%GX %G" >actual &&
+ test_cmp expect actual
+'
+
test_done
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/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/t7508-status.sh b/t/t7508-status.sh
index c987b5ed65..d48006960e 100755
--- a/t/t7508-status.sh
+++ b/t/t7508-status.sh
@@ -1380,7 +1380,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 +1413,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 +1486,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/t7510-signed-commit.sh b/t/t7510-signed-commit.sh
index 5ddac1a9f7..e97477a3b9 100755
--- a/t/t7510-signed-commit.sh
+++ b/t/t7510-signed-commit.sh
@@ -43,31 +43,44 @@ test_expect_success GPG 'create signed commits' '
test_tick && git rebase -f HEAD^^ && git tag sixth-signed HEAD^ &&
git tag seventh-signed
+
+ echo 8 >file && test_tick && git commit -a -m eighth -SB7227189 &&
+ git tag eighth-signed-alt
'
test_expect_success GPG 'show signatures' '
(
- for commit in initial second merge fourth-signed fifth-signed sixth-signed master
+ for commit in initial second merge fourth-signed fifth-signed sixth-signed seventh-signed
do
git show --pretty=short --show-signature $commit >actual &&
- grep "Good signature from" actual || exit 1
- ! grep "BAD signature from" actual || exit 1
- echo $commit OK
+ grep "Good signature from" actual &&
+ ! grep "BAD signature from" actual &&
+ echo $commit OK || exit 1
done
) &&
(
for commit in merge^2 fourth-unsigned sixth-unsigned seventh-unsigned
do
git show --pretty=short --show-signature $commit >actual &&
- grep "Good signature from" actual && exit 1
- ! grep "BAD signature from" actual || exit 1
- echo $commit OK
+ ! grep "Good signature from" actual &&
+ ! grep "BAD signature from" actual &&
+ echo $commit OK || exit 1
+ done
+ ) &&
+ (
+ for commit in eighth-signed-alt
+ do
+ git show --pretty=short --show-signature $commit >actual &&
+ grep "Good signature from" actual &&
+ ! grep "BAD signature from" actual &&
+ grep "not certified" actual &&
+ echo $commit OK || exit 1
done
)
'
test_expect_success GPG 'detect fudged signature' '
- git cat-file commit master >raw &&
+ git cat-file commit seventh-signed >raw &&
sed -e "s/seventh/7th forged/" raw >forged1 &&
git hash-object -w -t commit forged1 >forged1.commit &&
@@ -77,7 +90,7 @@ test_expect_success GPG 'detect fudged signature' '
'
test_expect_success GPG 'detect fudged signature with NUL' '
- git cat-file commit master >raw &&
+ git cat-file commit seventh-signed >raw &&
cat raw >forged2 &&
echo Qwik | tr "Q" "\000" >>forged2 &&
git hash-object -w -t commit forged2 >forged2.commit &&
@@ -94,4 +107,44 @@ test_expect_success GPG 'amending already signed commit' '
! grep "BAD signature from" actual
'
+test_expect_success GPG 'show good signature with custom format' '
+ cat >expect <<-\EOF &&
+ G
+ 13B6F51ECDDE430D
+ C O Mitter <committer@example.com>
+ EOF
+ git log -1 --format="%G?%n%GK%n%GS" sixth-signed >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success GPG 'show bad signature with custom format' '
+ cat >expect <<-\EOF &&
+ B
+ 13B6F51ECDDE430D
+ C O Mitter <committer@example.com>
+ EOF
+ git log -1 --format="%G?%n%GK%n%GS" $(cat forged1.commit) >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success GPG 'show unknown signature with custom format' '
+ cat >expect <<-\EOF &&
+ U
+ 61092E85B7227189
+ Eris Discordia <discord@example.net>
+ EOF
+ git log -1 --format="%G?%n%GK%n%GS" eighth-signed-alt >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success GPG 'show lack of signature with custom format' '
+ cat >expect <<-\EOF &&
+ N
+
+
+ EOF
+ git log -1 --format="%G?%n%GK%n%GS" seventh-unsigned >actual &&
+ test_cmp expect actual
+'
+
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..61e6ed37aa 100755
--- a/t/t7700-repack.sh
+++ b/t/t7700-repack.sh
@@ -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 pack.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/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/transport-helper.c b/transport-helper.c
index b468e4f88e..b9ba0416b2 100644
--- a/transport-helper.c
+++ b/transport-helper.c
@@ -1026,7 +1026,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/wrapper.c b/wrapper.c
index 0cc56368bd..bc1bfb8600 100644
--- a/wrapper.c
+++ b/wrapper.c
@@ -174,6 +174,24 @@ ssize_t xwrite(int fd, const void *buf, size_t len)
}
}
+/*
+ * xpread() is the same as pread(), but it automatically restarts pread()
+ * operations with a recoverable error (EAGAIN and EINTR). xpread() DOES
+ * NOT GUARANTEE that "len" bytes is read even if the data is available.
+ */
+ssize_t xpread(int fd, void *buf, size_t len, off_t offset)
+{
+ ssize_t nr;
+ if (len > MAX_IO_SIZE)
+ len = MAX_IO_SIZE;
+ while (1) {
+ nr = pread(fd, buf, len, offset);
+ if ((nr < 0) && (errno == EAGAIN || errno == EINTR))
+ continue;
+ return nr;
+ }
+}
+
ssize_t read_in_full(int fd, void *buf, size_t count)
{
char *p = buf;
@@ -214,6 +232,26 @@ ssize_t write_in_full(int fd, const void *buf, size_t count)
return total;
}
+ssize_t pread_in_full(int fd, void *buf, size_t count, off_t offset)
+{
+ char *p = buf;
+ ssize_t total = 0;
+
+ while (count > 0) {
+ ssize_t loaded = xpread(fd, p, count, offset);
+ if (loaded < 0)
+ return -1;
+ if (loaded == 0)
+ return total;
+ count -= loaded;
+ p += loaded;
+ total += loaded;
+ offset += loaded;
+ }
+
+ return total;
+}
+
int xdup(int fd)
{
int ret = dup(fd);
diff --git a/wt-status.c b/wt-status.c
index ec7344e508..86fec8986f 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -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;