diff options
351 files changed, 17175 insertions, 4711 deletions
diff --git a/Documentation/Makefile b/Documentation/Makefile index 7a8037f586..06b0c57b95 100644 --- a/Documentation/Makefile +++ b/Documentation/Makefile @@ -84,7 +84,7 @@ endif # ifdef ASCIIDOC8 -ASCIIDOC_EXTRA += -a asciidoc7compatible +ASCIIDOC_EXTRA += -a asciidoc7compatible -a no-inline-literal endif ifdef DOCBOOK_XSL_172 ASCIIDOC_EXTRA += -a git-asciidoc-no-roff diff --git a/Documentation/RelNotes-1.6.4.1.txt b/Documentation/RelNotes-1.6.4.1.txt new file mode 100644 index 0000000000..e439e45b96 --- /dev/null +++ b/Documentation/RelNotes-1.6.4.1.txt @@ -0,0 +1,46 @@ +GIT v1.6.4.1 Release Notes +========================== + +Fixes since v1.6.4 +------------------ + + * An unquoted value in the configuration file, when it contains more than + one whitespaces in a row, got them replaced with a single space. + + * "git am" used to accept a single piece of e-mail per file (not a mbox) + as its input, but multiple input format support in v1.6.4 broke it. + Apparently many people have been depending on this feature. + + * The short help text for "git filter-branch" command was a single long + line, wrapped by terminals, and was hard to read. + + * The "recursive" strategy of "git merge" segfaulted when a merge has + more than one merge-bases, and merging of these merge-bases involves + a rename/rename or a rename/add conflict. + + * "git pull --rebase" did not use the right fork point when the + repository has already fetched from the upstream that rewinds the + branch it is based on in an earlier fetch. + + * Explain the concept of fast-forward more fully in "git push" + documentation, and hint to refer to it from an error message when the + command refuses an update to protect the user. + + * The default value for pack.deltacachesize, used by "git repack", is now + 256M, instead of unbounded. Otherwise a repack of a moderately sized + repository would needlessly eat into swap. + + * Document how "git repack" (hence "git gc") interacts with a repository + that borrows its objects from other repositories (e.g. ones created by + "git clone -s"). + + * "git show" on an annotated tag lacked a delimiting blank line between + the tag itself and the contents of the object it tags. + + * "git verify-pack -v" erroneously reported number of objects with too + deep delta depths as "chain length 0" objects. + + * Long names of authors and committers outside US-ASCII were sometimes + incorrectly shown in "gitweb". + +Other minor documentation updates are included. diff --git a/Documentation/RelNotes-1.6.4.2.txt b/Documentation/RelNotes-1.6.4.2.txt new file mode 100644 index 0000000000..c11ec0115c --- /dev/null +++ b/Documentation/RelNotes-1.6.4.2.txt @@ -0,0 +1,32 @@ +GIT v1.6.4.2 Release Notes +========================== + +Fixes since v1.6.4.1 +-------------------- + +* --date=relative output between 1 and 5 years ago rounded the number of + years when saying X years Y months ago, instead of rounding it down. + +* "git add -p" did not handle changes in executable bits correctly + (a regression around 1.6.3). + +* "git apply" did not honor GNU diff's convention to mark the creation/deletion + event with UNIX epoch timestamp on missing side. + +* "git checkout" incorrectly removed files in a directory pointed by a + symbolic link during a branch switch that replaces a directory with + a symbolic link. + +* "git clean -d -f" happily descended into a subdirectory that is managed by a + separate git repository. It now requires two -f options for safety. + +* "git fetch/push" over http transports had two rather grave bugs. + +* "git format-patch --cover-letter" did not prepare the cover letter file + for use with non-ASCII strings when there are the series contributors with + non-ASCII names. + +* "git pull origin branch" and "git fetch origin && git merge origin/branch" + left different merge messages in the resulting commit. + +Other minor documentation updates are included. diff --git a/Documentation/RelNotes-1.6.4.txt b/Documentation/RelNotes-1.6.4.txt new file mode 100644 index 0000000000..7a904419f7 --- /dev/null +++ b/Documentation/RelNotes-1.6.4.txt @@ -0,0 +1,147 @@ +GIT v1.6.4 Release Notes +======================== + +With the next major release, "git push" into a branch that is +currently checked out will be refused by default. You can choose +what should happen upon such a push by setting the configuration +variable receive.denyCurrentBranch in the receiving repository. + +To ease the transition plan, the receiving repository of such a +push running this release will issue a big warning when the +configuration variable is missing. Please refer to: + + http://git.or.cz/gitwiki/GitFaq#non-bare + http://thread.gmane.org/gmane.comp.version-control.git/107758/focus=108007 + +for more details on the reason why this change is needed and the +transition plan. + +For a similar reason, "git push $there :$killed" to delete the branch +$killed in a remote repository $there, if $killed branch is the current +branch pointed at by its HEAD, gets a large warning. You can choose what +should happen upon such a push by setting the configuration variable +receive.denyDeleteCurrent in the receiving repository. + + +Updates since v1.6.3 +-------------------- + +(subsystems) + + * gitweb Perl style clean-up. + + * git-svn updates, including a new --authors-prog option to map author + names by invoking an external program, 'git svn reset' to unwind + 'git svn fetch', support for more than one branches, documenting + of the useful --minimize-url feature, new "git svn gc" command, etc. + +(portability) + + * We feed iconv with "UTF-8" instead of "utf8"; the former is + understood more widely. Similarly updated test scripts to use + encoding names more widely understood (e.g. use "ISO8859-1" instead + of "ISO-8859-1"). + + * Various portability fixes/workarounds for different vintages of + SunOS, IRIX, and Windows. + + * Git-over-ssh transport on Windows supports PuTTY plink and TortoisePlink. + +(performance) + + * Many repeated use of lstat() are optimized out in "checkout" codepath. + + * git-status (and underlying git-diff-index --cached) are optimized + to take advantage of cache-tree information in the index. + +(usability, bells and whistles) + + * "git add --edit" lets users edit the whole patch text to fine-tune what + is added to the index. + + * "git am" accepts StGIT series file as its input. + + * "git bisect skip" skips to a more randomly chosen place in the hope + to avoid testing a commit that is too close to a commit that is + already known to be untestable. + + * "git cvsexportcommit" learned -k option to stop CVS keywords expansion + + * "git fast-export" learned to handle history simplification more + gracefully. + + * "git fast-export" learned an option --tag-of-filtered-object to handle + dangling tags resulting from history simplification more usefully. + + * "git grep" learned -p option to show the location of the match using the + same context hunk marker "git diff" uses. + + * https transport can optionally be told that the used client + certificate is password protected, in which case it asks the + password only once. + + * "git imap-send" is IPv6 aware. + + * "git log --graph" draws graphs more compactly by using horizontal lines + when able. + + * "git log --decorate" shows shorter refnames by stripping well-known + refs/* prefix. + + * "git push $name" honors remote.$name.pushurl if present before + using remote.$name.url. In other words, the URL used for fetching + and pushing can be different. + + * "git send-email" understands quoted aliases in .mailrc files (might + have to be backported to 1.6.3.X). + + * "git send-email" can fetch the sender address from the configuration + variable "sendmail.from" (and "sendmail.<identity>.from"). + + * "git show-branch" can color its output. + + * "add" and "update" subcommands to "git submodule" learned --reference + option to use local clone with references. + + * "git submodule update" learned --rebase option to update checked + out submodules by rebasing the local changes. + + * "gitweb" can optionally use gravatar to adorn author/committer names. + +(developers) + + * A major part of the "git bisect" wrapper has moved to C. + + * Formatting with the new version of AsciiDoc 8.4.1 is now supported. + +Fixes since v1.6.3 +------------------ + +All of the fixes in v1.6.3.X maintenance series are included in this +release, unless otherwise noted. + +Here are fixes that this release has, but have not been backported to +v1.6.3.X series. + + * "git diff-tree -r -t" used to omit new or removed directories from + the output. df533f3 (diff-tree -r -t: include added/removed + directories in the output, 2009-06-13) may need to be cherry-picked + to backport this fix. + + * The way Git.pm sets up a Repository object was not friendly to callers + that chdir around. It now internally records the repository location + as an absolute path when autodetected. + + * Removing a section with "git config --remove-section", when its + section header has a variable definition on the same line, lost + that variable definition. + + * "git rebase -p --onto" used to always leave side branches of a merge + intact, even when both branches are subject to rewriting. + + * "git repack" used to faithfully follow grafts and considered true + parents recorded in the commit object unreachable from the commit. + After such a repacking, you cannot remove grafts without corrupting + the repository. + + * "git send-email" did not detect erroneous loops in alias expansion. diff --git a/Documentation/config.txt b/Documentation/config.txt index ae0e5db50c..2632c5149e 100644 --- a/Documentation/config.txt +++ b/Documentation/config.txt @@ -49,7 +49,8 @@ There is also a case insensitive alternative `[section.subsection]` syntax. In this syntax, subsection names follow the same restrictions as for section names. -All the other lines are recognized as setting variables, in the form +All the other lines (and the remainder of the line after the section +header) are recognized as setting variables, in the form 'name = value'. If there is no equal sign on the line, the entire line is taken as 'name' and the variable is recognized as boolean "true". The variable names are case-insensitive and only alphanumeric @@ -604,13 +605,19 @@ color.interactive.<slot>:: Use customized color for 'git-add --interactive' output. `<slot>` may be `prompt`, `header`, `help` or `error`, for four distinct types of normal output from interactive - programs. The values of these variables may be specified as + commands. The values of these variables may be specified as in color.branch.<slot>. color.pager:: A boolean to enable/disable colored output when the pager is in use (default is true). +color.showbranch:: + A boolean to enable/disable color in the output of + linkgit:git-show-branch[1]. May be set to `always`, + `false` (or `never`) or `auto` (or `true`), in which case colors are used + only when the output is to a terminal. Defaults to false. + color.status:: A boolean to enable/disable color in the output of linkgit:git-status[1]. May be set to `always`, @@ -1039,6 +1046,12 @@ http.sslKey:: over HTTPS. Can be overridden by the 'GIT_SSL_KEY' environment variable. +http.sslCertPasswordProtected:: + Enable git's password prompt for the SSL certificate. Otherwise + OpenSSL will prompt the user, possibly many times, if the + certificate or private key is encrypted. Can be overridden by the + 'GIT_SSL_CERT_PASSWORD_PROTECTED' environment variable. + http.sslCAInfo:: File containing the certificates to verify the peer with when fetching or pushing over HTTPS. Can be overridden by the @@ -1100,7 +1113,7 @@ instaweb.port:: linkgit:git-instaweb[1]. interactive.singlekey:: - In interactive programs, allow the user to provide one-letter + In interactive commands, allow the user to provide one-letter input with a single key (i.e., without hitting enter). Currently this is used only by the `\--patch` mode of linkgit:git-add[1]. Note that this setting is silently @@ -1205,12 +1218,20 @@ pack.compression:: pack.deltaCacheSize:: The maximum memory in bytes used for caching deltas in - linkgit:git-pack-objects[1]. - A value of 0 means no limit. Defaults to 0. + linkgit:git-pack-objects[1] before writing them out to a pack. + This cache is used to speed up the writing object phase by not + having to recompute the final delta result once the best match + for all objects is found. Repacking large repositories on machines + which are tight with memory might be badly impacted by this though, + especially if this cache pushes the system into swapping. + A value of 0 means no limit. The smallest size of 1 byte may be + used to virtually disable this cache. Defaults to 256 MiB. pack.deltaCacheLimit:: The maximum size of a delta, that is cached in - linkgit:git-pack-objects[1]. Defaults to 1000. + linkgit:git-pack-objects[1]. This cache is used to speed up the + writing object phase by not having to recompute the final delta + result once the best match for all objects is found. Defaults to 1000. pack.threads:: Specifies the number of threads to spawn when searching for best @@ -1315,6 +1336,9 @@ remote.<name>.url:: The URL of a remote repository. See linkgit:git-fetch[1] or linkgit:git-push[1]. +remote.<name>.pushurl:: + The push URL of a remote repository. See linkgit:git-push[1]. + remote.<name>.proxy:: For remotes that require curl (http, https and ftp), the URL to the proxy to use for that remote. Set to the empty string to @@ -1372,6 +1396,50 @@ rerere.enabled:: default enabled if you create `rr-cache` directory under `$GIT_DIR`, but can be disabled by setting this option to false. +sendemail.identity:: + A configuration identity. When given, causes values in the + 'sendemail.<identity>' subsection to take precedence over + values in the 'sendemail' section. The default identity is + the value of 'sendemail.identity'. + +sendemail.smtpencryption:: + See linkgit:git-send-email[1] for description. Note that this + setting is not subject to the 'identity' mechanism. + +sendemail.smtpssl:: + Deprecated alias for 'sendemail.smtpencryption = ssl'. + +sendemail.<identity>.*:: + Identity-specific versions of the 'sendemail.*' parameters + found below, taking precedence over those when the this + identity is selected, through command-line or + 'sendemail.identity'. + +sendemail.aliasesfile:: +sendemail.aliasfiletype:: +sendemail.bcc:: +sendemail.cc:: +sendemail.cccmd:: +sendemail.chainreplyto:: +sendemail.confirm:: +sendemail.envelopesender:: +sendemail.from:: +sendemail.multiedit:: +sendemail.signedoffbycc:: +sendemail.smtppass:: +sendemail.suppresscc:: +sendemail.suppressfrom:: +sendemail.to:: +sendemail.smtpserver:: +sendemail.smtpserverport:: +sendemail.smtpuser:: +sendemail.thread:: +sendemail.validate:: + See linkgit:git-send-email[1] for description. + +sendemail.signedoffcc:: + Deprecated alias for 'sendemail.signedoffbycc'. + showbranch.default:: The default set of branches for linkgit:git-show-branch[1]. See linkgit:git-show-branch[1]. diff --git a/Documentation/diff-format.txt b/Documentation/diff-format.txt index 1eeb1c7683..b71712473e 100644 --- a/Documentation/diff-format.txt +++ b/Documentation/diff-format.txt @@ -1,4 +1,7 @@ -The output format from "git-diff-index", "git-diff-tree", +Raw output format +----------------- + +The raw output format from "git-diff-index", "git-diff-tree", "git-diff-files" and "git diff --raw" are very similar. These commands all compare two sets of things; what is @@ -16,6 +19,9 @@ git-diff-tree [-r] <tree-ish-1> <tree-ish-2> [<pattern>...]:: git-diff-files [<pattern>...]:: compares the index and the files on the filesystem. +The "git-diff-tree" command begins its ouput by printing the hash of +what is being compared. After that, all the commands print one output +line per changed file. An output line is formatted this way: diff --git a/Documentation/fetch-options.txt b/Documentation/fetch-options.txt index d313795fdb..5eb2b0ee07 100644 --- a/Documentation/fetch-options.txt +++ b/Documentation/fetch-options.txt @@ -1,11 +1,13 @@ +ifndef::git-pull[] -q:: --quiet:: Pass --quiet to git-fetch-pack and silence any other internally - used programs. + used git commands. -v:: --verbose:: Be verbose. +endif::git-pull[] -a:: --append:: diff --git a/Documentation/git-add.txt b/Documentation/git-add.txt index d938b42289..e67b7e875e 100644 --- a/Documentation/git-add.txt +++ b/Documentation/git-add.txt @@ -9,8 +9,8 @@ SYNOPSIS -------- [verse] 'git add' [-n] [-v] [--force | -f] [--interactive | -i] [--patch | -p] - [--all | [--update | -u]] [--intent-to-add | -N] - [--refresh] [--ignore-errors] [--] <filepattern>... + [--edit | -e] [--all | [--update | -u]] [--intent-to-add | -N] + [--refresh] [--ignore-errors] [--] [<filepattern>...] DESCRIPTION ----------- @@ -76,6 +76,15 @@ OPTIONS bypassed and the 'patch' subcommand is invoked using each of the specified filepatterns before exiting. +-e, \--edit:: + Open the diff vs. the index in an editor and let the user + edit it. After the editor was closed, adjust the hunk headers + and apply the patch to the index. ++ +*NOTE*: Obviously, if you change anything else than the first character +on lines beginning with a space or a minus, the patch will no longer +apply. + -u:: --update:: Update only files that git already knows about, staging modified diff --git a/Documentation/git-am.txt b/Documentation/git-am.txt index 6d92cbee64..32e689b2bf 100644 --- a/Documentation/git-am.txt +++ b/Documentation/git-am.txt @@ -13,7 +13,7 @@ SYNOPSIS [--3way] [--interactive] [--committer-date-is-author-date] [--ignore-date] [--whitespace=<option>] [-C<n>] [-p<n>] [--directory=<dir>] - [--reject] + [--reject] [-q | --quiet] [<mbox> | <Maildir>...] 'git am' (--skip | --resolved | --abort) @@ -39,6 +39,10 @@ OPTIONS --keep:: Pass `-k` flag to 'git-mailinfo' (see linkgit:git-mailinfo[1]). +-q:: +--quiet:: + Be quiet. Only print error messages. + -u:: --utf8:: Pass `-u` flag to 'git-mailinfo' (see linkgit:git-mailinfo[1]). diff --git a/Documentation/git-apply.txt b/Documentation/git-apply.txt index 9e5baa2777..735374d7df 100644 --- a/Documentation/git-apply.txt +++ b/Documentation/git-apply.txt @@ -3,7 +3,7 @@ git-apply(1) NAME ---- -git-apply - Apply a patch on a git index file and a working tree +git-apply - Apply a patch on a git index file and/or a working tree SYNOPSIS diff --git a/Documentation/git-archive.txt b/Documentation/git-archive.txt index bc132c87e1..92444ddf10 100644 --- a/Documentation/git-archive.txt +++ b/Documentation/git-archive.txt @@ -9,7 +9,7 @@ git-archive - Create an archive of files from a named tree SYNOPSIS -------- [verse] -'git archive' --format=<fmt> [--list] [--prefix=<prefix>/] [<extra>] +'git archive' [--format=<fmt>] [--list] [--prefix=<prefix>/] [<extra>] [--output=<file>] [--worktree-attributes] [--remote=<repo> [--exec=<git-upload-archive>]] <tree-ish> [path...] diff --git a/Documentation/git-bisect.txt b/Documentation/git-bisect.txt index ffc02c737c..63e7a42cb3 100644 --- a/Documentation/git-bisect.txt +++ b/Documentation/git-bisect.txt @@ -164,9 +164,8 @@ to do it for you by issuing the command: $ git bisect skip # Current version cannot be tested ------------ -But computing the commit to test may be slower afterwards and git may -eventually not be able to tell the first bad commit among a bad commit -and one or more skipped commits. +But git may eventually be unable to tell the first bad commit among +a bad commit and one or more skipped commits. You can even skip a range of commits, instead of just one commit, using the "'<commit1>'..'<commit2>'" notation. For example: diff --git a/Documentation/git-branch.txt b/Documentation/git-branch.txt index cbd4275871..ae201deb7a 100644 --- a/Documentation/git-branch.txt +++ b/Documentation/git-branch.txt @@ -111,6 +111,7 @@ OPTIONS --no-abbrev:: Display the full sha1s in the output listing rather than abbreviating them. +-t:: --track:: When creating a new branch, set up configuration to mark the start-point branch as "upstream" from the new branch. This diff --git a/Documentation/git-check-ref-format.txt b/Documentation/git-check-ref-format.txt index c1ce26884e..0b7982ea76 100644 --- a/Documentation/git-check-ref-format.txt +++ b/Documentation/git-check-ref-format.txt @@ -25,6 +25,10 @@ imposes the following rules on how references are named: grouping, but no slash-separated component can begin with a dot `.`. +. They must contain at least one `/`. This enforces the presence of a + category like `heads/`, `tags/` etc. but the actual names are not + restricted. + . They cannot have two consecutive dots `..` anywhere. . They cannot have ASCII control characters (i.e. bytes whose @@ -38,6 +42,8 @@ imposes the following rules on how references are named: . They cannot contain a sequence `@{`. +- They cannot contain a `\\`. + These rules make it easy for shell script based tools to parse reference names, pathname expansion by the shell when a reference name is used unquoted (by mistake), and also avoids ambiguities in certain diff --git a/Documentation/git-clean.txt b/Documentation/git-clean.txt index be894af39f..ae8938b2de 100644 --- a/Documentation/git-clean.txt +++ b/Documentation/git-clean.txt @@ -27,6 +27,9 @@ OPTIONS ------- -d:: Remove untracked directories in addition to untracked files. + If an untracked directory is managed by a different git + repository, it is not removed by default. Use -f option twice + if you really want to remove such a directory. -f:: If the git configuration specifies clean.requireForce as true, diff --git a/Documentation/git-clone.txt b/Documentation/git-clone.txt index b14de6c407..1709a2dbd0 100644 --- a/Documentation/git-clone.txt +++ b/Documentation/git-clone.txt @@ -72,11 +72,19 @@ These objects may be removed by normal git operations (such as 'git-commit') which automatically call `git gc --auto`. (See linkgit:git-gc[1].) If these objects are removed and were referenced by the cloned repository, then the cloned repository will become corrupt. - - ++ +Note that running `git repack` without the `-l` option in a repository +cloned with `-s` will copy objects from the source repository into a pack +in the cloned repository, removing the disk space savings of `clone -s`. +It is safe, however, to run `git gc`, which uses the `-l` option by +default. ++ +If you want to break the dependency of a repository cloned with `-s` on +its source repository, you can simply run `git repack -a` to copy all +objects from the source repository into a pack in the cloned repository. --reference <repository>:: - If the reference repository is on the local machine + If the reference repository is on the local machine, automatically setup .git/objects/info/alternates to obtain objects from the reference repository. Using an already existing repository as an alternate will diff --git a/Documentation/git-cvsexportcommit.txt b/Documentation/git-cvsexportcommit.txt index 2da8588f4f..abaaf273bb 100644 --- a/Documentation/git-cvsexportcommit.txt +++ b/Documentation/git-cvsexportcommit.txt @@ -63,6 +63,10 @@ OPTIONS -u:: Update affected files from CVS repository before attempting export. +-k:: + Reverse CVS keyword expansion (e.g. $Revision: 1.2.3.4$ + becomes $Revision$) in working CVS checkout before applying patch. + -w:: Specify the location of the CVS checkout to use for the export. This option does not require GIT_DIR to be set before execution if the diff --git a/Documentation/git-diff-files.txt b/Documentation/git-diff-files.txt index c526141564..4ef03578eb 100644 --- a/Documentation/git-diff-files.txt +++ b/Documentation/git-diff-files.txt @@ -43,8 +43,7 @@ omit diff output for unmerged entries and just show "Unmerged". -q:: Remain silent even on nonexistent files -Output format -------------- + include::diff-format.txt[] diff --git a/Documentation/git-diff-index.txt b/Documentation/git-diff-index.txt index 26920d4f63..8b9ed29299 100644 --- a/Documentation/git-diff-index.txt +++ b/Documentation/git-diff-index.txt @@ -34,8 +34,6 @@ include::diff-options.txt[] 'git-diff-index' say that all non-checked-out files are up to date. -Output format -------------- include::diff-format.txt[] Operating Modes diff --git a/Documentation/git-diff-tree.txt b/Documentation/git-diff-tree.txt index 23b7abd3c6..f2cef1260b 100644 --- a/Documentation/git-diff-tree.txt +++ b/Documentation/git-diff-tree.txt @@ -159,8 +159,7 @@ HEAD commits it finds, which is even more interesting. in case you care). -Output format -------------- + include::diff-format.txt[] diff --git a/Documentation/git-diff.txt b/Documentation/git-diff.txt index a2f192fb75..0ac711230e 100644 --- a/Documentation/git-diff.txt +++ b/Documentation/git-diff.txt @@ -84,8 +84,7 @@ include::diff-options.txt[] the diff to the named paths (you can give directory names and get diff for all files under them). -Output format -------------- + include::diff-format.txt[] EXAMPLES diff --git a/Documentation/git-difftool.txt b/Documentation/git-difftool.txt index 15b247bab4..96a6c51a4b 100644 --- a/Documentation/git-difftool.txt +++ b/Documentation/git-difftool.txt @@ -31,7 +31,7 @@ OPTIONS Use the diff tool specified by <tool>. Valid merge tools are: kdiff3, kompare, tkdiff, meld, xxdiff, emerge, vimdiff, gvimdiff, - ecmerge, diffuse and opendiff + ecmerge, diffuse, opendiff and araxis. + If a diff tool is not specified, 'git-difftool' will use the configuration variable `diff.tool`. If the diff --git a/Documentation/git-fast-export.txt b/Documentation/git-fast-export.txt index 0c9eb567cb..af2328d401 100644 --- a/Documentation/git-fast-export.txt +++ b/Documentation/git-fast-export.txt @@ -36,6 +36,17 @@ when encountering a signed tag. With 'strip', the tags will be made unsigned, with 'verbatim', they will be silently exported and with 'warn', they will be exported, but you will see a warning. +--tag-of-filtered-object=(abort|drop|rewrite):: + Specify how to handle tags whose tagged objectis filtered out. + Since revisions and files to export can be limited by path, + tagged objects may be filtered completely. ++ +When asking to 'abort' (which is the default), this program will die +when encountering such a tag. With 'drop' it will omit such tags from +the output. With 'rewrite', if the tagged object is a commit, it will +rewrite the tag to tag an ancestor commit (via parent rewriting; see +linkgit:git-rev-list[1]) + -M:: -C:: Perform move and/or copy detection, as described in the @@ -71,6 +82,12 @@ marks the same across runs. allow that. So fake a tagger to be able to fast-import the output. +[git-rev-list-args...]:: + A list of arguments, acceptable to 'git-rev-parse' and + 'git-rev-list', that specifies the specific objects and references + to export. For example, `master\~10..master` causes the + current master reference to be exported along with all objects + added since its 10th ancestor commit. EXAMPLES -------- diff --git a/Documentation/git-filter-branch.txt b/Documentation/git-filter-branch.txt index ab527b5b31..32ea8564a5 100644 --- a/Documentation/git-filter-branch.txt +++ b/Documentation/git-filter-branch.txt @@ -305,6 +305,16 @@ range in addition to the new branch name. The new branch name will point to the top-most revision that a 'git-rev-list' of this range will print. +If you need to add 'Acked-by' lines to, say, the last 10 commits (none +of which is a merge), use this command: + +-------------------------------------------------------- +git filter-branch --msg-filter ' + cat && + echo "Acked-by: Bugs Bunny <bunny@bugzilla.org>" +' HEAD~10..HEAD +-------------------------------------------------------- + *NOTE* the changes introduced by the commits, and which are not reverted by subsequent commits, will still be in the rewritten branch. If you want to throw out _changes_ together with the commits, you should use the diff --git a/Documentation/git-format-patch.txt b/Documentation/git-format-patch.txt index 6f1fc80119..687e667598 100644 --- a/Documentation/git-format-patch.txt +++ b/Documentation/git-format-patch.txt @@ -10,7 +10,7 @@ SYNOPSIS -------- [verse] 'git format-patch' [-k] [(-o|--output-directory) <dir> | --stdout] - [--thread[=<style>]] + [--no-thread | --thread[=<style>]] [(--attach|--inline)[=<boundary>] | --no-attach] [-s | --signoff] [-n | --numbered | -N | --no-numbered] @@ -124,17 +124,25 @@ include::diff-options.txt[] second part, with "Content-Disposition: inline". --thread[=<style>]:: - Add In-Reply-To and References headers to make the second and - subsequent mails appear as replies to the first. Also generates - the Message-Id header to reference. +--no-thread:: + Controls addition of In-Reply-To and References headers to + make the second and subsequent mails appear as replies to the + first. Also controls generation of the Message-Id header to + reference. + The optional <style> argument can be either `shallow` or `deep`. 'shallow' threading makes every mail a reply to the head of the series, where the head is chosen from the cover letter, the `\--in-reply-to`, and the first patch mail, in this order. 'deep' -threading makes every mail a reply to the previous one. If not -specified, defaults to the 'format.thread' configuration, or `shallow` -if that is not set. +threading makes every mail a reply to the previous one. ++ +The default is --no-thread, unless the 'format.thread' configuration +is set. If --thread is specified without a style, it defaults to the +style specified by 'format.thread' if any, or else `shallow`. ++ +Beware that the default for 'git send-email' is to thread emails +itself. If you want 'git format-patch' to take care of hreading, you +will want to ensure that threading is disabled for 'git send-email'. --in-reply-to=Message-Id:: Make the first mail (or all the mails with --no-thread) appear as a diff --git a/Documentation/git-gc.txt b/Documentation/git-gc.txt index b292e9843a..dcac8c8e29 100644 --- a/Documentation/git-gc.txt +++ b/Documentation/git-gc.txt @@ -61,7 +61,7 @@ automatic consolidation of packs. --prune=<date>:: Prune loose objects older than date (default is 2 weeks ago, - overrideable by the config variable `gc.pruneExpire`). This + overridable by the config variable `gc.pruneExpire`). This option is on by default. --no-prune:: diff --git a/Documentation/git-grep.txt b/Documentation/git-grep.txt index fccb82deb4..b753c9d76f 100644 --- a/Documentation/git-grep.txt +++ b/Documentation/git-grep.txt @@ -122,6 +122,14 @@ OPTIONS -<num>:: A shortcut for specifying -C<num>. +-p:: +--show-function:: + Show the preceding line that contains the function name of + the match, unless the matching line is a function name itself. + The name is determined in the same way as 'git diff' works out + patch hunk headers (see 'Defining a custom hunk-header' in + linkgit:gitattributes[5]). + -f <file>:: Read patterns from <file>, one per line. diff --git a/Documentation/git-log.txt b/Documentation/git-log.txt index 34cf4e5811..3d79de11ec 100644 --- a/Documentation/git-log.txt +++ b/Documentation/git-log.txt @@ -37,8 +37,12 @@ include::diff-options.txt[] and <until>, see "SPECIFYING REVISIONS" section in linkgit:git-rev-parse[1]. ---decorate:: - Print out the ref names of any commits that are shown. +--decorate[=short|full]:: + Print out the ref names of any commits that are shown. If 'short' is + specified, the ref name prefixes 'refs/heads/', 'refs/tags/' and + 'refs/remotes/' will not be printed. If 'full' is specified, the + full ref name (including prefix) will be printed. The default option + is 'short'. --source:: Print out the ref name given on the command line by which each diff --git a/Documentation/git-merge.txt b/Documentation/git-merge.txt index c04ae739ed..af68d694a0 100644 --- a/Documentation/git-merge.txt +++ b/Documentation/git-merge.txt @@ -10,7 +10,7 @@ SYNOPSIS -------- [verse] 'git merge' [-n] [--stat] [--no-commit] [--squash] [-s <strategy>]... - [-m <msg>] <remote> <remote>... + [-m <msg>] <remote>... 'git merge' <msg> HEAD <remote>... DESCRIPTION diff --git a/Documentation/git-mergetool.txt b/Documentation/git-mergetool.txt index ff9700d17a..68ed6c0956 100644 --- a/Documentation/git-mergetool.txt +++ b/Documentation/git-mergetool.txt @@ -27,7 +27,7 @@ OPTIONS Use the merge resolution program specified by <tool>. Valid merge tools are: kdiff3, tkdiff, meld, xxdiff, emerge, vimdiff, gvimdiff, ecmerge, - diffuse, tortoisemerge and opendiff + diffuse, tortoisemerge, opendiff and araxis. + If a merge resolution program is not specified, 'git-mergetool' will use the configuration variable `merge.tool`. If the diff --git a/Documentation/git-mktree.txt b/Documentation/git-mktree.txt index af19f06ed7..81e3326772 100644 --- a/Documentation/git-mktree.txt +++ b/Documentation/git-mktree.txt @@ -8,12 +8,13 @@ git-mktree - Build a tree-object from ls-tree formatted text SYNOPSIS -------- -'git mktree' [-z] +'git mktree' [-z] [--missing] [--batch] DESCRIPTION ----------- -Reads standard input in non-recursive `ls-tree` output format, -and creates a tree object. The object name of the tree object +Reads standard input in non-recursive `ls-tree` output format, and creates +a tree object. The order of the tree entries is normalised by mktree so +pre-sorting the input is not required. The object name of the tree object built is written to the standard output. OPTIONS @@ -21,6 +22,18 @@ OPTIONS -z:: Read the NUL-terminated `ls-tree -z` output instead. +--missing:: + Allow missing objects. The default behaviour (without this option) + is to verify that each tree entry's sha1 identifies an existing + object. This option has no effect on the treatment of gitlink entries + (aka "submodules") which are always allowed to be missing. + +--batch:: + Allow building of more than one tree object before exiting. Each + tree is separated by as single blank line. The final new-line is + optional. Note - if the '-z' option is used, lines are terminated + with NUL. + Author ------ Written by Junio C Hamano <gitster@pobox.com> diff --git a/Documentation/git-pack-objects.txt b/Documentation/git-pack-objects.txt index 7d4c1a7556..2e4992970e 100644 --- a/Documentation/git-pack-objects.txt +++ b/Documentation/git-pack-objects.txt @@ -11,7 +11,8 @@ SYNOPSIS [verse] 'git pack-objects' [-q] [--no-reuse-delta] [--delta-base-offset] [--non-empty] [--local] [--incremental] [--window=N] [--depth=N] [--all-progress] - [--revs [--unpacked | --all]*] [--stdout | base-name] < object-list + [--revs [--unpacked | --all]*] [--stdout | base-name] + [--keep-true-parents] < object-list DESCRIPTION @@ -197,6 +198,10 @@ base-name:: to force the version for the generated pack index, and to force 64-bit index entries on objects located above the given offset. +--keep-true-parents:: + With this option, parents that are hidden by grafts are packed + nevertheless. + Author ------ diff --git a/Documentation/git-parse-remote.txt b/Documentation/git-parse-remote.txt index cd43069874..39d9daa7e0 100644 --- a/Documentation/git-parse-remote.txt +++ b/Documentation/git-parse-remote.txt @@ -17,26 +17,6 @@ routines to parse files under $GIT_DIR/remotes/ and $GIT_DIR/branches/ and configuration variables that are related to fetching, pulling and pushing. -The primary entry points are: - -get_remote_refs_for_fetch:: - Given the list of user-supplied `<repo> <refspec>...`, - return the list of refs to fetch after canonicalizing - them into `$GIT_DIR` relative paths - (e.g. `refs/heads/foo`). When `<refspec>...` is empty - the returned list of refs consists of the defaults - for the given `<repo>`, if specified in - `$GIT_DIR/remotes/`, `$GIT_DIR/branches/`, or `remote.*.fetch` - configuration. - -get_remote_refs_for_push:: - Given the list of user-supplied `<repo> <refspec>...`, - return the list of refs to push in a form suitable to be - fed to the 'git-send-pack' command. When `<refspec>...` - is empty the returned list of refs consists of the - defaults for the given `<repo>`, if specified in - `$GIT_DIR/remotes/`. - Author ------ Written by Junio C Hamano. diff --git a/Documentation/git-push.txt b/Documentation/git-push.txt index fd53c49fb8..58d2bd5d4a 100644 --- a/Documentation/git-push.txt +++ b/Documentation/git-push.txt @@ -85,6 +85,11 @@ nor in any Push line of the corresponding remotes file---see below). --dry-run:: Do everything except actually send the updates. +--porcelain:: + Produce machine-readable output. The output status line for each ref + will be tab-separated and sent to stdout instead of stderr. The full + symbolic names of the refs will be given. + --tags:: All refs under `$GIT_DIR/refs/tags` are pushed, in addition to refspecs explicitly listed on the command @@ -148,6 +153,12 @@ representing the status of a single ref. Each line is of the form: <flag> <summary> <from> -> <to> (<reason>) ------------------------------- +If --porcelain is used, then each line of the output is of the form: + +------------------------------- + <flag> \t <from>:<to> \t <summary> (<reason>) +------------------------------- + flag:: A single character indicating the status of the ref. This is blank for a successfully pushed ref, `!` for a ref that was @@ -184,6 +195,92 @@ reason:: refs, no explanation is needed. For a failed ref, the reason for failure is described. +Note about fast-forwards +------------------------ + +When an update changes a branch (or more in general, a ref) that used to +point at commit A to point at another commit B, it is called a +fast-forward update if and only if B is a descendant of A. + +In a fast-forward update from A to B, the set of commits that the original +commit A built on top of is a subset of the commits the new commit B +builds on top of. Hence, it does not lose any history. + +In contrast, a non-fast-forward update will lose history. For example, +suppose you and somebody else started at the same commit X, and you built +a history leading to commit B while the other person built a history +leading to commit A. The history looks like this: + +---------------- + + B + / + ---X---A + +---------------- + +Further suppose that the other person already pushed changes leading to A +back to the original repository you two obtained the original commit X. + +The push done by the other person updated the branch that used to point at +commit X to point at commit A. It is a fast-forward. + +But if you try to push, you will attempt to update the branch (that +now points at A) with commit B. This does _not_ fast-forward. If you did +so, the changes introduced by commit A will be lost, because everybody +will now start building on top of B. + +The command by default does not allow an update that is not a fast-forward +to prevent such loss of history. + +If you do not want to lose your work (history from X to B) nor the work by +the other person (history from X to A), you would need to first fetch the +history from the repository, create a history that contains changes done +by both parties, and push the result back. + +You can perform "git pull", resolve potential conflicts, and "git push" +the result. A "git pull" will create a merge commit C between commits A +and B. + +---------------- + + B---C + / / + ---X---A + +---------------- + +Updating A with the resulting merge commit will fast-forward and your +push will be accepted. + +Alternatively, you can rebase your change between X and B on top of A, +with "git pull --rebase", and push the result back. The rebase will +create a new commit D that builds the change between X and B on top of +A. + +---------------- + + B D + / / + ---X---A + +---------------- + +Again, updating A with this commit will fast-forward and your push will be +accepted. + +There is another common situation where you may encounter non-fast-forward +rejection when you try to push, and it is possible even when you are +pushing into a repository nobody else pushes into. After you push commit +A yourself (in the first picture in this section), replace it with "git +commit --amend" to produce commit B, and you try to push it out, because +forgot that you have pushed A out already. In such a case, and only if +you are certain that nobody in the meantime fetched your earlier commit A +(and started building on top of it), you can run "git push --force" to +overwrite it. In other words, "git push --force" is a method reserved for +a case where you do mean to lose history. + + Examples -------- diff --git a/Documentation/git-rebase.txt b/Documentation/git-rebase.txt index 3d5a066c31..db1b71d248 100644 --- a/Documentation/git-rebase.txt +++ b/Documentation/git-rebase.txt @@ -231,12 +231,15 @@ OPTIONS -s <strategy>:: --strategy=<strategy>:: - Use the given merge strategy; can be supplied more than - once to specify them in the order they should be tried. + Use the given merge strategy. If there is no `-s` option, a built-in list of strategies is used instead ('git-merge-recursive' when merging a single head, 'git-merge-octopus' otherwise). This implies --merge. +-q:: +--quiet:: + Be quiet. Implies --no-stat. + -v:: --verbose:: Be verbose. Implies --stat. diff --git a/Documentation/git-remote.txt b/Documentation/git-remote.txt index 9e2b4eaa38..82a3d29673 100644 --- a/Documentation/git-remote.txt +++ b/Documentation/git-remote.txt @@ -114,14 +114,14 @@ These stale branches have already been removed from the remote repository referenced by <name>, but are still locally available in "remotes/<name>". + -With `--dry-run` option, report what branches will be pruned, but do no +With `--dry-run` option, report what branches will be pruned, but do not actually prune them. 'update':: Fetch updates for a named set of remotes in the repository as defined by remotes.<group>. If a named group is not specified on the command line, -the configuration parameter remotes.default will get used; if +the configuration parameter remotes.default will be used; if remotes.default is not defined, all remotes which do not have the configuration parameter remote.<name>.skipDefaultUpdate set to true will be updated. (See linkgit:git-config[1]). diff --git a/Documentation/git-repack.txt b/Documentation/git-repack.txt index aaa8852629..c9257a10c9 100644 --- a/Documentation/git-repack.txt +++ b/Documentation/git-repack.txt @@ -31,11 +31,14 @@ OPTIONS Instead of incrementally packing the unpacked objects, pack everything referenced into a single pack. Especially useful when packing a repository that is used - for private development and there is no need to worry - about people fetching via dumb protocols from it. Use + for private development. Use with '-d'. This will clean up the objects that `git prune` leaves behind, but `git fsck --full` shows as dangling. ++ +Note that users fetching over dumb protocols will have to fetch the +whole new pack in order to get any contained object, no matter how many +other objects in that pack they already have locally. -A:: Same as `-a`, unless '-d' is used. Then any unreachable diff --git a/Documentation/git-rerere.txt b/Documentation/git-rerere.txt index a53c3cd35b..7dd515b8cc 100644 --- a/Documentation/git-rerere.txt +++ b/Documentation/git-rerere.txt @@ -23,7 +23,7 @@ on the initial manual merge, and applying previously recorded hand resolutions to their corresponding automerge results. [NOTE] -You need to set the configuration variable rerere.enabled to +You need to set the configuration variable rerere.enabled in order to enable this command. diff --git a/Documentation/git-rev-list.txt b/Documentation/git-rev-list.txt index 1c9cc28895..974d9f527f 100644 --- a/Documentation/git-rev-list.txt +++ b/Documentation/git-rev-list.txt @@ -14,6 +14,7 @@ SYNOPSIS [ \--max-age=timestamp ] [ \--min-age=timestamp ] [ \--sparse ] + [ \--merges ] [ \--no-merges ] [ \--first-parent ] [ \--remove-empty ] @@ -83,7 +84,7 @@ between the two operands. The following two commands are equivalent: $ git rev-list A...B ----------------------------------------------------------------------- -'git-rev-list' is a very essential git program, since it +'rev-list' is a very essential git command, since it provides the ability to build and traverse commit ancestry graphs. For this reason, it has a lot of different options that enables it to be used by commands as different as 'git-bisect' and diff --git a/Documentation/git-rev-parse.txt b/Documentation/git-rev-parse.txt index 52c353e674..82045a2522 100644 --- a/Documentation/git-rev-parse.txt +++ b/Documentation/git-rev-parse.txt @@ -30,6 +30,16 @@ OPTIONS Only meaningful in `--parseopt` mode. Tells the option parser to echo out the first `--` met instead of skipping it. +--stop-at-non-option:: + Only meaningful in `--parseopt` mode. Lets the option parser stop at + the first non-option argument. This can be used to parse sub-commands + that take options themself. + +--sq-quote:: + Use 'git-rev-parse' in shell quoting mode (see SQ-QUOTE + section below). In contrast to the `--sq` option below, this + mode does only quoting. Nothing else is done to command input. + --revs-only:: Do not output flags and parameters not meant for 'git-rev-list' command. @@ -64,7 +74,8 @@ OPTIONS properly quoted for consumption by shell. Useful when you expect your parameter to contain whitespaces and newlines (e.g. when using pickaxe `-S` with - 'git-diff-\*'). + 'git-diff-\*'). In contrast to the `--sq-quote` option, + the command input is still interpreted as usual. --not:: When showing object names, prefix them with '{caret}' and @@ -406,6 +417,33 @@ C? option C with an optional argument" eval `echo "$OPTS_SPEC" | git rev-parse --parseopt -- "$@" || echo exit $?` ------------ +SQ-QUOTE +-------- + +In `--sq-quote` mode, 'git-rev-parse' echoes on the standard output a +single line suitable for `sh(1)` `eval`. This line is made by +normalizing the arguments following `--sq-quote`. Nothing other than +quoting the arguments is done. + +If you want command input to still be interpreted as usual by +'git-rev-parse' before the output is shell quoted, see the `--sq` +option. + +Example +~~~~~~~ + +------------ +$ cat >your-git-script.sh <<\EOF +#!/bin/sh +args=$(git rev-parse --sq-quote "$@") # quote user-supplied arguments +command="git frotz -n24 $args" # and use it inside a handcrafted + # command line +eval "$command" +EOF + +$ sh your-git-script.sh "a b'c" +------------ + EXAMPLES -------- diff --git a/Documentation/git-send-email.txt b/Documentation/git-send-email.txt index a2821907c7..d6b192b7b9 100644 --- a/Documentation/git-send-email.txt +++ b/Documentation/git-send-email.txt @@ -43,6 +43,10 @@ OPTIONS Composing ~~~~~~~~~ +--annotate:: + Review and edit each patch you're about to send. See the + CONFIGURATION section for 'sendemail.multiedit'. + --bcc=<address>:: Specify a "Bcc:" value for each email. Default is the value of 'sendemail.bcc'. @@ -55,11 +59,6 @@ The --bcc option must be repeated for each user you want on the bcc list. + The --cc option must be repeated for each user you want on the cc list. ---annotate:: - Review each patch you're about to send in an editor. The setting - 'sendemail.multiedit' defines if this will spawn one editor per patch - or one for all of them at once. - --compose:: Use $GIT_EDITOR, core.editor, $VISUAL, or $EDITOR to edit an introductory message for the patch series. @@ -71,11 +70,16 @@ In-Reply-To headers specified in the message. If the body of the message and In-Reply-To headers will be used unless they are removed. + Missing From or In-Reply-To headers will be prompted for. ++ +See the CONFIGURATION section for 'sendemail.multiedit'. --from=<address>:: - Specify the sender of the emails. This will default to - the value GIT_COMMITTER_IDENT, as returned by "git var -l". - The user will still be prompted to confirm this entry. + Specify the sender of the emails. If not specified on the command line, + the value of the 'sendemail.from' configuration option is used. If + neither the command line option nor 'sendemail.from' are set, then the + user will be prompted for the value. The default for the prompt will be + the value of GIT_AUTHOR_IDENT, or GIT_COMMITTER_IDENT if that is not + set, as returned by "git var -l". --in-reply-to=<identifier>:: Specify the contents of the first In-Reply-To header. @@ -139,7 +143,9 @@ user is prompted for a password while the input is masked for privacy. --smtp-server-port=<port>:: Specifies a port different from the default port (SMTP servers typically listen to smtp port 25 and ssmtp port - 465). This can be set with 'sendemail.smtpserverport'. + 465); symbolic port names (e.g. "submission" instead of 465) + are also accepted. The port can also be set with the + 'sendemail.smtpserverport' configuration variable. --smtp-ssl:: Legacy alias for '--smtp-encryption ssl'. @@ -159,7 +165,7 @@ Automating Output of this command must be single email address per line. Default is the value of 'sendemail.cccmd' configuration value. ---[no-]chain-reply-to=<identifier>:: +--[no-]chain-reply-to:: If this is set, each email will be sent as a reply to the previous email sent. If disabled with "--no-chain-reply-to", all emails after the first will be sent as replies to the first email sent. When using @@ -187,12 +193,12 @@ Automating - 'self' will avoid including the sender - 'cc' will avoid including anyone mentioned in Cc lines in the patch header except for self (use 'self' for that). -- 'ccbody' will avoid including anyone mentioned in Cc lines in the +- 'bodycc' will avoid including anyone mentioned in Cc lines in the patch body (commit message) except for self (use 'self' for that). - 'sob' will avoid including anyone mentioned in Signed-off-by lines except for self (use 'self' for that). - 'cccmd' will avoid running the --cc-cmd. -- 'body' is equivalent to 'sob' + 'ccbody' +- 'body' is equivalent to 'sob' + 'bodycc' - 'all' will suppress all auto cc values. -- + @@ -206,10 +212,22 @@ specified, as well as 'body' if --no-signed-off-cc is specified. value; if that is unspecified, default to --no-suppress-from. --[no-]thread:: - If this is set, the In-Reply-To header will be set on each email sent. - If disabled with "--no-thread", no emails will have the In-Reply-To - header set. Default is the value of the 'sendemail.thread' configuration - value; if that is unspecified, default to --thread. + If this is set, the In-Reply-To and References headers will be + added to each email sent. Whether each mail refers to the + previous email (`deep` threading per 'git format-patch' + wording) or to the first email (`shallow` threading) is + governed by "--[no-]chain-reply-to". ++ +If disabled with "--no-thread", those headers will not be added +(unless specified with --in-reply-to). Default is the value of the +'sendemail.thread' configuration value; if that is unspecified, +default to --thread. ++ +It is up to the user to ensure that no In-Reply-To header already +exists when 'git send-email' is asked to add it (especially note that +'git format-patch' can be configured to do the threading itself). +Failure to do so may not produce the expected result in the +recipient's MUA. Administering @@ -234,6 +252,12 @@ have been specified, in which case default to 'compose'. --dry-run:: Do everything except actually send the emails. +--[no-]format-patch:: + When an argument may be understood either as a reference or as a file name, + choose to understand it as a format-patch argument ('--format-patch') + or as a file name ('--no-format-patch'). By default, when such a conflict + occurs, git send-email will fail. + --quiet:: Make git-send-email less verbose. One line per email should be all that is output. @@ -250,12 +274,6 @@ have been specified, in which case default to 'compose'. Default is the value of 'sendemail.validate'; if this is not set, default to '--validate'. ---[no-]format-patch:: - When an argument may be understood either as a reference or as a file name, - choose to understand it as a format-patch argument ('--format-patch') - or as a file name ('--no-format-patch'). By default, when such a conflict - occurs, git send-email will fail. - CONFIGURATION ------------- diff --git a/Documentation/git-show-branch.txt b/Documentation/git-show-branch.txt index 51a4e9d6d7..89ec5364ec 100644 --- a/Documentation/git-show-branch.txt +++ b/Documentation/git-show-branch.txt @@ -8,9 +8,11 @@ git-show-branch - Show branches and their commits SYNOPSIS -------- [verse] -'git show-branch' [--all] [--remotes] [--topo-order] [--current] +'git show-branch' [--all] [--remotes] [--topo-order | --date-order] + [--current] [--color | --no-color] [--more=<n> | --list | --independent | --merge-base] - [--no-name | --sha1-name] [--topics] [<rev> | <glob>]... + [--no-name | --sha1-name] [--topics] + [<rev> | <glob>]... 'git show-branch' (-g|--reflog)[=<n>[,<base>]] [--list] [<ref>] DESCRIPTION @@ -57,6 +59,11 @@ OPTIONS appear in topological order (i.e., descendant commits are shown before their parents). +--date-order:: + This option is similar to '--topo-order' in the sense that no + parent comes before all of its children, but otherwise commits + are ordered according to their commit date. + --sparse:: By default, the output omits merges that are reachable from only one tip being shown. This option makes them @@ -107,6 +114,14 @@ OPTIONS When no explicit <ref> parameter is given, it defaults to the current branch (or `HEAD` if it is detached). +--color:: + Color the status sign (one of these: `*` `!` `+` `-`) of each commit + corresponding to the branch it's in. + +--no-color:: + Turn off colored output, even when the configuration file gives the + default to color output. + Note that --more, --list, --independent and --merge-base options are mutually exclusive. diff --git a/Documentation/git-show-ref.txt b/Documentation/git-show-ref.txt index 98e294aa86..f4429bdc68 100644 --- a/Documentation/git-show-ref.txt +++ b/Documentation/git-show-ref.txt @@ -9,8 +9,9 @@ SYNOPSIS -------- [verse] 'git show-ref' [-q|--quiet] [--verify] [-h|--head] [-d|--dereference] - [-s|--hash] [--abbrev] [--tags] [--heads] [--] <pattern>... -'git show-ref' --exclude-existing[=pattern] + [-s|--hash[=<n>]] [--abbrev[=<n>]] [--tags] + [--heads] [--] <pattern>... +'git show-ref' --exclude-existing[=<pattern>] < ref-list DESCRIPTION ----------- @@ -48,7 +49,7 @@ OPTIONS appended. -s:: ---hash:: +--hash[=<n>]:: Only show the SHA1 hash, not the reference name. When combined with --dereference the dereferenced tag will still be shown after the SHA1. @@ -59,11 +60,10 @@ OPTIONS Aside from returning an error code of 1, it will also print an error message if '--quiet' was not specified. ---abbrev:: ---abbrev=len:: +--abbrev[=<n>]:: Abbreviate the object name. When using `--hash`, you do - not have to say `--hash --abbrev`; `--hash=len` would do. + not have to say `--hash --abbrev`; `--hash=n` would do. -q:: --quiet:: @@ -71,8 +71,7 @@ OPTIONS Do not print any results to stdout. When combined with '--verify' this can be used to silently check if a reference exists. ---exclude-existing:: ---exclude-existing=pattern:: +--exclude-existing[=<pattern>]:: Make 'git-show-ref' act as a filter that reads refs from stdin of the form "^(?:<anything>\s)?<refname>(?:\^\{\})?$" and performs the diff --git a/Documentation/git-stash.txt b/Documentation/git-stash.txt index 1cc24cc47e..1c64a02fe5 100644 --- a/Documentation/git-stash.txt +++ b/Documentation/git-stash.txt @@ -9,10 +9,11 @@ SYNOPSIS -------- [verse] 'git stash' list [<options>] -'git stash' (show | drop | pop ) [<stash>] -'git stash' apply [--index] [<stash>] +'git stash' show [<stash>] +'git stash' drop [-q|--quiet] [<stash>] +'git stash' ( pop | apply ) [--index] [-q|--quiet] [<stash>] 'git stash' branch <branchname> [<stash>] -'git stash' [save [--keep-index] [<message>]] +'git stash' [save [--keep-index] [-q|--quiet] [<message>]] 'git stash' clear 'git stash' create @@ -41,7 +42,7 @@ is also possible). OPTIONS ------- -save [--keep-index] [<message>]:: +save [--keep-index] [-q|--quiet] [<message>]:: Save your local modifications to a new 'stash', and run `git reset --hard` to revert them. This is the default action when no @@ -75,7 +76,7 @@ show [<stash>]:: it will accept any format known to 'git-diff' (e.g., `git stash show -p stash@\{1}` to view the second most recent stash in patch form). -pop [<stash>]:: +pop [--index] [-q|--quiet] [<stash>]:: Remove a single stashed state from the stash list and apply it on top of the current working tree state, i.e., do the inverse @@ -86,16 +87,16 @@ Applying the state can fail with conflicts; in this case, it is not removed from the stash list. You need to resolve the conflicts by hand and call `git stash drop` manually afterwards. + -When no `<stash>` is given, `stash@\{0}` is assumed. See also `apply`. - -apply [--index] [<stash>]:: - - Like `pop`, but do not remove the state from the stash list. -+ If the `--index` option is used, then tries to reinstate not only the working tree's changes, but also the index's ones. However, this can fail, when you have conflicts (which are stored in the index, where you therefore can no longer apply the changes as they were originally). ++ +When no `<stash>` is given, `stash@\{0}` is assumed. + +apply [--index] [-q|--quiet] [<stash>]:: + + Like `pop`, but do not remove the state from the stash list. branch <branchname> [<stash>]:: @@ -115,7 +116,7 @@ clear:: Remove all the stashed states. Note that those states will then be subject to pruning, and may be difficult or impossible to recover. -drop [<stash>]:: +drop [-q|--quiet] [<stash>]:: Remove a single stashed state from the stash list. When no `<stash>` is given, it removes the latest one. i.e. `stash@\{0}` diff --git a/Documentation/git-submodule.txt b/Documentation/git-submodule.txt index 15b34d3760..7dd73ae14e 100644 --- a/Documentation/git-submodule.txt +++ b/Documentation/git-submodule.txt @@ -9,11 +9,13 @@ git-submodule - Initialize, update or inspect submodules SYNOPSIS -------- [verse] -'git submodule' [--quiet] add [-b branch] [--] <repository> <path> +'git submodule' [--quiet] add [-b branch] + [--reference <repository>] [--] <repository> <path> 'git submodule' [--quiet] status [--cached] [--] [<path>...] 'git submodule' [--quiet] init [--] [<path>...] -'git submodule' [--quiet] update [--init] [-N|--no-fetch] [--] [<path>...] -'git submodule' [--quiet] summary [--summary-limit <n>] [commit] [--] [<path>...] +'git submodule' [--quiet] update [--init] [-N|--no-fetch] [--rebase] + [--reference <repository>] [--merge] [--] [<path>...] +'git submodule' [--quiet] summary [--cached] [--summary-limit <n>] [commit] [--] [<path>...] 'git submodule' [--quiet] foreach <command> 'git submodule' [--quiet] sync [--] [<path>...] @@ -113,7 +115,9 @@ init:: update:: Update the registered submodules, i.e. clone missing submodules and checkout the commit specified in the index of the containing repository. - This will make the submodules HEAD be detached. + This will make the submodules HEAD be detached unless '--rebase' or + '--merge' is specified or the key `submodule.$name.update` is set to + `rebase` or `merge`. + If the submodule is not yet initialized, and you just want to use the setting as stored in .gitmodules, you can automatically initialize the @@ -178,6 +182,33 @@ OPTIONS This option is only valid for the update command. Don't fetch new objects from the remote site. +--merge:: + This option is only valid for the update command. + Merge the commit recorded in the superproject into the current branch + of the submodule. If this option is given, the submodule's HEAD will + not be detached. If a merge failure prevents this process, you will + have to resolve the resulting conflicts within the submodule with the + usual conflict resolution tools. + If the key `submodule.$name.update` is set to `merge`, this option is + implicit. + +--rebase:: + This option is only valid for the update command. + Rebase the current branch onto the commit recorded in the + superproject. If this option is given, the submodule's HEAD will not + be detached. If a a merge failure prevents this process, you will have + to resolve these failures with linkgit:git-rebase[1]. + If the key `submodule.$name.update` is set to `rebase`, this option is + implicit. + +--reference <repository>:: + This option is only valid for add and update commands. These + commands sometimes need to clone a remote repository. In this case, + this option will be passed to the linkgit:git-clone[1] command. ++ +*NOTE*: Do *not* use this option unless you have read the note +for linkgit:git-clone[1]'s --reference and --shared options carefully. + <path>...:: Paths to submodule(s). When specified this will restrict the command to only operate on the submodules found at the specified paths. diff --git a/Documentation/git-svn.txt b/Documentation/git-svn.txt index 74be8435cc..22a0389f1e 100644 --- a/Documentation/git-svn.txt +++ b/Documentation/git-svn.txt @@ -3,7 +3,7 @@ git-svn(1) NAME ---- -git-svn - Bidirectional operation between a single Subversion branch and git +git-svn - Bidirectional operation between a Subversion repository and git SYNOPSIS -------- @@ -11,27 +11,25 @@ SYNOPSIS DESCRIPTION ----------- -'git-svn' is a simple conduit for changesets between Subversion and git. +'git svn' is a simple conduit for changesets between Subversion and git. It provides a bidirectional flow of changes between a Subversion and a git repository. -'git-svn' can track a single Subversion branch simply by using a -URL to the branch, follow branches laid out in the Subversion recommended -method (trunk, branches, tags directories) with the --stdlayout option, or -follow branches in any layout with the -T/-t/-b options (see options to -'init' below, and also the 'clone' command). +'git svn' can track a standard Subversion repository, +following the common "trunk/branches/tags" layout, with the --stdlayout option. +It can also follow branches and tags in any layout with the -T/-t/-b options +(see options to 'init' below, and also the 'clone' command). -Once tracking a Subversion branch (with any of the above methods), the git +Once tracking a Subversion repository (with any of the above methods), the git repository can be updated from Subversion by the 'fetch' command and Subversion updated from git by the 'dcommit' command. COMMANDS -------- --- 'init':: Initializes an empty git repository with additional - metadata directories for 'git-svn'. The Subversion URL + metadata directories for 'git svn'. The Subversion URL may be specified as a command-line argument, or as full URL arguments to -T/-t/-b. Optionally, the target directory to operate on can be specified as a second @@ -48,8 +46,11 @@ COMMANDS --stdlayout;; These are optional command-line options for init. Each of these flags can point to a relative repository path - (--tags=project/tags') or a full url - (--tags=https://foo.org/project/tags). The option --stdlayout is + (--tags=project/tags) or a full url + (--tags=https://foo.org/project/tags). + You can specify more than one --tags and/or --branches options, in case + your Subversion repository places tags or branches under multiple paths. + The option --stdlayout is a shorthand way of setting trunk,tags,branches as the relative paths, which is the Subversion default. If any of the other options are given as well, they take precedence. @@ -61,16 +62,6 @@ COMMANDS Set the 'useSvnsyncProps' option in the [svn-remote] config. --rewrite-root=<URL>;; Set the 'rewriteRoot' option in the [svn-remote] config. ---use-log-author;; - When retrieving svn commits into git (as part of fetch, rebase, or - dcommit operations), look for the first From: or Signed-off-by: line - in the log message and use that as the author string. ---add-author-from;; - When committing to svn from git (as part of commit or dcommit - operations), if the existing log message doesn't already have a - From: or Signed-off-by: line, append a From: line based on the - git commit's author string. If you use this, then --use-log-author - will retrieve a valid author string for all commits. --username=<USER>;; For transports that SVN handles authentication for (http, https, and plain svn), specify the username. For other @@ -89,6 +80,17 @@ COMMANDS When passed to 'init' or 'clone' this regular expression will be preserved as a config key. See 'fetch' for a description of '--ignore-paths'. +--no-minimize-url;; + When tracking multiple directories (using --stdlayout, + --branches, or --tags options), git svn will attempt to connect + to the root (or highest allowed level) of the Subversion + repository. This default allows better tracking of history if + entire projects are moved within a repository, but may cause + issues on repositories where read access restrictions are in + place. Passing '--no-minimize-url' will allow git svn to + accept URLs as-is without attempting to connect to a higher + level directory. This option is off by default when only + one URL/branch is tracked (it would do little good). 'fetch':: Fetch unfetched revisions from the Subversion remote we are @@ -98,12 +100,12 @@ COMMANDS --localtime;; Store Git commit times in the local timezone instead of UTC. This - makes 'git-log' (even without --date=local) show the same times + makes 'git log' (even without --date=local) show the same times that `svn log` would in the local timezone. --parent;; Fetch only from the SVN parent of the current HEAD. - ++ This doesn't interfere with interoperating with the Subversion repository you cloned from, but if you wish for your local Git repository to be able to interoperate with someone else's local Git @@ -116,20 +118,39 @@ the same local timezone. The '--ignore-paths' option should match for every 'fetch' (including automatic fetches due to 'clone', 'dcommit', 'rebase', etc) on a given repository. - ++ +[verse] config key: svn-remote.<name>.ignore-paths - - If the ignore-paths config key is set and the command - line option is also given, both regular expressions - will be used. - ++ +If the ignore-paths config key is set and the command line option is +also given, both regular expressions will be used. ++ Examples: ++ +-- +Skip "doc*" directory for every fetch;; ++ +------------------------------------------------------------------------ +--ignore-paths="^doc" +------------------------------------------------------------------------ - --ignore-paths="^doc" - skip "doc*" directory for every - fetch. +Skip "branches" and "tags" of first level directories;; ++ +------------------------------------------------------------------------ +--ignore-paths="^[^/]+/(?:branches|tags)" +------------------------------------------------------------------------ +-- - --ignore-paths="^[^/]+/(?:branches|tags)" - skip - "branches" and "tags" of first level directories. +--use-log-author;; + When retrieving svn commits into git (as part of fetch, rebase, or + dcommit operations), look for the first From: or Signed-off-by: line + in the log message and use that as the author string. +--add-author-from;; + When committing to svn from git (as part of commit or dcommit + operations), if the existing log message doesn't already have a + From: or Signed-off-by: line, append a From: line based on the + git commit's author string. If you use this, then --use-log-author + will retrieve a valid author string for all commits. 'clone':: Runs 'init' and 'fetch'. It will automatically create a @@ -137,29 +158,29 @@ Examples: or if a second argument is passed; it will create a directory and work within that. It accepts all arguments that the 'init' and 'fetch' commands accept; with the exception of - '--fetch-all'. After a repository is cloned, the 'fetch' - command will be able to update revisions without affecting - the working tree; and the 'rebase' command will be able - to update the working tree with the latest changes. + '--fetch-all' and '--parent'. After a repository is cloned, + the 'fetch' command will be able to update revisions without + affecting the working tree; and the 'rebase' command will be + able to update the working tree with the latest changes. 'rebase':: This fetches revisions from the SVN parent of the current HEAD and rebases the current (uncommitted to SVN) work against it. - -This works similarly to `svn update` or 'git-pull' except that -it preserves linear history with 'git-rebase' instead of -'git-merge' for ease of dcommitting with 'git-svn'. - -This accepts all options that 'git-svn fetch' and 'git-rebase' ++ +This works similarly to `svn update` or 'git pull' except that +it preserves linear history with 'git rebase' instead of +'git merge' for ease of dcommitting with 'git svn'. ++ +This accepts all options that 'git svn fetch' and 'git rebase' accept. However, '--fetch-all' only fetches from the current [svn-remote], and not all [svn-remote] definitions. - -Like 'git-rebase'; this requires that the working tree be clean ++ +Like 'git rebase'; this requires that the working tree be clean and have no uncommitted changes. -l;; --local;; - Do not fetch remotely; only run 'git-rebase' against the + Do not fetch remotely; only run 'git rebase' against the last fetched commit from the upstream SVN. 'dcommit':: @@ -167,11 +188,12 @@ and have no uncommitted changes. repository, and then rebase or reset (depending on whether or not there is a diff between SVN and head). This will create a revision in SVN for each commit in git. - It is recommended that you run 'git-svn' fetch and rebase (not + It is recommended that you run 'git svn' fetch and rebase (not pull or merge) your commits against the latest changes in the SVN repository. - An optional command-line argument may be specified as an - alternative to HEAD. + An optional revision or branch argument may be specified, and + causes 'git svn' to do all work on that revision/branch + instead of HEAD. This is advantageous over 'set-tree' (below) because it produces cleaner, more linear history. + @@ -179,18 +201,17 @@ and have no uncommitted changes. After committing, do not rebase or reset. --commit-url <URL>;; Commit to this SVN URL (the full path). This is intended to - allow existing git-svn repositories created with one transport + allow existing 'git svn' repositories created with one transport method (e.g. `svn://` or `http://` for anonymous read) to be reused if a user is later given access to an alternate transport method (e.g. `svn+ssh://` or `https://`) for commit. - ++ +[verse] config key: svn-remote.<name>.commiturl - config key: svn.commiturl (overwrites all svn-remote.<name>.commiturl options) - - Using this option for any other purpose (don't ask) - is very strongly discouraged. --- ++ +Using this option for any other purpose (don't ask) is very strongly +discouraged. 'branch':: Create a branch in the SVN repository. @@ -204,6 +225,20 @@ config key: svn.commiturl (overwrites all svn-remote.<name>.commiturl options) Create a tag by using the tags_subdir instead of the branches_subdir specified during git svn init. +-d;; +--destination;; + If more than one --branches (or --tags) option was given to the 'init' + or 'clone' command, you must provide the location of the branch (or + tag) you wish to create in the SVN repository. The value of this + option must match one of the paths specified by a --branches (or + --tags) option. You can see these paths with the commands ++ + git config --get-all svn-remote.<name>.branches + git config --get-all svn-remote.<name>.tags ++ +where <name> is the name of the SVN repository as specified by the -R option to +'init' (or "svn" by default). + 'tag':: Create a tag in the SVN repository. This is a shorthand for 'branch -t'. @@ -215,10 +250,12 @@ config key: svn.commiturl (overwrites all svn-remote.<name>.commiturl options) The following features from `svn log' are supported: + -- +-r <n>[:<n>];; --revision=<n>[:<n>];; is supported, non-numeric args are not: HEAD, NEXT, BASE, PREV, etc ... --v/--verbose;; +-v;; +--verbose;; it's not completely compatible with the --verbose output in svn log, but reasonably close. --limit=<n>;; @@ -241,7 +278,7 @@ NOTE: SVN itself only stores times in UTC and nothing else. The regular svn client converts the UTC time to the local time (or based on the TZ= environment). This command has the same behaviour. + -Any other arguments are passed directly to 'git-log' +Any other arguments are passed directly to 'git log' 'blame':: Show what revision and author last modified each line of a file. The @@ -249,15 +286,14 @@ Any other arguments are passed directly to 'git-log' `svn blame' by default. Like the SVN blame command, local uncommitted changes in the working copy are ignored; the version of the file in the HEAD revision is annotated. Unknown - arguments are passed directly to 'git-blame'. + arguments are passed directly to 'git blame'. + --git-format;; - Produce output in the same format as 'git-blame', but with + Produce output in the same format as 'git blame', but with SVN revision numbers instead of git commit hashes. In this mode, changes that haven't been committed to SVN (including local working-copy edits) are shown as revision 0. --- 'find-rev':: When given an SVN revision number of the form 'rN', returns the corresponding git commit hash (this can optionally be followed by a @@ -271,7 +307,7 @@ Any other arguments are passed directly to 'git-log' absolutely no attempts to do patching when committing to SVN, it simply overwrites files with those specified in the tree or commit. All merging is assumed to have taken place - independently of 'git-svn' functions. + independently of 'git svn' functions. 'create-ignore':: Recursively finds the svn:ignore property on directories and @@ -286,12 +322,12 @@ Any other arguments are passed directly to 'git-log' 'commit-diff':: Commits the diff of two tree-ish arguments from the - command-line. This command does not rely on being inside an `git-svn + command-line. This command does not rely on being inside an `git svn init`-ed repository. This command takes three arguments, (a) the original tree to diff against, (b) the new tree result, (c) the URL of the target Subversion repository. The final argument - (URL) may be omitted if you are working from a 'git-svn'-aware - repository (that has been `init`-ed with 'git-svn'). + (URL) may be omitted if you are working from a 'git svn'-aware + repository (that has been `init`-ed with 'git svn'). The -r<revision> option is required for this. 'info':: @@ -313,108 +349,170 @@ Any other arguments are passed directly to 'git-log' Shows the Subversion externals. Use -r/--revision to specify a specific revision. --- +'gc':: + Compress $GIT_DIR/svn/<refname>/unhandled.log files in .git/svn + and remove $GIT_DIR/svn/<refname>index files in .git/svn. + +'reset':: + Undoes the effects of 'fetch' back to the specified revision. + This allows you to re-'fetch' an SVN revision. Normally the + contents of an SVN revision should never change and 'reset' + should not be necessary. However, if SVN permissions change, + or if you alter your --ignore-paths option, a 'fetch' may fail + with "not found in commit" (file not previously visible) or + "checksum mismatch" (missed a modification). If the problem + file cannot be ignored forever (with --ignore-paths) the only + way to repair the repo is to use 'reset'. ++ +Only the rev_map and refs/remotes/git-svn are changed. Follow 'reset' +with a 'fetch' and then 'git reset' or 'git rebase' to move local +branches onto the new tree. + +-r <n>;; +--revision=<n>;; + Specify the most recent revision to keep. All later revisions + are discarded. +-p;; +--parent;; + Discard the specified revision as well, keeping the nearest + parent instead. +Example:;; +Assume you have local changes in "master", but you need to refetch "r2". ++ +------------ + r1---r2---r3 remotes/git-svn + \ + A---B master +------------ ++ +Fix the ignore-paths or SVN permissions problem that caused "r2" to +be incomplete in the first place. Then: ++ +[verse] +git svn reset -r2 -p +git svn fetch ++ +------------ + r1---r2'--r3' remotes/git-svn + \ + r2---r3---A---B master +------------ ++ +Then fixup "master" with 'git rebase'. +Do NOT use 'git merge' or your history will not be compatible with a +future 'dcommit'! ++ +[verse] +git rebase --onto remotes/git-svn A^ master ++ +------------ + r1---r2'--r3' remotes/git-svn + \ + A'--B' master +------------ OPTIONS ------- --- --shared[={false|true|umask|group|all|world|everybody}]:: --template=<template_directory>:: Only used with the 'init' command. - These are passed directly to 'git-init'. + These are passed directly to 'git init'. -r <ARG>:: --revision <ARG>:: - -Used with the 'fetch' command. - + Used with the 'fetch' command. ++ This allows revision ranges for partial/cauterized history to be supported. $NUMBER, $NUMBER1:$NUMBER2 (numeric ranges), $NUMBER:HEAD, and BASE:$NUMBER are all supported. - ++ This can allow you to make partial mirrors when running fetch; but is generally not recommended because history will be skipped and lost. -:: --stdin:: - -Only used with the 'set-tree' command. - + Only used with the 'set-tree' command. ++ Read a list of commits from stdin and commit them in reverse order. Only the leading sha1 is read from each line, so -'git-rev-list --pretty=oneline' output can be used. +'git rev-list --pretty=oneline' output can be used. --rmdir:: - -Only used with the 'dcommit', 'set-tree' and 'commit-diff' commands. - + Only used with the 'dcommit', 'set-tree' and 'commit-diff' commands. ++ Remove directories from the SVN tree if there are no files left behind. SVN can version empty directories, and they are not removed by default if there are no files left in them. git cannot version empty directories. Enabling this flag will make the commit to SVN act like git. - ++ +[verse] config key: svn.rmdir -e:: --edit:: - -Only used with the 'dcommit', 'set-tree' and 'commit-diff' commands. - + Only used with the 'dcommit', 'set-tree' and 'commit-diff' commands. ++ Edit the commit message before committing to SVN. This is off by default for objects that are commits, and forced on when committing tree objects. - ++ +[verse] config key: svn.edit -l<num>:: --find-copies-harder:: - -Only used with the 'dcommit', 'set-tree' and 'commit-diff' commands. - -They are both passed directly to 'git-diff-tree'; see + Only used with the 'dcommit', 'set-tree' and 'commit-diff' commands. ++ +They are both passed directly to 'git diff-tree'; see linkgit:git-diff-tree[1] for more information. - ++ [verse] config key: svn.l config key: svn.findcopiesharder -A<filename>:: --authors-file=<filename>:: - -Syntax is compatible with the file used by 'git-cvsimport': - + Syntax is compatible with the file used by 'git cvsimport': ++ ------------------------------------------------------------------------ loginname = Joe User <user@example.com> ------------------------------------------------------------------------ - -If this option is specified and 'git-svn' encounters an SVN -committer name that does not exist in the authors-file, 'git-svn' ++ +If this option is specified and 'git svn' encounters an SVN +committer name that does not exist in the authors-file, 'git svn' will abort operation. The user will then have to add the -appropriate entry. Re-running the previous 'git-svn' command +appropriate entry. Re-running the previous 'git svn' command after the authors-file is modified should continue operation. - ++ +[verse] config key: svn.authorsfile +--authors-prog=<filename>:: + If this option is specified, for each SVN committer name that + does not exist in the authors file, the given file is executed + with the committer name as the first argument. The program is + expected to return a single line of the form "Name <email>", + which will be treated as if included in the authors file. + -q:: --quiet:: - Make 'git-svn' less verbose. Specify a second time to make it + Make 'git svn' less verbose. Specify a second time to make it even less verbose. --repack[=<n>]:: --repack-flags=<flags>:: - -These should help keep disk usage sane for large fetches -with many revisions. - + These should help keep disk usage sane for large fetches with + many revisions. ++ --repack takes an optional argument for the number of revisions to fetch before repacking. This defaults to repacking every 1000 commits fetched if no argument is specified. - ---repack-flags are passed directly to 'git-repack'. - ++ +--repack-flags are passed directly to 'git repack'. ++ [verse] config key: svn.repack config key: svn.repackflags @@ -423,41 +521,36 @@ config key: svn.repackflags --merge:: -s<strategy>:: --strategy=<strategy>:: - -These are only used with the 'dcommit' and 'rebase' commands. - -Passed directly to 'git-rebase' when using 'dcommit' if a -'git-reset' cannot be used (see 'dcommit'). + These are only used with the 'dcommit' and 'rebase' commands. ++ +Passed directly to 'git rebase' when using 'dcommit' if a +'git reset' cannot be used (see 'dcommit'). -n:: --dry-run:: - -This can be used with the 'dcommit', 'rebase', 'branch' and 'tag' -commands. - + This can be used with the 'dcommit', 'rebase', 'branch' and + 'tag' commands. ++ For 'dcommit', print out the series of git arguments that would show which diffs would be committed to SVN. - ++ For 'rebase', display the local branch associated with the upstream svn repository associated with the current branch and the URL of svn repository that will be fetched from. - ++ For 'branch' and 'tag', display the urls that will be used for copying when creating the branch or tag. --- ADVANCED OPTIONS ---------------- --- -i<GIT_SVN_ID>:: --id <GIT_SVN_ID>:: - -This sets GIT_SVN_ID (instead of using the environment). This -allows the user to override the default refname to fetch from -when tracking a single URL. The 'log' and 'dcommit' commands -no longer require this switch as an argument. + This sets GIT_SVN_ID (instead of using the environment). This + allows the user to override the default refname to fetch from + when tracking a single URL. The 'log' and 'dcommit' commands + no longer require this switch as an argument. -R<remote name>:: --svn-remote <remote name>:: @@ -471,33 +564,30 @@ no longer require this switch as an argument. started tracking a branch and never tracked the trunk it was descended from. This feature is enabled by default, use --no-follow-parent to disable it. - ++ +[verse] config key: svn.followparent --- CONFIG FILE-ONLY OPTIONS ------------------------ --- svn.noMetadata:: svn-remote.<name>.noMetadata:: - -This gets rid of the 'git-svn-id:' lines at the end of every commit. - -If you lose your .git/svn/git-svn/.rev_db file, 'git-svn' will not + This gets rid of the 'git-svn-id:' lines at the end of every commit. ++ +If you lose your .git/svn/git-svn/.rev_db file, 'git svn' will not be able to rebuild it and you won't be able to fetch again, either. This is fine for one-shot imports. - -The 'git-svn log' command will not work on repositories using ++ +The 'git svn log' command will not work on repositories using this, either. Using this conflicts with the 'useSvmProps' option for (hopefully) obvious reasons. svn.useSvmProps:: svn-remote.<name>.useSvmProps:: - -This allows 'git-svn' to re-map repository URLs and UUIDs from -mirrors created using SVN::Mirror (or svk) for metadata. - + This allows 'git svn' to re-map repository URLs and UUIDs from + mirrors created using SVN::Mirror (or svk) for metadata. ++ If an SVN revision has a property, "svm:headrev", it is likely that the revision was created by SVN::Mirror (also used by SVK). The property contains a repository UUID and a revision. We want @@ -514,23 +604,22 @@ svn-remote.<name>.useSvnsyncprops:: svn-remote.<name>.rewriteRoot:: This allows users to create repositories from alternate - URLs. For example, an administrator could run 'git-svn' on the + URLs. For example, an administrator could run 'git svn' on the server locally (accessing via file://) but wish to distribute the repository with a public http:// or svn:// URL in the metadata so users of it will see the public URL. svn.brokenSymlinkWorkaround:: -This disables potentially expensive checks to workaround broken symlinks -checked into SVN by broken clients. Set this option to "false" if you -track a SVN repository with many empty blobs that are not symlinks. -This option may be changed while "git-svn" is running and take effect on -the next revision fetched. If unset, git-svn assumes this option to be -"true". - --- + This disables potentially expensive checks to workaround + broken symlinks checked into SVN by broken clients. Set this + option to "false" if you track a SVN repository with many + empty blobs that are not symlinks. This option may be changed + while 'git svn' is running and take effect on the next + revision fetched. If unset, 'git svn' assumes this option to + be "true". Since the noMetadata, rewriteRoot, useSvnsyncProps and useSvmProps -options all affect the metadata generated and used by 'git-svn'; they +options all affect the metadata generated and used by 'git svn'; they *must* be set in the configuration file before any history is imported and these settings should never be changed once they are set. @@ -548,7 +637,7 @@ Tracking and contributing to the trunk of a Subversion-managed project: git svn clone http://svn.example.com/project/trunk # Enter the newly cloned directory: cd trunk -# You should be on master branch, double-check with git-branch +# You should be on master branch, double-check with 'git branch' git branch # Do some work and commit locally to git: git commit ... @@ -579,12 +668,12 @@ Tracking and contributing to an entire Subversion-managed project # of dcommit/rebase/show-ignore should be the same as above. ------------------------------------------------------------------------ -The initial 'git-svn clone' can be quite time-consuming +The initial 'git svn clone' can be quite time-consuming (especially for large Subversion repositories). If multiple people (or one person with multiple machines) want to use -'git-svn' to interact with the same Subversion repository, you can -do the initial 'git-svn clone' to a repository on a server and -have each person clone that repository with 'git-clone': +'git svn' to interact with the same Subversion repository, you can +do the initial 'git svn clone' to a repository on a server and +have each person clone that repository with 'git clone': ------------------------------------------------------------------------ # Do the initial import on a server @@ -598,7 +687,7 @@ have each person clone that repository with 'git-clone': git fetch # Create a local branch from one of the branches just fetched git checkout -b master FETCH_HEAD -# Initialize git-svn locally (be sure to use the same URL and -T/-b/-t options as were used on server) +# Initialize 'git svn' locally (be sure to use the same URL and -T/-b/-t options as were used on server) git svn init http://svn.example.com/project # Pull the latest changes from Subversion git svn rebase @@ -607,7 +696,7 @@ have each person clone that repository with 'git-clone': REBASE VS. PULL/MERGE --------------------- -Originally, 'git-svn' recommended that the 'remotes/git-svn' branch be +Originally, 'git svn' recommended that the 'remotes/git-svn' branch be pulled or merged from. This is because the author favored `git svn set-tree B` to commit a single head rather than the `git svn set-tree A..B` notation to commit multiple commits. @@ -622,7 +711,7 @@ previous commits in SVN. DESIGN PHILOSOPHY ----------------- Merge tracking in Subversion is lacking and doing branched development -with Subversion can be cumbersome as a result. While 'git-svn' can track +with Subversion can be cumbersome as a result. While 'git svn' can track copy history (including branches and tags) for repositories adopting a standard layout, it cannot yet represent merge history that happened inside git back upstream to SVN users. Therefore it is advised that @@ -633,25 +722,25 @@ CAVEATS ------- For the sake of simplicity and interoperating with a less-capable system -(SVN), it is recommended that all 'git-svn' users clone, fetch and dcommit -directly from the SVN server, and avoid all 'git-clone'/'pull'/'merge'/'push' +(SVN), it is recommended that all 'git svn' users clone, fetch and dcommit +directly from the SVN server, and avoid all 'git clone'/'pull'/'merge'/'push' operations between git repositories and branches. The recommended method of exchanging code between git branches and users is -'git-format-patch' and 'git-am', or just 'dcommit'ing to the SVN repository. +'git format-patch' and 'git am', or just 'dcommit'ing to the SVN repository. -Running 'git-merge' or 'git-pull' is NOT recommended on a branch you +Running 'git merge' or 'git pull' is NOT recommended on a branch you plan to 'dcommit' from. Subversion does not represent merges in any reasonable or useful fashion; so users using Subversion cannot see any merges you've made. Furthermore, if you merge or pull from a git branch that is a mirror of an SVN branch, 'dcommit' may commit to the wrong branch. -'git-clone' does not clone branches under the refs/remotes/ hierarchy or -any 'git-svn' metadata, or config. So repositories created and managed with -using 'git-svn' should use 'rsync' for cloning, if cloning is to be done +'git clone' does not clone branches under the refs/remotes/ hierarchy or +any 'git svn' metadata, or config. So repositories created and managed with +using 'git svn' should use 'rsync' for cloning, if cloning is to be done at all. -Since 'dcommit' uses rebase internally, any git branches you 'git-push' to +Since 'dcommit' uses rebase internally, any git branches you 'git push' to before 'dcommit' on will require forcing an overwrite of the existing ref on the remote repository. This is generally considered bad practice, see the linkgit:git-push[1] documentation for details. @@ -661,6 +750,16 @@ already dcommitted. It is considered bad practice to --amend commits you've already pushed to a remote repository for other users, and dcommit with SVN is analogous to that. +When using multiple --branches or --tags, 'git svn' does not automatically +handle name collisions (for example, if two branches from different paths have +the same name, or if a branch and a tag have the same name). In these cases, +use 'init' to set up your git repository then, before your first 'fetch', edit +the .git/config file so that the branches and tags are associated with +different name spaces. For example: + + branches = stable/*:refs/remotes/svn/stable/* + branches = debug/*:refs/remotes/svn/debug/* + BUGS ---- @@ -677,7 +776,7 @@ for git to detect them. CONFIGURATION ------------- -'git-svn' stores [svn-remote] configuration information in the +'git svn' stores [svn-remote] configuration information in the repository .git/config file. It is similar the core git [remote] sections except 'fetch' keys do not accept glob arguments; but they are instead handled by the 'branches' @@ -698,7 +797,7 @@ Keep in mind that the '\*' (asterisk) wildcard of the local ref however the remote wildcard may be anywhere as long as it's an independent path component (surrounded by '/' or EOL). This type of configuration is not automatically created by 'init' and -should be manually entered with a text-editor or using 'git-config'. +should be manually entered with a text-editor or using 'git config'. SEE ALSO -------- diff --git a/Documentation/git-symbolic-ref.txt b/Documentation/git-symbolic-ref.txt index 210fde03a1..6392538807 100644 --- a/Documentation/git-symbolic-ref.txt +++ b/Documentation/git-symbolic-ref.txt @@ -14,9 +14,9 @@ DESCRIPTION Given one argument, reads which branch head the given symbolic ref refers to and outputs its path, relative to the `.git/` directory. Typically you would give `HEAD` as the <name> -argument to see on which branch your working tree is on. +argument to see which branch your working tree is on. -Give two arguments, create or update a symbolic ref <name> to +Given two arguments, creates or updates a symbolic ref <name> to point at the given branch <ref>. A symbolic ref is a regular file that stores a string that diff --git a/Documentation/git-write-tree.txt b/Documentation/git-write-tree.txt index 26d3850e73..c8899d528a 100644 --- a/Documentation/git-write-tree.txt +++ b/Documentation/git-write-tree.txt @@ -12,7 +12,8 @@ SYNOPSIS DESCRIPTION ----------- -Creates a tree object using the current index. +Creates a tree object using the current index. The name of the new +tree object is printed to standard output. The index must be in a fully merged state. diff --git a/Documentation/git.txt b/Documentation/git.txt index 3589a12e49..ad44cac71d 100644 --- a/Documentation/git.txt +++ b/Documentation/git.txt @@ -43,7 +43,21 @@ unreleased) version of git, that is available from 'master' branch of the `git.git` repository. Documentation for older releases are available here: -* link:v1.6.3/git.html[documentation for release 1.6.3] +* link:v1.6.4.2/git.html[documentation for release 1.6.4.2] + +* release notes for + link:RelNotes-1.6.4.2.txt[1.6.4.2], + link:RelNotes-1.6.4.1.txt[1.6.4.1], + link:RelNotes-1.6.4.txt[1.6.4]. + +* link:v1.6.3.4/git.html[documentation for release 1.6.3.4] + +* release notes for + link:RelNotes-1.6.3.4.txt[1.6.3.4], + link:RelNotes-1.6.3.3.txt[1.6.3.3], + link:RelNotes-1.6.3.2.txt[1.6.3.2], + link:RelNotes-1.6.3.1.txt[1.6.3.1], + link:RelNotes-1.6.3.txt[1.6.3]. * release notes for link:RelNotes-1.6.2.5.txt[1.6.2.5], @@ -315,7 +329,7 @@ Synching repositories include::cmds-synchingrepositories.txt[] -The following are helper programs used by the above; end users +The following are helper commands used by the above; end users typically do not use them directly. include::cmds-synchelpers.txt[] diff --git a/Documentation/gitattributes.txt b/Documentation/gitattributes.txt index aaa073efc8..1195e83b6e 100644 --- a/Documentation/gitattributes.txt +++ b/Documentation/gitattributes.txt @@ -404,7 +404,7 @@ Performing a three-way merge The attribute `merge` affects how three versions of a file is merged when a file-level merge is necessary during `git merge`, -and other programs such as `git revert` and `git cherry-pick`. +and other commands such as `git revert` and `git cherry-pick`. Set:: diff --git a/Documentation/gitcore-tutorial.txt b/Documentation/gitcore-tutorial.txt index 7ba5e589d7..b3640c4e64 100644 --- a/Documentation/gitcore-tutorial.txt +++ b/Documentation/gitcore-tutorial.txt @@ -12,7 +12,7 @@ git * DESCRIPTION ----------- -This tutorial explains how to use the "core" git programs to set up and +This tutorial explains how to use the "core" git commands to set up and work with a git repository. If you just need to use git as a revision control system you may prefer @@ -1328,7 +1328,7 @@ into it later. Obviously, this repository creation needs to be done only once. [NOTE] -'git-push' uses a pair of programs, +'git-push' uses a pair of commands, 'git-send-pack' on your local machine, and 'git-receive-pack' on the remote machine. The communication between the two over the network internally uses an SSH connection. diff --git a/Documentation/githooks.txt b/Documentation/githooks.txt index 1c736738cc..acc408d7e6 100644 --- a/Documentation/githooks.txt +++ b/Documentation/githooks.txt @@ -26,8 +26,11 @@ executable by default. This document describes the currently defined hooks. +HOOKS +----- + applypatch-msg --------------- +~~~~~~~~~~~~~~ This hook is invoked by 'git-am' script. It takes a single parameter, the name of the file that holds the proposed commit @@ -43,7 +46,7 @@ The default 'applypatch-msg' hook, when enabled, runs the 'commit-msg' hook, if the latter is enabled. pre-applypatch --------------- +~~~~~~~~~~~~~~ This hook is invoked by 'git-am'. It takes no parameter, and is invoked after the patch is applied, but before a commit is made. @@ -58,7 +61,7 @@ The default 'pre-applypatch' hook, when enabled, runs the 'pre-commit' hook, if the latter is enabled. post-applypatch ---------------- +~~~~~~~~~~~~~~~ This hook is invoked by 'git-am'. It takes no parameter, and is invoked after the patch is applied and a commit is made. @@ -67,7 +70,7 @@ This hook is meant primarily for notification, and cannot affect the outcome of 'git-am'. pre-commit ----------- +~~~~~~~~~~ This hook is invoked by 'git-commit', and can be bypassed with `\--no-verify` option. It takes no parameter, and is @@ -84,7 +87,7 @@ variable `GIT_EDITOR=:` if the command will not bring up an editor to modify the commit message. prepare-commit-msg ------------------- +~~~~~~~~~~~~~~~~~~ This hook is invoked by 'git-commit' right after preparing the default log message, and before the editor is started. @@ -109,7 +112,7 @@ The sample `prepare-commit-msg` hook that comes with git comments out the `Conflicts:` part of a merge's commit message. commit-msg ----------- +~~~~~~~~~~ This hook is invoked by 'git-commit', and can be bypassed with `\--no-verify` option. It takes a single parameter, the @@ -126,7 +129,7 @@ The default 'commit-msg' hook, when enabled, detects duplicate "Signed-off-by" lines, and aborts the commit if one is found. post-commit ------------ +~~~~~~~~~~~ This hook is invoked by 'git-commit'. It takes no parameter, and is invoked after a commit is made. @@ -135,14 +138,14 @@ This hook is meant primarily for notification, and cannot affect the outcome of 'git-commit'. pre-rebase ----------- +~~~~~~~~~~ This hook is called by 'git-rebase' and can be used to prevent a branch from getting rebased. post-checkout ------------ +~~~~~~~~~~~~~ This hook is invoked when a 'git-checkout' is run after having updated the worktree. The hook is given three parameters: the ref of the previous HEAD, @@ -160,7 +163,7 @@ differences from the previous HEAD if different, or set working dir metadata properties. post-merge ------------ +~~~~~~~~~~ This hook is invoked by 'git-merge', which happens when a 'git-pull' is done on a local repository. The hook takes a single parameter, a status @@ -175,7 +178,7 @@ for an example of how to do this. [[pre-receive]] pre-receive ------------ +~~~~~~~~~~~ This hook is invoked by 'git-receive-pack' on the remote repository, which happens when a 'git-push' is done on a local repository. @@ -204,7 +207,7 @@ for the user. [[update]] update ------- +~~~~~~ This hook is invoked by 'git-receive-pack' on the remote repository, which happens when a 'git-push' is done on a local repository. @@ -247,7 +250,7 @@ unannotated tags to be pushed. [[post-receive]] post-receive ------------- +~~~~~~~~~~~~ This hook is invoked by 'git-receive-pack' on the remote repository, which happens when a 'git-push' is done on a local repository. @@ -277,7 +280,7 @@ emails. [[post-update]] post-update ------------ +~~~~~~~~~~~ This hook is invoked by 'git-receive-pack' on the remote repository, which happens when a 'git-push' is done on a local repository. @@ -308,7 +311,7 @@ Both standard output and standard error output are forwarded to for the user. pre-auto-gc ------------ +~~~~~~~~~~~ This hook is invoked by 'git-gc --auto'. It takes no parameter, and exiting with non-zero status from this script causes the 'git-gc --auto' diff --git a/Documentation/gitmodules.txt b/Documentation/gitmodules.txt index d1a17e2625..5daf750d19 100644 --- a/Documentation/gitmodules.txt +++ b/Documentation/gitmodules.txt @@ -30,6 +30,17 @@ submodule.<name>.path:: submodule.<name>.url:: Defines an url from where the submodule repository can be cloned. +submodule.<name>.update:: + Defines what to do when the submodule is updated by the superproject. + If 'checkout' (the default), the new commit specified in the + superproject will be checked out in the submodule on a detached HEAD. + If 'rebase', the current branch of the submodule will be rebased onto + the commit specified in the superproject. If 'merge', the commit + specified in the superproject will be merged into the current branch + in the submodule. + This config option is overridden if 'git submodule update' is given + the '--merge' or '--rebase' options. + EXAMPLES -------- diff --git a/Documentation/merge-config.txt b/Documentation/merge-config.txt index 4832bc75e2..c0f96e7070 100644 --- a/Documentation/merge-config.txt +++ b/Documentation/merge-config.txt @@ -23,7 +23,7 @@ merge.tool:: Controls which merge resolution program is used by linkgit:git-mergetool[1]. Valid built-in values are: "kdiff3", "tkdiff", "meld", "xxdiff", "emerge", "vimdiff", "gvimdiff", - "diffuse", "ecmerge", "tortoisemerge", and + "diffuse", "ecmerge", "tortoisemerge", "araxis", and "opendiff". Any other value is treated is custom merge tool and there must be a corresponding mergetool.<tool>.cmd option. diff --git a/Documentation/rev-list-options.txt b/Documentation/rev-list-options.txt index 11eec941df..bf66116d61 100644 --- a/Documentation/rev-list-options.txt +++ b/Documentation/rev-list-options.txt @@ -201,6 +201,10 @@ endif::git-rev-list[] Stop when a given path disappears from the tree. +--merges:: + + Print only merge commits. + --no-merges:: Do not print commits with more than one parent. diff --git a/Documentation/technical/api-parse-options.txt b/Documentation/technical/api-parse-options.txt index e30c602f47..50f9e9ac17 100644 --- a/Documentation/technical/api-parse-options.txt +++ b/Documentation/technical/api-parse-options.txt @@ -60,13 +60,13 @@ Steps to parse options . in `cmd_foo(int argc, const char **argv, const char *prefix)` call - argc = parse_options(argc, argv, builtin_foo_options, builtin_foo_usage, flags); + argc = parse_options(argc, argv, prefix, builtin_foo_options, builtin_foo_usage, flags); + `parse_options()` will filter out the processed options of `argv[]` and leave the non-option arguments in `argv[]`. `argc` is updated appropriately because of the assignment. + -You can also pass NULL instead of a usage array as fourth parameter of +You can also pass NULL instead of a usage array as the fifth parameter of parse_options(), to avoid displaying a help screen with usage info and option list. This should only be done if necessary, e.g. to implement a limited parser for only a subset of the options that needs to be run @@ -137,6 +137,10 @@ There are some macros to easily define options: Introduce a boolean option. If used, `int_var` is bitwise-ored with `mask`. +`OPT_NEGBIT(short, long, &int_var, description, mask)`:: + Introduce a boolean option. + If used, `int_var` is bitwise-anded with the inverted `mask`. + `OPT_SET_INT(short, long, &int_var, description, integer)`:: Introduce a boolean option. If used, set `int_var` to `integer`. @@ -163,9 +167,22 @@ There are some macros to easily define options: and the result will be put into `var`. See 'Option Callbacks' below for a more elaborate description. +`OPT_FILENAME(short, long, &var, description)`:: + Introduce an option with a filename argument. + The filename will be prefixed by passing the filename along with + the prefix argument of `parse_options()` to `prefix_filename()`. + `OPT_ARGUMENT(long, description)`:: Introduce a long-option argument that will be kept in `argv[]`. +`OPT_NUMBER_CALLBACK(&var, description, func_ptr)`:: + Recognize numerical options like -123 and feed the integer as + if it was an argument to the function given by `func_ptr`. + The result will be put into `var`. There can be only one such + option definition. It cannot be negated and it takes no + arguments. Short options that happen to be digits take + precedence over it. + The last element of the array must be `OPT_END()`. diff --git a/Documentation/technical/api-remote.txt b/Documentation/technical/api-remote.txt index 073b22bd83..c54b17db69 100644 --- a/Documentation/technical/api-remote.txt +++ b/Documentation/technical/api-remote.txt @@ -18,6 +18,10 @@ struct remote An array of all of the url_nr URLs configured for the remote +`pushurl`:: + + An array of all of the pushurl_nr push URLs configured for the remote + `push`:: An array of refspecs configured for pushing, with diff --git a/Documentation/urls-remotes.txt b/Documentation/urls-remotes.txt index 41ec7774f4..2a0e7b8944 100644 --- a/Documentation/urls-remotes.txt +++ b/Documentation/urls-remotes.txt @@ -27,10 +27,13 @@ config file would appear like this: ------------ [remote "<name>"] url = <url> + pushurl = <pushurl> push = <refspec> fetch = <refspec> ------------ +The `<pushurl>` is used for pushes only. It is optional and defaults +to `<url>`. Named file in `$GIT_DIR/remotes` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/Documentation/user-manual.txt b/Documentation/user-manual.txt index 0b88a51d0b..67ebffa568 100644 --- a/Documentation/user-manual.txt +++ b/Documentation/user-manual.txt @@ -4131,7 +4131,7 @@ What does this mean? `git rev-list` is the original version of the revision walker, which _always_ printed a list of revisions to stdout. It is still functional, -and needs to, since most new Git programs start out as scripts using +and needs to, since most new Git commands start out as scripts using `git rev-list`. `git rev-parse` is not as important any more; it was only used to filter out diff --git a/GIT-VERSION-GEN b/GIT-VERSION-GEN index a56dcb26e7..76c6dd2fef 100755 --- a/GIT-VERSION-GEN +++ b/GIT-VERSION-GEN @@ -1,7 +1,7 @@ #!/bin/sh GVF=GIT-VERSION-FILE -DEF_VER=v1.6.3.4 +DEF_VER=v1.6.4.2 LF=' ' @@ -3,6 +3,11 @@ all:: # Define V=1 to have a more verbose compile. # +# Define SHELL_PATH to a POSIX shell if your /bin/sh is broken. +# +# Define SANE_TOOL_PATH to a colon-separated list of paths to prepend +# to PATH if your tools in /usr/bin are broken. +# # Define SNPRINTF_RETURNS_BOGUS if your are on a system which snprintf() # or vsnprintf() return -1 instead of number of characters which would # have been written to the final string if enough space had been available. @@ -52,6 +57,12 @@ all:: # # Define NO_MKDTEMP if you don't have mkdtemp in the C library. # +# Define NO_MKSTEMPS if you don't have mkstemps in the C library. +# +# Define NO_LIBGEN_H if you don't have libgen.h. +# +# Define NEEDS_LIBGEN if your libgen needs -lgen when linking +# # Define NO_SYS_SELECT_H if you don't have sys/select.h. # # Define NO_SYMLINK_HEAD if you never want .git/HEAD to be a symbolic link. @@ -91,6 +102,10 @@ all:: # Define NEEDS_SOCKET if linking with libc is not enough (SunOS, # Patrick Mauritz). # +# Define NEEDS_RESOLV if linking with -lnsl and/or -lsocket is not enough. +# Notably on Solaris hstrerror resides in libresolv and on Solaris 7 +# inet_ntop and inet_pton additionally reside there. +# # Define NO_MMAP if you want to avoid mmap. # # Define NO_PTHREADS if you do not have or do not want to use Pthreads. @@ -178,6 +193,11 @@ all:: # # Define NO_CROSS_DIRECTORY_HARDLINKS if you plan to distribute the installed # programs as a tar, where bin/ and libexec/ might be on different file systems. +# +# Define USE_NED_ALLOCATOR if you want to replace the platforms default +# memory allocators with the nedmalloc allocator written by Niall Douglas. +# +# Define NO_REGEX if you have no or inferior regex support in your C library. GIT-VERSION-FILE: .FORCE-GIT-VERSION-FILE @$(SHELL_PATH) ./GIT-VERSION-GEN @@ -228,6 +248,7 @@ ETC_GITCONFIG = etc/gitconfig endif lib = lib # DESTDIR= +pathsep = : # default configuration for gitweb GITWEB_CONFIG = gitweb_config.perl @@ -335,7 +356,6 @@ PROGRAMS += git-index-pack$X PROGRAMS += git-merge-index$X PROGRAMS += git-merge-tree$X PROGRAMS += git-mktag$X -PROGRAMS += git-mktree$X PROGRAMS += git-pack-redundant$X PROGRAMS += git-patch-id$X PROGRAMS += git-shell$X @@ -589,6 +609,7 @@ BUILTIN_OBJS += builtin-merge-base.o BUILTIN_OBJS += builtin-merge-file.o BUILTIN_OBJS += builtin-merge-ours.o BUILTIN_OBJS += builtin-merge-recursive.o +BUILTIN_OBJS += builtin-mktree.o BUILTIN_OBJS += builtin-mv.o BUILTIN_OBJS += builtin-name-rev.o BUILTIN_OBJS += builtin-pack-objects.o @@ -635,10 +656,12 @@ EXTLIBS = ifeq ($(uname_S),Linux) NO_STRLCPY = YesPlease + NO_MKSTEMPS = YesPlease THREADED_DELTA_SEARCH = YesPlease endif ifeq ($(uname_S),GNU/kFreeBSD) NO_STRLCPY = YesPlease + NO_MKSTEMPS = YesPlease THREADED_DELTA_SEARCH = YesPlease endif ifeq ($(uname_S),UnixWare) @@ -650,6 +673,7 @@ ifeq ($(uname_S),UnixWare) SHELL_PATH = /usr/local/bin/bash NO_IPV6 = YesPlease NO_HSTRERROR = YesPlease + NO_MKSTEMPS = YesPlease BASIC_CFLAGS += -Kthread BASIC_CFLAGS += -I/usr/local/include BASIC_LDFLAGS += -L/usr/local/lib @@ -673,6 +697,7 @@ ifeq ($(uname_S),SCO_SV) SHELL_PATH = /usr/bin/bash NO_IPV6 = YesPlease NO_HSTRERROR = YesPlease + NO_MKSTEMPS = YesPlease BASIC_CFLAGS += -I/usr/local/include BASIC_LDFLAGS += -L/usr/local/lib NO_STRCASESTR = YesPlease @@ -697,12 +722,23 @@ ifeq ($(uname_S),SunOS) NEEDS_SOCKET = YesPlease NEEDS_NSL = YesPlease SHELL_PATH = /bin/bash + SANE_TOOL_PATH = /usr/xpg6/bin:/usr/xpg4/bin NO_STRCASESTR = YesPlease NO_MEMMEM = YesPlease - NO_HSTRERROR = YesPlease NO_MKDTEMP = YesPlease - OLD_ICONV = UnfortunatelyYes + NO_MKSTEMPS = YesPlease + NO_REGEX = YesPlease NO_EXTERNAL_GREP = YesPlease + ifeq ($(uname_R),5.7) + NEEDS_RESOLV = YesPlease + NO_IPV6 = YesPlease + NO_SOCKADDR_STORAGE = YesPlease + NO_UNSETENV = YesPlease + NO_SETENV = YesPlease + NO_STRLCPY = YesPlease + NO_C99_FORMAT = YesPlease + NO_STRTOUMAX = YesPlease + endif ifeq ($(uname_R),5.8) NO_UNSETENV = YesPlease NO_SETENV = YesPlease @@ -715,15 +751,19 @@ ifeq ($(uname_S),SunOS) NO_C99_FORMAT = YesPlease NO_STRTOUMAX = YesPlease endif - INSTALL = ginstall + ifdef NO_IPV6 + NEEDS_RESOLV = YesPlease + endif + INSTALL = /usr/ucb/install TAR = gtar - BASIC_CFLAGS += -D__EXTENSIONS__ + BASIC_CFLAGS += -D__EXTENSIONS__ -D__sun__ -DHAVE_ALLOCA_H endif ifeq ($(uname_O),Cygwin) NO_D_TYPE_IN_DIRENT = YesPlease NO_D_INO_IN_DIRENT = YesPlease NO_STRCASESTR = YesPlease NO_MEMMEM = YesPlease + NO_MKSTEMPS = YesPlease NO_SYMLINK_HEAD = YesPlease NEEDS_LIBICONV = YesPlease NO_FAST_WORKING_DIRECTORY = UnfortunatelyYes @@ -767,11 +807,13 @@ ifeq ($(uname_S),NetBSD) BASIC_LDFLAGS += -L/usr/pkg/lib $(CC_LD_DYNPATH)/usr/pkg/lib THREADED_DELTA_SEARCH = YesPlease USE_ST_TIMESPEC = YesPlease + NO_MKSTEMPS = YesPlease endif ifeq ($(uname_S),AIX) NO_STRCASESTR=YesPlease NO_MEMMEM = YesPlease NO_MKDTEMP = YesPlease + NO_MKSTEMPS = YesPlease NO_STRLCPY = YesPlease NO_NSEC = YesPlease FREAD_READS_DIRECTORIES = UnfortunatelyYes @@ -787,24 +829,40 @@ endif ifeq ($(uname_S),GNU) # GNU/Hurd NO_STRLCPY=YesPlease + NO_MKSTEMPS = YesPlease +endif +ifeq ($(uname_S),IRIX) + NO_SETENV = YesPlease + NO_UNSETENV = YesPlease + NO_STRCASESTR = YesPlease + NO_MEMMEM = YesPlease + NO_MKSTEMPS = YesPlease + NO_MKDTEMP = YesPlease + NO_MMAP = YesPlease + NO_EXTERNAL_GREP = UnfortunatelyYes + SNPRINTF_RETURNS_BOGUS = YesPlease + SHELL_PATH = /usr/gnu/bin/bash + NEEDS_LIBGEN = YesPlease endif ifeq ($(uname_S),IRIX64) - NO_IPV6=YesPlease NO_SETENV=YesPlease + NO_UNSETENV = YesPlease NO_STRCASESTR=YesPlease NO_MEMMEM = YesPlease - NO_STRLCPY = YesPlease - NO_SOCKADDR_STORAGE=YesPlease + NO_MKSTEMPS = YesPlease + NO_MKDTEMP = YesPlease + NO_MMAP = YesPlease + NO_EXTERNAL_GREP = UnfortunatelyYes + SNPRINTF_RETURNS_BOGUS = YesPlease SHELL_PATH=/usr/gnu/bin/bash - BASIC_CFLAGS += -DPATH_MAX=1024 - # for now, build 32-bit version - BASIC_LDFLAGS += -L/usr/lib32 + NEEDS_LIBGEN = YesPlease endif ifeq ($(uname_S),HP-UX) NO_IPV6=YesPlease NO_SETENV=YesPlease NO_STRCASESTR=YesPlease NO_MEMMEM = YesPlease + NO_MKSTEMPS = YesPlease NO_STRLCPY = YesPlease NO_MKDTEMP = YesPlease NO_UNSETENV = YesPlease @@ -817,9 +875,10 @@ ifneq (,$(findstring CYGWIN,$(uname_S))) UNRELIABLE_FSTAT = UnfortunatelyYes endif ifneq (,$(findstring MINGW,$(uname_S))) + pathsep = ; NO_PREAD = YesPlease NO_OPENSSL = YesPlease - NO_CURL = YesPlease + NO_LIBGEN_H = YesPlease NO_SYMLINK_HEAD = YesPlease NO_IPV6 = YesPlease NO_SETENV = YesPlease @@ -827,12 +886,12 @@ ifneq (,$(findstring MINGW,$(uname_S))) NO_STRCASESTR = YesPlease NO_STRLCPY = YesPlease NO_MEMMEM = YesPlease - NO_PTHREADS = YesPlease NEEDS_LIBICONV = YesPlease OLD_ICONV = YesPlease NO_C99_FORMAT = YesPlease NO_STRTOUMAX = YesPlease NO_MKDTEMP = YesPlease + NO_MKSTEMPS = YesPlease SNPRINTF_RETURNS_BOGUS = YesPlease NO_SVN_TESTS = YesPlease NO_PERL_MAKEMAKER = YesPlease @@ -841,22 +900,44 @@ ifneq (,$(findstring MINGW,$(uname_S))) NO_ST_BLOCKS_IN_STRUCT_STAT = YesPlease NO_NSEC = YesPlease USE_WIN32_MMAP = YesPlease + USE_NED_ALLOCATOR = YesPlease UNRELIABLE_FSTAT = UnfortunatelyYes OBJECT_CREATION_USES_RENAMES = UnfortunatelyNeedsTo - COMPAT_CFLAGS += -D__USE_MINGW_ACCESS -DNOGDI -Icompat -Icompat/regex -Icompat/fnmatch - COMPAT_CFLAGS += -DSNPRINTF_SIZE_CORR=1 + NO_REGEX = YesPlease + COMPAT_CFLAGS += -D__USE_MINGW_ACCESS -DNOGDI -Icompat -Icompat/fnmatch COMPAT_CFLAGS += -DSTRIP_EXTENSION=\".exe\" - COMPAT_OBJS += compat/mingw.o compat/fnmatch/fnmatch.o compat/regex/regex.o compat/winansi.o + COMPAT_OBJS += compat/mingw.o compat/fnmatch/fnmatch.o compat/winansi.o EXTLIBS += -lws2_32 X = .exe +ifneq (,$(wildcard ../THIS_IS_MSYSGIT)) + htmldir=doc/git/html/ + prefix = + INSTALL = /bin/install + EXTLIBS += /mingw/lib/libz.a + NO_R_TO_GCC_LINKER = YesPlease + INTERNAL_QSORT = YesPlease + THREADED_DELTA_SEARCH = YesPlease +else + NO_CURL = YesPlease + NO_PTHREADS = YesPlease +endif endif ifneq (,$(findstring arm,$(uname_M))) ARM_SHA1 = YesPlease + NO_MKSTEMPS = YesPlease endif -include config.mak.autogen -include config.mak +ifdef SANE_TOOL_PATH +SANE_TOOL_PATH_SQ = $(subst ','\'',$(SANE_TOOL_PATH)) +BROKEN_PATH_FIX = 's|^\# @@BROKEN_PATH_FIX@@$$|git_broken_path_fix $(SANE_TOOL_PATH_SQ)|' +PATH := $(SANE_TOOL_PATH):${PATH} +else +BROKEN_PATH_FIX = '/^\# @@BROKEN_PATH_FIX@@$$/d' +endif + ifeq ($(uname_S),Darwin) ifndef NO_FINK ifeq ($(shell test -d /sw/lib && echo y),y) @@ -883,6 +964,11 @@ ifndef CC_LD_DYNPATH endif endif +ifdef NO_LIBGEN_H + COMPAT_CFLAGS += -DNO_LIBGEN_H + COMPAT_OBJS += compat/basename.o +endif + ifdef NO_CURL BASIC_CFLAGS += -DNO_CURL else @@ -949,12 +1035,18 @@ ifdef NEEDS_LIBICONV endif EXTLIBS += $(ICONV_LINK) -liconv endif +ifdef NEEDS_LIBGEN + EXTLIBS += -lgen +endif ifdef NEEDS_SOCKET EXTLIBS += -lsocket endif ifdef NEEDS_NSL EXTLIBS += -lnsl endif +ifdef NEEDS_RESOLV + EXTLIBS += -lresolv +endif ifdef NO_D_TYPE_IN_DIRENT BASIC_CFLAGS += -DNO_D_TYPE_IN_DIRENT endif @@ -1010,6 +1102,10 @@ ifdef NO_MKDTEMP COMPAT_CFLAGS += -DNO_MKDTEMP COMPAT_OBJS += compat/mkdtemp.o endif +ifdef NO_MKSTEMPS + COMPAT_CFLAGS += -DNO_MKSTEMPS + COMPAT_OBJS += compat/mkstemps.o +endif ifdef NO_UNSETENV COMPAT_CFLAGS += -DNO_UNSETENV COMPAT_OBJS += compat/unsetenv.o @@ -1127,6 +1223,15 @@ endif ifdef UNRELIABLE_FSTAT BASIC_CFLAGS += -DUNRELIABLE_FSTAT endif +ifdef NO_REGEX + COMPAT_CFLAGS += -Icompat/regex + COMPAT_OBJS += compat/regex/regex.o +endif + +ifdef USE_NED_ALLOCATOR + COMPAT_CFLAGS += -DUSE_NED_ALLOCATOR -DOVERRIDE_STRDUP -DNDEBUG -DREPLACE_SYSTEM_ALLOCATOR -Icompat/nedmalloc + COMPAT_OBJS += compat/nedmalloc/nedmalloc.o +endif ifeq ($(TCLTK_PATH),) NO_TCLTK=NoThanks @@ -1202,7 +1307,7 @@ SHELL = $(SHELL_PATH) all:: shell_compatibility_test $(ALL_PROGRAMS) $(BUILT_INS) $(OTHER_PROGRAMS) GIT-BUILD-OPTIONS ifneq (,$X) - $(foreach p,$(patsubst %$X,%,$(filter %$X,$(ALL_PROGRAMS) $(BUILT_INS) git$X)), test '$p' -ef '$p$X' || $(RM) '$p';) + $(QUIET_BUILT_IN)$(foreach p,$(patsubst %$X,%,$(filter %$X,$(ALL_PROGRAMS) $(BUILT_INS) git$X)), test '$p' -ef '$p$X' || $(RM) '$p';) endif all:: @@ -1253,9 +1358,9 @@ $(patsubst %.sh,%,$(SCRIPT_SH)) : % : %.sh $(QUIET_GEN)$(RM) $@ $@+ && \ sed -e '1s|#!.*/sh|#!$(SHELL_PATH_SQ)|' \ -e 's|@SHELL_PATH@|$(SHELL_PATH_SQ)|' \ - -e 's|@@PERL@@|$(PERL_PATH_SQ)|g' \ -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \ -e 's/@@NO_CURL@@/$(NO_CURL)/g' \ + -e $(BROKEN_PATH_FIX) \ $@.sh >$@+ && \ chmod +x $@+ && \ mv $@+ $@ @@ -1272,7 +1377,7 @@ $(patsubst %.perl,%,$(SCRIPT_PERL)): % : %.perl sed -e '1{' \ -e ' s|#!.*perl|#!$(PERL_PATH_SQ)|' \ -e ' h' \ - -e ' s=.*=use lib (split(/:/, $$ENV{GITPERLLIB} || "@@INSTLIBDIR@@"));=' \ + -e ' s=.*=use lib (split(/$(pathsep)/, $$ENV{GITPERLLIB} || "@@INSTLIBDIR@@"));=' \ -e ' H' \ -e ' x' \ -e '}' \ @@ -1495,6 +1600,8 @@ test-delta$X: diff-delta.o patch-delta.o test-parse-options$X: parse-options.o +test-parse-options.o: parse-options.h + .PRECIOUS: $(patsubst test-%$X,test-%.o,$(TEST_PROGRAMS)) test-%$X: test-%.o $(GITLIBS) @@ -1553,15 +1660,16 @@ ifneq (,$X) endif bindir=$$(cd '$(DESTDIR_SQ)$(bindir_SQ)' && pwd) && \ execdir=$$(cd '$(DESTDIR_SQ)$(gitexec_instdir_SQ)' && pwd) && \ - { $(RM) "$$execdir/git-add$X" && \ + { test "$$bindir/" = "$$execdir/" || \ + { $(RM) "$$execdir/git$X" && \ test -z "$(NO_CROSS_DIRECTORY_HARDLINKS)" && \ - ln "$$bindir/git$X" "$$execdir/git-add$X" 2>/dev/null || \ - cp "$$bindir/git$X" "$$execdir/git-add$X"; } && \ - { for p in $(filter-out git-add$X,$(BUILT_INS)); do \ + ln "$$bindir/git$X" "$$execdir/git$X" 2>/dev/null || \ + cp "$$bindir/git$X" "$$execdir/git$X"; } ; } && \ + { for p in $(BUILT_INS); do \ $(RM) "$$execdir/$$p" && \ - ln "$$execdir/git-add$X" "$$execdir/$$p" 2>/dev/null || \ - ln -s "git-add$X" "$$execdir/$$p" 2>/dev/null || \ - cp "$$execdir/git-add$X" "$$execdir/$$p" || exit; \ + ln "$$execdir/git$X" "$$execdir/$$p" 2>/dev/null || \ + ln -s "git$X" "$$execdir/$$p" 2>/dev/null || \ + cp "$$execdir/git$X" "$$execdir/$$p" || exit; \ done; } && \ ./check_bindir "z$$bindir" "z$$execdir" "$$bindir/git-add$X" @@ -1642,7 +1750,7 @@ distclean: clean $(RM) configure clean: - $(RM) *.o mozilla-sha1/*.o arm/*.o ppc/*.o compat/*.o xdiff/*.o \ + $(RM) *.o mozilla-sha1/*.o arm/*.o ppc/*.o compat/*.o compat/*/*.o xdiff/*.o \ $(LIB_FILE) $(XDIFF_LIB) $(RM) $(ALL_PROGRAMS) $(BUILT_INS) git$X $(RM) $(TEST_PROGRAMS) @@ -1 +1 @@ -Documentation/RelNotes-1.6.3.4.txt
\ No newline at end of file +Documentation/RelNotes-1.6.4.2.txt
\ No newline at end of file @@ -41,13 +41,13 @@ const char *make_absolute_path(const char *path) if (*buf) { if (!*cwd && !getcwd(cwd, sizeof(cwd))) - die ("Could not get current working directory"); + die_errno ("Could not get current working directory"); if (chdir(buf)) - die ("Could not switch to '%s'", buf); + die_errno ("Could not switch to '%s'", buf); } if (!getcwd(buf, PATH_MAX)) - die ("Could not get current working directory"); + die_errno ("Could not get current working directory"); if (last_elem) { int len = strlen(buf); @@ -63,7 +63,7 @@ const char *make_absolute_path(const char *path) if (!lstat(buf, &st) && S_ISLNK(st.st_mode)) { len = readlink(buf, next_buf, PATH_MAX); if (len < 0) - die ("Invalid symlink: %s", buf); + die_errno ("Invalid symlink '%s'", buf); if (PATH_MAX <= len) die("symbolic link too long: %s", buf); next_buf[len] = '\0'; @@ -75,7 +75,7 @@ const char *make_absolute_path(const char *path) } if (*cwd && chdir(cwd)) - die ("Could not change back to '%s'", cwd); + die_errno ("Could not change back to '%s'", cwd); return buf; } @@ -109,7 +109,7 @@ const char *make_nonrelative_path(const char *path) } else { const char *cwd = get_pwd_cwd(); if (!cwd) - die("Cannot determine the current working directory"); + die_errno("Cannot determine the current working directory"); if (snprintf(buf, PATH_MAX, "%s/%s", cwd, path) >= PATH_MAX) die("Too long path: %.*s", 60, path); } @@ -309,7 +309,7 @@ static int parse_archive_args(int argc, const char **argv, OPT_END() }; - argc = parse_options(argc, argv, opts, archive_usage, 0); + argc = parse_options(argc, argv, NULL, opts, archive_usage, 0); if (remote) die("Unexpected option --remote"); @@ -6,15 +6,30 @@ #include "list-objects.h" #include "quote.h" #include "sha1-lookup.h" +#include "run-command.h" +#include "log-tree.h" #include "bisect.h" -static unsigned char (*skipped_sha1)[20]; -static int skipped_sha1_nr; -static int skipped_sha1_alloc; +struct sha1_array { + unsigned char (*sha1)[20]; + int sha1_nr; + int sha1_alloc; + int sorted; +}; + +static struct sha1_array good_revs; +static struct sha1_array skipped_revs; + +static const unsigned char *current_bad_sha1; + +struct argv_array { + const char **argv; + int argv_nr; + int argv_alloc; +}; -static const char **rev_argv; -static int rev_argv_nr; -static int rev_argv_alloc; +static const char *argv_checkout[] = {"checkout", "-q", NULL, "--", NULL}; +static const char *argv_show_branch[] = {"show-branch", NULL, NULL}; /* bits #0-15 in revision.h */ @@ -398,23 +413,37 @@ struct commit_list *find_bisection(struct commit_list *list, return best; } +static void argv_array_push(struct argv_array *array, const char *string) +{ + ALLOC_GROW(array->argv, array->argv_nr + 1, array->argv_alloc); + array->argv[array->argv_nr++] = string; +} + +static void argv_array_push_sha1(struct argv_array *array, + const unsigned char *sha1, + const char *format) +{ + struct strbuf buf = STRBUF_INIT; + strbuf_addf(&buf, format, sha1_to_hex(sha1)); + argv_array_push(array, strbuf_detach(&buf, NULL)); +} + +static void sha1_array_push(struct sha1_array *array, + const unsigned char *sha1) +{ + ALLOC_GROW(array->sha1, array->sha1_nr + 1, array->sha1_alloc); + hashcpy(array->sha1[array->sha1_nr++], sha1); +} + static int register_ref(const char *refname, const unsigned char *sha1, int flags, void *cb_data) { if (!strcmp(refname, "bad")) { - ALLOC_GROW(rev_argv, rev_argv_nr + 1, rev_argv_alloc); - rev_argv[rev_argv_nr++] = xstrdup(sha1_to_hex(sha1)); + current_bad_sha1 = sha1; } else if (!prefixcmp(refname, "good-")) { - const char *hex = sha1_to_hex(sha1); - char *good = xmalloc(strlen(hex) + 2); - *good = '^'; - memcpy(good + 1, hex, strlen(hex) + 1); - ALLOC_GROW(rev_argv, rev_argv_nr + 1, rev_argv_alloc); - rev_argv[rev_argv_nr++] = good; + sha1_array_push(&good_revs, sha1); } else if (!prefixcmp(refname, "skip-")) { - ALLOC_GROW(skipped_sha1, skipped_sha1_nr + 1, - skipped_sha1_alloc); - hashcpy(skipped_sha1[skipped_sha1_nr++], sha1); + sha1_array_push(&skipped_revs, sha1); } return 0; @@ -425,14 +454,14 @@ static int read_bisect_refs(void) return for_each_ref_in("refs/bisect/", register_ref, NULL); } -void read_bisect_paths(void) +static void read_bisect_paths(struct argv_array *array) { struct strbuf str = STRBUF_INIT; const char *filename = git_path("BISECT_NAMES"); FILE *fp = fopen(filename, "r"); if (!fp) - die("Could not open file '%s': %s", filename, strerror(errno)); + die_errno("Could not open file '%s'", filename); while (strbuf_getline(&str, fp, '\n') != EOF) { char *quoted; @@ -440,8 +469,8 @@ void read_bisect_paths(void) strbuf_trim(&str); quoted = strbuf_detach(&str, NULL); - res = sq_dequote_to_argv(quoted, &rev_argv, - &rev_argv_nr, &rev_argv_alloc); + res = sq_dequote_to_argv(quoted, &array->argv, + &array->argv_nr, &array->argv_alloc); if (res) die("Badly quoted content in file '%s': %s", filename, quoted); @@ -451,106 +480,527 @@ void read_bisect_paths(void) fclose(fp); } -static int skipcmp(const void *a, const void *b) +static int array_cmp(const void *a, const void *b) { return hashcmp(a, b); } -static void prepare_skipped(void) +static void sort_sha1_array(struct sha1_array *array) +{ + qsort(array->sha1, array->sha1_nr, sizeof(*array->sha1), array_cmp); + + array->sorted = 1; +} + +static const unsigned char *sha1_access(size_t index, void *table) { - qsort(skipped_sha1, skipped_sha1_nr, sizeof(*skipped_sha1), skipcmp); + unsigned char (*array)[20] = table; + return array[index]; } -static const unsigned char *skipped_sha1_access(size_t index, void *table) +static int lookup_sha1_array(struct sha1_array *array, + const unsigned char *sha1) { - unsigned char (*skipped)[20] = table; - return skipped[index]; + if (!array->sorted) + sort_sha1_array(array); + + return sha1_pos(sha1, array->sha1, array->sha1_nr, sha1_access); } -static int lookup_skipped(unsigned char *sha1) +static char *join_sha1_array_hex(struct sha1_array *array, char delim) { - return sha1_pos(sha1, skipped_sha1, skipped_sha1_nr, - skipped_sha1_access); + struct strbuf joined_hexs = STRBUF_INIT; + int i; + + for (i = 0; i < array->sha1_nr; i++) { + strbuf_addstr(&joined_hexs, sha1_to_hex(array->sha1[i])); + if (i + 1 < array->sha1_nr) + strbuf_addch(&joined_hexs, delim); + } + + return strbuf_detach(&joined_hexs, NULL); } +/* + * In this function, passing a not NULL skipped_first is very special. + * It means that we want to know if the first commit in the list is + * skipped because we will want to test a commit away from it if it is + * indeed skipped. + * So if the first commit is skipped, we cannot take the shortcut to + * just "return list" when we find the first non skipped commit, we + * have to return a fully filtered list. + * + * We use (*skipped_first == -1) to mean "it has been found that the + * first commit is not skipped". In this case *skipped_first is set back + * to 0 just before the function returns. + */ struct commit_list *filter_skipped(struct commit_list *list, struct commit_list **tried, - int show_all) + int show_all, + int *count, + int *skipped_first) { struct commit_list *filtered = NULL, **f = &filtered; *tried = NULL; - if (!skipped_sha1_nr) - return list; + if (skipped_first) + *skipped_first = 0; + if (count) + *count = 0; - prepare_skipped(); + if (!skipped_revs.sha1_nr) + return list; while (list) { struct commit_list *next = list->next; list->next = NULL; - if (0 <= lookup_skipped(list->item->object.sha1)) { + if (0 <= lookup_sha1_array(&skipped_revs, + list->item->object.sha1)) { + if (skipped_first && !*skipped_first) + *skipped_first = 1; /* Move current to tried list */ *tried = list; tried = &list->next; } else { - if (!show_all) - return list; + if (!show_all) { + if (!skipped_first || !*skipped_first) + return list; + } else if (skipped_first && !*skipped_first) { + /* This means we know it's not skipped */ + *skipped_first = -1; + } /* Move current to filtered list */ *f = list; f = &list->next; + if (count) + (*count)++; } list = next; } + if (skipped_first && *skipped_first == -1) + *skipped_first = 0; + return filtered; } -static void bisect_rev_setup(struct rev_info *revs, const char *prefix) +#define PRN_MODULO 32768 + +/* + * This is a pseudo random number generator based on "man 3 rand". + * It is not used properly because the seed is the argument and it + * is increased by one between each call, but that should not matter + * for this application. + */ +int get_prn(int count) { + count = count * 1103515245 + 12345; + return ((unsigned)(count/65536) % PRN_MODULO); +} + +/* + * Custom integer square root from + * http://en.wikipedia.org/wiki/Integer_square_root + */ +static int sqrti(int val) +{ + float d, x = val; + + if (val == 0) + return 0; + + do { + float y = (x + (float)val / x) / 2; + d = (y > x) ? y - x : x - y; + x = y; + } while (d >= 0.5); + + return (int)x; +} + +static struct commit_list *skip_away(struct commit_list *list, int count) +{ + struct commit_list *cur, *previous; + int prn, index, i; + + prn = get_prn(count); + index = (count * prn / PRN_MODULO) * sqrti(prn) / sqrti(PRN_MODULO); + + cur = list; + previous = NULL; + + for (i = 0; cur; cur = cur->next, i++) { + if (i == index) { + if (hashcmp(cur->item->object.sha1, current_bad_sha1)) + return cur; + if (previous) + return previous; + return list; + } + previous = cur; + } + + return list; +} + +static struct commit_list *managed_skipped(struct commit_list *list, + struct commit_list **tried) +{ + int count, skipped_first; + + *tried = NULL; + + if (!skipped_revs.sha1_nr) + return list; + + list = filter_skipped(list, tried, 0, &count, &skipped_first); + + if (!skipped_first) + return list; + + return skip_away(list, count); +} + +static void bisect_rev_setup(struct rev_info *revs, const char *prefix, + const char *bad_format, const char *good_format, + int read_paths) { + struct argv_array rev_argv = { NULL, 0, 0 }; + int i; + init_revisions(revs, prefix); revs->abbrev = 0; revs->commit_format = CMIT_FMT_UNSPECIFIED; - /* argv[0] will be ignored by setup_revisions */ - ALLOC_GROW(rev_argv, rev_argv_nr + 1, rev_argv_alloc); - rev_argv[rev_argv_nr++] = xstrdup("bisect_rev_setup"); + /* rev_argv.argv[0] will be ignored by setup_revisions */ + argv_array_push(&rev_argv, xstrdup("bisect_rev_setup")); + argv_array_push_sha1(&rev_argv, current_bad_sha1, bad_format); + for (i = 0; i < good_revs.sha1_nr; i++) + argv_array_push_sha1(&rev_argv, good_revs.sha1[i], + good_format); + argv_array_push(&rev_argv, xstrdup("--")); + if (read_paths) + read_bisect_paths(&rev_argv); + argv_array_push(&rev_argv, NULL); + + setup_revisions(rev_argv.argv_nr, rev_argv.argv, revs, NULL); +} - if (read_bisect_refs()) - die("reading bisect refs failed"); +static void bisect_common(struct rev_info *revs) +{ + if (prepare_revision_walk(revs)) + die("revision walk setup failed"); + if (revs->tree_objects) + mark_edges_uninteresting(revs->commits, revs, NULL); +} + +static void exit_if_skipped_commits(struct commit_list *tried, + const unsigned char *bad) +{ + if (!tried) + return; + + printf("There are only 'skip'ped commits left to test.\n" + "The first bad commit could be any of:\n"); + print_commit_list(tried, "%s\n", "%s\n"); + if (bad) + printf("%s\n", sha1_to_hex(bad)); + printf("We cannot bisect more!\n"); + exit(2); +} + +static int is_expected_rev(const unsigned char *sha1) +{ + const char *filename = git_path("BISECT_EXPECTED_REV"); + struct stat st; + struct strbuf str = STRBUF_INIT; + FILE *fp; + int res = 0; + + if (stat(filename, &st) || !S_ISREG(st.st_mode)) + return 0; + + fp = fopen(filename, "r"); + if (!fp) + return 0; + + if (strbuf_getline(&str, fp, '\n') != EOF) + res = !strcmp(str.buf, sha1_to_hex(sha1)); - ALLOC_GROW(rev_argv, rev_argv_nr + 1, rev_argv_alloc); - rev_argv[rev_argv_nr++] = xstrdup("--"); + strbuf_release(&str); + fclose(fp); + + return res; +} + +static void mark_expected_rev(char *bisect_rev_hex) +{ + int len = strlen(bisect_rev_hex); + const char *filename = git_path("BISECT_EXPECTED_REV"); + int fd = open(filename, O_CREAT | O_TRUNC | O_WRONLY, 0600); + + if (fd < 0) + die_errno("could not create file '%s'", filename); + + bisect_rev_hex[len] = '\n'; + write_or_die(fd, bisect_rev_hex, len + 1); + bisect_rev_hex[len] = '\0'; + + if (close(fd) < 0) + die("closing file %s: %s", filename, strerror(errno)); +} + +static int bisect_checkout(char *bisect_rev_hex) +{ + int res; + + mark_expected_rev(bisect_rev_hex); + + argv_checkout[2] = bisect_rev_hex; + res = run_command_v_opt(argv_checkout, RUN_GIT_CMD); + if (res) + exit(res); + + argv_show_branch[1] = bisect_rev_hex; + return run_command_v_opt(argv_show_branch, RUN_GIT_CMD); +} + +static struct commit *get_commit_reference(const unsigned char *sha1) +{ + struct commit *r = lookup_commit_reference(sha1); + if (!r) + die("Not a valid commit name %s", sha1_to_hex(sha1)); + return r; +} + +static struct commit **get_bad_and_good_commits(int *rev_nr) +{ + int len = 1 + good_revs.sha1_nr; + struct commit **rev = xmalloc(len * sizeof(*rev)); + int i, n = 0; + + rev[n++] = get_commit_reference(current_bad_sha1); + for (i = 0; i < good_revs.sha1_nr; i++) + rev[n++] = get_commit_reference(good_revs.sha1[i]); + *rev_nr = n; + + return rev; +} + +static void handle_bad_merge_base(void) +{ + if (is_expected_rev(current_bad_sha1)) { + char *bad_hex = sha1_to_hex(current_bad_sha1); + char *good_hex = join_sha1_array_hex(&good_revs, ' '); + + fprintf(stderr, "The merge base %s is bad.\n" + "This means the bug has been fixed " + "between %s and [%s].\n", + bad_hex, bad_hex, good_hex); + + exit(3); + } + + fprintf(stderr, "Some good revs are not ancestor of the bad rev.\n" + "git bisect cannot work properly in this case.\n" + "Maybe you mistake good and bad revs?\n"); + exit(1); +} + +static void handle_skipped_merge_base(const unsigned char *mb) +{ + char *mb_hex = sha1_to_hex(mb); + char *bad_hex = sha1_to_hex(current_bad_sha1); + char *good_hex = join_sha1_array_hex(&good_revs, ' '); + + fprintf(stderr, "Warning: the merge base between %s and [%s] " + "must be skipped.\n" + "So we cannot be sure the first bad commit is " + "between %s and %s.\n" + "We continue anyway.\n", + bad_hex, good_hex, mb_hex, bad_hex); + free(good_hex); +} + +/* + * "check_merge_bases" checks that merge bases are not "bad". + * + * - If one is "bad", it means the user assumed something wrong + * and we must exit with a non 0 error code. + * - If one is "good", that's good, we have nothing to do. + * - If one is "skipped", we can't know but we should warn. + * - If we don't know, we should check it out and ask the user to test. + */ +static void check_merge_bases(void) +{ + struct commit_list *result; + int rev_nr; + struct commit **rev = get_bad_and_good_commits(&rev_nr); + + result = get_merge_bases_many(rev[0], rev_nr - 1, rev + 1, 0); - read_bisect_paths(); + for (; result; result = result->next) { + const unsigned char *mb = result->item->object.sha1; + if (!hashcmp(mb, current_bad_sha1)) { + handle_bad_merge_base(); + } else if (0 <= lookup_sha1_array(&good_revs, mb)) { + continue; + } else if (0 <= lookup_sha1_array(&skipped_revs, mb)) { + handle_skipped_merge_base(mb); + } else { + printf("Bisecting: a merge base must be tested\n"); + exit(bisect_checkout(sha1_to_hex(mb))); + } + } + + free(rev); + free_commit_list(result); +} + +static int check_ancestors(const char *prefix) +{ + struct rev_info revs; + struct object_array pending_copy; + int i, res; + + bisect_rev_setup(&revs, prefix, "^%s", "%s", 0); + + /* Save pending objects, so they can be cleaned up later. */ + memset(&pending_copy, 0, sizeof(pending_copy)); + for (i = 0; i < revs.pending.nr; i++) + add_object_array(revs.pending.objects[i].item, + revs.pending.objects[i].name, + &pending_copy); + + bisect_common(&revs); + res = (revs.commits != NULL); + + /* Clean up objects used, as they will be reused. */ + for (i = 0; i < pending_copy.nr; i++) { + struct object *o = pending_copy.objects[i].item; + clear_commit_marks((struct commit *)o, ALL_REV_FLAGS); + } + + return res; +} + +/* + * "check_good_are_ancestors_of_bad" checks that all "good" revs are + * ancestor of the "bad" rev. + * + * If that's not the case, we need to check the merge bases. + * If a merge base must be tested by the user, its source code will be + * checked out to be tested by the user and we will exit. + */ +static void check_good_are_ancestors_of_bad(const char *prefix) +{ + const char *filename = git_path("BISECT_ANCESTORS_OK"); + struct stat st; + int fd; + + if (!current_bad_sha1) + die("a bad revision is needed"); + + /* Check if file BISECT_ANCESTORS_OK exists. */ + if (!stat(filename, &st) && S_ISREG(st.st_mode)) + return; + + /* Bisecting with no good rev is ok. */ + if (good_revs.sha1_nr == 0) + return; + + /* Check if all good revs are ancestor of the bad rev. */ + if (check_ancestors(prefix)) + check_merge_bases(); + + /* Create file BISECT_ANCESTORS_OK. */ + fd = open(filename, O_CREAT | O_TRUNC | O_WRONLY, 0600); + if (fd < 0) + warning("could not create file '%s': %s", + filename, strerror(errno)); + else + close(fd); +} + +/* + * This does "git diff-tree --pretty COMMIT" without one fork+exec. + */ +static void show_diff_tree(const char *prefix, struct commit *commit) +{ + struct rev_info opt; + + /* diff-tree init */ + init_revisions(&opt, prefix); + git_config(git_diff_basic_config, NULL); /* no "diff" UI options */ + opt.abbrev = 0; + opt.diff = 1; - ALLOC_GROW(rev_argv, rev_argv_nr + 1, rev_argv_alloc); - rev_argv[rev_argv_nr++] = NULL; + /* This is what "--pretty" does */ + opt.verbose_header = 1; + opt.use_terminator = 0; + opt.commit_format = CMIT_FMT_DEFAULT; - setup_revisions(rev_argv_nr, rev_argv, revs, NULL); + /* diff-tree init */ + if (!opt.diffopt.output_format) + opt.diffopt.output_format = DIFF_FORMAT_RAW; - revs->limited = 1; + log_tree_commit(&opt, commit); } -int bisect_next_vars(const char *prefix) +/* + * We use the convention that exiting with an exit code 10 means that + * the bisection process finished successfully. + * In this case the calling shell script should exit 0. + */ +int bisect_next_all(const char *prefix) { struct rev_info revs; - struct rev_list_info info; - int reaches = 0, all = 0; + struct commit_list *tried; + int reaches = 0, all = 0, nr; + const unsigned char *bisect_rev; + char bisect_rev_hex[41]; - memset(&info, 0, sizeof(info)); - info.revs = &revs; - info.bisect_show_flags = BISECT_SHOW_TRIED | BISECT_SHOW_STRINGED; + if (read_bisect_refs()) + die("reading bisect refs failed"); - bisect_rev_setup(&revs, prefix); + check_good_are_ancestors_of_bad(prefix); - if (prepare_revision_walk(&revs)) - die("revision walk setup failed"); - if (revs.tree_objects) - mark_edges_uninteresting(revs.commits, &revs, NULL); + bisect_rev_setup(&revs, prefix, "%s", "^%s", 1); + revs.limited = 1; + + bisect_common(&revs); revs.commits = find_bisection(revs.commits, &reaches, &all, - !!skipped_sha1_nr); + !!skipped_revs.sha1_nr); + revs.commits = managed_skipped(revs.commits, &tried); + + if (!revs.commits) { + /* + * We should exit here only if the "bad" + * commit is also a "skip" commit. + */ + exit_if_skipped_commits(tried, NULL); + + printf("%s was both good and bad\n", + sha1_to_hex(current_bad_sha1)); + exit(1); + } - return show_bisect_vars(&info, reaches, all); + bisect_rev = revs.commits->item->object.sha1; + memcpy(bisect_rev_hex, sha1_to_hex(bisect_rev), 41); + + if (!hashcmp(bisect_rev, current_bad_sha1)) { + exit_if_skipped_commits(tried, current_bad_sha1); + printf("%s is the first bad commit\n", bisect_rev_hex); + show_diff_tree(prefix, revs.commits->item); + /* This means the bisection process succeeded. */ + exit(10); + } + + nr = all - reaches - 1; + printf("Bisecting: %d revisions left to test after this " + "(roughly %d steps)\n", nr, estimate_bisect_steps(all)); + + return bisect_checkout(bisect_rev_hex); } + @@ -7,12 +7,17 @@ extern struct commit_list *find_bisection(struct commit_list *list, extern struct commit_list *filter_skipped(struct commit_list *list, struct commit_list **tried, - int show_all); + int show_all, + int *count, + int *skipped_first); + +extern void print_commit_list(struct commit_list *list, + const char *format_cur, + const char *format_last); /* bisect_show_flags flags in struct rev_list_info */ #define BISECT_SHOW_ALL (1<<0) #define BISECT_SHOW_TRIED (1<<1) -#define BISECT_SHOW_STRINGED (1<<2) struct rev_list_info { struct rev_info *revs; @@ -24,6 +29,8 @@ struct rev_list_info { extern int show_bisect_vars(struct rev_list_info *info, int reaches, int all); -extern int bisect_next_vars(const char *prefix); +extern int bisect_next_all(const char *prefix); + +extern int estimate_bisect_steps(int all); #endif @@ -172,7 +172,7 @@ void create_branch(const char *head, lock = lock_any_ref_for_update(ref.buf, NULL, 0); if (!lock) - die("Failed to lock ref for update: %s.", strerror(errno)); + die_errno("Failed to lock ref for update"); if (reflog) log_all_ref_updates = 1; @@ -188,7 +188,7 @@ void create_branch(const char *head, setup_tracking(name, real_ref, track); if (write_ref_sha1(lock, sha1, msg) < 0) - die("Failed to write ref: %s.", strerror(errno)); + die_errno("Failed to write ref"); strbuf_release(&ref); free(real_ref); diff --git a/builtin-add.c b/builtin-add.c index d6ad57bfc2..581a2a1748 100644 --- a/builtin-add.c +++ b/builtin-add.c @@ -10,12 +10,14 @@ #include "cache-tree.h" #include "run-command.h" #include "parse-options.h" +#include "diff.h" +#include "revision.h" static const char * const builtin_add_usage[] = { "git add [options] [--] <filepattern>...", NULL }; -static int patch_interactive, add_interactive; +static int patch_interactive, add_interactive, edit_interactive; static int take_worktree_changes; static void fill_pathspec_matches(const char **pathspec, char *seen, int specs) @@ -95,35 +97,6 @@ static void treat_gitlinks(const char **pathspec) } } -static void fill_directory(struct dir_struct *dir, const char **pathspec, - int ignored_too) -{ - const char *path, *base; - int baselen; - - /* Set up the default git porcelain excludes */ - memset(dir, 0, sizeof(*dir)); - if (!ignored_too) { - dir->flags |= DIR_COLLECT_IGNORED; - setup_standard_excludes(dir); - } - - /* - * Calculate common prefix for the pathspec, and - * use that to optimize the directory walk - */ - baselen = common_prefix(pathspec); - path = "."; - base = ""; - if (baselen) - path = base = xmemdupz(*pathspec, baselen); - - /* Read the directory and prune it */ - read_directory(dir, path, base, baselen, pathspec); - if (pathspec) - prune_directory(dir, pathspec, baselen); -} - static void refresh(int verbose, const char **pathspec) { char *seen; @@ -187,6 +160,51 @@ int interactive_add(int argc, const char **argv, const char *prefix) return status; } +static int edit_patch(int argc, const char **argv, const char *prefix) +{ + char *file = xstrdup(git_path("ADD_EDIT.patch")); + const char *apply_argv[] = { "apply", "--recount", "--cached", + file, NULL }; + struct child_process child; + struct rev_info rev; + int out; + struct stat st; + + git_config(git_diff_basic_config, NULL); /* no "diff" UI options */ + + if (read_cache() < 0) + die ("Could not read the index"); + + init_revisions(&rev, prefix); + rev.diffopt.context = 7; + + argc = setup_revisions(argc, argv, &rev, NULL); + rev.diffopt.output_format = DIFF_FORMAT_PATCH; + out = open(file, O_CREAT | O_WRONLY, 0644); + if (out < 0) + die ("Could not open '%s' for writing.", file); + rev.diffopt.file = fdopen(out, "w"); + rev.diffopt.close_file = 1; + if (run_diff_files(&rev, 0)) + die ("Could not write patch"); + + launch_editor(file, NULL, NULL); + + if (stat(file, &st)) + die_errno("Could not stat '%s'", file); + if (!st.st_size) + die("Empty patch. Aborted."); + + memset(&child, 0, sizeof(child)); + child.git_cmd = 1; + child.argv = apply_argv; + if (run_command(&child)) + die ("Could not apply '%s'", file); + + unlink(file); + return 0; +} + static struct lock_file lock_file; static const char ignore_error[] = @@ -201,6 +219,7 @@ static struct option builtin_add_options[] = { OPT_GROUP(""), OPT_BOOLEAN('i', "interactive", &add_interactive, "interactive picking"), OPT_BOOLEAN('p', "patch", &patch_interactive, "interactive patching"), + OPT_BOOLEAN('e', "edit", &edit_interactive, "edit current diff and apply"), OPT_BOOLEAN('f', "force", &ignored_too, "allow adding otherwise ignored files"), OPT_BOOLEAN('u', "update", &take_worktree_changes, "update tracked files"), OPT_BOOLEAN('N', "intent-to-add", &intent_to_add, "record only the fact that the path will be added later"), @@ -252,12 +271,17 @@ int cmd_add(int argc, const char **argv, const char *prefix) git_config(add_config, NULL); - argc = parse_options(argc, argv, builtin_add_options, - builtin_add_usage, 0); + argc = parse_options(argc, argv, prefix, builtin_add_options, + builtin_add_usage, PARSE_OPT_KEEP_ARGV0); if (patch_interactive) add_interactive = 1; if (add_interactive) - exit(interactive_add(argc, argv, prefix)); + exit(interactive_add(argc - 1, argv + 1, prefix)); + + if (edit_interactive) + return(edit_patch(argc, argv, prefix)); + argc--; + argv++; if (addremove && take_worktree_changes) die("-A and -u are mutually incompatible"); @@ -290,9 +314,21 @@ int cmd_add(int argc, const char **argv, const char *prefix) die("index file corrupt"); treat_gitlinks(pathspec); - if (add_new_files) + if (add_new_files) { + int baselen; + + /* Set up the default git porcelain excludes */ + memset(&dir, 0, sizeof(dir)); + if (!ignored_too) { + dir.flags |= DIR_COLLECT_IGNORED; + setup_standard_excludes(&dir); + } + /* This picks up the paths that are not tracked */ - fill_directory(&dir, pathspec, ignored_too); + baselen = fill_directory(&dir, pathspec); + if (pathspec) + prune_directory(&dir, pathspec, baselen); + } if (refresh_only) { refresh(verbose, pathspec); diff --git a/builtin-apply.c b/builtin-apply.c index a40b982242..39dc96ae02 100644 --- a/builtin-apply.c +++ b/builtin-apply.c @@ -280,7 +280,7 @@ static void say_patch_name(FILE *output, const char *pre, static void read_patch_file(struct strbuf *sb, int fd) { if (strbuf_read(sb, fd, 0) < 0) - die("git apply: read returned %s", strerror(errno)); + die_errno("git apply: failed to read"); /* * Make sure that we have some slop in the buffer @@ -320,6 +320,20 @@ static int name_terminate(const char *name, int namelen, int c, int terminate) return 1; } +/* remove double slashes to make --index work with such filenames */ +static char *squash_slash(char *name) +{ + int i = 0, j = 0; + + while (name[i]) { + if ((name[j++] = name[i++]) == '/') + while (name[i] == '/') + i++; + } + name[j] = '\0'; + return name; +} + static char *find_name(const char *line, char *def, int p_value, int terminate) { int len; @@ -349,7 +363,7 @@ static char *find_name(const char *line, char *def, int p_value, int terminate) free(def); if (root) strbuf_insert(&name, 0, root, root_len); - return strbuf_detach(&name, NULL); + return squash_slash(strbuf_detach(&name, NULL)); } } strbuf_release(&name); @@ -369,10 +383,10 @@ static char *find_name(const char *line, char *def, int p_value, int terminate) start = line; } if (!start) - return def; + return squash_slash(def); len = line - start; if (!len) - return def; + return squash_slash(def); /* * Generally we prefer the shorter name, especially @@ -383,7 +397,7 @@ static char *find_name(const char *line, char *def, int p_value, int terminate) if (def) { int deflen = strlen(def); if (deflen < len && !strncmp(start, def, deflen)) - return def; + return squash_slash(def); free(def); } @@ -392,10 +406,10 @@ static char *find_name(const char *line, char *def, int p_value, int terminate) strcpy(ret, root); memcpy(ret + root_len, start, len); ret[root_len + len] = '\0'; - return ret; + return squash_slash(ret); } - return xmemdupz(start, len); + return squash_slash(xmemdupz(start, len)); } static int count_slashes(const char *cp) @@ -444,6 +458,76 @@ static int guess_p_value(const char *nameline) } /* + * Does the ---/+++ line has the POSIX timestamp after the last HT? + * GNU diff puts epoch there to signal a creation/deletion event. Is + * this such a timestamp? + */ +static int has_epoch_timestamp(const char *nameline) +{ + /* + * We are only interested in epoch timestamp; any non-zero + * fraction cannot be one, hence "(\.0+)?" in the regexp below. + * For the same reason, the date must be either 1969-12-31 or + * 1970-01-01, and the seconds part must be "00". + */ + const char stamp_regexp[] = + "^(1969-12-31|1970-01-01)" + " " + "[0-2][0-9]:[0-5][0-9]:00(\\.0+)?" + " " + "([-+][0-2][0-9][0-5][0-9])\n"; + const char *timestamp = NULL, *cp; + static regex_t *stamp; + regmatch_t m[10]; + int zoneoffset; + int hourminute; + int status; + + for (cp = nameline; *cp != '\n'; cp++) { + if (*cp == '\t') + timestamp = cp + 1; + } + if (!timestamp) + return 0; + if (!stamp) { + stamp = xmalloc(sizeof(*stamp)); + if (regcomp(stamp, stamp_regexp, REG_EXTENDED)) { + warning("Cannot prepare timestamp regexp %s", + stamp_regexp); + return 0; + } + } + + status = regexec(stamp, timestamp, ARRAY_SIZE(m), m, 0); + if (status) { + if (status != REG_NOMATCH) + warning("regexec returned %d for input: %s", + status, timestamp); + return 0; + } + + zoneoffset = strtol(timestamp + m[3].rm_so + 1, NULL, 10); + zoneoffset = (zoneoffset / 100) * 60 + (zoneoffset % 100); + if (timestamp[m[3].rm_so] == '-') + zoneoffset = -zoneoffset; + + /* + * YYYY-MM-DD hh:mm:ss must be from either 1969-12-31 + * (west of GMT) or 1970-01-01 (east of GMT) + */ + if ((zoneoffset < 0 && memcmp(timestamp, "1969-12-31", 10)) || + (0 <= zoneoffset && memcmp(timestamp, "1970-01-01", 10))) + return 0; + + hourminute = (strtol(timestamp + 11, NULL, 10) * 60 + + strtol(timestamp + 14, NULL, 10) - + zoneoffset); + + return ((zoneoffset < 0 && hourminute == 1440) || + (0 <= zoneoffset && !hourminute)); +} + +/* * Get the name etc info from the ---/+++ lines of a traditional patch header * * FIXME! The end-of-filename heuristics are kind of screwy. For existing @@ -479,7 +563,17 @@ static void parse_traditional_patch(const char *first, const char *second, struc } else { name = find_name(first, NULL, p_value, TERM_SPACE | TERM_TAB); name = find_name(second, name, p_value, TERM_SPACE | TERM_TAB); - patch->old_name = patch->new_name = name; + if (has_epoch_timestamp(first)) { + patch->is_new = 1; + patch->is_delete = 0; + patch->new_name = name; + } else if (has_epoch_timestamp(second)) { + patch->is_new = 0; + patch->is_delete = 1; + patch->old_name = name; + } else { + patch->old_name = patch->new_name = name; + } } if (!name) die("unable to find filename in patch at line %d", linenr); @@ -2600,7 +2694,7 @@ static int get_current_sha1(const char *path, unsigned char *sha1) static void build_fake_ancestor(struct patch *list, const char *filename) { struct patch *patch; - struct index_state result = { 0 }; + struct index_state result = { NULL }; int fd; /* Once we start supporting the reverse patch, it may be @@ -2809,8 +2903,8 @@ static void add_index_file(const char *path, unsigned mode, void *buf, unsigned } else { if (!cached) { if (lstat(path, &st) < 0) - die("unable to stat newly created file %s", - path); + die_errno("unable to stat newly created file '%s'", + path); fill_stat_cache_info(ce, &st); } if (write_sha1_file(buf, size, blob_type, ce->sha1) < 0) @@ -2850,7 +2944,7 @@ static int try_create_file(const char *path, unsigned int mode, const char *buf, strbuf_release(&nbuf); if (close(fd) < 0) - die("closing file %s: %s", path, strerror(errno)); + die_errno("closing file '%s'", path); return 0; } @@ -2899,7 +2993,7 @@ static void create_one_file(char *path, unsigned mode, const char *buf, unsigned ++nr; } } - die("unable to write file %s mode %o", path, mode); + die_errno("unable to write file '%s' mode %o", path, mode); } static void create_file(struct patch *patch) @@ -3263,9 +3357,11 @@ int cmd_apply(int argc, const char **argv, const char *unused_prefix) OPT_BOOLEAN(0, "stat", &diffstat, "instead of applying the patch, output diffstat for the input"), { OPTION_BOOLEAN, 0, "allow-binary-replacement", &binary, - NULL, "old option, now no-op", PARSE_OPT_HIDDEN }, + NULL, "old option, now no-op", + PARSE_OPT_HIDDEN | PARSE_OPT_NOARG }, { OPTION_BOOLEAN, 0, "binary", &binary, - NULL, "old option, now no-op", PARSE_OPT_HIDDEN }, + NULL, "old option, now no-op", + PARSE_OPT_HIDDEN | PARSE_OPT_NOARG }, OPT_BOOLEAN(0, "numstat", &numstat, "shows number of added and deleted lines in decimal notation"), OPT_BOOLEAN(0, "summary", &summary, @@ -3278,7 +3374,7 @@ int cmd_apply(int argc, const char **argv, const char *unused_prefix) "apply a patch without touching the working tree"), OPT_BOOLEAN(0, "apply", &force_apply, "also apply the patch (use with --stat/--summary/--check)"), - OPT_STRING(0, "build-fake-ancestor", &fake_ancestor, "file", + OPT_FILENAME(0, "build-fake-ancestor", &fake_ancestor, "build a temporary index based on embedded index information"), { OPTION_CALLBACK, 'z', NULL, NULL, NULL, "paths are separated with NUL character", @@ -3313,11 +3409,8 @@ int cmd_apply(int argc, const char **argv, const char *unused_prefix) if (apply_default_whitespace) parse_whitespace_option(apply_default_whitespace); - argc = parse_options(argc, argv, builtin_apply_options, + argc = parse_options(argc, argv, prefix, builtin_apply_options, apply_usage, 0); - fake_ancestor = parse_options_fix_filename(prefix, fake_ancestor); - if (fake_ancestor) - fake_ancestor = xstrdup(fake_ancestor); if (apply_with_reject) apply = apply_verbosely = 1; @@ -3343,7 +3436,7 @@ int cmd_apply(int argc, const char **argv, const char *unused_prefix) fd = open(arg, O_RDONLY); if (fd < 0) - die("can't open patch '%s': %s", arg, strerror(errno)); + die_errno("can't open patch '%s'", arg); read_stdin = 0; set_default_whitespace_mode(whitespace_option); errs |= apply_patch(fd, arg, options); diff --git a/builtin-archive.c b/builtin-archive.c index ab50cebba0..f9a4bea41e 100644 --- a/builtin-archive.c +++ b/builtin-archive.c @@ -13,10 +13,10 @@ static void create_output_file(const char *output_file) { int output_fd = open(output_file, O_CREAT | O_WRONLY | O_TRUNC, 0666); if (output_fd < 0) - die("could not create archive file: %s ", output_file); + die_errno("could not create archive file '%s'", output_file); if (output_fd != 1) { if (dup2(output_fd, 1) < 0) - die("could not redirect output"); + die_errno("could not redirect output"); else close(output_fd); } @@ -80,7 +80,8 @@ int cmd_archive(int argc, const char **argv, const char *prefix) OPT_END() }; - argc = parse_options(argc, argv, local_opts, NULL, PARSE_OPT_KEEP_ALL); + argc = parse_options(argc, argv, prefix, local_opts, NULL, + PARSE_OPT_KEEP_ALL); if (output) create_output_file(output); diff --git a/builtin-bisect--helper.c b/builtin-bisect--helper.c index 8fe778766a..5b226399e1 100644 --- a/builtin-bisect--helper.c +++ b/builtin-bisect--helper.c @@ -4,24 +4,25 @@ #include "bisect.h" static const char * const git_bisect_helper_usage[] = { - "git bisect--helper --next-vars", + "git bisect--helper --next-all", NULL }; int cmd_bisect__helper(int argc, const char **argv, const char *prefix) { - int next_vars = 0; + int next_all = 0; struct option options[] = { - OPT_BOOLEAN(0, "next-vars", &next_vars, - "output next bisect step variables"), + OPT_BOOLEAN(0, "next-all", &next_all, + "perform 'git bisect next'"), OPT_END() }; - argc = parse_options(argc, argv, options, git_bisect_helper_usage, 0); + argc = parse_options(argc, argv, prefix, options, + git_bisect_helper_usage, 0); - if (!next_vars) + if (!next_all) usage_with_options(git_bisect_helper_usage, options); - /* next-vars */ - return bisect_next_vars(prefix); + /* next-all */ + return bisect_next_all(prefix); } diff --git a/builtin-blame.c b/builtin-blame.c index 0afdb16cb0..fd6ca51eeb 100644 --- a/builtin-blame.c +++ b/builtin-blame.c @@ -2008,23 +2008,23 @@ static struct commit *fake_working_tree_commit(const char *path, const char *con if (contents_from) { if (stat(contents_from, &st) < 0) - die("Cannot stat %s", contents_from); + die_errno("Cannot stat '%s'", contents_from); read_from = contents_from; } else { if (lstat(path, &st) < 0) - die("Cannot lstat %s", path); + die_errno("Cannot lstat '%s'", path); read_from = path; } mode = canon_mode(st.st_mode); switch (st.st_mode & S_IFMT) { case S_IFREG: if (strbuf_read_file(&buf, read_from, st.st_size) != st.st_size) - die("cannot open or read %s", read_from); + die_errno("cannot open or read '%s'", read_from); break; case S_IFLNK: if (strbuf_readlink(&buf, read_from, st.st_size) < 0) - die("cannot readlink %s", read_from); + die_errno("cannot readlink '%s'", read_from); break; default: die("unsupported file type %s", read_from); @@ -2035,7 +2035,7 @@ static struct commit *fake_working_tree_commit(const char *path, const char *con contents_from = "standard input"; mode = 0; if (strbuf_read(&buf, 0, 0) < 0) - die("read error %s from stdin", strerror(errno)); + die_errno("failed to read from stdin"); } convert_to_git(path, buf.buf, buf.len, &buf, 0); origin->file.ptr = buf.buf; @@ -2239,7 +2239,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix) save_commit_buffer = 0; dashdash_pos = 0; - parse_options_start(&ctx, argc, argv, PARSE_OPT_KEEP_DASHDASH | + parse_options_start(&ctx, argc, argv, prefix, PARSE_OPT_KEEP_DASHDASH | PARSE_OPT_KEEP_ARGV0); for (;;) { switch (parse_options_step(&ctx, options, blame_opt_usage)) { @@ -2261,8 +2261,7 @@ parse_done: argc = parse_options_end(&ctx); if (revs_file && read_ancestry(revs_file)) - die("reading graft file %s failed: %s", - revs_file, strerror(errno)); + die_errno("reading graft file '%s' failed", revs_file); if (cmd_is_annotate) { output_option |= OUTPUT_ANNOTATE_COMPAT; @@ -2350,7 +2349,7 @@ parse_done: setup_work_tree(); if (!has_string_in_work_tree(path)) - die("cannot stat path %s: %s", path, strerror(errno)); + die_errno("cannot stat path '%s'", path); } setup_revisions(argc, argv, &revs, NULL); diff --git a/builtin-branch.c b/builtin-branch.c index 887fa60fa5..1a03d5f356 100644 --- a/builtin-branch.c +++ b/builtin-branch.c @@ -559,7 +559,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix) struct option options[] = { OPT_GROUP("Generic options"), OPT__VERBOSE(&verbose), - OPT_SET_INT( 0 , "track", &track, "set up tracking mode (see git-pull(1))", + OPT_SET_INT('t', "track", &track, "set up tracking mode (see git-pull(1))", BRANCH_TRACK_EXPLICIT), OPT_BOOLEAN( 0 , "color", &branch_use_color, "use colored output"), OPT_SET_INT('r', NULL, &kinds, "act on remote-tracking branches", @@ -622,7 +622,8 @@ int cmd_branch(int argc, const char **argv, const char *prefix) } hashcpy(merge_filter_ref, head_sha1); - argc = parse_options(argc, argv, options, builtin_branch_usage, 0); + argc = parse_options(argc, argv, prefix, options, builtin_branch_usage, + 0); if (!!delete + !!rename + !!force_create > 1) usage_with_options(builtin_branch_usage, options); diff --git a/builtin-cat-file.c b/builtin-cat-file.c index 43ffe7ffae..5906842008 100644 --- a/builtin-cat-file.c +++ b/builtin-cat-file.c @@ -231,7 +231,7 @@ int cmd_cat_file(int argc, const char **argv, const char *prefix) if (argc != 3 && argc != 2) usage_with_options(cat_file_usage, options); - argc = parse_options(argc, argv, options, cat_file_usage, 0); + argc = parse_options(argc, argv, prefix, options, cat_file_usage, 0); if (opt) { if (argc == 1) diff --git a/builtin-check-attr.c b/builtin-check-attr.c index 15a04b7179..8bd0430098 100644 --- a/builtin-check-attr.c +++ b/builtin-check-attr.c @@ -69,8 +69,8 @@ int cmd_check_attr(int argc, const char **argv, const char *prefix) int cnt, i, doubledash; const char *errstr = NULL; - argc = parse_options(argc, argv, check_attr_options, check_attr_usage, - PARSE_OPT_KEEP_DASHDASH); + argc = parse_options(argc, argv, prefix, check_attr_options, + check_attr_usage, PARSE_OPT_KEEP_DASHDASH); if (!argc) usage_with_options(check_attr_usage, check_attr_options); diff --git a/builtin-checkout-index.c b/builtin-checkout-index.c index afe35e246c..a7a5ee10f3 100644 --- a/builtin-checkout-index.c +++ b/builtin-checkout-index.c @@ -249,7 +249,7 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix) die("invalid cache"); } - argc = parse_options(argc, argv, builtin_checkout_index_options, + argc = parse_options(argc, argv, prefix, builtin_checkout_index_options, builtin_checkout_index_usage, 0); state.force = force; state.quiet = quiet; diff --git a/builtin-checkout.c b/builtin-checkout.c index b8a4b0139b..8a9a474218 100644 --- a/builtin-checkout.c +++ b/builtin-checkout.c @@ -605,7 +605,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix) opts.track = BRANCH_TRACK_UNSPECIFIED; - argc = parse_options(argc, argv, options, checkout_usage, + argc = parse_options(argc, argv, prefix, options, checkout_usage, PARSE_OPT_KEEP_DASHDASH); /* --track without -b should DWIM */ diff --git a/builtin-clean.c b/builtin-clean.c index c5ad33d3e6..05c763cbec 100644 --- a/builtin-clean.c +++ b/builtin-clean.c @@ -31,9 +31,9 @@ int cmd_clean(int argc, const char **argv, const char *prefix) int i; int show_only = 0, remove_directories = 0, quiet = 0, ignored = 0; int ignored_only = 0, baselen = 0, config_set = 0, errors = 0; + int rm_flags = REMOVE_DIR_KEEP_NESTED_GIT; struct strbuf directory = STRBUF_INIT; struct dir_struct dir; - const char *path, *base; static const char **pathspec; struct strbuf buf = STRBUF_INIT; const char *qname; @@ -56,7 +56,8 @@ int cmd_clean(int argc, const char **argv, const char *prefix) else config_set = 1; - argc = parse_options(argc, argv, options, builtin_clean_usage, 0); + argc = parse_options(argc, argv, prefix, options, builtin_clean_usage, + 0); memset(&dir, 0, sizeof(dir)); if (ignored_only) @@ -69,6 +70,9 @@ int cmd_clean(int argc, const char **argv, const char *prefix) die("clean.requireForce%s set and -n or -f not given; " "refusing to clean", config_set ? "" : " not"); + if (force > 1) + rm_flags = 0; + dir.flags |= DIR_SHOW_OTHER_DIRECTORIES; if (!ignored) @@ -77,16 +81,7 @@ int cmd_clean(int argc, const char **argv, const char *prefix) pathspec = get_pathspec(prefix, argv); read_cache(); - /* - * Calculate common prefix for the pathspec, and - * use that to optimize the directory walk - */ - baselen = common_prefix(pathspec); - path = "."; - base = ""; - if (baselen) - path = base = xmemdupz(*pathspec, baselen); - read_directory(&dir, path, base, baselen, pathspec); + fill_directory(&dir, pathspec); if (pathspec) seen = xmalloc(argc > 0 ? argc : 1); @@ -140,7 +135,8 @@ int cmd_clean(int argc, const char **argv, const char *prefix) (matches == MATCHED_EXACTLY)) { if (!quiet) printf("Removing %s\n", qname); - if (remove_dir_recursively(&directory, 0) != 0) { + if (remove_dir_recursively(&directory, + rm_flags) != 0) { warning("failed to remove '%s'", qname); errors++; } diff --git a/builtin-clone.c b/builtin-clone.c index ba286e0160..e51978a157 100644 --- a/builtin-clone.c +++ b/builtin-clone.c @@ -104,11 +104,12 @@ static char *get_repo_path(const char *repo, int *is_bundle) static char *guess_dir_name(const char *repo, int is_bundle, int is_bare) { const char *end = repo + strlen(repo), *start; + char *dir; /* - * Strip trailing slashes and /.git + * Strip trailing spaces, slashes and /.git */ - while (repo < end && is_dir_sep(end[-1])) + while (repo < end && (is_dir_sep(end[-1]) || isspace(end[-1]))) end--; if (end - repo > 5 && is_dir_sep(end[-5]) && !strncmp(end - 4, ".git", 4)) { @@ -140,10 +141,33 @@ static char *guess_dir_name(const char *repo, int is_bundle, int is_bare) if (is_bare) { struct strbuf result = STRBUF_INIT; strbuf_addf(&result, "%.*s.git", (int)(end - start), start); - return strbuf_detach(&result, 0); + dir = strbuf_detach(&result, NULL); + } else + dir = xstrndup(start, end - start); + /* + * Replace sequences of 'control' characters and whitespace + * with one ascii space, remove leading and trailing spaces. + */ + if (*dir) { + char *out = dir; + int prev_space = 1 /* strip leading whitespace */; + for (end = dir; *end; ++end) { + char ch = *end; + if ((unsigned char)ch < '\x20') + ch = '\x20'; + if (isspace(ch)) { + if (prev_space) + continue; + prev_space = 1; + } else + prev_space = 0; + *out++ = ch; + } + *out = '\0'; + if (out > dir && prev_space) + out[-1] = '\0'; } - - return xstrndup(start, end - start); + return dir; } static void strip_trailing_slashes(char *dir) @@ -196,13 +220,13 @@ static void copy_or_link_directory(struct strbuf *src, struct strbuf *dest) dir = opendir(src->buf); if (!dir) - die("failed to open %s", src->buf); + die_errno("failed to open '%s'", src->buf); if (mkdir(dest->buf, 0777)) { if (errno != EEXIST) - die("failed to create directory %s", dest->buf); + die_errno("failed to create directory '%s'", dest->buf); else if (stat(dest->buf, &buf)) - die("failed to stat %s", dest->buf); + die_errno("failed to stat '%s'", dest->buf); else if (!S_ISDIR(buf.st_mode)) die("%s exists and is not a directory", dest->buf); } @@ -228,17 +252,16 @@ static void copy_or_link_directory(struct strbuf *src, struct strbuf *dest) } if (unlink(dest->buf) && errno != ENOENT) - die("failed to unlink %s: %s", - dest->buf, strerror(errno)); + die_errno("failed to unlink '%s'", dest->buf); if (!option_no_hardlinks) { if (!link(src->buf, dest->buf)) continue; if (option_local) - die("failed to create link %s", dest->buf); + die_errno("failed to create link '%s'", dest->buf); option_no_hardlinks = 1; } if (copy_file(dest->buf, src->buf, 0666)) - die("failed to copy file to %s", dest->buf); + die_errno("failed to copy file to '%s'", dest->buf); } closedir(dir); } @@ -336,7 +359,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix) junk_pid = getpid(); - argc = parse_options(argc, argv, builtin_clone_options, + argc = parse_options(argc, argv, prefix, builtin_clone_options, builtin_clone_usage, 0); if (argc == 0) @@ -396,11 +419,11 @@ int cmd_clone(int argc, const char **argv, const char *prefix) if (!option_bare) { junk_work_tree = work_tree; if (safe_create_leading_directories_const(work_tree) < 0) - die("could not create leading directories of '%s': %s", - work_tree, strerror(errno)); + die_errno("could not create leading directories of '%s'", + work_tree); if (!dest_exists && mkdir(work_tree, 0755)) - die("could not create work tree dir '%s': %s.", - work_tree, strerror(errno)); + die_errno("could not create work tree dir '%s'.", + work_tree); set_git_work_tree(work_tree); } junk_git_dir = git_dir; @@ -551,8 +574,10 @@ int cmd_clone(int argc, const char **argv, const char *prefix) option_no_checkout = 1; } - if (transport) + if (transport) { transport_unlock_pack(transport); + transport_disconnect(transport); + } if (!option_no_checkout) { struct lock_file *lock_file = xcalloc(1, sizeof(struct lock_file)); diff --git a/builtin-commit-tree.c b/builtin-commit-tree.c index 0453425c47..6467077731 100644 --- a/builtin-commit-tree.c +++ b/builtin-commit-tree.c @@ -124,7 +124,7 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix) } if (strbuf_read(&buffer, 0, 0) < 0) - die("git commit-tree: read returned %s", strerror(errno)); + die_errno("git commit-tree: failed to read"); if (!commit_tree(buffer.buf, tree_sha1, parents, commit_sha1, NULL)) { printf("%s\n", sha1_to_hex(commit_sha1)); diff --git a/builtin-commit.c b/builtin-commit.c index baaa75cf90..4bcce06fbf 100644 --- a/builtin-commit.c +++ b/builtin-commit.c @@ -88,13 +88,13 @@ static struct option builtin_commit_options[] = { OPT__VERBOSE(&verbose), OPT_GROUP("Commit message options"), - OPT_STRING('F', "file", &logfile, "FILE", "read log from file"), + OPT_FILENAME('F', "file", &logfile, "read log from file"), OPT_STRING(0, "author", &force_author, "AUTHOR", "override author for commit"), OPT_CALLBACK('m', "message", &message, "MESSAGE", "specify commit message", opt_parse_m), OPT_STRING('c', "reedit-message", &edit_message, "COMMIT", "reuse and edit message from specified commit "), OPT_STRING('C', "reuse-message", &use_message, "COMMIT", "reuse message from specified commit"), OPT_BOOLEAN('s', "signoff", &signoff, "add Signed-off-by:"), - OPT_STRING('t', "template", &template_file, "FILE", "use specified template file"), + OPT_FILENAME('t', "template", &template_file, "use specified template file"), OPT_BOOLEAN('e', "edit", &edit_flag, "force edit of commit"), OPT_GROUP("Commit contents options"), @@ -434,12 +434,12 @@ static int prepare_to_commit(const char *index_file, const char *prefix) if (isatty(0)) fprintf(stderr, "(reading log message from standard input)\n"); if (strbuf_read(&sb, 0, 0) < 0) - die("could not read log from standard input"); + die_errno("could not read log from standard input"); hook_arg1 = "message"; } else if (logfile) { if (strbuf_read_file(&sb, logfile, 0) < 0) - die("could not read log file '%s': %s", - logfile, strerror(errno)); + die_errno("could not read log file '%s'", + logfile); hook_arg1 = "message"; } else if (use_message) { buffer = strstr(use_message_buffer, "\n\n"); @@ -450,16 +450,15 @@ static int prepare_to_commit(const char *index_file, const char *prefix) hook_arg2 = use_message; } else if (!stat(git_path("MERGE_MSG"), &statbuf)) { if (strbuf_read_file(&sb, git_path("MERGE_MSG"), 0) < 0) - die("could not read MERGE_MSG: %s", strerror(errno)); + die_errno("could not read MERGE_MSG"); hook_arg1 = "merge"; } else if (!stat(git_path("SQUASH_MSG"), &statbuf)) { if (strbuf_read_file(&sb, git_path("SQUASH_MSG"), 0) < 0) - die("could not read SQUASH_MSG: %s", strerror(errno)); + die_errno("could not read SQUASH_MSG"); hook_arg1 = "squash"; } else if (template_file && !stat(template_file, &statbuf)) { if (strbuf_read_file(&sb, template_file, 0) < 0) - die("could not read %s: %s", - template_file, strerror(errno)); + die_errno("could not read '%s'", template_file); hook_arg1 = "template"; } @@ -472,8 +471,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix) fp = fopen(git_path(commit_editmsg), "w"); if (fp == NULL) - die("could not open %s: %s", - git_path(commit_editmsg), strerror(errno)); + die_errno("could not open '%s'", git_path(commit_editmsg)); if (cleanup_mode != CLEANUP_NONE) stripspace(&sb, 0); @@ -497,7 +495,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix) } if (fwrite(sb.buf, 1, sb.len, fp) < sb.len) - die("could not write commit template: %s", strerror(errno)); + die_errno("could not write commit template"); strbuf_release(&sb); @@ -697,13 +695,8 @@ static int parse_and_validate_options(int argc, const char *argv[], { int f = 0; - argc = parse_options(argc, argv, builtin_commit_options, usage, 0); - logfile = parse_options_fix_filename(prefix, logfile); - if (logfile) - logfile = xstrdup(logfile); - template_file = parse_options_fix_filename(prefix, template_file); - if (template_file) - template_file = xstrdup(template_file); + argc = parse_options(argc, argv, prefix, builtin_commit_options, usage, + 0); if (force_author && !strchr(force_author, '>')) force_author = find_author_by_nickname(force_author); @@ -945,8 +938,8 @@ int cmd_commit(int argc, const char **argv, const char *prefix) pptr = &commit_list_insert(lookup_commit(head_sha1), pptr)->next; fp = fopen(git_path("MERGE_HEAD"), "r"); if (fp == NULL) - die("could not open %s for reading: %s", - git_path("MERGE_HEAD"), strerror(errno)); + die_errno("could not open '%s' for reading", + git_path("MERGE_HEAD")); while (strbuf_getline(&m, fp, '\n') != EOF) { unsigned char sha1[20]; if (get_sha1_hex(m.buf, sha1) < 0) @@ -957,8 +950,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix) strbuf_release(&m); if (!stat(git_path("MERGE_MODE"), &statbuf)) { if (strbuf_read_file(&sb, git_path("MERGE_MODE"), 0) < 0) - die("could not read MERGE_MODE: %s", - strerror(errno)); + die_errno("could not read MERGE_MODE"); if (!strcmp(sb.buf, "no-ff")) allow_fast_forward = 0; } @@ -972,8 +964,9 @@ int cmd_commit(int argc, const char **argv, const char *prefix) /* Finally, get the commit message */ strbuf_reset(&sb); if (strbuf_read_file(&sb, git_path(commit_editmsg), 0) < 0) { + int saved_errno = errno; rollback_index_files(); - die("could not read commit message"); + die("could not read commit message: %s", strerror(saved_errno)); } /* Truncate the message just before the diff, if any. */ diff --git a/builtin-config.c b/builtin-config.c index a81bc8bbf0..a2d656edb3 100644 --- a/builtin-config.c +++ b/builtin-config.c @@ -316,7 +316,8 @@ int cmd_config(int argc, const char **argv, const char *unused_prefix) config_exclusive_filename = getenv(CONFIG_ENVIRONMENT); - argc = parse_options(argc, argv, builtin_config_options, builtin_config_usage, + argc = parse_options(argc, argv, prefix, builtin_config_options, + builtin_config_usage, PARSE_OPT_STOP_AT_NON_OPTION); if (use_global_config + use_system_config + !!given_config_file > 1) { @@ -382,8 +383,8 @@ int cmd_config(int argc, const char **argv, const char *unused_prefix) check_argc(argc, 0, 0); if (git_config(show_all_config, NULL) < 0) { if (config_exclusive_filename) - die("unable to read config file %s: %s", - config_exclusive_filename, strerror(errno)); + die_errno("unable to read config file '%s'", + config_exclusive_filename); else die("error processing config file(s)"); } diff --git a/builtin-count-objects.c b/builtin-count-objects.c index b814fe5070..1b0b6c84ea 100644 --- a/builtin-count-objects.c +++ b/builtin-count-objects.c @@ -83,7 +83,7 @@ int cmd_count_objects(int argc, const char **argv, const char *prefix) OPT_END(), }; - argc = parse_options(argc, argv, opts, count_objects_usage, 0); + argc = parse_options(argc, argv, prefix, opts, count_objects_usage, 0); /* we do not take arguments other than flags for now */ if (argc) usage_with_options(count_objects_usage, opts); diff --git a/builtin-describe.c b/builtin-describe.c index 63c6a19da5..7a662980d1 100644 --- a/builtin-describe.c +++ b/builtin-describe.c @@ -322,7 +322,7 @@ int cmd_describe(int argc, const char **argv, const char *prefix) OPT_END(), }; - argc = parse_options(argc, argv, options, describe_usage, 0); + argc = parse_options(argc, argv, prefix, options, describe_usage, 0); if (max_candidates < 0) max_candidates = 0; else if (max_candidates > MAX_TAGS) diff --git a/builtin-diff.c b/builtin-diff.c index d75d69bf57..2e51f408f9 100644 --- a/builtin-diff.c +++ b/builtin-diff.c @@ -70,7 +70,7 @@ static int builtin_diff_b_f(struct rev_info *revs, usage(builtin_diff_usage); if (lstat(path, &st)) - die("'%s': %s", path, strerror(errno)); + die_errno("failed to stat '%s'", path); if (!(S_ISREG(st.st_mode) || S_ISLNK(st.st_mode))) die("'%s': not a regular file or symlink", path); diff --git a/builtin-fast-export.c b/builtin-fast-export.c index 9091481fd5..c48c18d0c8 100644 --- a/builtin-fast-export.c +++ b/builtin-fast-export.c @@ -23,7 +23,8 @@ static const char *fast_export_usage[] = { }; static int progress; -static enum { VERBATIM, WARN, STRIP, ABORT } signed_tag_mode = ABORT; +static enum { ABORT, VERBATIM, WARN, STRIP } signed_tag_mode = ABORT; +static enum { ERROR, DROP, REWRITE } tag_of_filtered_mode = ABORT; static int fake_missing_tagger; static int parse_opt_signed_tag_mode(const struct option *opt, @@ -42,6 +43,20 @@ static int parse_opt_signed_tag_mode(const struct option *opt, return 0; } +static int parse_opt_tag_of_filtered_mode(const struct option *opt, + const char *arg, int unset) +{ + if (unset || !strcmp(arg, "abort")) + tag_of_filtered_mode = ABORT; + else if (!strcmp(arg, "drop")) + tag_of_filtered_mode = DROP; + else if (!strcmp(arg, "rewrite")) + tag_of_filtered_mode = REWRITE; + else + return error("Unknown tag-of-filtered mode: %s", arg); + return 0; +} + static struct decoration idnums; static uint32_t last_idnum; @@ -119,7 +134,7 @@ static void handle_object(const unsigned char *sha1) printf("blob\nmark :%"PRIu32"\ndata %lu\n", last_idnum, size); if (size && fwrite(buf, size, 1, stdout) != 1) - die ("Could not write blob %s", sha1_to_hex(sha1)); + die_errno ("Could not write blob '%s'", sha1_to_hex(sha1)); printf("\n"); show_progress(); @@ -289,6 +304,23 @@ static void handle_tag(const char *name, struct tag *tag) char *buf; const char *tagger, *tagger_end, *message; size_t message_size = 0; + struct object *tagged; + int tagged_mark; + struct commit *p; + + /* Trees have no identifer in fast-export output, thus we have no way + * to output tags of trees, tags of tags of trees, etc. Simply omit + * such tags. + */ + tagged = tag->tagged; + while (tagged->type == OBJ_TAG) { + tagged = ((struct tag *)tagged)->tagged; + } + if (tagged->type == OBJ_TREE) { + warning("Omitting tag %s,\nsince tags of trees (or tags of tags of trees, etc.) are not supported.", + sha1_to_hex(tag->object.sha1)); + return; + } buf = read_sha1_file(tag->object.sha1, &type, &size); if (!buf) @@ -333,10 +365,45 @@ static void handle_tag(const char *name, struct tag *tag) } } + /* handle tag->tagged having been filtered out due to paths specified */ + tagged = tag->tagged; + tagged_mark = get_object_mark(tagged); + if (!tagged_mark) { + switch(tag_of_filtered_mode) { + case ABORT: + die ("Tag %s tags unexported object; use " + "--tag-of-filtered-object=<mode> to handle it.", + sha1_to_hex(tag->object.sha1)); + case DROP: + /* Ignore this tag altogether */ + return; + case REWRITE: + if (tagged->type != OBJ_COMMIT) { + die ("Tag %s tags unexported %s!", + sha1_to_hex(tag->object.sha1), + typename(tagged->type)); + } + p = (struct commit *)tagged; + for (;;) { + if (p->parents && p->parents->next) + break; + if (p->object.flags & UNINTERESTING) + break; + if (!(p->object.flags & TREESAME)) + break; + if (!p->parents) + die ("Can't find replacement commit for tag %s\n", + sha1_to_hex(tag->object.sha1)); + p = p->parents->item; + } + tagged_mark = get_object_mark(&p->object); + } + } + if (!prefixcmp(name, "refs/tags/")) name += 10; printf("tag %s\nfrom :%d\n%.*s%sdata %d\n%.*s\n", - name, get_object_mark(tag->tagged), + name, tagged_mark, (int)(tagger_end - tagger), tagger, tagger == tagger_end ? "" : "\n", (int)message_size, (int)message_size, message ? message : ""); @@ -457,7 +524,7 @@ static void import_marks(char *input_file) char line[512]; FILE *f = fopen(input_file, "r"); if (!f) - die("cannot read %s: %s", input_file, strerror(errno)); + die_errno("cannot read '%s'", input_file); while (fgets(line, sizeof(line), f)) { uint32_t mark; @@ -504,6 +571,9 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix) OPT_CALLBACK(0, "signed-tags", &signed_tag_mode, "mode", "select handling of signed tags", parse_opt_signed_tag_mode), + OPT_CALLBACK(0, "tag-of-filtered-object", &tag_of_filtered_mode, "mode", + "select handling of tags that tag filtered objects", + parse_opt_tag_of_filtered_mode), OPT_STRING(0, "export-marks", &export_filename, "FILE", "Dump marks to this file"), OPT_STRING(0, "import-marks", &import_filename, "FILE", @@ -520,8 +590,11 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix) git_config(git_default_config, NULL); init_revisions(&revs, prefix); + revs.topo_order = 1; + revs.show_source = 1; + revs.rewrite_parents = 1; argc = setup_revisions(argc, argv, &revs, NULL); - argc = parse_options(argc, argv, options, fast_export_usage, 0); + argc = parse_options(argc, argv, prefix, options, fast_export_usage, 0); if (argc > 1) usage_with_options (fast_export_usage, options); @@ -530,18 +603,13 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix) get_tags_and_duplicates(&revs.pending, &extra_refs); - revs.topo_order = 1; if (prepare_revision_walk(&revs)) die("revision walk setup failed"); revs.diffopt.format_callback = show_filemodify; DIFF_OPT_SET(&revs.diffopt, RECURSIVE); while ((commit = get_revision(&revs))) { if (has_unshown_parent(commit)) { - struct commit_list *parent = commit->parents; add_object_array(&commit->object, NULL, &commits); - for (; parent; parent = parent->next) - if (!parent->item->util) - parent->item->util = commit->util; } else { handle_commit(commit, &revs); diff --git a/builtin-fetch--tool.c b/builtin-fetch--tool.c index 29356d25db..3dbdf7a288 100644 --- a/builtin-fetch--tool.c +++ b/builtin-fetch--tool.c @@ -8,7 +8,7 @@ static char *get_stdin(void) { struct strbuf buf = STRBUF_INIT; if (strbuf_read(&buf, 0, 1024) < 0) { - die("error reading standard input: %s", strerror(errno)); + die_errno("error reading standard input"); } return strbuf_detach(&buf, NULL); } diff --git a/builtin-fetch.c b/builtin-fetch.c index 1f7a3f1ce6..817dd6bff0 100644 --- a/builtin-fetch.c +++ b/builtin-fetch.c @@ -202,7 +202,7 @@ static int update_local_ref(struct ref *ref, struct commit *current = NULL, *updated; enum object_type type; struct branch *current_branch = branch_get(NULL); - const char *pretty_ref = prettify_ref(ref); + const char *pretty_ref = prettify_refname(ref->name); *display = 0; type = sha1_object_info(ref->new_sha1, NULL); @@ -294,7 +294,7 @@ static int update_local_ref(struct ref *ref, } } -static int store_updated_refs(const char *url, const char *remote_name, +static int store_updated_refs(const char *raw_url, const char *remote_name, struct ref *ref_map) { FILE *fp; @@ -303,11 +303,13 @@ static int store_updated_refs(const char *url, const char *remote_name, char note[1024]; const char *what, *kind; struct ref *rm; - char *filename = git_path("FETCH_HEAD"); + char *url, *filename = git_path("FETCH_HEAD"); fp = fopen(filename, "a"); if (!fp) return error("cannot open %s: %s\n", filename, strerror(errno)); + + url = transport_anonymize_url(raw_url); for (rm = ref_map; rm; rm = rm->next) { struct ref *ref = NULL; @@ -358,12 +360,18 @@ static int store_updated_refs(const char *url, const char *remote_name, kind); note_len += sprintf(note + note_len, "'%s' of ", what); } - note_len += sprintf(note + note_len, "%.*s", url_len, url); - fprintf(fp, "%s\t%s\t%s\n", + note[note_len] = '\0'; + fprintf(fp, "%s\t%s\t%s", sha1_to_hex(commit ? commit->object.sha1 : rm->old_sha1), rm->merge ? "" : "not-for-merge", note); + for (i = 0; i < url_len; ++i) + if ('\n' == url[i]) + fputs("\\n", fp); + else + fputc(url[i], fp); + fputc('\n', fp); if (ref) rc |= update_local_ref(ref, what, note); @@ -381,6 +389,7 @@ static int store_updated_refs(const char *url, const char *remote_name, fprintf(stderr, " %s\n", note); } } + free(url); fclose(fp); if (rc & STORE_REF_ERROR_DF_CONFLICT) error("some local refs could not be updated; try running\n" @@ -391,14 +400,14 @@ static int store_updated_refs(const char *url, const char *remote_name, /* * We would want to bypass the object transfer altogether if - * everything we are going to fetch already exists and connected + * everything we are going to fetch already exists and is connected * locally. * - * The refs we are going to fetch are in to_fetch (nr_heads in - * total). If running + * The refs we are going to fetch are in ref_map. If running * - * $ git rev-list --objects to_fetch[0] to_fetch[1] ... --not --all + * $ git rev-list --objects --stdin --not --all * + * (feeding all the refs in ref_map on its standard input) * does not error out, that means everything reachable from the * refs we are going to fetch exists and is connected to some of * our existing refs. @@ -407,8 +416,9 @@ static int quickfetch(struct ref *ref_map) { struct child_process revlist; struct ref *ref; - char **argv; - int i, err; + int err; + const char *argv[] = {"rev-list", + "--quiet", "--objects", "--stdin", "--not", "--all", NULL}; /* * If we are deepening a shallow clone we already have these @@ -420,34 +430,46 @@ static int quickfetch(struct ref *ref_map) if (depth) return -1; - for (i = 0, ref = ref_map; ref; ref = ref->next) - i++; - if (!i) + if (!ref_map) return 0; - argv = xmalloc(sizeof(*argv) * (i + 6)); - i = 0; - argv[i++] = xstrdup("rev-list"); - argv[i++] = xstrdup("--quiet"); - argv[i++] = xstrdup("--objects"); - for (ref = ref_map; ref; ref = ref->next) - argv[i++] = xstrdup(sha1_to_hex(ref->old_sha1)); - argv[i++] = xstrdup("--not"); - argv[i++] = xstrdup("--all"); - argv[i++] = NULL; - memset(&revlist, 0, sizeof(revlist)); - revlist.argv = (const char**)argv; + revlist.argv = argv; revlist.git_cmd = 1; - revlist.no_stdin = 1; revlist.no_stdout = 1; revlist.no_stderr = 1; - err = run_command(&revlist); + revlist.in = -1; + + err = start_command(&revlist); + if (err) { + error("could not run rev-list"); + return err; + } + + /* + * If rev-list --stdin encounters an unknown commit, it terminates, + * which will cause SIGPIPE in the write loop below. + */ + sigchain_push(SIGPIPE, SIG_IGN); + + for (ref = ref_map; ref; ref = ref->next) { + if (write_in_full(revlist.in, sha1_to_hex(ref->old_sha1), 40) < 0 || + write_in_full(revlist.in, "\n", 1) < 0) { + if (errno != EPIPE && errno != EINVAL) + error("failed write to rev-list: %s", strerror(errno)); + err = -1; + break; + } + } + + if (close(revlist.in)) { + error("failed to close rev-list's stdin: %s", strerror(errno)); + err = -1; + } + + sigchain_pop(SIGPIPE); - for (i = 0; argv[i]; i++) - free(argv[i]); - free(argv); - return err; + return finish_command(&revlist) || err; } static int fetch_refs(struct transport *transport, struct ref *ref_map) @@ -630,7 +652,7 @@ int cmd_fetch(int argc, const char **argv, const char *prefix) for (i = 1; i < argc; i++) strbuf_addf(&default_rla, " %s", argv[i]); - argc = parse_options(argc, argv, + argc = parse_options(argc, argv, prefix, builtin_fetch_options, builtin_fetch_usage, 0); if (argc == 0) diff --git a/builtin-fmt-merge-msg.c b/builtin-fmt-merge-msg.c index fae1482ba9..9d524000b5 100644 --- a/builtin-fmt-merge-msg.c +++ b/builtin-fmt-merge-msg.c @@ -351,7 +351,7 @@ int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix) struct option options[] = { OPT_BOOLEAN(0, "log", &merge_summary, "populate log with the shortlog"), OPT_BOOLEAN(0, "summary", &merge_summary, "alias for --log"), - OPT_STRING('F', "file", &inpath, "file", "file to read from"), + OPT_FILENAME('F', "file", &inpath, "file to read from"), OPT_END() }; @@ -360,20 +360,19 @@ int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix) int ret; git_config(fmt_merge_msg_config, NULL); - argc = parse_options(argc, argv, options, fmt_merge_msg_usage, 0); + argc = parse_options(argc, argv, prefix, options, fmt_merge_msg_usage, + 0); if (argc > 0) usage_with_options(fmt_merge_msg_usage, options); - inpath = parse_options_fix_filename(prefix, inpath); if (inpath && strcmp(inpath, "-")) { in = fopen(inpath, "r"); if (!in) - die("cannot open %s", inpath); + die_errno("cannot open '%s'", inpath); } if (strbuf_read(&input, fileno(in), 0) < 0) - die("could not read input file %s", strerror(errno)); - + die_errno("could not read input file"); ret = fmt_merge_msg(merge_summary, &input, &output); if (ret) return ret; diff --git a/builtin-for-each-ref.c b/builtin-for-each-ref.c index 1911cda1c2..d7cc8cafbf 100644 --- a/builtin-for-each-ref.c +++ b/builtin-for-each-ref.c @@ -913,7 +913,7 @@ int cmd_for_each_ref(int argc, const char **argv, const char *prefix) OPT_END(), }; - parse_options(argc, argv, opts, for_each_ref_usage, 0); + parse_options(argc, argv, prefix, opts, for_each_ref_usage, 0); if (maxcount < 0) { error("invalid --count argument: `%d'", maxcount); usage_with_options(for_each_ref_usage, opts); diff --git a/builtin-fsck.c b/builtin-fsck.c index 6436bc2248..b3d38fa277 100644 --- a/builtin-fsck.c +++ b/builtin-fsck.c @@ -104,7 +104,7 @@ static int mark_object(struct object *obj, int type, void *data) static void mark_object_reachable(struct object *obj) { - mark_object(obj, OBJ_ANY, 0); + mark_object(obj, OBJ_ANY, NULL); } static int traverse_one_object(struct object *obj, struct object *parent) @@ -217,7 +217,7 @@ static void check_unreachable_object(struct object *obj) return; } if (!(f = fopen(filename, "w"))) - die("Could not open %s", filename); + die_errno("Could not open '%s'", filename); if (obj->type == OBJ_BLOB) { enum object_type type; unsigned long size; @@ -225,15 +225,15 @@ static void check_unreachable_object(struct object *obj) &type, &size); if (buf) { if (fwrite(buf, size, 1, f) != 1) - die("Could not write %s: %s", - filename, strerror(errno)); + die_errno("Could not write '%s'", + filename); free(buf); } } else fprintf(f, "%s\n", sha1_to_hex(obj->sha1)); if (fclose(f)) - die("Could not finish %s: %s", - filename, strerror(errno)); + die_errno("Could not finish '%s'", + filename); } return; } @@ -292,7 +292,7 @@ static int fsck_sha1(const unsigned char *sha1) fprintf(stderr, "Checking %s %s\n", typename(obj->type), sha1_to_hex(obj->sha1)); - if (fsck_walk(obj, mark_used, 0)) + if (fsck_walk(obj, mark_used, NULL)) objerror(obj, "broken links"); if (fsck_object(obj, check_strict, fsck_error_func)) return -1; @@ -590,7 +590,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix) errors_found = 0; - argc = parse_options(argc, argv, fsck_opts, fsck_usage, 0); + argc = parse_options(argc, argv, prefix, fsck_opts, fsck_usage, 0); if (write_lost_and_found) { check_full = 1; include_reflogs = 0; diff --git a/builtin-gc.c b/builtin-gc.c index fc556ed7f3..7d3e9cc7a0 100644 --- a/builtin-gc.c +++ b/builtin-gc.c @@ -194,7 +194,8 @@ int cmd_gc(int argc, const char **argv, const char *prefix) if (pack_refs < 0) pack_refs = !is_bare_repository(); - argc = parse_options(argc, argv, builtin_gc_options, builtin_gc_usage, 0); + argc = parse_options(argc, argv, prefix, builtin_gc_options, + builtin_gc_usage, 0); if (argc > 0) usage_with_options(builtin_gc_usage, builtin_gc_options); diff --git a/builtin-grep.c b/builtin-grep.c index eda2c88487..fd450bc16e 100644 --- a/builtin-grep.c +++ b/builtin-grep.c @@ -10,6 +10,8 @@ #include "tag.h" #include "tree-walk.h" #include "builtin.h" +#include "parse-options.h" +#include "userdiff.h" #include "grep.h" #include "quote.h" @@ -21,12 +23,21 @@ #endif #endif -static int builtin_grep; +static char const * const grep_usage[] = { + "git grep [options] [-e] <pattern> [<rev>...] [[--] path...]", + NULL +}; static int grep_config(const char *var, const char *value, void *cb) { struct grep_opt *opt = cb; + switch (userdiff_config(var, value)) { + case 0: break; + case -1: return -1; + default: return 0; + } + if (!strcmp(var, "color.grep")) { opt->color = git_config_colorbool(var, value, -1); return 0; @@ -264,6 +275,17 @@ static int flush_grep(struct grep_opt *opt, argc -= 2; } + if (opt->pre_context || opt->post_context) { + /* + * grep handles hunk marks between files, but we need to + * do that ourselves between multiple calls. + */ + if (opt->show_hunk_mark) + write_or_die(1, "--\n", 3); + else + opt->show_hunk_mark = 1; + } + status = exec_grep(argc, argv); if (kept_0) { @@ -422,7 +444,8 @@ static int external_grep(struct grep_opt *opt, const char **paths, int cached) } #endif -static int grep_cache(struct grep_opt *opt, const char **paths, int cached) +static int grep_cache(struct grep_opt *opt, const char **paths, int cached, + int external_grep_allowed) { int hit = 0; int nr; @@ -434,7 +457,7 @@ static int grep_cache(struct grep_opt *opt, const char **paths, int cached) * we grep through the checked-out files. It tends to * be a lot more optimized */ - if (!cached && !builtin_grep) { + if (!cached && external_grep_allowed) { hit = external_grep(opt, paths, cached); if (hit >= 0) return hit; @@ -551,25 +574,184 @@ static int grep_object(struct grep_opt *opt, const char **paths, die("unable to grep from object of type %s", typename(obj->type)); } -static const char builtin_grep_usage[] = -"git grep <option>* [-e] <pattern> <rev>* [[--] <path>...]"; +static int context_callback(const struct option *opt, const char *arg, + int unset) +{ + struct grep_opt *grep_opt = opt->value; + int value; + const char *endp; -static const char emsg_invalid_context_len[] = -"%s: invalid context length argument"; -static const char emsg_missing_context_len[] = -"missing context length argument"; -static const char emsg_missing_argument[] = -"option requires an argument -%s"; + if (unset) { + grep_opt->pre_context = grep_opt->post_context = 0; + return 0; + } + value = strtol(arg, (char **)&endp, 10); + if (*endp) { + return error("switch `%c' expects a numerical value", + opt->short_name); + } + grep_opt->pre_context = grep_opt->post_context = value; + return 0; +} + +static int file_callback(const struct option *opt, const char *arg, int unset) +{ + struct grep_opt *grep_opt = opt->value; + FILE *patterns; + int lno = 0; + struct strbuf sb; + + patterns = fopen(arg, "r"); + if (!patterns) + die_errno("cannot open '%s'", arg); + while (strbuf_getline(&sb, patterns, '\n') == 0) { + /* ignore empty line like grep does */ + if (sb.len == 0) + continue; + append_grep_pattern(grep_opt, strbuf_detach(&sb, NULL), arg, + ++lno, GREP_PATTERN); + } + fclose(patterns); + strbuf_release(&sb); + return 0; +} + +static int not_callback(const struct option *opt, const char *arg, int unset) +{ + struct grep_opt *grep_opt = opt->value; + append_grep_pattern(grep_opt, "--not", "command line", 0, GREP_NOT); + return 0; +} + +static int and_callback(const struct option *opt, const char *arg, int unset) +{ + struct grep_opt *grep_opt = opt->value; + append_grep_pattern(grep_opt, "--and", "command line", 0, GREP_AND); + return 0; +} + +static int open_callback(const struct option *opt, const char *arg, int unset) +{ + struct grep_opt *grep_opt = opt->value; + append_grep_pattern(grep_opt, "(", "command line", 0, GREP_OPEN_PAREN); + return 0; +} + +static int close_callback(const struct option *opt, const char *arg, int unset) +{ + struct grep_opt *grep_opt = opt->value; + append_grep_pattern(grep_opt, ")", "command line", 0, GREP_CLOSE_PAREN); + return 0; +} + +static int pattern_callback(const struct option *opt, const char *arg, + int unset) +{ + struct grep_opt *grep_opt = opt->value; + append_grep_pattern(grep_opt, arg, "-e option", 0, GREP_PATTERN); + return 0; +} + +static int help_callback(const struct option *opt, const char *arg, int unset) +{ + return -1; +} int cmd_grep(int argc, const char **argv, const char *prefix) { int hit = 0; int cached = 0; + int external_grep_allowed = 1; int seen_dashdash = 0; struct grep_opt opt; struct object_array list = { 0, 0, NULL }; const char **paths = NULL; int i; + int dummy; + struct option options[] = { + OPT_BOOLEAN(0, "cached", &cached, + "search in index instead of in the work tree"), + OPT_GROUP(""), + OPT_BOOLEAN('v', "invert-match", &opt.invert, + "show non-matching lines"), + OPT_BIT('i', "ignore-case", &opt.regflags, + "case insensitive matching", REG_ICASE), + OPT_BOOLEAN('w', "word-regexp", &opt.word_regexp, + "match patterns only at word boundaries"), + OPT_SET_INT('a', "text", &opt.binary, + "process binary files as text", GREP_BINARY_TEXT), + OPT_SET_INT('I', NULL, &opt.binary, + "don't match patterns in binary files", + GREP_BINARY_NOMATCH), + OPT_GROUP(""), + OPT_BIT('E', "extended-regexp", &opt.regflags, + "use extended POSIX regular expressions", REG_EXTENDED), + OPT_NEGBIT('G', "basic-regexp", &opt.regflags, + "use basic POSIX regular expressions (default)", + REG_EXTENDED), + OPT_BOOLEAN('F', "fixed-strings", &opt.fixed, + "interpret patterns as fixed strings"), + OPT_GROUP(""), + OPT_BOOLEAN('n', NULL, &opt.linenum, "show line numbers"), + OPT_NEGBIT('h', NULL, &opt.pathname, "don't show filenames", 1), + OPT_BIT('H', NULL, &opt.pathname, "show filenames", 1), + OPT_NEGBIT(0, "full-name", &opt.relative, + "show filenames relative to top directory", 1), + OPT_BOOLEAN('l', "files-with-matches", &opt.name_only, + "show only filenames instead of matching lines"), + OPT_BOOLEAN(0, "name-only", &opt.name_only, + "synonym for --files-with-matches"), + OPT_BOOLEAN('L', "files-without-match", + &opt.unmatch_name_only, + "show only the names of files without match"), + OPT_BOOLEAN('z', "null", &opt.null_following_name, + "print NUL after filenames"), + OPT_BOOLEAN('c', "count", &opt.count, + "show the number of matches instead of matching lines"), + OPT_SET_INT(0, "color", &opt.color, "highlight matches", 1), + OPT_GROUP(""), + OPT_CALLBACK('C', NULL, &opt, "n", + "show <n> context lines before and after matches", + context_callback), + OPT_INTEGER('B', NULL, &opt.pre_context, + "show <n> context lines before matches"), + OPT_INTEGER('A', NULL, &opt.post_context, + "show <n> context lines after matches"), + OPT_NUMBER_CALLBACK(&opt, "shortcut for -C NUM", + context_callback), + OPT_BOOLEAN('p', "show-function", &opt.funcname, + "show a line with the function name before matches"), + OPT_GROUP(""), + OPT_CALLBACK('f', NULL, &opt, "file", + "read patterns from file", file_callback), + { OPTION_CALLBACK, 'e', NULL, &opt, "pattern", + "match <pattern>", PARSE_OPT_NONEG, pattern_callback }, + { OPTION_CALLBACK, 0, "and", &opt, NULL, + "combine patterns specified with -e", + PARSE_OPT_NOARG | PARSE_OPT_NONEG, and_callback }, + OPT_BOOLEAN(0, "or", &dummy, ""), + { OPTION_CALLBACK, 0, "not", &opt, NULL, "", + PARSE_OPT_NOARG | PARSE_OPT_NONEG, not_callback }, + { OPTION_CALLBACK, '(', NULL, &opt, NULL, "", + PARSE_OPT_NOARG | PARSE_OPT_NONEG | PARSE_OPT_NODASH, + open_callback }, + { OPTION_CALLBACK, ')', NULL, &opt, NULL, "", + PARSE_OPT_NOARG | PARSE_OPT_NONEG | PARSE_OPT_NODASH, + close_callback }, + OPT_BOOLEAN(0, "all-match", &opt.all_match, + "show only matches from files that match all patterns"), + OPT_GROUP(""), +#if NO_EXTERNAL_GREP + OPT_BOOLEAN(0, "ext-grep", &external_grep_allowed, + "allow calling of grep(1) (ignored by this build)"), +#else + OPT_BOOLEAN(0, "ext-grep", &external_grep_allowed, + "allow calling of grep(1) (default)"), +#endif + { OPTION_CALLBACK, 0, "help-all", &options, NULL, "show usage", + PARSE_OPT_HIDDEN | PARSE_OPT_NOARG, help_callback }, + OPT_END() + }; memset(&opt, 0, sizeof(opt)); opt.prefix = prefix; @@ -595,227 +777,21 @@ int cmd_grep(int argc, const char **argv, const char *prefix) * unrecognized non option is the beginning of the refs list * that continues up to the -- (if exists), and then paths. */ - - while (1 < argc) { - const char *arg = argv[1]; - argc--; argv++; - if (!strcmp("--cached", arg)) { - cached = 1; - continue; - } - if (!strcmp("--no-ext-grep", arg)) { - builtin_grep = 1; - continue; - } - if (!strcmp("-a", arg) || - !strcmp("--text", arg)) { - opt.binary = GREP_BINARY_TEXT; - continue; - } - if (!strcmp("-i", arg) || - !strcmp("--ignore-case", arg)) { - opt.regflags |= REG_ICASE; - continue; - } - if (!strcmp("-I", arg)) { - opt.binary = GREP_BINARY_NOMATCH; - continue; - } - if (!strcmp("-v", arg) || - !strcmp("--invert-match", arg)) { - opt.invert = 1; - continue; - } - if (!strcmp("-E", arg) || - !strcmp("--extended-regexp", arg)) { - opt.regflags |= REG_EXTENDED; - continue; - } - if (!strcmp("-F", arg) || - !strcmp("--fixed-strings", arg)) { - opt.fixed = 1; - continue; - } - if (!strcmp("-G", arg) || - !strcmp("--basic-regexp", arg)) { - opt.regflags &= ~REG_EXTENDED; - continue; - } - if (!strcmp("-n", arg)) { - opt.linenum = 1; - continue; - } - if (!strcmp("-h", arg)) { - opt.pathname = 0; - continue; - } - if (!strcmp("-H", arg)) { - opt.pathname = 1; - continue; - } - if (!strcmp("-l", arg) || - !strcmp("--name-only", arg) || - !strcmp("--files-with-matches", arg)) { - opt.name_only = 1; - continue; - } - if (!strcmp("-L", arg) || - !strcmp("--files-without-match", arg)) { - opt.unmatch_name_only = 1; - continue; - } - if (!strcmp("-z", arg) || - !strcmp("--null", arg)) { - opt.null_following_name = 1; - continue; - } - if (!strcmp("-c", arg) || - !strcmp("--count", arg)) { - opt.count = 1; - continue; - } - if (!strcmp("-w", arg) || - !strcmp("--word-regexp", arg)) { - opt.word_regexp = 1; - continue; - } - if (!prefixcmp(arg, "-A") || - !prefixcmp(arg, "-B") || - !prefixcmp(arg, "-C") || - (arg[0] == '-' && '1' <= arg[1] && arg[1] <= '9')) { - unsigned num; - const char *scan; - switch (arg[1]) { - case 'A': case 'B': case 'C': - if (!arg[2]) { - if (argc <= 1) - die(emsg_missing_context_len); - scan = *++argv; - argc--; - } - else - scan = arg + 2; - break; - default: - scan = arg + 1; - break; - } - if (strtoul_ui(scan, 10, &num)) - die(emsg_invalid_context_len, scan); - switch (arg[1]) { - case 'A': - opt.post_context = num; - break; - default: - case 'C': - opt.post_context = num; - case 'B': - opt.pre_context = num; - break; - } - continue; - } - if (!strcmp("-f", arg)) { - FILE *patterns; - int lno = 0; - char buf[1024]; - if (argc <= 1) - die(emsg_missing_argument, arg); - patterns = fopen(argv[1], "r"); - if (!patterns) - die("'%s': %s", argv[1], strerror(errno)); - while (fgets(buf, sizeof(buf), patterns)) { - int len = strlen(buf); - if (len && buf[len-1] == '\n') - buf[len-1] = 0; - /* ignore empty line like grep does */ - if (!buf[0]) - continue; - append_grep_pattern(&opt, xstrdup(buf), - argv[1], ++lno, - GREP_PATTERN); - } - fclose(patterns); - argv++; - argc--; - continue; - } - if (!strcmp("--not", arg)) { - append_grep_pattern(&opt, arg, "command line", 0, - GREP_NOT); - continue; - } - if (!strcmp("--and", arg)) { - append_grep_pattern(&opt, arg, "command line", 0, - GREP_AND); - continue; - } - if (!strcmp("--or", arg)) - continue; /* no-op */ - if (!strcmp("(", arg)) { - append_grep_pattern(&opt, arg, "command line", 0, - GREP_OPEN_PAREN); - continue; - } - if (!strcmp(")", arg)) { - append_grep_pattern(&opt, arg, "command line", 0, - GREP_CLOSE_PAREN); - continue; - } - if (!strcmp("--all-match", arg)) { - opt.all_match = 1; - continue; - } - if (!strcmp("-e", arg)) { - if (1 < argc) { - append_grep_pattern(&opt, argv[1], - "-e option", 0, - GREP_PATTERN); - argv++; - argc--; - continue; - } - die(emsg_missing_argument, arg); - } - if (!strcmp("--full-name", arg)) { - opt.relative = 0; - continue; - } - if (!strcmp("--color", arg)) { - opt.color = 1; - continue; - } - if (!strcmp("--no-color", arg)) { - opt.color = 0; - continue; - } - if (!strcmp("--", arg)) { - /* later processing wants to have this at argv[1] */ - argv--; - argc++; - break; - } - if (*arg == '-') - usage(builtin_grep_usage); - - /* First unrecognized non-option token */ - if (!opt.pattern_list) { - append_grep_pattern(&opt, arg, "command line", 0, - GREP_PATTERN); - break; - } - else { - /* We are looking at the first path or rev; - * it is found at argv[1] after leaving the - * loop. - */ - argc++; argv--; - break; - } + argc = parse_options(argc, argv, prefix, options, grep_usage, + PARSE_OPT_KEEP_DASHDASH | + PARSE_OPT_STOP_AT_NON_OPTION | + PARSE_OPT_NO_INTERNAL_HELP); + + /* First unrecognized non-option token */ + if (argc > 0 && !opt.pattern_list) { + append_grep_pattern(&opt, argv[0], "command line", 0, + GREP_PATTERN); + argv++; + argc--; } - if (opt.color && !opt.color_external) - builtin_grep = 1; + if ((opt.color && !opt.color_external) || opt.funcname) + external_grep_allowed = 0; if (!opt.pattern_list) die("no pattern given."); if ((opt.regflags != REG_NEWLINE) && opt.fixed) @@ -823,7 +799,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix) compile_grep_patterns(&opt); /* Check revs and then paths */ - for (i = 1; i < argc; i++) { + for (i = 0; i < argc; i++) { const char *arg = argv[i]; unsigned char sha1[20]; /* Is it a rev? */ @@ -859,7 +835,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix) if (!list.nr) { if (!cached) setup_work_tree(); - return !grep_cache(&opt, paths, cached); + return !grep_cache(&opt, paths, cached, external_grep_allowed); } if (cached) diff --git a/builtin-help.c b/builtin-help.c index 67dda3e6e6..e1eba778a5 100644 --- a/builtin-help.c +++ b/builtin-help.c @@ -80,10 +80,9 @@ static int check_emacsclient_version(void) ec_process.argv = argv_ec; ec_process.err = -1; ec_process.stdout_to_stderr = 1; - if (start_command(&ec_process)) { - fprintf(stderr, "Failed to start emacsclient.\n"); - return -1; - } + if (start_command(&ec_process)) + return error("Failed to start emacsclient."); + strbuf_read(&buffer, ec_process.err, 20); close(ec_process.err); @@ -94,20 +93,17 @@ static int check_emacsclient_version(void) finish_command(&ec_process); if (prefixcmp(buffer.buf, "emacsclient")) { - fprintf(stderr, "Failed to parse emacsclient version.\n"); strbuf_release(&buffer); - return -1; + return error("Failed to parse emacsclient version."); } strbuf_remove(&buffer, 0, strlen("emacsclient")); version = atoi(buffer.buf); if (version < 22) { - fprintf(stderr, - "emacsclient version '%d' too old (< 22).\n", - version); strbuf_release(&buffer); - return -1; + return error("emacsclient version '%d' too old (< 22).", + version); } strbuf_release(&buffer); @@ -398,7 +394,7 @@ static void get_html_page_path(struct strbuf *page_path, const char *page) * HTML. */ #ifndef open_html -void open_html(const char *path) +static void open_html(const char *path) { execl_git_cmd("web--browse", "-c", "help.browser", path, NULL); } @@ -423,7 +419,7 @@ int cmd_help(int argc, const char **argv, const char *prefix) setup_git_directory_gently(&nongit); git_config(git_help_config, NULL); - argc = parse_options(argc, argv, builtin_help_options, + argc = parse_options(argc, argv, prefix, builtin_help_options, builtin_help_usage, 0); if (show_all) { diff --git a/builtin-init-db.c b/builtin-init-db.c index d1fa12a59e..4a5600631c 100644 --- a/builtin-init-db.c +++ b/builtin-init-db.c @@ -61,20 +61,20 @@ static void copy_templates_1(char *path, int baselen, memcpy(template + template_baselen, de->d_name, namelen+1); if (lstat(path, &st_git)) { if (errno != ENOENT) - die("cannot stat %s", path); + die_errno("cannot stat '%s'", path); } else exists = 1; if (lstat(template, &st_template)) - die("cannot stat template %s", template); + die_errno("cannot stat template '%s'", template); if (S_ISDIR(st_template.st_mode)) { DIR *subdir = opendir(template); int baselen_sub = baselen + namelen; int template_baselen_sub = template_baselen + namelen; if (!subdir) - die("cannot opendir %s", template); + die_errno("cannot opendir '%s'", template); path[baselen_sub++] = template[template_baselen_sub++] = '/'; path[baselen_sub] = @@ -91,16 +91,17 @@ static void copy_templates_1(char *path, int baselen, int len; len = readlink(template, lnk, sizeof(lnk)); if (len < 0) - die("cannot readlink %s", template); + die_errno("cannot readlink '%s'", template); if (sizeof(lnk) <= len) die("insanely long symlink %s", template); lnk[len] = 0; if (symlink(lnk, path)) - die("cannot symlink %s %s", lnk, path); + die_errno("cannot symlink '%s' '%s'", lnk, path); } else if (S_ISREG(st_template.st_mode)) { if (copy_file(path, template, st_template.st_mode)) - die("cannot copy %s to %s", template, path); + die_errno("cannot copy '%s' to '%s'", template, + path); } else error("ignoring template %s", template); @@ -350,7 +351,7 @@ static int guess_repository_type(const char *git_dir) if (!strcmp(".", git_dir)) return 1; if (!getcwd(cwd, sizeof(cwd))) - die("cannot tell cwd"); + die_errno("cannot tell cwd"); if (!strcmp(git_dir, cwd)) return 1; /* @@ -440,11 +441,11 @@ int cmd_init_db(int argc, const char **argv, const char *prefix) if (!git_work_tree_cfg) { git_work_tree_cfg = xcalloc(PATH_MAX, 1); if (!getcwd(git_work_tree_cfg, PATH_MAX)) - die ("Cannot access current working directory."); + die_errno ("Cannot access current working directory"); } if (access(get_git_work_tree(), X_OK)) - die ("Cannot access work tree '%s'", - get_git_work_tree()); + die_errno ("Cannot access work tree '%s'", + get_git_work_tree()); } set_git_dir(make_absolute_path(git_dir)); diff --git a/builtin-log.c b/builtin-log.c index f10cfebdbb..8d93c1a2a4 100644 --- a/builtin-log.c +++ b/builtin-log.c @@ -18,6 +18,7 @@ #include "shortlog.h" #include "remote.h" #include "string-list.h" +#include "parse-options.h" /* Set a default date-time format for git log ("log.date" config variable) */ static const char *default_date_mode = NULL; @@ -30,6 +31,7 @@ static void cmd_log_init(int argc, const char **argv, const char *prefix, struct rev_info *rev) { int i; + int decoration_style = 0; rev->abbrev = DEFAULT_ABBREV; rev->commit_format = CMIT_FMT_DEFAULT; @@ -56,13 +58,24 @@ static void cmd_log_init(int argc, const char **argv, const char *prefix, for (i = 1; i < argc; i++) { const char *arg = argv[i]; if (!strcmp(arg, "--decorate")) { - load_ref_decorations(); - rev->show_decorations = 1; + decoration_style = DECORATE_SHORT_REFS; + } else if (!prefixcmp(arg, "--decorate=")) { + const char *v = skip_prefix(arg, "--decorate="); + if (!strcmp(v, "full")) + decoration_style = DECORATE_FULL_REFS; + else if (!strcmp(v, "short")) + decoration_style = DECORATE_SHORT_REFS; + else + die("invalid --decorate option: %s", arg); } else if (!strcmp(arg, "--source")) { rev->show_source = 1; } else die("unrecognized argument: %s", arg); } + if (decoration_style) { + rev->show_decorations = 1; + load_ref_decorations(decoration_style); + } } /* @@ -93,7 +106,7 @@ static void show_early_header(struct rev_info *rev, const char *stage, int nr) printf("Final output: %d %s\n", nr, stage); } -struct itimerval early_output_timer; +static struct itimerval early_output_timer; static void log_show_early(struct rev_info *revs, struct commit_list *list) { @@ -256,7 +269,7 @@ static void show_tagger(char *buf, int len, struct rev_info *rev) pp_user_info("Tagger", rev->commit_format, &out, buf, rev->date_mode, git_log_output_encoding ? git_log_output_encoding: git_commit_encoding); - printf("%s\n", out.buf); + printf("%s", out.buf); strbuf_release(&out); } @@ -328,11 +341,14 @@ int cmd_show(int argc, const char **argv, const char *prefix) case OBJ_TAG: { struct tag *t = (struct tag *)o; + if (rev.shown_one) + putchar('\n'); printf("%stag %s%s\n", diff_get_color_opt(&rev.diffopt, DIFF_COMMIT), t->tag, diff_get_color_opt(&rev.diffopt, DIFF_RESET)); ret = show_object(o->sha1, 1, &rev); + rev.shown_one = 1; if (ret) break; o = parse_object(t->tagged->sha1); @@ -344,12 +360,15 @@ int cmd_show(int argc, const char **argv, const char *prefix) break; } case OBJ_TREE: + if (rev.shown_one) + putchar('\n'); printf("%stree %s%s\n\n", diff_get_color_opt(&rev.diffopt, DIFF_COMMIT), name, diff_get_color_opt(&rev.diffopt, DIFF_RESET)); read_tree_recursive((struct tree *)o, "", 0, 0, NULL, show_tree_object, NULL); + rev.shown_one = 1; break; case OBJ_COMMIT: rev.pending.nr = rev.pending.alloc = 0; @@ -619,7 +638,7 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout, struct shortlog log; struct strbuf sb = STRBUF_INIT; int i; - const char *encoding = "utf-8"; + const char *encoding = "UTF-8"; struct diff_options opts; int need_8bit_cte = 0; struct commit *commit = NULL; @@ -657,6 +676,10 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout, log_write_email_headers(rev, head, &subject_start, &extra_headers, &need_8bit_cte); + for (i = 0; !need_8bit_cte && i < nr; i++) + if (has_non_ascii(list[i]->buffer)) + need_8bit_cte = 1; + msg = body; pp_user_info(NULL, CMIT_FMT_EMAIL, &sb, committer, DATE_RFC2822, encoding); @@ -740,27 +763,179 @@ static const char *set_outdir(const char *prefix, const char *output_directory) output_directory)); } +static const char * const builtin_format_patch_usage[] = { + "git format-patch [options] [<since> | <revision range>]", + NULL +}; + +static int keep_subject = 0; + +static int keep_callback(const struct option *opt, const char *arg, int unset) +{ + ((struct rev_info *)opt->value)->total = -1; + keep_subject = 1; + return 0; +} + +static int subject_prefix = 0; + +static int subject_prefix_callback(const struct option *opt, const char *arg, + int unset) +{ + subject_prefix = 1; + ((struct rev_info *)opt->value)->subject_prefix = arg; + return 0; +} + +static int numbered_cmdline_opt = 0; + +static int numbered_callback(const struct option *opt, const char *arg, + int unset) +{ + *(int *)opt->value = numbered_cmdline_opt = unset ? 0 : 1; + if (unset) + auto_number = 0; + return 0; +} + +static int no_numbered_callback(const struct option *opt, const char *arg, + int unset) +{ + return numbered_callback(opt, arg, 1); +} + +static int output_directory_callback(const struct option *opt, const char *arg, + int unset) +{ + const char **dir = (const char **)opt->value; + if (*dir) + die("Two output directories?"); + *dir = arg; + return 0; +} + +static int thread_callback(const struct option *opt, const char *arg, int unset) +{ + int *thread = (int *)opt->value; + if (unset) + *thread = 0; + else if (!arg || !strcmp(arg, "shallow")) + *thread = THREAD_SHALLOW; + else if (!strcmp(arg, "deep")) + *thread = THREAD_DEEP; + else + return 1; + return 0; +} + +static int attach_callback(const struct option *opt, const char *arg, int unset) +{ + struct rev_info *rev = (struct rev_info *)opt->value; + if (unset) + rev->mime_boundary = NULL; + else if (arg) + rev->mime_boundary = arg; + else + rev->mime_boundary = git_version_string; + rev->no_inline = unset ? 0 : 1; + return 0; +} + +static int inline_callback(const struct option *opt, const char *arg, int unset) +{ + struct rev_info *rev = (struct rev_info *)opt->value; + if (unset) + rev->mime_boundary = NULL; + else if (arg) + rev->mime_boundary = arg; + else + rev->mime_boundary = git_version_string; + rev->no_inline = 0; + return 0; +} + +static int header_callback(const struct option *opt, const char *arg, int unset) +{ + add_header(arg); + return 0; +} + +static int cc_callback(const struct option *opt, const char *arg, int unset) +{ + ALLOC_GROW(extra_cc, extra_cc_nr + 1, extra_cc_alloc); + extra_cc[extra_cc_nr++] = xstrdup(arg); + return 0; +} + int cmd_format_patch(int argc, const char **argv, const char *prefix) { struct commit *commit; struct commit **list = NULL; struct rev_info rev; - int nr = 0, total, i, j; + int nr = 0, total, i; int use_stdout = 0; int start_number = -1; - int keep_subject = 0; int numbered_files = 0; /* _just_ numbers */ - int subject_prefix = 0; int ignore_if_in_upstream = 0; int cover_letter = 0; int boundary_count = 0; int no_binary_diff = 0; - int numbered_cmdline_opt = 0; struct commit *origin = NULL, *head = NULL; const char *in_reply_to = NULL; struct patch_ids ids; char *add_signoff = NULL; struct strbuf buf = STRBUF_INIT; + const struct option builtin_format_patch_options[] = { + { OPTION_CALLBACK, 'n', "numbered", &numbered, NULL, + "use [PATCH n/m] even with a single patch", + PARSE_OPT_NOARG, numbered_callback }, + { OPTION_CALLBACK, 'N', "no-numbered", &numbered, NULL, + "use [PATCH] even with multiple patches", + PARSE_OPT_NOARG, no_numbered_callback }, + OPT_BOOLEAN('s', "signoff", &do_signoff, "add Signed-off-by:"), + OPT_BOOLEAN(0, "stdout", &use_stdout, + "print patches to standard out"), + OPT_BOOLEAN(0, "cover-letter", &cover_letter, + "generate a cover letter"), + OPT_BOOLEAN(0, "numbered-files", &numbered_files, + "use simple number sequence for output file names"), + OPT_STRING(0, "suffix", &fmt_patch_suffix, "sfx", + "use <sfx> instead of '.patch'"), + OPT_INTEGER(0, "start-number", &start_number, + "start numbering patches at <n> instead of 1"), + { OPTION_CALLBACK, 0, "subject-prefix", &rev, "prefix", + "Use [<prefix>] instead of [PATCH]", + PARSE_OPT_NONEG, subject_prefix_callback }, + { OPTION_CALLBACK, 'o', "output-directory", &output_directory, + "dir", "store resulting files in <dir>", + PARSE_OPT_NONEG, output_directory_callback }, + { OPTION_CALLBACK, 'k', "keep-subject", &rev, NULL, + "don't strip/add [PATCH]", + PARSE_OPT_NOARG | PARSE_OPT_NONEG, keep_callback }, + OPT_BOOLEAN(0, "no-binary", &no_binary_diff, + "don't output binary diffs"), + OPT_BOOLEAN(0, "ignore-if-in-upstream", &ignore_if_in_upstream, + "don't include a patch matching a commit upstream"), + OPT_GROUP("Messaging"), + { OPTION_CALLBACK, 0, "add-header", NULL, "header", + "add email header", PARSE_OPT_NONEG, + header_callback }, + { OPTION_CALLBACK, 0, "cc", NULL, "email", "add Cc: header", + PARSE_OPT_NONEG, cc_callback }, + OPT_STRING(0, "in-reply-to", &in_reply_to, "message-id", + "make first mail a reply to <message-id>"), + { OPTION_CALLBACK, 0, "attach", &rev, "boundary", + "attach the patch", PARSE_OPT_OPTARG, + attach_callback }, + { OPTION_CALLBACK, 0, "inline", &rev, "boundary", + "inline the patch", + PARSE_OPT_OPTARG | PARSE_OPT_NONEG, + inline_callback }, + { OPTION_CALLBACK, 0, "thread", &thread, "style", + "enable message threading, styles: shallow, deep", + PARSE_OPT_OPTARG, thread_callback }, + OPT_END() + }; git_config(git_format_config, NULL); init_revisions(&rev, prefix); @@ -783,102 +958,9 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix) * like "git format-patch -o a123 HEAD^.." may fail; a123 is * possibly a valid SHA1. */ - for (i = 1, j = 1; i < argc; i++) { - if (!strcmp(argv[i], "--stdout")) - use_stdout = 1; - else if (!strcmp(argv[i], "-n") || - !strcmp(argv[i], "--numbered")) { - numbered = 1; - numbered_cmdline_opt = 1; - } - else if (!strcmp(argv[i], "-N") || - !strcmp(argv[i], "--no-numbered")) { - numbered = 0; - auto_number = 0; - } - else if (!prefixcmp(argv[i], "--start-number=")) - start_number = strtol(argv[i] + 15, NULL, 10); - else if (!strcmp(argv[i], "--numbered-files")) - numbered_files = 1; - else if (!strcmp(argv[i], "--start-number")) { - i++; - if (i == argc) - die("Need a number for --start-number"); - start_number = strtol(argv[i], NULL, 10); - } - else if (!prefixcmp(argv[i], "--cc=")) { - ALLOC_GROW(extra_cc, extra_cc_nr + 1, extra_cc_alloc); - extra_cc[extra_cc_nr++] = xstrdup(argv[i] + 5); - } - else if (!strcmp(argv[i], "-k") || - !strcmp(argv[i], "--keep-subject")) { - keep_subject = 1; - rev.total = -1; - } - else if (!strcmp(argv[i], "--output-directory") || - !strcmp(argv[i], "-o")) { - i++; - if (argc <= i) - die("Which directory?"); - if (output_directory) - die("Two output directories?"); - output_directory = argv[i]; - } - else if (!strcmp(argv[i], "--signoff") || - !strcmp(argv[i], "-s")) { - do_signoff = 1; - } - else if (!strcmp(argv[i], "--attach")) { - rev.mime_boundary = git_version_string; - rev.no_inline = 1; - } - else if (!prefixcmp(argv[i], "--attach=")) { - rev.mime_boundary = argv[i] + 9; - rev.no_inline = 1; - } - else if (!strcmp(argv[i], "--no-attach")) { - rev.mime_boundary = NULL; - rev.no_inline = 0; - } - else if (!strcmp(argv[i], "--inline")) { - rev.mime_boundary = git_version_string; - rev.no_inline = 0; - } - else if (!prefixcmp(argv[i], "--inline=")) { - rev.mime_boundary = argv[i] + 9; - rev.no_inline = 0; - } - else if (!strcmp(argv[i], "--ignore-if-in-upstream")) - ignore_if_in_upstream = 1; - else if (!strcmp(argv[i], "--thread") - || !strcmp(argv[i], "--thread=shallow")) - thread = THREAD_SHALLOW; - else if (!strcmp(argv[i], "--thread=deep")) - thread = THREAD_DEEP; - else if (!strcmp(argv[i], "--no-thread")) - thread = 0; - else if (!prefixcmp(argv[i], "--in-reply-to=")) - in_reply_to = argv[i] + 14; - else if (!strcmp(argv[i], "--in-reply-to")) { - i++; - if (i == argc) - die("Need a Message-Id for --in-reply-to"); - in_reply_to = argv[i]; - } else if (!prefixcmp(argv[i], "--subject-prefix=")) { - subject_prefix = 1; - rev.subject_prefix = argv[i] + 17; - } else if (!prefixcmp(argv[i], "--suffix=")) - fmt_patch_suffix = argv[i] + 9; - else if (!strcmp(argv[i], "--cover-letter")) - cover_letter = 1; - else if (!strcmp(argv[i], "--no-binary")) - no_binary_diff = 1; - else if (!prefixcmp(argv[i], "--add-header=")) - add_header(argv[i] + 13); - else - argv[j++] = argv[i]; - } - argc = j; + argc = parse_options(argc, argv, prefix, builtin_format_patch_options, + builtin_format_patch_usage, + PARSE_OPT_KEEP_ARGV0 | PARSE_OPT_KEEP_UNKNOWN); if (do_signoff) { const char *committer; @@ -917,7 +999,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix) strbuf_addch(&buf, '\n'); } - rev.extra_headers = strbuf_detach(&buf, 0); + rev.extra_headers = strbuf_detach(&buf, NULL); if (start_number < 0) start_number = 1; @@ -953,8 +1035,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix) if (use_stdout) die("standard output, or directory, which one?"); if (mkdir(output_directory, 0777) < 0 && errno != EEXIST) - die("Could not create directory %s", - output_directory); + die_errno("Could not create directory '%s'", + output_directory); } if (rev.pending.nr == 1) { diff --git a/builtin-ls-files.c b/builtin-ls-files.c index da2daf45ac..f473220502 100644 --- a/builtin-ls-files.c +++ b/builtin-ls-files.c @@ -161,12 +161,7 @@ static void show_files(struct dir_struct *dir, const char *prefix) /* For cached/deleted files we don't need to even do the readdir */ if (show_others || show_killed) { - const char *path = ".", *base = ""; - int baselen = prefix_len; - - if (baselen) - path = base = prefix; - read_directory(dir, path, base, baselen, pathspec); + fill_directory(dir, pathspec); if (show_others) show_other_files(dir); if (show_killed) @@ -454,7 +449,7 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix) OPT_BIT(0, "directory", &dir.flags, "show 'other' directories' name only", DIR_SHOW_OTHER_DIRECTORIES), - OPT_BIT(0, "no-empty-directory", &dir.flags, + OPT_NEGBIT(0, "empty-directory", &dir.flags, "don't show empty directories", DIR_HIDE_EMPTY_DIRECTORIES), OPT_BOOLEAN('u', "unmerged", &show_unmerged, @@ -486,7 +481,7 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix) prefix_offset = strlen(prefix); git_config(git_default_config, NULL); - argc = parse_options(argc, argv, builtin_ls_files_options, + argc = parse_options(argc, argv, prefix, builtin_ls_files_options, ls_files_usage, 0); if (show_tag || show_valid_bit) { tag_cached = "H "; diff --git a/builtin-mailinfo.c b/builtin-mailinfo.c index 1eeeb4de6d..92637ac0ba 100644 --- a/builtin-mailinfo.c +++ b/builtin-mailinfo.c @@ -193,8 +193,7 @@ static void handle_content_type(struct strbuf *line) *content_top = boundary; boundary = NULL; } - if (slurp_attr(line->buf, "charset=", &charset)) - strbuf_tolower(&charset); + slurp_attr(line->buf, "charset=", &charset); if (boundary) { strbuf_release(boundary); @@ -481,7 +480,7 @@ static const char *guess_charset(const struct strbuf *line, const char *target_c if (is_utf8(line->buf)) return NULL; } - return "latin1"; + return "ISO8859-1"; } static void convert_to_utf8(struct strbuf *line, const char *charset) @@ -494,7 +493,7 @@ static void convert_to_utf8(struct strbuf *line, const char *charset) return; } - if (!strcmp(metainfo_charset, charset)) + if (!strcasecmp(metainfo_charset, charset)) return; out = reencode_string(line->buf, metainfo_charset, charset); if (!out) @@ -550,7 +549,6 @@ static int decode_header_bq(struct strbuf *it) if (cp + 3 - it->buf > it->len) goto decode_header_bq_out; strbuf_add(&charset_q, ep, cp - ep); - strbuf_tolower(&charset_q); encoding = cp[1]; if (!encoding || cp[2] != '?') @@ -944,7 +942,7 @@ int cmd_mailinfo(int argc, const char **argv, const char *prefix) */ git_config(git_default_config, NULL); - def_charset = (git_commit_encoding ? git_commit_encoding : "utf-8"); + def_charset = (git_commit_encoding ? git_commit_encoding : "UTF-8"); metainfo_charset = def_charset; while (1 < argc && argv[1][0] == '-') { diff --git a/builtin-mailsplit.c b/builtin-mailsplit.c index 71f3b3b874..ad5f6b593d 100644 --- a/builtin-mailsplit.c +++ b/builtin-mailsplit.c @@ -81,7 +81,7 @@ static int split_one(FILE *mbox, const char *name, int allow_bare) fd = open(name, O_WRONLY | O_CREAT | O_EXCL, 0666); if (fd < 0) - die("cannot open output file %s", name); + die_errno("cannot open output file '%s'", name); output = fdopen(fd, "w"); /* Copy it out, while searching for a line that begins with @@ -91,7 +91,7 @@ static int split_one(FILE *mbox, const char *name, int allow_bare) int is_partial = len && buf[len-1] != '\n'; if (fwrite(buf, 1, len, output) != len) - die("cannot write output"); + die_errno("cannot write output"); len = read_line_with_nul(buf, sizeof(buf), mbox); if (len == 0) { @@ -99,7 +99,7 @@ static int split_one(FILE *mbox, const char *name, int allow_bare) status = 1; break; } - die("cannot read mbox"); + die_errno("cannot read mbox"); } if (!is_partial && !is_bare && is_from_line(buf, len)) break; /* done with one message */ diff --git a/builtin-merge-base.c b/builtin-merge-base.c index 03fc1c2114..a6ec2f7ab7 100644 --- a/builtin-merge-base.c +++ b/builtin-merge-base.c @@ -53,7 +53,7 @@ int cmd_merge_base(int argc, const char **argv, const char *prefix) }; git_config(git_default_config, NULL); - argc = parse_options(argc, argv, options, merge_base_usage, 0); + argc = parse_options(argc, argv, prefix, options, merge_base_usage, 0); if (argc < 2) usage_with_options(merge_base_usage, options); rev = xmalloc(argc * sizeof(*rev)); diff --git a/builtin-merge-file.c b/builtin-merge-file.c index 96edb97a83..afd2ea7a73 100644 --- a/builtin-merge-file.c +++ b/builtin-merge-file.c @@ -48,7 +48,7 @@ int cmd_merge_file(int argc, const char **argv, const char *prefix) merge_style = git_xmerge_style; } - argc = parse_options(argc, argv, options, merge_file_usage, 0); + argc = parse_options(argc, argv, prefix, options, merge_file_usage, 0); if (argc != 3) usage_with_options(merge_file_usage, options); if (quiet) { diff --git a/builtin-merge-recursive.c b/builtin-merge-recursive.c index 703045bfc8..d26a96e486 100644 --- a/builtin-merge-recursive.c +++ b/builtin-merge-recursive.c @@ -45,8 +45,9 @@ int cmd_merge_recursive(int argc, const char **argv, const char *prefix) bases[bases_count++] = sha; } else - warning("Cannot handle more than %zu bases. " - "Ignoring %s.", ARRAY_SIZE(bases)-1, argv[i]); + warning("Cannot handle more than %d bases. " + "Ignoring %s.", + (int)ARRAY_SIZE(bases)-1, argv[i]); } if (argc - i != 3) /* "--" "<head>" "<remote>" */ die("Not handling anything other than two heads merge."); diff --git a/builtin-merge.c b/builtin-merge.c index 9e9bd526c3..f4de73fa9d 100644 --- a/builtin-merge.c +++ b/builtin-merge.c @@ -268,7 +268,7 @@ static void squash_message(void) printf("Squash commit -- not updating HEAD\n"); fd = open(git_path("SQUASH_MSG"), O_WRONLY | O_CREAT, 0666); if (fd < 0) - die("Could not write to %s", git_path("SQUASH_MSG")); + die_errno("Could not write to '%s'", git_path("SQUASH_MSG")); init_revisions(&rev, NULL); rev.ignore_merges = 1; @@ -294,9 +294,9 @@ static void squash_message(void) NULL, NULL, rev.date_mode, 0); } if (write(fd, out.buf, out.len) < 0) - die("Writing SQUASH_MSG: %s", strerror(errno)); + die_errno("Writing SQUASH_MSG"); if (close(fd)) - die("Finishing SQUASH_MSG: %s", strerror(errno)); + die_errno("Finishing SQUASH_MSG"); strbuf_release(&out); } @@ -358,6 +358,7 @@ static void merge_name(const char *remote, struct strbuf *msg) struct strbuf buf = STRBUF_INIT; struct strbuf bname = STRBUF_INIT; const char *ptr; + char *found_ref; int len, early; strbuf_branchname(&bname, remote); @@ -368,14 +369,17 @@ static void merge_name(const char *remote, struct strbuf *msg) if (!remote_head) die("'%s' does not point to a commit", remote); - strbuf_addstr(&buf, "refs/heads/"); - strbuf_addstr(&buf, remote); - resolve_ref(buf.buf, branch_head, 0, 0); - - if (!hashcmp(remote_head->sha1, branch_head)) { - strbuf_addf(msg, "%s\t\tbranch '%s' of .\n", - sha1_to_hex(branch_head), remote); - goto cleanup; + if (dwim_ref(remote, strlen(remote), branch_head, &found_ref) > 0) { + if (!prefixcmp(found_ref, "refs/heads/")) { + strbuf_addf(msg, "%s\t\tbranch '%s' of .\n", + sha1_to_hex(branch_head), remote); + goto cleanup; + } + if (!prefixcmp(found_ref, "refs/remotes/")) { + strbuf_addf(msg, "%s\t\tremote branch '%s' of .\n", + sha1_to_hex(branch_head), remote); + goto cleanup; + } } /* See if remote matches <name>^^^.. or <name>~<number> */ @@ -409,7 +413,7 @@ static void merge_name(const char *remote, struct strbuf *msg) strbuf_addstr(&truname, "refs/heads/"); strbuf_addstr(&truname, remote); strbuf_setlen(&truname, truname.len - len); - if (resolve_ref(truname.buf, buf_sha, 0, 0)) { + if (resolve_ref(truname.buf, buf_sha, 0, NULL)) { strbuf_addf(msg, "%s\t\tbranch '%s'%s of .\n", sha1_to_hex(remote_head->sha1), @@ -428,8 +432,8 @@ static void merge_name(const char *remote, struct strbuf *msg) fp = fopen(git_path("FETCH_HEAD"), "r"); if (!fp) - die("could not open %s for reading: %s", - git_path("FETCH_HEAD"), strerror(errno)); + die_errno("could not open '%s' for reading", + git_path("FETCH_HEAD")); strbuf_getline(&line, fp, '\n'); fclose(fp); ptr = strstr(line.buf, "\tnot-for-merge\t"); @@ -462,7 +466,7 @@ static int git_merge_config(const char *k, const char *v, void *cb) argv = xrealloc(argv, sizeof(*argv) * (argc + 2)); memmove(argv + 1, argv, sizeof(*argv) * (argc + 1)); argc++; - parse_options(argc, argv, builtin_merge_options, + parse_options(argc, argv, NULL, builtin_merge_options, builtin_merge_usage, 0); free(buf); } @@ -764,7 +768,8 @@ static int suggest_conflicts(void) fp = fopen(git_path("MERGE_MSG"), "a"); if (!fp) - die("Could not open %s for writing", git_path("MERGE_MSG")); + die_errno("Could not open '%s' for writing", + git_path("MERGE_MSG")); fprintf(fp, "\nConflicts:\n"); for (pos = 0; pos < active_nr; pos++) { struct cache_entry *ce = active_cache[pos]; @@ -858,7 +863,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix) if (diff_use_color_default == -1) diff_use_color_default = git_use_color_default; - argc = parse_options(argc, argv, builtin_merge_options, + argc = parse_options(argc, argv, prefix, builtin_merge_options, builtin_merge_usage, 0); if (verbosity < 0) show_diffstat = 0; @@ -1189,27 +1194,29 @@ int cmd_merge(int argc, const char **argv, const char *prefix) sha1_to_hex(j->item->object.sha1)); fd = open(git_path("MERGE_HEAD"), O_WRONLY | O_CREAT, 0666); if (fd < 0) - die("Could open %s for writing", - git_path("MERGE_HEAD")); + die_errno("Could not open '%s' for writing", + git_path("MERGE_HEAD")); if (write_in_full(fd, buf.buf, buf.len) != buf.len) - die("Could not write to %s", git_path("MERGE_HEAD")); + die_errno("Could not write to '%s'", git_path("MERGE_HEAD")); close(fd); strbuf_addch(&merge_msg, '\n'); fd = open(git_path("MERGE_MSG"), O_WRONLY | O_CREAT, 0666); if (fd < 0) - die("Could open %s for writing", git_path("MERGE_MSG")); + die_errno("Could not open '%s' for writing", + git_path("MERGE_MSG")); if (write_in_full(fd, merge_msg.buf, merge_msg.len) != merge_msg.len) - die("Could not write to %s", git_path("MERGE_MSG")); + die_errno("Could not write to '%s'", git_path("MERGE_MSG")); close(fd); fd = open(git_path("MERGE_MODE"), O_WRONLY | O_CREAT | O_TRUNC, 0666); if (fd < 0) - die("Could open %s for writing", git_path("MERGE_MODE")); + die_errno("Could not open '%s' for writing", + git_path("MERGE_MODE")); strbuf_reset(&buf); if (!allow_fast_forward) strbuf_addf(&buf, "no-ff"); if (write_in_full(fd, buf.buf, buf.len) != buf.len) - die("Could not write to %s", git_path("MERGE_MODE")); + die_errno("Could not write to '%s'", git_path("MERGE_MODE")); close(fd); } diff --git a/builtin-mktree.c b/builtin-mktree.c new file mode 100644 index 0000000000..098395fda1 --- /dev/null +++ b/builtin-mktree.c @@ -0,0 +1,190 @@ +/* + * GIT - the stupid content tracker + * + * Copyright (c) Junio C Hamano, 2006, 2009 + */ +#include "builtin.h" +#include "quote.h" +#include "tree.h" +#include "parse-options.h" + +static struct treeent { + unsigned mode; + unsigned char sha1[20]; + int len; + char name[FLEX_ARRAY]; +} **entries; +static int alloc, used; + +static void append_to_tree(unsigned mode, unsigned char *sha1, char *path) +{ + struct treeent *ent; + int len = strlen(path); + if (strchr(path, '/')) + die("path %s contains slash", path); + + if (alloc <= used) { + alloc = alloc_nr(used); + entries = xrealloc(entries, sizeof(*entries) * alloc); + } + ent = entries[used++] = xmalloc(sizeof(**entries) + len + 1); + ent->mode = mode; + ent->len = len; + hashcpy(ent->sha1, sha1); + memcpy(ent->name, path, len+1); +} + +static int ent_compare(const void *a_, const void *b_) +{ + struct treeent *a = *(struct treeent **)a_; + struct treeent *b = *(struct treeent **)b_; + return base_name_compare(a->name, a->len, a->mode, + b->name, b->len, b->mode); +} + +static void write_tree(unsigned char *sha1) +{ + struct strbuf buf; + size_t size; + int i; + + qsort(entries, used, sizeof(*entries), ent_compare); + for (size = i = 0; i < used; i++) + size += 32 + entries[i]->len; + + strbuf_init(&buf, size); + for (i = 0; i < used; i++) { + struct treeent *ent = entries[i]; + strbuf_addf(&buf, "%o %s%c", ent->mode, ent->name, '\0'); + strbuf_add(&buf, ent->sha1, 20); + } + + write_sha1_file(buf.buf, buf.len, tree_type, sha1); +} + +static const char *mktree_usage[] = { + "git mktree [-z] [--missing] [--batch]", + NULL +}; + +static void mktree_line(char *buf, size_t len, int line_termination, int allow_missing) +{ + char *ptr, *ntr; + unsigned mode; + enum object_type mode_type; /* object type derived from mode */ + enum object_type obj_type; /* object type derived from sha */ + char *path; + unsigned char sha1[20]; + + ptr = buf; + /* + * Read non-recursive ls-tree output format: + * mode SP type SP sha1 TAB name + */ + mode = strtoul(ptr, &ntr, 8); + if (ptr == ntr || !ntr || *ntr != ' ') + die("input format error: %s", buf); + ptr = ntr + 1; /* type */ + ntr = strchr(ptr, ' '); + if (!ntr || buf + len <= ntr + 40 || + ntr[41] != '\t' || + get_sha1_hex(ntr + 1, sha1)) + die("input format error: %s", buf); + + /* It is perfectly normal if we do not have a commit from a submodule */ + if (S_ISGITLINK(mode)) + allow_missing = 1; + + + *ntr++ = 0; /* now at the beginning of SHA1 */ + + path = ntr + 41; /* at the beginning of name */ + if (line_termination && path[0] == '"') { + struct strbuf p_uq = STRBUF_INIT; + if (unquote_c_style(&p_uq, path, NULL)) + die("invalid quoting"); + path = strbuf_detach(&p_uq, NULL); + } + + /* + * Object type is redundantly derivable three ways. + * These should all agree. + */ + mode_type = object_type(mode); + if (mode_type != type_from_string(ptr)) { + die("entry '%s' object type (%s) doesn't match mode type (%s)", + path, ptr, typename(mode_type)); + } + + /* Check the type of object identified by sha1 */ + obj_type = sha1_object_info(sha1, NULL); + if (obj_type < 0) { + if (allow_missing) { + ; /* no problem - missing objects are presumed to be of the right type */ + } else { + die("entry '%s' object %s is unavailable", path, sha1_to_hex(sha1)); + } + } else { + if (obj_type != mode_type) { + /* + * The object exists but is of the wrong type. + * This is a problem regardless of allow_missing + * because the new tree entry will never be correct. + */ + die("entry '%s' object %s is a %s but specified type was (%s)", + path, sha1_to_hex(sha1), typename(obj_type), typename(mode_type)); + } + } + + append_to_tree(mode, sha1, path); +} + +int cmd_mktree(int ac, const char **av, const char *prefix) +{ + struct strbuf sb = STRBUF_INIT; + unsigned char sha1[20]; + int line_termination = '\n'; + int allow_missing = 0; + int is_batch_mode = 0; + int got_eof = 0; + + const struct option option[] = { + OPT_SET_INT('z', NULL, &line_termination, "input is NUL terminated", '\0'), + OPT_SET_INT( 0 , "missing", &allow_missing, "allow missing objects", 1), + OPT_SET_INT( 0 , "batch", &is_batch_mode, "allow creation of more than one tree", 1), + OPT_END() + }; + + ac = parse_options(ac, av, prefix, option, mktree_usage, 0); + + while (!got_eof) { + while (1) { + if (strbuf_getline(&sb, stdin, line_termination) == EOF) { + got_eof = 1; + break; + } + if (sb.buf[0] == '\0') { + /* empty lines denote tree boundaries in batch mode */ + if (is_batch_mode) + break; + die("input format error: (blank line only valid in batch mode)"); + } + mktree_line(sb.buf, sb.len, line_termination, allow_missing); + } + if (is_batch_mode && got_eof && used < 1) { + /* + * Execution gets here if the last tree entry is terminated with a + * new-line. The final new-line has been made optional to be + * consistent with the original non-batch behaviour of mktree. + */ + ; /* skip creating an empty tree */ + } else { + write_tree(sha1); + puts(sha1_to_hex(sha1)); + fflush(stdout); + } + used=0; /* reset tree entry buffer for re-use in batch mode */ + } + strbuf_release(&sb); + exit(0); +} diff --git a/builtin-mv.c b/builtin-mv.c index 01270fefdf..b592c367b2 100644 --- a/builtin-mv.c +++ b/builtin-mv.c @@ -24,14 +24,10 @@ static const char **copy_pathspec(const char *prefix, const char **pathspec, result[count] = NULL; for (i = 0; i < count; i++) { int length = strlen(result[i]); - if (length > 0 && result[i][length - 1] == '/') { + if (length > 0 && is_dir_sep(result[i][length - 1])) result[i] = xmemdupz(result[i], length - 1); - } - if (base_name) { - const char *last_slash = strrchr(result[i], '/'); - if (last_slash) - result[i] = last_slash + 1; - } + if (base_name) + result[i] = basename((char *)result[i]); } return get_pathspec(prefix, result); } @@ -72,7 +68,8 @@ int cmd_mv(int argc, const char **argv, const char *prefix) if (read_cache() < 0) die("index file corrupt"); - argc = parse_options(argc, argv, builtin_mv_options, builtin_mv_usage, 0); + argc = parse_options(argc, argv, prefix, builtin_mv_options, + builtin_mv_usage, 0); if (--argc < 1) usage_with_options(builtin_mv_usage, builtin_mv_options); @@ -208,7 +205,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix) printf("Renaming %s to %s\n", src, dst); if (!show_only && mode != INDEX && rename(src, dst) < 0 && !ignore_errors) - die ("renaming %s failed: %s", src, strerror(errno)); + die_errno ("renaming '%s' failed", src); if (mode == WORKING_DIRECTORY) continue; diff --git a/builtin-name-rev.c b/builtin-name-rev.c index 08c8aabf94..06a38ac8c1 100644 --- a/builtin-name-rev.c +++ b/builtin-name-rev.c @@ -238,7 +238,7 @@ int cmd_name_rev(int argc, const char **argv, const char *prefix) }; git_config(git_default_config, NULL); - argc = parse_options(argc, argv, opts, name_rev_usage, 0); + argc = parse_options(argc, argv, prefix, opts, name_rev_usage, 0); if (!!all + !!transform_stdin + !!argc > 1) { error("Specify either a list, or --all, not both!"); usage_with_options(name_rev_usage, opts); diff --git a/builtin-pack-objects.c b/builtin-pack-objects.c index 941cc2d73c..9cc8a8451d 100644 --- a/builtin-pack-objects.c +++ b/builtin-pack-objects.c @@ -86,7 +86,7 @@ static int pack_compression_level = Z_DEFAULT_COMPRESSION; static int pack_compression_seen; static unsigned long delta_cache_size = 0; -static unsigned long max_delta_cache_size = 0; +static unsigned long max_delta_cache_size = 256 * 1024 * 1024; static unsigned long cache_max_small_delta_size = 1000; static unsigned long window_memory_limit = 0; @@ -536,11 +536,9 @@ static void write_pack_file(void) base_name, sha1_to_hex(sha1)); free_pack_by_name(tmpname); if (adjust_perm(pack_tmp_name, mode)) - die("unable to make temporary pack file readable: %s", - strerror(errno)); + die_errno("unable to make temporary pack file readable"); if (rename(pack_tmp_name, tmpname)) - die("unable to rename temporary pack file: %s", - strerror(errno)); + die_errno("unable to rename temporary pack file"); /* * Packs are runtime accessed in their mtime @@ -566,11 +564,9 @@ static void write_pack_file(void) snprintf(tmpname, sizeof(tmpname), "%s-%s.idx", base_name, sha1_to_hex(sha1)); if (adjust_perm(idx_tmp_name, mode)) - die("unable to make temporary index file readable: %s", - strerror(errno)); + die_errno("unable to make temporary index file readable"); if (rename(idx_tmp_name, tmpname)) - die("unable to rename temporary index file: %s", - strerror(errno)); + die_errno("unable to rename temporary index file"); free(idx_tmp_name); free(pack_tmp_name); @@ -1879,7 +1875,7 @@ static void read_object_list_from_stdin(void) if (!ferror(stdin)) die("fgets returned NULL, not EOF, not error!"); if (errno != EINTR) - die("fgets: %s", strerror(errno)); + die_errno("fgets"); clearerr(stdin); continue; } @@ -2259,6 +2255,10 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix) die("bad %s", arg); continue; } + if (!strcmp(arg, "--keep-true-parents")) { + grafts_replace_parents = 0; + continue; + } usage(pack_usage); } diff --git a/builtin-pack-refs.c b/builtin-pack-refs.c index 34246df4ec..091860b2e3 100644 --- a/builtin-pack-refs.c +++ b/builtin-pack-refs.c @@ -15,7 +15,7 @@ int cmd_pack_refs(int argc, const char **argv, const char *prefix) OPT_BIT(0, "prune", &flags, "prune loose refs (default)", PACK_REFS_PRUNE), OPT_END(), }; - if (parse_options(argc, argv, opts, pack_refs_usage, 0)) + if (parse_options(argc, argv, prefix, opts, pack_refs_usage, 0)) usage_with_options(pack_refs_usage, opts); return pack_refs(flags); } diff --git a/builtin-prune.c b/builtin-prune.c index 145ba83651..0ed9cce4a2 100644 --- a/builtin-prune.c +++ b/builtin-prune.c @@ -142,7 +142,7 @@ int cmd_prune(int argc, const char **argv, const char *prefix) save_commit_buffer = 0; init_revisions(&revs, prefix); - argc = parse_options(argc, argv, options, prune_usage, 0); + argc = parse_options(argc, argv, prefix, options, prune_usage, 0); while (argc--) { unsigned char sha1[20]; const char *name = *argv++; diff --git a/builtin-push.c b/builtin-push.c index 2eabcd3bdf..f8376cffa4 100644 --- a/builtin-push.c +++ b/builtin-push.c @@ -10,7 +10,7 @@ #include "parse-options.h" static const char * const push_usage[] = { - "git push [--all | --mirror] [--dry-run] [--tags] [--receive-pack=<git-receive-pack>] [--repo=<repository>] [-f | --force] [-v] [<repository> <refspec>...]", + "git push [--all | --mirror] [--dry-run] [--porcelain] [--tags] [--receive-pack=<git-receive-pack>] [--repo=<repository>] [-f | --force] [-v] [<repository> <refspec>...]", NULL, }; @@ -64,36 +64,11 @@ static void setup_push_tracking(void) add_refspec(refspec.buf); } -static const char *warn_unconfigured_push_msg[] = { - "You did not specify any refspecs to push, and the current remote", - "has not configured any push refspecs. The default action in this", - "case is to push all matching refspecs, that is, all branches", - "that exist both locally and remotely will be updated. This may", - "not necessarily be what you want to happen.", - "", - "You can specify what action you want to take in this case, and", - "avoid seeing this message again, by configuring 'push.default' to:", - " 'nothing' : Do not push anything", - " 'matching' : Push all matching branches (default)", - " 'tracking' : Push the current branch to whatever it is tracking", - " 'current' : Push the current branch" -}; - -static void warn_unconfigured_push(void) -{ - int i; - for (i = 0; i < ARRAY_SIZE(warn_unconfigured_push_msg); i++) - warning("%s", warn_unconfigured_push_msg[i]); -} - static void setup_default_push_refspecs(void) { git_config(git_default_config, NULL); switch (push_default) { - case PUSH_DEFAULT_UNSPECIFIED: - warn_unconfigured_push(); - /* fallthrough */ - + default: case PUSH_DEFAULT_MATCHING: add_refspec(":"); break; @@ -117,6 +92,8 @@ static int do_push(const char *repo, int flags) { int i, errs; struct remote *remote = remote_get(repo); + const char **url; + int url_nr; if (!remote) { if (repo) @@ -152,10 +129,18 @@ static int do_push(const char *repo, int flags) setup_default_push_refspecs(); } errs = 0; - for (i = 0; i < remote->url_nr; i++) { + if (remote->pushurl_nr) { + url = remote->pushurl; + url_nr = remote->pushurl_nr; + } else { + url = remote->url; + url_nr = remote->url_nr; + } + for (i = 0; i < url_nr; i++) { struct transport *transport = - transport_get(remote, remote->url[i]); + transport_get(remote, url[i]); int err; + int nonfastforward; if (receivepack) transport_set_option(transport, TRANS_OPT_RECEIVEPACK, receivepack); @@ -163,14 +148,20 @@ static int do_push(const char *repo, int flags) transport_set_option(transport, TRANS_OPT_THIN, "yes"); if (flags & TRANSPORT_PUSH_VERBOSE) - fprintf(stderr, "Pushing to %s\n", remote->url[i]); - err = transport_push(transport, refspec_nr, refspec, flags); + fprintf(stderr, "Pushing to %s\n", url[i]); + err = transport_push(transport, refspec_nr, refspec, flags, + &nonfastforward); err |= transport_disconnect(transport); if (!err) continue; - error("failed to push some refs to '%s'", remote->url[i]); + error("failed to push some refs to '%s'", url[i]); + if (nonfastforward) { + printf("To prevent you from losing history, non-fast-forward updates were rejected\n" + "Merge the remote changes before pushing again. See the 'non-fast forward'\n" + "section of 'git push --help' for details.\n"); + } errs++; } return !!errs; @@ -191,6 +182,7 @@ int cmd_push(int argc, const char **argv, const char *prefix) (TRANSPORT_PUSH_MIRROR|TRANSPORT_PUSH_FORCE)), OPT_BOOLEAN( 0 , "tags", &tags, "push tags"), OPT_BIT( 0 , "dry-run", &flags, "dry run", TRANSPORT_PUSH_DRY_RUN), + OPT_BIT( 0, "porcelain", &flags, "machine-readable output", TRANSPORT_PUSH_PORCELAIN), OPT_BIT('f', "force", &flags, "force updates", TRANSPORT_PUSH_FORCE), OPT_BOOLEAN( 0 , "thin", &thin, "use thin pack"), OPT_STRING( 0 , "receive-pack", &receivepack, "receive-pack", "receive pack program"), @@ -198,7 +190,7 @@ int cmd_push(int argc, const char **argv, const char *prefix) OPT_END() }; - argc = parse_options(argc, argv, options, push_usage, 0); + argc = parse_options(argc, argv, prefix, options, push_usage, 0); if (tags) add_refspec("refs/tags/*"); diff --git a/builtin-receive-pack.c b/builtin-receive-pack.c index 0b08da9b59..6ec1d056e6 100644 --- a/builtin-receive-pack.c +++ b/builtin-receive-pack.c @@ -123,27 +123,27 @@ static struct command *commands; static const char pre_receive_hook[] = "hooks/pre-receive"; static const char post_receive_hook[] = "hooks/post-receive"; -static int hook_status(int code, const char *hook_name) +static int run_status(int code, const char *cmd_name) { switch (code) { case 0: return 0; case -ERR_RUN_COMMAND_FORK: - return error("hook fork failed"); + return error("fork of %s failed", cmd_name); case -ERR_RUN_COMMAND_EXEC: - return error("hook execute failed"); + return error("execute of %s failed", cmd_name); case -ERR_RUN_COMMAND_PIPE: - return error("hook pipe failed"); + return error("pipe failed"); case -ERR_RUN_COMMAND_WAITPID: return error("waitpid failed"); case -ERR_RUN_COMMAND_WAITPID_WRONG_PID: return error("waitpid is confused"); case -ERR_RUN_COMMAND_WAITPID_SIGNAL: - return error("%s died of signal", hook_name); + return error("%s died of signal", cmd_name); case -ERR_RUN_COMMAND_WAITPID_NOEXIT: - return error("%s died strangely", hook_name); + return error("%s died strangely", cmd_name); default: - error("%s exited with error code %d", hook_name, -code); + error("%s exited with error code %d", cmd_name, -code); return -code; } } @@ -174,7 +174,7 @@ static int run_receive_hook(const char *hook_name) code = start_command(&proc); if (code) - return hook_status(code, hook_name); + return run_status(code, hook_name); for (cmd = commands; cmd; cmd = cmd->next) { if (!cmd->error_string) { size_t n = snprintf(buf, sizeof(buf), "%s %s %s\n", @@ -186,13 +186,12 @@ static int run_receive_hook(const char *hook_name) } } close(proc.in); - return hook_status(finish_command(&proc), hook_name); + return run_status(finish_command(&proc), hook_name); } static int run_update_hook(struct command *cmd) { static const char update_hook[] = "hooks/update"; - struct child_process proc; const char *argv[5]; if (access(update_hook, X_OK) < 0) @@ -204,12 +203,9 @@ static int run_update_hook(struct command *cmd) argv[3] = sha1_to_hex(cmd->new_sha1); argv[4] = NULL; - memset(&proc, 0, sizeof(proc)); - proc.argv = argv; - proc.no_stdin = 1; - proc.stdout_to_stderr = 1; - - return hook_status(run_command(&proc), update_hook); + return run_status(run_command_v_opt(argv, RUN_COMMAND_NO_STDIN | + RUN_COMMAND_STDOUT_TO_STDERR), + update_hook); } static int is_ref_checked_out(const char *ref) @@ -398,7 +394,7 @@ static char update_post_hook[] = "hooks/post-update"; static void run_update_post_hook(struct command *cmd) { struct command *cmd_p; - int argc; + int argc, status; const char **argv; for (argc = 0, cmd_p = cmd; cmd_p; cmd_p = cmd_p->next) { @@ -421,8 +417,9 @@ static void run_update_post_hook(struct command *cmd) argc++; } argv[argc] = NULL; - run_command_v_opt(argv, RUN_COMMAND_NO_STDIN - | RUN_COMMAND_STDOUT_TO_STDERR); + status = run_command_v_opt(argv, RUN_COMMAND_NO_STDIN + | RUN_COMMAND_STDOUT_TO_STDERR); + run_status(status, update_post_hook); } static void execute_commands(const char *unpacker_error) @@ -538,24 +535,10 @@ static const char *unpack(void) unpacker[i++] = hdr_arg; unpacker[i++] = NULL; code = run_command_v_opt(unpacker, RUN_GIT_CMD); - switch (code) { - case 0: + if (!code) return NULL; - case -ERR_RUN_COMMAND_FORK: - return "unpack fork failed"; - case -ERR_RUN_COMMAND_EXEC: - return "unpack execute failed"; - case -ERR_RUN_COMMAND_WAITPID: - return "waitpid failed"; - case -ERR_RUN_COMMAND_WAITPID_WRONG_PID: - return "waitpid is confused"; - case -ERR_RUN_COMMAND_WAITPID_SIGNAL: - return "unpacker died of signal"; - case -ERR_RUN_COMMAND_WAITPID_NOEXIT: - return "unpacker died strangely"; - default: - return "unpacker exited with error code"; - } + run_status(code, unpacker[0]); + return "unpack-objects abnormal exit"; } else { const char *keeper[7]; int s, status, i = 0; @@ -578,8 +561,11 @@ static const char *unpack(void) ip.argv = keeper; ip.out = -1; ip.git_cmd = 1; - if (start_command(&ip)) + status = start_command(&ip); + if (status) { + run_status(status, keeper[0]); return "index-pack fork failed"; + } pack_lockfile = index_pack_lockfile(ip.out); close(ip.out); status = finish_command(&ip); @@ -587,6 +573,7 @@ static const char *unpack(void) reprepare_packed_git(); return NULL; } + run_status(status, keeper[0]); return "index-pack abnormal exit"; } } diff --git a/builtin-reflog.c b/builtin-reflog.c index ddfdf5a3cb..95198c5de4 100644 --- a/builtin-reflog.c +++ b/builtin-reflog.c @@ -694,7 +694,7 @@ static int cmd_reflog_delete(int argc, const char **argv, const char *prefix) */ static const char reflog_usage[] = -"git reflog (expire | ...)"; +"git reflog [ show | expire | delete ]"; int cmd_reflog(int argc, const char **argv, const char *prefix) { diff --git a/builtin-remote.c b/builtin-remote.c index 7685cfcaf0..008abfe092 100644 --- a/builtin-remote.c +++ b/builtin-remote.c @@ -79,7 +79,8 @@ static int add(int argc, const char **argv) OPT_END() }; - argc = parse_options(argc, argv, options, builtin_remote_usage, 0); + argc = parse_options(argc, argv, NULL, options, builtin_remote_usage, + 0); if (argc < 2) usage_with_options(builtin_remote_usage, options); @@ -294,17 +295,14 @@ static int get_push_ref_states(const struct ref *remote_refs, struct ref_states *states) { struct remote *remote = states->remote; - struct ref *ref, *local_refs, *push_map, **push_tail; + struct ref *ref, *local_refs, *push_map; if (remote->mirror) return 0; local_refs = get_local_heads(); push_map = copy_ref_list(remote_refs); - push_tail = &push_map; - while (*push_tail) - push_tail = &((*push_tail)->next); - match_refs(local_refs, push_map, &push_tail, remote->push_refspec_nr, + match_refs(local_refs, &push_map, remote->push_refspec_nr, remote->push_refspec, MATCH_REFS_NONE); states->push.strdup_strings = 1; @@ -742,7 +740,7 @@ static int rm(int argc, const char **argv) return result; } -void clear_push_info(void *util, const char *string) +static void clear_push_info(void *util, const char *string) { struct push_info *info = util; free(info->dest); @@ -817,7 +815,7 @@ struct show_info { int any_rebase; }; -int add_remote_to_show_info(struct string_list_item *item, void *cb_data) +static int add_remote_to_show_info(struct string_list_item *item, void *cb_data) { struct show_info *info = cb_data; int n = strlen(item->string); @@ -827,7 +825,7 @@ int add_remote_to_show_info(struct string_list_item *item, void *cb_data) return 0; } -int show_remote_info_item(struct string_list_item *item, void *cb_data) +static int show_remote_info_item(struct string_list_item *item, void *cb_data) { struct show_info *info = cb_data; struct ref_states *states = info->states; @@ -854,7 +852,7 @@ int show_remote_info_item(struct string_list_item *item, void *cb_data) return 0; } -int add_local_to_show_info(struct string_list_item *branch_item, void *cb_data) +static int add_local_to_show_info(struct string_list_item *branch_item, void *cb_data) { struct show_info *show_info = cb_data; struct ref_states *states = show_info->states; @@ -876,7 +874,7 @@ int add_local_to_show_info(struct string_list_item *branch_item, void *cb_data) return 0; } -int show_local_info_item(struct string_list_item *item, void *cb_data) +static int show_local_info_item(struct string_list_item *item, void *cb_data) { struct show_info *show_info = cb_data; struct branch_info *branch_info = item->util; @@ -908,7 +906,7 @@ int show_local_info_item(struct string_list_item *item, void *cb_data) return 0; } -int add_push_to_show_info(struct string_list_item *push_item, void *cb_data) +static int add_push_to_show_info(struct string_list_item *push_item, void *cb_data) { struct show_info *show_info = cb_data; struct push_info *push_info = push_item->util; @@ -937,7 +935,7 @@ static int cmp_string_with_push(const void *va, const void *vb) return cmp ? cmp : strcmp(a_push->dest, b_push->dest); } -int show_push_info_item(struct string_list_item *item, void *cb_data) +static int show_push_info_item(struct string_list_item *item, void *cb_data) { struct show_info *show_info = cb_data; struct push_info *push_info = item->util; @@ -986,7 +984,8 @@ static int show(int argc, const char **argv) struct string_list info_list = { NULL, 0, 0, 0 }; struct show_info info; - argc = parse_options(argc, argv, options, builtin_remote_usage, 0); + argc = parse_options(argc, argv, NULL, options, builtin_remote_usage, + 0); if (argc < 1) return show_all(); @@ -1000,15 +999,25 @@ static int show(int argc, const char **argv) info.list = &info_list; for (; argc; argc--, argv++) { int i; + const char **url; + int url_nr; get_remote_ref_states(*argv, &states, query_flag); printf("* remote %s\n", *argv); - if (states.remote->url_nr) { - for (i=0; i < states.remote->url_nr; i++) - printf(" URL: %s\n", states.remote->url[i]); - } else - printf(" URL: %s\n", "(no URL)"); + printf(" Fetch URL: %s\n", states.remote->url_nr > 0 ? + states.remote->url[0] : "(no URL)"); + if (states.remote->pushurl_nr) { + url = states.remote->pushurl; + url_nr = states.remote->pushurl_nr; + } else { + url = states.remote->url; + url_nr = states.remote->url_nr; + } + for (i=0; i < url_nr; i++) + printf(" Push URL: %s\n", url[i]); + if (!i) + printf(" Push URL: %s\n", "(no URL)"); if (no_query) printf(" HEAD branch: (not queried)\n"); else if (!states.heads.nr) @@ -1079,7 +1088,8 @@ static int set_head(int argc, const char **argv) "delete refs/remotes/<name>/HEAD"), OPT_END() }; - argc = parse_options(argc, argv, options, builtin_remote_usage, 0); + argc = parse_options(argc, argv, NULL, options, builtin_remote_usage, + 0); if (argc) strbuf_addf(&buf, "refs/remotes/%s/HEAD", argv[0]); @@ -1133,7 +1143,8 @@ static int prune(int argc, const char **argv) OPT_END() }; - argc = parse_options(argc, argv, options, builtin_remote_usage, 0); + argc = parse_options(argc, argv, NULL, options, builtin_remote_usage, + 0); if (argc < 1) usage_with_options(builtin_remote_usage, options); @@ -1186,7 +1197,7 @@ static int get_one_remote_for_update(struct remote *remote, void *priv) return 0; } -struct remote_group { +static struct remote_group { const char *name; struct string_list *list; } remote_group; @@ -1223,7 +1234,7 @@ static int update(int argc, const char **argv) OPT_END() }; - argc = parse_options(argc, argv, options, builtin_remote_usage, + argc = parse_options(argc, argv, NULL, options, builtin_remote_usage, PARSE_OPT_KEEP_ARGV0); if (argc < 2) { argc = 2; @@ -1265,14 +1276,29 @@ static int update(int argc, const char **argv) static int get_one_entry(struct remote *remote, void *priv) { struct string_list *list = priv; + struct strbuf url_buf = STRBUF_INIT; + const char **url; + int i, url_nr; if (remote->url_nr > 0) { - int i; - - for (i = 0; i < remote->url_nr; i++) - string_list_append(remote->name, list)->util = (void *)remote->url[i]; + strbuf_addf(&url_buf, "%s (fetch)", remote->url[0]); + string_list_append(remote->name, list)->util = + strbuf_detach(&url_buf, NULL); } else string_list_append(remote->name, list)->util = NULL; + if (remote->pushurl_nr) { + url = remote->pushurl; + url_nr = remote->pushurl_nr; + } else { + url = remote->url; + url_nr = remote->url_nr; + } + for (i = 0; i < url_nr; i++) + { + strbuf_addf(&url_buf, "%s (push)", url[i]); + string_list_append(remote->name, list)->util = + strbuf_detach(&url_buf, NULL); + } return 0; } @@ -1280,7 +1306,10 @@ static int get_one_entry(struct remote *remote, void *priv) static int show_all(void) { struct string_list list = { NULL, 0, 0 }; - int result = for_each_remote(get_one_entry, &list); + int result; + + list.strdup_strings = 1; + result = for_each_remote(get_one_entry, &list); if (!result) { int i; @@ -1298,6 +1327,7 @@ static int show_all(void) } } } + string_list_clear(&list, 1); return result; } @@ -1309,7 +1339,7 @@ int cmd_remote(int argc, const char **argv, const char *prefix) }; int result; - argc = parse_options(argc, argv, options, builtin_remote_usage, + argc = parse_options(argc, argv, prefix, options, builtin_remote_usage, PARSE_OPT_STOP_AT_NON_OPTION); if (argc < 1) diff --git a/builtin-reset.c b/builtin-reset.c index 7e7ebabaa8..5fa1789d0c 100644 --- a/builtin-reset.c +++ b/builtin-reset.c @@ -203,7 +203,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix) git_config(git_default_config, NULL); - argc = parse_options(argc, argv, options, git_reset_usage, + argc = parse_options(argc, argv, prefix, options, git_reset_usage, PARSE_OPT_KEEP_DASHDASH); reflog_action = args_to_str(argv); setenv("GIT_REFLOG_ACTION", reflog_action, 0); diff --git a/builtin-rev-list.c b/builtin-rev-list.c index 38a8f234de..4ba1c12e0b 100644 --- a/builtin-rev-list.c +++ b/builtin-rev-list.c @@ -211,7 +211,7 @@ static inline int exp2i(int n) * * and P(2^n + x) < 0.5 means 2^n < 3x */ -static int estimate_bisect_steps(int all) +int estimate_bisect_steps(int all) { int n, x, e; @@ -225,27 +225,46 @@ static int estimate_bisect_steps(int all) return (e < 3 * x) ? n : n - 1; } -static void show_tried_revs(struct commit_list *tried, int stringed) +void print_commit_list(struct commit_list *list, + const char *format_cur, + const char *format_last) { - printf("bisect_tried='"); - for (;tried; tried = tried->next) { - char *format = tried->next ? "%s|" : "%s"; - printf(format, sha1_to_hex(tried->item->object.sha1)); + for ( ; list; list = list->next) { + const char *format = list->next ? format_cur : format_last; + printf(format, sha1_to_hex(list->item->object.sha1)); } - printf(stringed ? "' &&\n" : "'\n"); +} + +static void show_tried_revs(struct commit_list *tried) +{ + printf("bisect_tried='"); + print_commit_list(tried, "%s|", "%s"); + printf("'\n"); +} + +static void print_var_str(const char *var, const char *val) +{ + printf("%s='%s'\n", var, val); +} + +static void print_var_int(const char *var, int val) +{ + printf("%s=%d\n", var, val); } int show_bisect_vars(struct rev_list_info *info, int reaches, int all) { int cnt, flags = info->bisect_show_flags; - char hex[41] = "", *format; + char hex[41] = ""; struct commit_list *tried; struct rev_info *revs = info->revs; if (!revs->commits && !(flags & BISECT_SHOW_TRIED)) return 1; - revs->commits = filter_skipped(revs->commits, &tried, flags & BISECT_SHOW_ALL); + revs->commits = filter_skipped(revs->commits, &tried, + flags & BISECT_SHOW_ALL, + NULL, NULL); /* * revs->commits can reach "reaches" commits among @@ -269,28 +288,14 @@ int show_bisect_vars(struct rev_list_info *info, int reaches, int all) } if (flags & BISECT_SHOW_TRIED) - show_tried_revs(tried, flags & BISECT_SHOW_STRINGED); - format = (flags & BISECT_SHOW_STRINGED) ? - "bisect_rev=%s &&\n" - "bisect_nr=%d &&\n" - "bisect_good=%d &&\n" - "bisect_bad=%d &&\n" - "bisect_all=%d &&\n" - "bisect_steps=%d\n" - : - "bisect_rev=%s\n" - "bisect_nr=%d\n" - "bisect_good=%d\n" - "bisect_bad=%d\n" - "bisect_all=%d\n" - "bisect_steps=%d\n"; - printf(format, - hex, - cnt - 1, - all - reaches - 1, - reaches - 1, - all, - estimate_bisect_steps(all)); + show_tried_revs(tried); + + print_var_str("bisect_rev", hex); + print_var_int("bisect_nr", cnt - 1); + print_var_int("bisect_good", all - reaches - 1); + print_var_int("bisect_bad", reaches - 1); + print_var_int("bisect_all", all); + print_var_int("bisect_steps", estimate_bisect_steps(all)); return 0; } diff --git a/builtin-rev-parse.c b/builtin-rev-parse.c index 22c6d6ad16..45bead6545 100644 --- a/builtin-rev-parse.c +++ b/builtin-rev-parse.c @@ -301,7 +301,7 @@ static const char *skipspaces(const char *s) static int cmd_parseopt(int argc, const char **argv, const char *prefix) { - static int keep_dashdash = 0; + static int keep_dashdash = 0, stop_at_non_option = 0; static char const * const parseopt_usage[] = { "git rev-parse --parseopt [options] -- [<args>...]", NULL @@ -309,6 +309,9 @@ static int cmd_parseopt(int argc, const char **argv, const char *prefix) static struct option parseopt_opts[] = { OPT_BOOLEAN(0, "keep-dashdash", &keep_dashdash, "keep the `--` passed as an arg"), + OPT_BOOLEAN(0, "stop-at-non-option", &stop_at_non_option, + "stop parsing after the " + "first non-option argument"), OPT_END(), }; @@ -318,7 +321,7 @@ static int cmd_parseopt(int argc, const char **argv, const char *prefix) int onb = 0, osz = 0, unb = 0, usz = 0; strbuf_addstr(&parsed, "set --"); - argc = parse_options(argc, argv, parseopt_opts, parseopt_usage, + argc = parse_options(argc, argv, prefix, parseopt_opts, parseopt_usage, PARSE_OPT_KEEP_DASHDASH); if (argc < 1 || strcmp(argv[0], "--")) usage_with_options(parseopt_usage, parseopt_opts); @@ -393,8 +396,9 @@ static int cmd_parseopt(int argc, const char **argv, const char *prefix) /* put an OPT_END() */ ALLOC_GROW(opts, onb + 1, osz); memset(opts + onb, 0, sizeof(opts[onb])); - argc = parse_options(argc, argv, opts, usage, - keep_dashdash ? PARSE_OPT_KEEP_DASHDASH : 0); + argc = parse_options(argc, argv, prefix, opts, usage, + keep_dashdash ? PARSE_OPT_KEEP_DASHDASH : 0 | + stop_at_non_option ? PARSE_OPT_STOP_AT_NON_OPTION : 0); strbuf_addf(&parsed, " --"); sq_quote_argv(&parsed, argv, 0); @@ -402,6 +406,18 @@ static int cmd_parseopt(int argc, const char **argv, const char *prefix) return 0; } +static int cmd_sq_quote(int argc, const char **argv) +{ + struct strbuf buf = STRBUF_INIT; + + if (argc) + sq_quote_argv(&buf, argv, 0); + printf("%s\n", buf.buf); + strbuf_release(&buf); + + return 0; +} + static void die_no_single_rev(int quiet) { if (quiet) @@ -419,6 +435,9 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix) if (argc > 1 && !strcmp("--parseopt", argv[1])) return cmd_parseopt(argc - 1, argv + 1, prefix); + if (argc > 1 && !strcmp("--sq-quote", argv[1])) + return cmd_sq_quote(argc - 2, argv + 2); + prefix = setup_git_directory(); git_config(git_default_config, NULL); for (i = 1; i < argc; i++) { @@ -577,7 +596,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix) continue; } if (!getcwd(cwd, PATH_MAX)) - die("unable to get current working directory"); + die_errno("unable to get current working directory"); printf("%s/.git\n", cwd); continue; } diff --git a/builtin-revert.c b/builtin-revert.c index 3f2614e1bb..151aa6a981 100644 --- a/builtin-revert.c +++ b/builtin-revert.c @@ -60,7 +60,7 @@ static void parse_args(int argc, const char **argv) OPT_END(), }; - if (parse_options(argc, argv, options, usage_str, 0) != 1) + if (parse_options(argc, argv, NULL, options, usage_str, 0) != 1) usage_with_options(usage_str, options); arg = argv[0]; @@ -135,7 +135,7 @@ static void add_to_msg(const char *string) { int len = strlen(string); if (write_in_full(msg_fd, string, len) < 0) - die ("Could not write to MERGE_MSG"); + die_errno ("Could not write to MERGE_MSG"); } static void add_message_to_msg(const char *message) @@ -323,9 +323,9 @@ static int revert_or_cherry_pick(int argc, const char **argv) encoding = get_encoding(message); if (!encoding) - encoding = "utf-8"; + encoding = "UTF-8"; if (!git_commit_encoding) - git_commit_encoding = "utf-8"; + git_commit_encoding = "UTF-8"; if ((reencoded_message = reencode_string(message, git_commit_encoding, encoding))) message = reencoded_message; diff --git a/builtin-rm.c b/builtin-rm.c index 269d60890a..57975dbcfd 100644 --- a/builtin-rm.c +++ b/builtin-rm.c @@ -157,7 +157,8 @@ int cmd_rm(int argc, const char **argv, const char *prefix) git_config(git_default_config, NULL); - argc = parse_options(argc, argv, builtin_rm_options, builtin_rm_usage, 0); + argc = parse_options(argc, argv, prefix, builtin_rm_options, + builtin_rm_usage, 0); if (!argc) usage_with_options(builtin_rm_usage, builtin_rm_options); @@ -256,7 +257,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix) continue; } if (!removed) - die("git rm: %s: %s", path, strerror(errno)); + die_errno("git rm: '%s'", path); } } diff --git a/builtin-send-pack.c b/builtin-send-pack.c index 473a3de40c..47fb9f7baa 100644 --- a/builtin-send-pack.c +++ b/builtin-send-pack.c @@ -59,7 +59,7 @@ static int pack_objects(int fd, struct ref *refs, struct extra_have_objects *ext po.out = fd; po.git_cmd = 1; if (start_command(&po)) - die("git pack-objects failed (%s)", strerror(errno)); + die_errno("git pack-objects failed"); /* * We feed the pack-objects we just spawned with revision @@ -178,9 +178,9 @@ static void print_ref_status(char flag, const char *summary, struct ref *to, str { fprintf(stderr, " %c %-*s ", flag, SUMMARY_WIDTH, summary); if (from) - fprintf(stderr, "%s -> %s", prettify_ref(from), prettify_ref(to)); + fprintf(stderr, "%s -> %s", prettify_refname(from->name), prettify_refname(to->name)); else - fputs(prettify_ref(to), stderr); + fputs(prettify_refname(to->name), stderr); if (msg) { fputs(" (", stderr); fputs(msg, stderr); @@ -473,7 +473,7 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix) int fd[2]; struct child_process *conn; struct extra_have_objects extra_have; - struct ref *remote_refs, **remote_tail, *local_refs; + struct ref *remote_refs, *local_refs; int ret; int send_all = 0; const char *receivepack = "git-receive-pack"; @@ -567,13 +567,8 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix) flags |= MATCH_REFS_MIRROR; /* match them up */ - remote_tail = &remote_refs; - while (*remote_tail) - remote_tail = &((*remote_tail)->next); - if (match_refs(local_refs, remote_refs, &remote_tail, - nr_refspecs, refspecs, flags)) { + if (match_refs(local_refs, &remote_refs, nr_refspecs, refspecs, flags)) return -1; - } ret = send_pack(&args, fd, conn, remote_refs, &extra_have); diff --git a/builtin-shortlog.c b/builtin-shortlog.c index b28091b445..6a3812ee18 100644 --- a/builtin-shortlog.c +++ b/builtin-shortlog.c @@ -263,7 +263,7 @@ int cmd_shortlog(int argc, const char **argv, const char *prefix) git_config(git_default_config, NULL); shortlog_init(&log); init_revisions(&rev, prefix); - parse_options_start(&ctx, argc, argv, PARSE_OPT_KEEP_DASHDASH | + parse_options_start(&ctx, argc, argv, prefix, PARSE_OPT_KEEP_DASHDASH | PARSE_OPT_KEEP_ARGV0); for (;;) { diff --git a/builtin-show-branch.c b/builtin-show-branch.c index c3afabbe91..01bea3b583 100644 --- a/builtin-show-branch.c +++ b/builtin-show-branch.c @@ -2,11 +2,26 @@ #include "commit.h" #include "refs.h" #include "builtin.h" +#include "color.h" +#include "parse-options.h" -static const char show_branch_usage[] = -"git show-branch [--sparse] [--current] [--all] [--remotes] [--topo-order] [--more=count | --list | --independent | --merge-base ] [--topics] [<refs>...] | --reflog[=n[,b]] <branch>"; -static const char show_branch_usage_reflog[] = -"--reflog is incompatible with --all, --remotes, --independent or --merge-base"; +static const char* show_branch_usage[] = { + "git show-branch [--sparse] [--current] [--all] [--remotes] [--topo-order] [--more=count | --list | --independent | --merge-base] [--topics] [--color] [<refs>...]", + "--reflog[=n[,b]] [--list] [--color] <branch>", + NULL +}; + +static int showbranch_use_color = -1; +static char column_colors[][COLOR_MAXLEN] = { + GIT_COLOR_RED, + GIT_COLOR_GREEN, + GIT_COLOR_YELLOW, + GIT_COLOR_BLUE, + GIT_COLOR_MAGENTA, + GIT_COLOR_CYAN, +}; + +#define COLUMN_COLORS_MAX (ARRAY_SIZE(column_colors)) static int default_num; static int default_alloc; @@ -19,6 +34,20 @@ static const char **default_arg; #define DEFAULT_REFLOG 4 +static const char *get_color_code(int idx) +{ + if (showbranch_use_color) + return column_colors[idx]; + return ""; +} + +static const char *get_color_reset_code(void) +{ + if (showbranch_use_color) + return GIT_COLOR_RESET; + return ""; +} + static struct commit *interesting(struct commit_list *list) { while (list) { @@ -545,7 +574,12 @@ static int git_show_branch_config(const char *var, const char *value, void *cb) return 0; } - return git_default_config(var, value, cb); + if (!strcmp(var, "color.showbranch")) { + showbranch_use_color = git_config_colorbool(var, value, -1); + return 0; + } + + return git_color_default_config(var, value, cb); } static int omit_in_dense(struct commit *commit, struct commit **rev, int n) @@ -569,18 +603,25 @@ static int omit_in_dense(struct commit *commit, struct commit **rev, int n) return 0; } -static void parse_reflog_param(const char *arg, int *cnt, const char **base) +static int reflog = 0; + +static int parse_reflog_param(const struct option *opt, const char *arg, + int unset) { char *ep; - *cnt = strtoul(arg, &ep, 10); + const char **base = (const char **)opt->value; + if (!arg) + arg = ""; + reflog = strtoul(arg, &ep, 10); if (*ep == ',') *base = ep + 1; else if (*ep) - die("unrecognized reflog param '%s'", arg); + return error("unrecognized reflog param '%s'", arg); else *base = NULL; - if (*cnt <= 0) - *cnt = DEFAULT_REFLOG; + if (reflog <= 0) + reflog = DEFAULT_REFLOG; + return 0; } int cmd_show_branch(int ac, const char **av, const char *prefix) @@ -606,70 +647,67 @@ int cmd_show_branch(int ac, const char **av, const char *prefix) int head_at = -1; int topics = 0; int dense = 1; - int reflog = 0; const char *reflog_base = NULL; + struct option builtin_show_branch_options[] = { + OPT_BOOLEAN('a', "all", &all_heads, + "show remote-tracking and local branches"), + OPT_BOOLEAN('r', "remotes", &all_remotes, + "show remote-tracking branches"), + OPT_BOOLEAN(0, "color", &showbranch_use_color, + "color '*!+-' corresponding to the branch"), + { OPTION_INTEGER, 0, "more", &extra, "n", + "show <n> more commits after the common ancestor", + PARSE_OPT_OPTARG, NULL, (intptr_t)1 }, + OPT_SET_INT(0, "list", &extra, "synonym to more=-1", -1), + OPT_BOOLEAN(0, "no-name", &no_name, "suppress naming strings"), + OPT_BOOLEAN(0, "current", &with_current_branch, + "include the current branch"), + OPT_BOOLEAN(0, "sha1-name", &sha1_name, + "name commits with their object names"), + OPT_BOOLEAN(0, "merge-base", &merge_base, + "act like git merge-base -a"), + OPT_BOOLEAN(0, "independent", &independent, + "show refs unreachable from any other ref"), + OPT_BOOLEAN(0, "topo-order", &lifo, + "show commits in topological order"), + OPT_BOOLEAN(0, "topics", &topics, + "show only commits not on the first branch"), + OPT_SET_INT(0, "sparse", &dense, + "show merges reachable from only one tip", 0), + OPT_SET_INT(0, "date-order", &lifo, + "show commits where no parent comes before its " + "children", 0), + { OPTION_CALLBACK, 'g', "reflog", &reflog_base, "<n>[,<base>]", + "show <n> most recent ref-log entries starting at " + "base", + PARSE_OPT_OPTARG | PARSE_OPT_LITERAL_ARGHELP, + parse_reflog_param }, + OPT_END() + }; git_config(git_show_branch_config, NULL); + if (showbranch_use_color == -1) + showbranch_use_color = git_use_color_default; + /* If nothing is specified, try the default first */ if (ac == 1 && default_num) { ac = default_num + 1; av = default_arg - 1; /* ick; we would not address av[0] */ } - while (1 < ac && av[1][0] == '-') { - const char *arg = av[1]; - if (!strcmp(arg, "--")) { - ac--; av++; - break; - } - else if (!strcmp(arg, "--all") || !strcmp(arg, "-a")) - all_heads = all_remotes = 1; - else if (!strcmp(arg, "--remotes") || !strcmp(arg, "-r")) - all_remotes = 1; - else if (!strcmp(arg, "--more")) - extra = 1; - else if (!strcmp(arg, "--list")) - extra = -1; - else if (!strcmp(arg, "--no-name")) - no_name = 1; - else if (!strcmp(arg, "--current")) - with_current_branch = 1; - else if (!strcmp(arg, "--sha1-name")) - sha1_name = 1; - else if (!prefixcmp(arg, "--more=")) - extra = atoi(arg + 7); - else if (!strcmp(arg, "--merge-base")) - merge_base = 1; - else if (!strcmp(arg, "--independent")) - independent = 1; - else if (!strcmp(arg, "--topo-order")) - lifo = 1; - else if (!strcmp(arg, "--topics")) - topics = 1; - else if (!strcmp(arg, "--sparse")) - dense = 0; - else if (!strcmp(arg, "--date-order")) - lifo = 0; - else if (!strcmp(arg, "--reflog") || !strcmp(arg, "-g")) { - reflog = DEFAULT_REFLOG; - } - else if (!prefixcmp(arg, "--reflog=")) - parse_reflog_param(arg + 9, &reflog, &reflog_base); - else if (!prefixcmp(arg, "-g=")) - parse_reflog_param(arg + 3, &reflog, &reflog_base); - else - usage(show_branch_usage); - ac--; av++; - } - ac--; av++; + ac = parse_options(ac, av, prefix, builtin_show_branch_options, + show_branch_usage, PARSE_OPT_STOP_AT_NON_OPTION); + if (all_heads) + all_remotes = 1; if (extra || reflog) { /* "listing" mode is incompatible with * independent nor merge-base modes. */ if (independent || merge_base) - usage(show_branch_usage); + usage_with_options(show_branch_usage, + builtin_show_branch_options); if (reflog && ((0 < extra) || all_heads || all_remotes)) /* * Asking for --more in reflog mode does not @@ -677,7 +715,8 @@ int cmd_show_branch(int ac, const char **av, const char *prefix) * * Also --all and --remotes do not make sense either. */ - usage(show_branch_usage_reflog); + die("--reflog is incompatible with --all, --remotes, " + "--independent or --merge-base"); } /* If nothing is specified, show all branches by default */ @@ -843,8 +882,10 @@ int cmd_show_branch(int ac, const char **av, const char *prefix) else { for (j = 0; j < i; j++) putchar(' '); - printf("%c [%s] ", - is_head ? '*' : '!', ref_name[i]); + printf("%s%c%s [%s] ", + get_color_code(i % COLUMN_COLORS_MAX), + is_head ? '*' : '!', + get_color_reset_code(), ref_name[i]); } if (!reflog) { @@ -903,7 +944,9 @@ int cmd_show_branch(int ac, const char **av, const char *prefix) mark = '*'; else mark = '+'; - putchar(mark); + printf("%s%c%s", + get_color_code(i % COLUMN_COLORS_MAX), + mark, get_color_reset_code()); } putchar(' '); } diff --git a/builtin-show-ref.c b/builtin-show-ref.c index dc76c5090f..c46550c9c0 100644 --- a/builtin-show-ref.c +++ b/builtin-show-ref.c @@ -4,12 +4,18 @@ #include "object.h" #include "tag.h" #include "string-list.h" +#include "parse-options.h" -static const char show_ref_usage[] = "git show-ref [-q|--quiet] [--verify] [-h|--head] [-d|--dereference] [-s|--hash[=<length>]] [--abbrev[=<length>]] [--tags] [--heads] [--] [pattern*] < ref-list"; +static const char * const show_ref_usage[] = { + "git show-ref [-q|--quiet] [--verify] [-h|--head] [-d|--dereference] [-s|--hash[=<n>]] [--abbrev[=<n>]] [--tags] [--heads] [--] [pattern*] ", + "git show-ref --exclude-existing[=pattern] < ref-list", + NULL +}; -static int deref_tags = 0, show_head = 0, tags_only = 0, heads_only = 0, - found_match = 0, verify = 0, quiet = 0, hash_only = 0, abbrev = 0; +static int deref_tags, show_head, tags_only, heads_only, found_match, verify, + quiet, hash_only, abbrev, exclude_arg; static const char **pattern; +static const char *exclude_existing_arg; static void show_one(const char *refname, const unsigned char *sha1) { @@ -150,79 +156,60 @@ static int exclude_existing(const char *match) return 0; } +static int hash_callback(const struct option *opt, const char *arg, int unset) +{ + hash_only = 1; + /* Use full length SHA1 if no argument */ + if (!arg) + return 0; + return parse_opt_abbrev_cb(opt, arg, unset); +} + +static int exclude_existing_callback(const struct option *opt, const char *arg, + int unset) +{ + exclude_arg = 1; + *(const char **)opt->value = arg; + return 0; +} + +static int help_callback(const struct option *opt, const char *arg, int unset) +{ + return -1; +} + +static const struct option show_ref_options[] = { + OPT_BOOLEAN(0, "tags", &tags_only, "only show tags (can be combined with heads)"), + OPT_BOOLEAN(0, "heads", &heads_only, "only show heads (can be combined with tags)"), + OPT_BOOLEAN(0, "verify", &verify, "stricter reference checking, " + "requires exact ref path"), + OPT_BOOLEAN('h', "head", &show_head, "show the HEAD reference"), + OPT_BOOLEAN('d', "dereference", &deref_tags, + "dereference tags into object IDs"), + { OPTION_CALLBACK, 's', "hash", &abbrev, "n", + "only show SHA1 hash using <n> digits", + PARSE_OPT_OPTARG, &hash_callback }, + OPT__ABBREV(&abbrev), + OPT__QUIET(&quiet), + { OPTION_CALLBACK, 0, "exclude-existing", &exclude_existing_arg, + "pattern", "show refs from stdin that aren't in local repository", + PARSE_OPT_OPTARG | PARSE_OPT_NONEG, exclude_existing_callback }, + { OPTION_CALLBACK, 0, "help-all", NULL, NULL, "show usage", + PARSE_OPT_HIDDEN | PARSE_OPT_NOARG, help_callback }, + OPT_END() +}; + int cmd_show_ref(int argc, const char **argv, const char *prefix) { - int i; + argc = parse_options(argc, argv, prefix, show_ref_options, + show_ref_usage, PARSE_OPT_NO_INTERNAL_HELP); - for (i = 1; i < argc; i++) { - const char *arg = argv[i]; - if (*arg != '-') { - pattern = argv + i; - break; - } - if (!strcmp(arg, "--")) { - pattern = argv + i + 1; - if (!*pattern) - pattern = NULL; - break; - } - if (!strcmp(arg, "-q") || !strcmp(arg, "--quiet")) { - quiet = 1; - continue; - } - if (!strcmp(arg, "-h") || !strcmp(arg, "--head")) { - show_head = 1; - continue; - } - if (!strcmp(arg, "-d") || !strcmp(arg, "--dereference")) { - deref_tags = 1; - continue; - } - if (!strcmp(arg, "-s") || !strcmp(arg, "--hash")) { - hash_only = 1; - continue; - } - if (!prefixcmp(arg, "--hash=") || - (!prefixcmp(arg, "--abbrev") && - (arg[8] == '=' || arg[8] == '\0'))) { - if (arg[2] != 'h' && !arg[8]) - /* --abbrev only */ - abbrev = DEFAULT_ABBREV; - else { - /* --hash= or --abbrev= */ - char *end; - if (arg[2] == 'h') { - hash_only = 1; - arg += 7; - } - else - arg += 9; - abbrev = strtoul(arg, &end, 10); - if (*end || abbrev > 40) - usage(show_ref_usage); - if (abbrev < MINIMUM_ABBREV) - abbrev = MINIMUM_ABBREV; - } - continue; - } - if (!strcmp(arg, "--verify")) { - verify = 1; - continue; - } - if (!strcmp(arg, "--tags")) { - tags_only = 1; - continue; - } - if (!strcmp(arg, "--heads")) { - heads_only = 1; - continue; - } - if (!strcmp(arg, "--exclude-existing")) - return exclude_existing(NULL); - if (!prefixcmp(arg, "--exclude-existing=")) - return exclude_existing(arg + 19); - usage(show_ref_usage); - } + if (exclude_arg) + return exclude_existing(exclude_existing_arg); + + pattern = argv; + if (!*pattern) + pattern = NULL; if (verify) { if (!pattern) diff --git a/builtin-stripspace.c b/builtin-stripspace.c index d6e3896c00..1fd2205d53 100644 --- a/builtin-stripspace.c +++ b/builtin-stripspace.c @@ -78,7 +78,7 @@ int cmd_stripspace(int argc, const char **argv, const char *prefix) strip_comments = 1; if (strbuf_read(&buf, 0, 1024) < 0) - die("could not read the input"); + die_errno("could not read the input"); stripspace(&buf, strip_comments); diff --git a/builtin-symbolic-ref.c b/builtin-symbolic-ref.c index 6ae6bcc0e8..ca855a5eb2 100644 --- a/builtin-symbolic-ref.c +++ b/builtin-symbolic-ref.c @@ -36,7 +36,8 @@ int cmd_symbolic_ref(int argc, const char **argv, const char *prefix) }; git_config(git_default_config, NULL); - argc = parse_options(argc, argv, options, git_symbolic_ref_usage, 0); + argc = parse_options(argc, argv, prefix, options, + git_symbolic_ref_usage, 0); if (msg &&!*msg) die("Refusing to perform update with empty message"); switch (argc) { diff --git a/builtin-tag.c b/builtin-tag.c index e544430094..a51a6d1ea2 100644 --- a/builtin-tag.c +++ b/builtin-tag.c @@ -308,8 +308,7 @@ static void create_tag(const unsigned char *object, const char *tag, path = git_pathdup("TAG_EDITMSG"); fd = open(path, O_CREAT | O_TRUNC | O_WRONLY, 0600); if (fd < 0) - die("could not create file '%s': %s", - path, strerror(errno)); + die_errno("could not create file '%s'", path); if (!is_null_sha1(prev)) write_tag_body(fd, prev); @@ -376,8 +375,8 @@ int cmd_tag(int argc, const char **argv, const char *prefix) struct commit_list *with_commit = NULL; struct option options[] = { OPT_BOOLEAN('l', NULL, &list, "list tag names"), - { OPTION_INTEGER, 'n', NULL, &lines, NULL, - "print n lines of each tag message", + { OPTION_INTEGER, 'n', NULL, &lines, "n", + "print <n> lines of each tag message", PARSE_OPT_OPTARG, NULL, 1 }, OPT_BOOLEAN('d', NULL, &delete, "delete tags"), OPT_BOOLEAN('v', NULL, &verify, "verify tags"), @@ -387,7 +386,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix) "annotated tag, needs a message"), OPT_CALLBACK('m', NULL, &msg, "msg", "message for the tag", parse_msg_arg), - OPT_STRING('F', NULL, &msgfile, "file", "message in a file"), + OPT_FILENAME('F', NULL, &msgfile, "message in a file"), OPT_BOOLEAN('s', NULL, &sign, "annotated and GPG-signed tag"), OPT_STRING('u', NULL, &keyid, "key-id", "use another key to sign the tag"), @@ -405,8 +404,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix) git_config(git_tag_config, NULL); - argc = parse_options(argc, argv, options, git_tag_usage, 0); - msgfile = parse_options_fix_filename(prefix, msgfile); + argc = parse_options(argc, argv, prefix, options, git_tag_usage, 0); if (keyid) { sign = 1; @@ -444,11 +442,11 @@ int cmd_tag(int argc, const char **argv, const char *prefix) else { if (!strcmp(msgfile, "-")) { if (strbuf_read(&buf, 0, 1024) < 0) - die("cannot read %s", msgfile); + die_errno("cannot read '%s'", msgfile); } else { if (strbuf_read_file(&buf, msgfile, 1024) < 0) - die("could not open or read '%s': %s", - msgfile, strerror(errno)); + die_errno("could not open or read '%s'", + msgfile); } } } diff --git a/builtin-tar-tree.c b/builtin-tar-tree.c index f88e721936..8b3a35e12d 100644 --- a/builtin-tar-tree.c +++ b/builtin-tar-tree.c @@ -91,7 +91,7 @@ int cmd_get_tar_commit_id(int argc, const char **argv, const char *prefix) n = write_in_full(1, content + 11, 41); if (n < 41) - die("git get-tar-commit-id: write error"); + die_errno("git get-tar-commit-id: write error"); return 0; } diff --git a/builtin-unpack-objects.c b/builtin-unpack-objects.c index 8e831be476..557148a693 100644 --- a/builtin-unpack-objects.c +++ b/builtin-unpack-objects.c @@ -68,7 +68,7 @@ static void *fill(int min) if (ret <= 0) { if (!ret) die("early EOF"); - die("read error on input: %s", strerror(errno)); + die_errno("read error on input"); } len += ret; } while (len < min); @@ -158,7 +158,7 @@ struct obj_info { #define FLAG_WRITTEN (1u<<21) static struct obj_info *obj_list; -unsigned nr_objects; +static unsigned nr_objects; /* * Called only from check_object() after it verified this object @@ -200,7 +200,7 @@ static int check_object(struct object *obj, int type, void *data) if (fsck_object(obj, 1, fsck_error_function)) die("Error in object"); - if (!fsck_walk(obj, check_object, 0)) + if (!fsck_walk(obj, check_object, NULL)) die("Error on reachable objects of %s", sha1_to_hex(obj->sha1)); write_cached_object(obj); return 1; @@ -210,7 +210,7 @@ static void write_rest(void) { unsigned i; for (i = 0; i < nr_objects; i++) - check_object(obj_list[i].obj, OBJ_ANY, 0); + check_object(obj_list[i].obj, OBJ_ANY, NULL); } static void added_object(unsigned nr, enum object_type type, diff --git a/builtin-update-ref.c b/builtin-update-ref.c index 378dc1b7a6..76ba1d5881 100644 --- a/builtin-update-ref.c +++ b/builtin-update-ref.c @@ -23,7 +23,8 @@ int cmd_update_ref(int argc, const char **argv, const char *prefix) }; git_config(git_default_config, NULL); - argc = parse_options(argc, argv, options, git_update_ref_usage, 0); + argc = parse_options(argc, argv, prefix, options, git_update_ref_usage, + 0); if (msg && !*msg) die("Refusing to perform update with empty message."); diff --git a/builtin-verify-pack.c b/builtin-verify-pack.c index 0ee0a9af60..a18df04cf9 100644 --- a/builtin-verify-pack.c +++ b/builtin-verify-pack.c @@ -7,10 +7,13 @@ static void show_pack_info(struct packed_git *p) { - uint32_t nr_objects, i, chain_histogram[MAX_CHAIN+1]; + uint32_t nr_objects, i; + int cnt; + unsigned long chain_histogram[MAX_CHAIN+1], baseobjects; nr_objects = p->num_objects; memset(chain_histogram, 0, sizeof(chain_histogram)); + baseobjects = 0; for (i = 0; i < nr_objects; i++) { const unsigned char *sha1; @@ -29,9 +32,11 @@ static void show_pack_info(struct packed_git *p) &delta_chain_length, base_sha1); printf("%s ", sha1_to_hex(sha1)); - if (!delta_chain_length) + if (!delta_chain_length) { printf("%-6s %lu %lu %"PRIuMAX"\n", type, size, store_size, (uintmax_t)offset); + baseobjects++; + } else { printf("%-6s %lu %lu %"PRIuMAX" %u %s\n", type, size, store_size, (uintmax_t)offset, @@ -43,15 +48,21 @@ static void show_pack_info(struct packed_git *p) } } - for (i = 0; i <= MAX_CHAIN; i++) { - if (!chain_histogram[i]) + if (baseobjects) + printf("non delta: %lu object%s\n", + baseobjects, baseobjects > 1 ? "s" : ""); + + for (cnt = 1; cnt <= MAX_CHAIN; cnt++) { + if (!chain_histogram[cnt]) continue; - printf("chain length = %"PRIu32": %"PRIu32" object%s\n", i, - chain_histogram[i], chain_histogram[i] > 1 ? "s" : ""); + printf("chain length = %d: %lu object%s\n", cnt, + chain_histogram[cnt], + chain_histogram[cnt] > 1 ? "s" : ""); } if (chain_histogram[0]) - printf("chain length > %d: %"PRIu32" object%s\n", MAX_CHAIN, - chain_histogram[0], chain_histogram[0] > 1 ? "s" : ""); + printf("chain length > %d: %lu object%s\n", MAX_CHAIN, + chain_histogram[0], + chain_histogram[0] > 1 ? "s" : ""); } static int verify_one_pack(const char *path, int verbose) diff --git a/builtin-write-tree.c b/builtin-write-tree.c index 9d640508dd..3a24ce8157 100644 --- a/builtin-write-tree.c +++ b/builtin-write-tree.c @@ -13,7 +13,7 @@ static const char write_tree_usage[] = int cmd_write_tree(int argc, const char **argv, const char *unused_prefix) { - int missing_ok = 0, ret; + int flags = 0, ret; const char *prefix = NULL; unsigned char sha1[20]; const char *me = "git-write-tree"; @@ -22,9 +22,15 @@ int cmd_write_tree(int argc, const char **argv, const char *unused_prefix) while (1 < argc) { const char *arg = argv[1]; if (!strcmp(arg, "--missing-ok")) - missing_ok = 1; + flags |= WRITE_TREE_MISSING_OK; else if (!prefixcmp(arg, "--prefix=")) prefix = arg + 9; + else if (!prefixcmp(arg, "--ignore-cache-tree")) + /* + * This is only useful for debugging, so I + * do not bother documenting it. + */ + flags |= WRITE_TREE_IGNORE_CACHE_TREE; else usage(write_tree_usage); argc--; argv++; @@ -33,7 +39,7 @@ int cmd_write_tree(int argc, const char **argv, const char *unused_prefix) if (argc > 2) die("too many options"); - ret = write_cache_as_tree(sha1, missing_ok, prefix); + ret = write_cache_as_tree(sha1, flags, prefix); switch (ret) { case 0: printf("%s\n", sha1_to_hex(sha1)); @@ -72,6 +72,7 @@ extern int cmd_merge_base(int argc, const char **argv, const char *prefix); extern int cmd_merge_ours(int argc, const char **argv, const char *prefix); extern int cmd_merge_file(int argc, const char **argv, const char *prefix); extern int cmd_merge_recursive(int argc, const char **argv, const char *prefix); +extern int cmd_mktree(int argc, const char **argv, const char *prefix); extern int cmd_mv(int argc, const char **argv, const char *prefix); extern int cmd_name_rev(int argc, const char **argv, const char *prefix); extern int cmd_pack_objects(int argc, const char **argv, const char *prefix); @@ -98,7 +98,7 @@ int verify_bundle(struct bundle_header *header, int verbose) */ struct ref_list *p = &header->prerequisites; struct rev_info revs; - const char *argv[] = {NULL, "--all"}; + const char *argv[] = {NULL, "--all", NULL}; struct object_array refs; struct commit *commit; int i, ret = 0, req_nr; diff --git a/cache-tree.c b/cache-tree.c index 37bf35e636..d91743775d 100644 --- a/cache-tree.c +++ b/cache-tree.c @@ -329,7 +329,8 @@ static int update_one(struct cache_tree *it, entlen = pathlen - baselen; } if (mode != S_IFGITLINK && !missing_ok && !has_sha1_file(sha1)) - return error("invalid object %s", sha1_to_hex(sha1)); + return error("invalid object %06o %s for '%.*s'", + mode, sha1_to_hex(sha1), entlen+baselen, path); if (ce->ce_flags & CE_REMOVE) continue; /* entry being removed */ @@ -514,6 +515,8 @@ struct cache_tree *cache_tree_read(const char *buffer, unsigned long size) static struct cache_tree *cache_tree_find(struct cache_tree *it, const char *path) { + if (!it) + return NULL; while (*path) { const char *slash; struct cache_tree_sub *sub; @@ -538,28 +541,32 @@ static struct cache_tree *cache_tree_find(struct cache_tree *it, const char *pat return it; } -int write_cache_as_tree(unsigned char *sha1, int missing_ok, const char *prefix) +int write_cache_as_tree(unsigned char *sha1, int flags, const char *prefix) { int entries, was_valid, newfd; + struct lock_file *lock_file; /* * We can't free this memory, it becomes part of a linked list * parsed atexit() */ - struct lock_file *lock_file = xcalloc(1, sizeof(struct lock_file)); + lock_file = xcalloc(1, sizeof(struct lock_file)); newfd = hold_locked_index(lock_file, 1); entries = read_cache(); if (entries < 0) return WRITE_TREE_UNREADABLE_INDEX; + if (flags & WRITE_TREE_IGNORE_CACHE_TREE) + cache_tree_free(&(active_cache_tree)); if (!active_cache_tree) active_cache_tree = cache_tree(); was_valid = cache_tree_fully_valid(active_cache_tree); - if (!was_valid) { + int missing_ok = flags & WRITE_TREE_MISSING_OK; + if (cache_tree_update(active_cache_tree, active_cache, active_nr, missing_ok, 0) < 0) @@ -625,3 +632,35 @@ void prime_cache_tree(struct cache_tree **it, struct tree *tree) *it = cache_tree(); prime_cache_tree_rec(*it, tree); } + +/* + * find the cache_tree that corresponds to the current level without + * exploding the full path into textual form. The root of the + * cache tree is given as "root", and our current level is "info". + * (1) When at root level, info->prev is NULL, so it is "root" itself. + * (2) Otherwise, find the cache_tree that corresponds to one level + * above us, and find ourselves in there. + */ +static struct cache_tree *find_cache_tree_from_traversal(struct cache_tree *root, + struct traverse_info *info) +{ + struct cache_tree *our_parent; + + if (!info->prev) + return root; + our_parent = find_cache_tree_from_traversal(root, info->prev); + return cache_tree_find(our_parent, info->name.path); +} + +int cache_tree_matches_traversal(struct cache_tree *root, + struct name_entry *ent, + struct traverse_info *info) +{ + struct cache_tree *it; + + it = find_cache_tree_from_traversal(root, info); + it = cache_tree_find(it, ent->path); + if (it && it->entry_count > 0 && !hashcmp(ent->sha1, it->sha1)) + return it->entry_count; + return 0; +} diff --git a/cache-tree.h b/cache-tree.h index e958835236..3df641f593 100644 --- a/cache-tree.h +++ b/cache-tree.h @@ -2,6 +2,7 @@ #define CACHE_TREE_H #include "tree.h" +#include "tree-walk.h" struct cache_tree; struct cache_tree_sub { @@ -30,11 +31,18 @@ struct cache_tree *cache_tree_read(const char *buffer, unsigned long size); int cache_tree_fully_valid(struct cache_tree *); int cache_tree_update(struct cache_tree *, struct cache_entry **, int, int, int); +/* bitmasks to write_cache_as_tree flags */ +#define WRITE_TREE_MISSING_OK 1 +#define WRITE_TREE_IGNORE_CACHE_TREE 2 + +/* error return codes */ #define WRITE_TREE_UNREADABLE_INDEX (-1) #define WRITE_TREE_UNMERGED_INDEX (-2) #define WRITE_TREE_PREFIX_ERROR (-3) -int write_cache_as_tree(unsigned char *sha1, int missing_ok, const char *prefix); +int write_cache_as_tree(unsigned char *sha1, int flags, const char *prefix); void prime_cache_tree(struct cache_tree **, struct tree *); +extern int cache_tree_matches_traversal(struct cache_tree *, struct name_entry *ent, struct traverse_info *info); + #endif @@ -468,6 +468,9 @@ extern int index_fd(unsigned char *sha1, int fd, struct stat *st, int write_obje extern int index_path(unsigned char *sha1, const char *path, struct stat *st, int write_object); extern void fill_stat_cache_info(struct cache_entry *ce, struct stat *st); +/* "careful lstat()" */ +extern int check_path(const char *path, int len, struct stat *st); + #define REFRESH_REALLY 0x0001 /* ignore_valid */ #define REFRESH_UNMERGED 0x0002 /* allow unmerged */ #define REFRESH_QUIET 0x0004 /* be quiet about it */ @@ -543,7 +546,6 @@ enum rebase_setup_type { }; enum push_default_type { - PUSH_DEFAULT_UNSPECIFIED = -1, PUSH_DEFAULT_NOTHING = 0, PUSH_DEFAULT_MATCHING, PUSH_DEFAULT_TRACKING, @@ -561,6 +563,8 @@ enum object_creation_mode { extern enum object_creation_mode object_creation_mode; +extern int grafts_replace_parents; + #define GIT_REPO_VERSION 0 extern int repository_format_version; extern int check_repository_format(void); @@ -614,6 +618,8 @@ extern int is_empty_blob_sha1(const unsigned char *sha1); int git_mkstemp(char *path, size_t n, const char *template); +int git_mkstemps(char *path, size_t n, const char *template, int suffix_len); + /* * NOTE NOTE NOTE!! * @@ -742,7 +748,17 @@ struct checkout { }; extern int checkout_entry(struct cache_entry *ce, const struct checkout *state, char *topath); + +struct cache_def { + char path[PATH_MAX + 1]; + int len; + int flags; + int track_flags; + int prefix_len_stat_func; +}; + extern int has_symlink_leading_path(const char *name, int len); +extern int threaded_has_symlink_leading_path(struct cache_def *, const char *, int); extern int has_symlink_or_noent_leading_path(const char *name, int len); extern int has_dirs_only_path(const char *name, int len, int prefix_len); extern void invalidate_lstat_cache(const char *name, int len); diff --git a/combine-diff.c b/combine-diff.c index 1a6f9d1df5..5b63af1eeb 100644 --- a/combine-diff.c +++ b/combine-diff.c @@ -745,7 +745,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent, done = read_in_full(fd, result, len); if (done < 0) - die("read error '%s'", elem->path); + die_errno("read error '%s'", elem->path); else if (done < len) die("early EOF '%s'", elem->path); @@ -50,7 +50,6 @@ struct commit *lookup_commit(const unsigned char *sha1) static unsigned long parse_commit_date(const char *buf, const char *tail) { - unsigned long date; const char *dateptr; if (buf + 6 >= tail) @@ -73,10 +72,7 @@ static unsigned long parse_commit_date(const char *buf, const char *tail) if (buf >= tail) return 0; /* dateptr < buf && buf[-1] == '\n', so strtoul will stop at buf-1 */ - date = strtoul(dateptr, NULL, 10); - if (date == ULONG_MAX) - date = 0; - return date; + return strtoul(dateptr, NULL, 10); } static struct commit_graft **commit_graft; @@ -266,7 +262,11 @@ int parse_commit_buffer(struct commit *item, void *buffer, unsigned long size) bufptr[47] != '\n') return error("bad parents in commit %s", sha1_to_hex(item->object.sha1)); bufptr += 48; - if (graft) + /* + * The clone is shallow if nr_parent < 0, and we must + * not traverse its real parents even when we unhide them. + */ + if (graft && (graft->nr_parent < 0 || grafts_replace_parents)) continue; new_parent = lookup_commit(parent); if (new_parent) @@ -64,6 +64,7 @@ enum cmit_fmt { }; extern int non_ascii(int); +extern int has_non_ascii(const char *text); struct rev_info; /* in revision.h, it circularly uses enum cmit_fmt */ extern char *reencode_commit_message(const struct commit *commit, const char **encoding_p); diff --git a/compat/basename.c b/compat/basename.c new file mode 100644 index 0000000000..d8f8a3c6dc --- /dev/null +++ b/compat/basename.c @@ -0,0 +1,15 @@ +#include "../git-compat-util.h" + +/* Adapted from libiberty's basename.c. */ +char *gitbasename (char *path) +{ + const char *base; + /* Skip over the disk name in MSDOS pathnames. */ + if (has_dos_drive_prefix(path)) + path += 2; + for (base = path; *path; path++) { + if (is_dir_sep(*path)) + base = path + 1; + } + return (char *)base; +} diff --git a/compat/mingw.c b/compat/mingw.c index cdeda1d985..bed417875e 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -1,5 +1,6 @@ #include "../git-compat-util.h" #include "win32.h" +#include <conio.h> #include "../strbuf.h" unsigned int _CRT_fmode = _O_BINARY; @@ -525,8 +526,8 @@ static const char *parse_interpreter(const char *cmd) if (buf[0] != '#' || buf[1] != '!') return NULL; buf[n] = '\0'; - p = strchr(buf, '\n'); - if (!p) + p = buf + strcspn(buf, "\r\n"); + if (!*p) return NULL; *p = '\0'; @@ -1156,3 +1157,77 @@ int link(const char *oldpath, const char *newpath) } return 0; } + +char *getpass(const char *prompt) +{ + struct strbuf buf = STRBUF_INIT; + + fputs(prompt, stderr); + for (;;) { + char c = _getch(); + if (c == '\r' || c == '\n') + break; + strbuf_addch(&buf, c); + } + fputs("\n", stderr); + return strbuf_detach(&buf, NULL); +} + +#ifndef NO_MINGW_REPLACE_READDIR +/* MinGW readdir implementation to avoid extra lstats for Git */ +struct mingw_DIR +{ + struct _finddata_t dd_dta; /* disk transfer area for this dir */ + struct mingw_dirent dd_dir; /* Our own implementation, including d_type */ + long dd_handle; /* _findnext handle */ + int dd_stat; /* 0 = next entry to read is first entry, -1 = off the end, positive = 0 based index of next entry */ + char dd_name[1]; /* given path for dir with search pattern (struct is extended) */ +}; + +struct dirent *mingw_readdir(DIR *dir) +{ + WIN32_FIND_DATAA buf; + HANDLE handle; + struct mingw_DIR *mdir = (struct mingw_DIR*)dir; + + if (!dir->dd_handle) { + errno = EBADF; /* No set_errno for mingw */ + return NULL; + } + + if (dir->dd_handle == (long)INVALID_HANDLE_VALUE && dir->dd_stat == 0) + { + handle = FindFirstFileA(dir->dd_name, &buf); + DWORD lasterr = GetLastError(); + dir->dd_handle = (long)handle; + if (handle == INVALID_HANDLE_VALUE && (lasterr != ERROR_NO_MORE_FILES)) { + errno = err_win_to_posix(lasterr); + return NULL; + } + } else if (dir->dd_handle == (long)INVALID_HANDLE_VALUE) { + return NULL; + } else if (!FindNextFileA((HANDLE)dir->dd_handle, &buf)) { + DWORD lasterr = GetLastError(); + FindClose((HANDLE)dir->dd_handle); + dir->dd_handle = (long)INVALID_HANDLE_VALUE; + /* POSIX says you shouldn't set errno when readdir can't + find any more files; so, if another error we leave it set. */ + if (lasterr != ERROR_NO_MORE_FILES) + errno = err_win_to_posix(lasterr); + return NULL; + } + + /* We get here if `buf' contains valid data. */ + strcpy(dir->dd_dir.d_name, buf.cFileName); + ++dir->dd_stat; + + /* Set file type, based on WIN32_FIND_DATA */ + mdir->dd_dir.d_type = 0; + if (buf.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) + mdir->dd_dir.d_type |= DT_DIR; + else + mdir->dd_dir.d_type |= DT_REG; + + return (struct dirent*)&dir->dd_dir; +} +#endif // !NO_MINGW_REPLACE_READDIR diff --git a/compat/mingw.h b/compat/mingw.h index 762eb143a7..c1859c5480 100644 --- a/compat/mingw.h +++ b/compat/mingw.h @@ -38,6 +38,8 @@ struct passwd { char *pw_dir; }; +extern char *getpass(const char *prompt); + struct pollfd { int fd; /* file descriptor */ short events; /* requested events */ @@ -90,6 +92,8 @@ static inline int fcntl(int fd, int cmd, long arg) errno = EINVAL; return -1; } +/* bash cannot reliably detect negative return codes as failure */ +#define exit(code) exit((code) & 0xff) /* * simple adaptors @@ -109,7 +113,7 @@ static inline int mingw_unlink(const char *pathname) } #define unlink mingw_unlink -static inline int waitpid(pid_t pid, unsigned *status, unsigned options) +static inline int waitpid(pid_t pid, int *status, unsigned options) { if (options == 0) return _cwait(status, pid, 0); @@ -233,3 +237,32 @@ int main(int argc, const char **argv) \ return mingw_main(argc, argv); \ } \ static int mingw_main(c,v) + +#ifndef NO_MINGW_REPLACE_READDIR +/* + * A replacement of readdir, to ensure that it reads the file type at + * the same time. This avoid extra unneeded lstats in git on MinGW + */ +#undef DT_UNKNOWN +#undef DT_DIR +#undef DT_REG +#undef DT_LNK +#define DT_UNKNOWN 0 +#define DT_DIR 1 +#define DT_REG 2 +#define DT_LNK 3 + +struct mingw_dirent +{ + long d_ino; /* Always zero. */ + union { + unsigned short d_reclen; /* Always zero. */ + unsigned char d_type; /* Reimplementation adds this */ + }; + unsigned short d_namlen; /* Length of name in d_name. */ + char d_name[FILENAME_MAX]; /* File name. */ +}; +#define dirent mingw_dirent +#define readdir(x) mingw_readdir(x) +struct dirent *mingw_readdir(DIR *dir); +#endif // !NO_MINGW_REPLACE_READDIR diff --git a/compat/mkstemps.c b/compat/mkstemps.c new file mode 100644 index 0000000000..14179c8e6d --- /dev/null +++ b/compat/mkstemps.c @@ -0,0 +1,70 @@ +#include "../git-compat-util.h" + +/* Adapted from libiberty's mkstemp.c. */ + +#undef TMP_MAX +#define TMP_MAX 16384 + +int gitmkstemps(char *pattern, int suffix_len) +{ + static const char letters[] = + "abcdefghijklmnopqrstuvwxyz" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "0123456789"; + static const int num_letters = 62; + uint64_t value; + struct timeval tv; + char *template; + size_t len; + int fd, count; + + len = strlen(pattern); + + if (len < 6 + suffix_len) { + errno = EINVAL; + return -1; + } + + if (strncmp(&pattern[len - 6 - suffix_len], "XXXXXX", 6)) { + errno = EINVAL; + return -1; + } + + /* + * Replace pattern's XXXXXX characters with randomness. + * Try TMP_MAX different filenames. + */ + gettimeofday(&tv, NULL); + value = ((size_t)(tv.tv_usec << 16)) ^ tv.tv_sec ^ getpid(); + template = &pattern[len - 6 - suffix_len]; + for (count = 0; count < TMP_MAX; ++count) { + uint64_t v = value; + /* Fill in the random bits. */ + template[0] = letters[v % num_letters]; v /= num_letters; + template[1] = letters[v % num_letters]; v /= num_letters; + template[2] = letters[v % num_letters]; v /= num_letters; + template[3] = letters[v % num_letters]; v /= num_letters; + template[4] = letters[v % num_letters]; v /= num_letters; + template[5] = letters[v % num_letters]; v /= num_letters; + + fd = open(pattern, O_CREAT | O_EXCL | O_RDWR, 0600); + if (fd > 0) + return fd; + /* + * Fatal error (EPERM, ENOSPC etc). + * It doesn't make sense to loop. + */ + if (errno != EEXIST) + break; + /* + * This is a random value. It is only necessary that + * the next TMP_MAX values generated by adding 7777 to + * VALUE are different with (module 2^32). + */ + value += 7777; + } + /* We return the null string if we can't find a unique file name. */ + pattern[0] = '\0'; + errno = EINVAL; + return -1; +} diff --git a/compat/nedmalloc/License.txt b/compat/nedmalloc/License.txt new file mode 100644 index 0000000000..36b7cd93cd --- /dev/null +++ b/compat/nedmalloc/License.txt @@ -0,0 +1,23 @@ +Boost Software License - Version 1.0 - August 17th, 2003 + +Permission is hereby granted, free of charge, to any person or organization +obtaining a copy of the software and accompanying documentation covered by +this license (the "Software") to use, reproduce, display, distribute, +execute, and transmit the Software, and to prepare derivative works of the +Software, and to permit third-parties to whom the Software is furnished to +do so, all subject to the following: + +The copyright notices in the Software and this entire statement, including +the above license grant, this restriction and the following disclaimer, +must be included in all copies of the Software, in whole or in part, and +all derivative works of the Software, unless such copies or derivative +works are solely in the form of machine-executable object code generated by +a source language processor. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. diff --git a/compat/nedmalloc/Readme.txt b/compat/nedmalloc/Readme.txt new file mode 100644 index 0000000000..876365646e --- /dev/null +++ b/compat/nedmalloc/Readme.txt @@ -0,0 +1,136 @@ +nedalloc v1.05 15th June 2008: +-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + +by Niall Douglas (http://www.nedprod.com/programs/portable/nedmalloc/) + +Enclosed is nedalloc, an alternative malloc implementation for multiple +threads without lock contention based on dlmalloc v2.8.4. It is more +or less a newer implementation of ptmalloc2, the standard allocator in +Linux (which is based on dlmalloc v2.7.0) but also contains a per-thread +cache for maximum CPU scalability. + +It is licensed under the Boost Software License which basically means +you can do anything you like with it. This does not apply to the malloc.c.h +file which remains copyright to others. + +It has been tested on win32 (x86), win64 (x64), Linux (x64), FreeBSD (x64) +and Apple MacOS X (x86). It works very well on all of these and is very +significantly faster than the system allocator on all of these platforms. + +By literally dropping in this allocator as a replacement for your system +allocator, you can see real world improvements of up to three times in normal +code! + +To use: +-=-=-=- +Drop in nedmalloc.h, nedmalloc.c and malloc.c.h into your project. +Configure using the instructions in nedmalloc.h. Run and enjoy. + +To test, compile test.c. It will run a comparison between your system +allocator and nedalloc and tell you how much faster nedalloc is. It also +serves as an example of usage. + +Notes: +-=-=-= +If you want the very latest version of this allocator, get it from the +TnFOX SVN repository at svn://svn.berlios.de/viewcvs/tnfox/trunk/src/nedmalloc + +Because of how nedalloc allocates an mspace per thread, it can cause +severe bloating of memory usage under certain allocation patterns. +You can substantially reduce this wastage by setting MAXTHREADSINPOOL +or the threads parameter to nedcreatepool() to a fraction of the number of +threads which would normally be in a pool at once. This will reduce +bloating at the cost of an increase in lock contention. If allocated size +is less than THREADCACHEMAX, locking is avoided 90-99% of the time and +if most of your allocations are below this value, you can safely set +MAXTHREADSINPOOL to one. + +You will suffer memory leakage unless you call neddisablethreadcache() +per pool for every thread which exits. This is because nedalloc cannot +portably know when a thread exits and thus when its thread cache can +be returned for use by other code. Don't forget pool zero, the system pool. + +For C++ type allocation patterns (where the same sizes of memory are +regularly allocated and deallocated as objects are created and destroyed), +the threadcache always benefits performance. If however your allocation +patterns are different, searching the threadcache may significantly slow +down your code - as a rule of thumb, if cache utilisation is below 80% +(see the source for neddisablethreadcache() for how to enable debug +printing in release mode) then you should disable the thread cache for +that thread. You can compile out the threadcache code by setting +THREADCACHEMAX to zero. + +Speed comparisons: +-=-=-=-=-=-=-=-=-= +See Benchmarks.xls for details. + +The enclosed test.c can do two things: it can be a torture test or a speed +test. The speed test is designed to be a representative synthetic +memory allocator test. It works by randomly mixing allocations with frees +with half of the allocation sizes being a two power multiple less than +512 bytes (to mimic C++ stack instantiated objects) and the other half +being a simple random value less than 16Kb. + +The real world code results are from Tn's TestIO benchmark. This is a +heavily multithreaded and memory intensive benchmark with a lot of branching +and other stuff modern processors don't like so much. As you'll note, the +test doesn't show the benefits of the threadcache mostly due to the saturation +of the memory bus being the limiting factor. + +ChangeLog: +-=-=-=-=-= +v1.05 15th June 2008: + * { 1042 } Added error check for TLSSET() and TLSFREE() macros. Thanks to +Markus Elfring for reporting this. + * { 1043 } Fixed a segfault when freeing memory allocated using +nedindependent_comalloc(). Thanks to Pavel Vozenilek for reporting this. + +v1.04 14th July 2007: + * Fixed a bug with the new optimised implementation that failed to lock +on a realloc under certain conditions. + * Fixed lack of thread synchronisation in InitPool() causing pool corruption + * Fixed a memory leak of thread cache contents on disabling. Thanks to Earl +Chew for reporting this. + * Added a sanity check for freed blocks being valid. + * Reworked test.c into being a torture test. + * Fixed GCC assembler optimisation misspecification + +v1.04alpha_svn915 7th October 2006: + * Fixed failure to unlock thread cache list if allocating a new list failed. +Thanks to Dmitry Chichkov for reporting this. Futher thanks to Aleksey Sanin. + * Fixed realloc(0, <size>) segfaulting. Thanks to Dmitry Chichkov for +reporting this. + * Made config defines #ifndef so they can be overriden by the build system. +Thanks to Aleksey Sanin for suggesting this. + * Fixed deadlock in nedprealloc() due to unnecessary locking of preferred +thread mspace when mspace_realloc() always uses the original block's mspace +anyway. Thanks to Aleksey Sanin for reporting this. + * Made some speed improvements by hacking mspace_malloc() to no longer lock +its mspace, thus allowing the recursive mutex implementation to be removed +with an associated speed increase. Thanks to Aleksey Sanin for suggesting this. + * Fixed a bug where allocating mspaces overran its max limit. Thanks to +Aleksey Sanin for reporting this. + +v1.03 10th July 2006: + * Fixed memory corruption bug in threadcache code which only appeared with >4 +threads and in heavy use of the threadcache. + +v1.02 15th May 2006: + * Integrated dlmalloc v2.8.4, fixing the win32 memory release problem and +improving performance still further. Speed is now up to twice the speed of v1.01 +(average is 67% faster). + * Fixed win32 critical section implementation. Thanks to Pavel Kuznetsov +for reporting this. + * Wasn't locking mspace if all mspaces were locked. Thanks to Pavel Kuznetsov +for reporting this. + * Added Apple Mac OS X support. + +v1.01 24th February 2006: + * Fixed multiprocessor scaling problems by removing sources of cache sloshing + * Earl Chew <earl_chew <at> agilent <dot> com> sent patches for the following: + 1. size2binidx() wasn't working for default code path (non x86) + 2. Fixed failure to release mspace lock under certain circumstances which + caused a deadlock + +v1.00 1st January 2006: + * First release diff --git a/compat/nedmalloc/malloc.c.h b/compat/nedmalloc/malloc.c.h new file mode 100644 index 0000000000..74c42e3162 --- /dev/null +++ b/compat/nedmalloc/malloc.c.h @@ -0,0 +1,5752 @@ +/* + This is a version (aka dlmalloc) of malloc/free/realloc written by + Doug Lea and released to the public domain, as explained at + http://creativecommons.org/licenses/publicdomain. Send questions, + comments, complaints, performance data, etc to dl@cs.oswego.edu + +* Version pre-2.8.4 Mon Nov 27 11:22:37 2006 (dl at gee) + + Note: There may be an updated version of this malloc obtainable at + ftp://gee.cs.oswego.edu/pub/misc/malloc.c + Check before installing! + +* Quickstart + + This library is all in one file to simplify the most common usage: + ftp it, compile it (-O3), and link it into another program. All of + the compile-time options default to reasonable values for use on + most platforms. You might later want to step through various + compile-time and dynamic tuning options. + + For convenience, an include file for code using this malloc is at: + ftp://gee.cs.oswego.edu/pub/misc/malloc-2.8.4.h + You don't really need this .h file unless you call functions not + defined in your system include files. The .h file contains only the + excerpts from this file needed for using this malloc on ANSI C/C++ + systems, so long as you haven't changed compile-time options about + naming and tuning parameters. If you do, then you can create your + own malloc.h that does include all settings by cutting at the point + indicated below. Note that you may already by default be using a C + library containing a malloc that is based on some version of this + malloc (for example in linux). You might still want to use the one + in this file to customize settings or to avoid overheads associated + with library versions. + +* Vital statistics: + + Supported pointer/size_t representation: 4 or 8 bytes + size_t MUST be an unsigned type of the same width as + pointers. (If you are using an ancient system that declares + size_t as a signed type, or need it to be a different width + than pointers, you can use a previous release of this malloc + (e.g. 2.7.2) supporting these.) + + Alignment: 8 bytes (default) + This suffices for nearly all current machines and C compilers. + However, you can define MALLOC_ALIGNMENT to be wider than this + if necessary (up to 128bytes), at the expense of using more space. + + Minimum overhead per allocated chunk: 4 or 8 bytes (if 4byte sizes) + 8 or 16 bytes (if 8byte sizes) + Each malloced chunk has a hidden word of overhead holding size + and status information, and additional cross-check word + if FOOTERS is defined. + + Minimum allocated size: 4-byte ptrs: 16 bytes (including overhead) + 8-byte ptrs: 32 bytes (including overhead) + + Even a request for zero bytes (i.e., malloc(0)) returns a + pointer to something of the minimum allocatable size. + The maximum overhead wastage (i.e., number of extra bytes + allocated than were requested in malloc) is less than or equal + to the minimum size, except for requests >= mmap_threshold that + are serviced via mmap(), where the worst case wastage is about + 32 bytes plus the remainder from a system page (the minimal + mmap unit); typically 4096 or 8192 bytes. + + Security: static-safe; optionally more or less + The "security" of malloc refers to the ability of malicious + code to accentuate the effects of errors (for example, freeing + space that is not currently malloc'ed or overwriting past the + ends of chunks) in code that calls malloc. This malloc + guarantees not to modify any memory locations below the base of + heap, i.e., static variables, even in the presence of usage + errors. The routines additionally detect most improper frees + and reallocs. All this holds as long as the static bookkeeping + for malloc itself is not corrupted by some other means. This + is only one aspect of security -- these checks do not, and + cannot, detect all possible programming errors. + + If FOOTERS is defined nonzero, then each allocated chunk + carries an additional check word to verify that it was malloced + from its space. These check words are the same within each + execution of a program using malloc, but differ across + executions, so externally crafted fake chunks cannot be + freed. This improves security by rejecting frees/reallocs that + could corrupt heap memory, in addition to the checks preventing + writes to statics that are always on. This may further improve + security at the expense of time and space overhead. (Note that + FOOTERS may also be worth using with MSPACES.) + + By default detected errors cause the program to abort (calling + "abort()"). You can override this to instead proceed past + errors by defining PROCEED_ON_ERROR. In this case, a bad free + has no effect, and a malloc that encounters a bad address + caused by user overwrites will ignore the bad address by + dropping pointers and indices to all known memory. This may + be appropriate for programs that should continue if at all + possible in the face of programming errors, although they may + run out of memory because dropped memory is never reclaimed. + + If you don't like either of these options, you can define + CORRUPTION_ERROR_ACTION and USAGE_ERROR_ACTION to do anything + else. And if if you are sure that your program using malloc has + no errors or vulnerabilities, you can define INSECURE to 1, + which might (or might not) provide a small performance improvement. + + Thread-safety: NOT thread-safe unless USE_LOCKS defined + When USE_LOCKS is defined, each public call to malloc, free, + etc is surrounded with either a pthread mutex or a win32 + spinlock (depending on WIN32). This is not especially fast, and + can be a major bottleneck. It is designed only to provide + minimal protection in concurrent environments, and to provide a + basis for extensions. If you are using malloc in a concurrent + program, consider instead using nedmalloc + (http://www.nedprod.com/programs/portable/nedmalloc/) or + ptmalloc (See http://www.malloc.de), which are derived + from versions of this malloc. + + System requirements: Any combination of MORECORE and/or MMAP/MUNMAP + This malloc can use unix sbrk or any emulation (invoked using + the CALL_MORECORE macro) and/or mmap/munmap or any emulation + (invoked using CALL_MMAP/CALL_MUNMAP) to get and release system + memory. On most unix systems, it tends to work best if both + MORECORE and MMAP are enabled. On Win32, it uses emulations + based on VirtualAlloc. It also uses common C library functions + like memset. + + Compliance: I believe it is compliant with the Single Unix Specification + (See http://www.unix.org). Also SVID/XPG, ANSI C, and probably + others as well. + +* Overview of algorithms + + This is not the fastest, most space-conserving, most portable, or + most tunable malloc ever written. However it is among the fastest + while also being among the most space-conserving, portable and + tunable. Consistent balance across these factors results in a good + general-purpose allocator for malloc-intensive programs. + + In most ways, this malloc is a best-fit allocator. Generally, it + chooses the best-fitting existing chunk for a request, with ties + broken in approximately least-recently-used order. (This strategy + normally maintains low fragmentation.) However, for requests less + than 256bytes, it deviates from best-fit when there is not an + exactly fitting available chunk by preferring to use space adjacent + to that used for the previous small request, as well as by breaking + ties in approximately most-recently-used order. (These enhance + locality of series of small allocations.) And for very large requests + (>= 256Kb by default), it relies on system memory mapping + facilities, if supported. (This helps avoid carrying around and + possibly fragmenting memory used only for large chunks.) + + All operations (except malloc_stats and mallinfo) have execution + times that are bounded by a constant factor of the number of bits in + a size_t, not counting any clearing in calloc or copying in realloc, + or actions surrounding MORECORE and MMAP that have times + proportional to the number of non-contiguous regions returned by + system allocation routines, which is often just 1. In real-time + applications, you can optionally suppress segment traversals using + NO_SEGMENT_TRAVERSAL, which assures bounded execution even when + system allocators return non-contiguous spaces, at the typical + expense of carrying around more memory and increased fragmentation. + + The implementation is not very modular and seriously overuses + macros. Perhaps someday all C compilers will do as good a job + inlining modular code as can now be done by brute-force expansion, + but now, enough of them seem not to. + + Some compilers issue a lot of warnings about code that is + dead/unreachable only on some platforms, and also about intentional + uses of negation on unsigned types. All known cases of each can be + ignored. + + For a longer but out of date high-level description, see + http://gee.cs.oswego.edu/dl/html/malloc.html + +* MSPACES + If MSPACES is defined, then in addition to malloc, free, etc., + this file also defines mspace_malloc, mspace_free, etc. These + are versions of malloc routines that take an "mspace" argument + obtained using create_mspace, to control all internal bookkeeping. + If ONLY_MSPACES is defined, only these versions are compiled. + So if you would like to use this allocator for only some allocations, + and your system malloc for others, you can compile with + ONLY_MSPACES and then do something like... + static mspace mymspace = create_mspace(0,0); // for example + #define mymalloc(bytes) mspace_malloc(mymspace, bytes) + + (Note: If you only need one instance of an mspace, you can instead + use "USE_DL_PREFIX" to relabel the global malloc.) + + You can similarly create thread-local allocators by storing + mspaces as thread-locals. For example: + static __thread mspace tlms = 0; + void* tlmalloc(size_t bytes) { + if (tlms == 0) tlms = create_mspace(0, 0); + return mspace_malloc(tlms, bytes); + } + void tlfree(void* mem) { mspace_free(tlms, mem); } + + Unless FOOTERS is defined, each mspace is completely independent. + You cannot allocate from one and free to another (although + conformance is only weakly checked, so usage errors are not always + caught). If FOOTERS is defined, then each chunk carries around a tag + indicating its originating mspace, and frees are directed to their + originating spaces. + + ------------------------- Compile-time options --------------------------- + +Be careful in setting #define values for numerical constants of type +size_t. On some systems, literal values are not automatically extended +to size_t precision unless they are explicitly casted. You can also +use the symbolic values MAX_SIZE_T, SIZE_T_ONE, etc below. + +WIN32 default: defined if _WIN32 defined + Defining WIN32 sets up defaults for MS environment and compilers. + Otherwise defaults are for unix. Beware that there seem to be some + cases where this malloc might not be a pure drop-in replacement for + Win32 malloc: Random-looking failures from Win32 GDI API's (eg; + SetDIBits()) may be due to bugs in some video driver implementations + when pixel buffers are malloc()ed, and the region spans more than + one VirtualAlloc()ed region. Because dlmalloc uses a small (64Kb) + default granularity, pixel buffers may straddle virtual allocation + regions more often than when using the Microsoft allocator. You can + avoid this by using VirtualAlloc() and VirtualFree() for all pixel + buffers rather than using malloc(). If this is not possible, + recompile this malloc with a larger DEFAULT_GRANULARITY. + +MALLOC_ALIGNMENT default: (size_t)8 + Controls the minimum alignment for malloc'ed chunks. It must be a + power of two and at least 8, even on machines for which smaller + alignments would suffice. It may be defined as larger than this + though. Note however that code and data structures are optimized for + the case of 8-byte alignment. + +MSPACES default: 0 (false) + If true, compile in support for independent allocation spaces. + This is only supported if HAVE_MMAP is true. + +ONLY_MSPACES default: 0 (false) + If true, only compile in mspace versions, not regular versions. + +USE_LOCKS default: 0 (false) + Causes each call to each public routine to be surrounded with + pthread or WIN32 mutex lock/unlock. (If set true, this can be + overridden on a per-mspace basis for mspace versions.) If set to a + non-zero value other than 1, locks are used, but their + implementation is left out, so lock functions must be supplied manually. + +USE_SPIN_LOCKS default: 1 iff USE_LOCKS and on x86 using gcc or MSC + If true, uses custom spin locks for locking. This is currently + supported only for x86 platforms using gcc or recent MS compilers. + Otherwise, posix locks or win32 critical sections are used. + +FOOTERS default: 0 + If true, provide extra checking and dispatching by placing + information in the footers of allocated chunks. This adds + space and time overhead. + +INSECURE default: 0 + If true, omit checks for usage errors and heap space overwrites. + +USE_DL_PREFIX default: NOT defined + Causes compiler to prefix all public routines with the string 'dl'. + This can be useful when you only want to use this malloc in one part + of a program, using your regular system malloc elsewhere. + +ABORT default: defined as abort() + Defines how to abort on failed checks. On most systems, a failed + check cannot die with an "assert" or even print an informative + message, because the underlying print routines in turn call malloc, + which will fail again. Generally, the best policy is to simply call + abort(). It's not very useful to do more than this because many + errors due to overwriting will show up as address faults (null, odd + addresses etc) rather than malloc-triggered checks, so will also + abort. Also, most compilers know that abort() does not return, so + can better optimize code conditionally calling it. + +PROCEED_ON_ERROR default: defined as 0 (false) + Controls whether detected bad addresses cause them to bypassed + rather than aborting. If set, detected bad arguments to free and + realloc are ignored. And all bookkeeping information is zeroed out + upon a detected overwrite of freed heap space, thus losing the + ability to ever return it from malloc again, but enabling the + application to proceed. If PROCEED_ON_ERROR is defined, the + static variable malloc_corruption_error_count is compiled in + and can be examined to see if errors have occurred. This option + generates slower code than the default abort policy. + +DEBUG default: NOT defined + The DEBUG setting is mainly intended for people trying to modify + this code or diagnose problems when porting to new platforms. + However, it may also be able to better isolate user errors than just + using runtime checks. The assertions in the check routines spell + out in more detail the assumptions and invariants underlying the + algorithms. The checking is fairly extensive, and will slow down + execution noticeably. Calling malloc_stats or mallinfo with DEBUG + set will attempt to check every non-mmapped allocated and free chunk + in the course of computing the summaries. + +ABORT_ON_ASSERT_FAILURE default: defined as 1 (true) + Debugging assertion failures can be nearly impossible if your + version of the assert macro causes malloc to be called, which will + lead to a cascade of further failures, blowing the runtime stack. + ABORT_ON_ASSERT_FAILURE cause assertions failures to call abort(), + which will usually make debugging easier. + +MALLOC_FAILURE_ACTION default: sets errno to ENOMEM, or no-op on win32 + The action to take before "return 0" when malloc fails to be able to + return memory because there is none available. + +HAVE_MORECORE default: 1 (true) unless win32 or ONLY_MSPACES + True if this system supports sbrk or an emulation of it. + +MORECORE default: sbrk + The name of the sbrk-style system routine to call to obtain more + memory. See below for guidance on writing custom MORECORE + functions. The type of the argument to sbrk/MORECORE varies across + systems. It cannot be size_t, because it supports negative + arguments, so it is normally the signed type of the same width as + size_t (sometimes declared as "intptr_t"). It doesn't much matter + though. Internally, we only call it with arguments less than half + the max value of a size_t, which should work across all reasonable + possibilities, although sometimes generating compiler warnings. + +MORECORE_CONTIGUOUS default: 1 (true) if HAVE_MORECORE + If true, take advantage of fact that consecutive calls to MORECORE + with positive arguments always return contiguous increasing + addresses. This is true of unix sbrk. It does not hurt too much to + set it true anyway, since malloc copes with non-contiguities. + Setting it false when definitely non-contiguous saves time + and possibly wasted space it would take to discover this though. + +MORECORE_CANNOT_TRIM default: NOT defined + True if MORECORE cannot release space back to the system when given + negative arguments. This is generally necessary only if you are + using a hand-crafted MORECORE function that cannot handle negative + arguments. + +NO_SEGMENT_TRAVERSAL default: 0 + If non-zero, suppresses traversals of memory segments + returned by either MORECORE or CALL_MMAP. This disables + merging of segments that are contiguous, and selectively + releasing them to the OS if unused, but bounds execution times. + +HAVE_MMAP default: 1 (true) + True if this system supports mmap or an emulation of it. If so, and + HAVE_MORECORE is not true, MMAP is used for all system + allocation. If set and HAVE_MORECORE is true as well, MMAP is + primarily used to directly allocate very large blocks. It is also + used as a backup strategy in cases where MORECORE fails to provide + space from system. Note: A single call to MUNMAP is assumed to be + able to unmap memory that may have be allocated using multiple calls + to MMAP, so long as they are adjacent. + +HAVE_MREMAP default: 1 on linux, else 0 + If true realloc() uses mremap() to re-allocate large blocks and + extend or shrink allocation spaces. + +MMAP_CLEARS default: 1 except on WINCE. + True if mmap clears memory so calloc doesn't need to. This is true + for standard unix mmap using /dev/zero and on WIN32 except for WINCE. + +USE_BUILTIN_FFS default: 0 (i.e., not used) + Causes malloc to use the builtin ffs() function to compute indices. + Some compilers may recognize and intrinsify ffs to be faster than the + supplied C version. Also, the case of x86 using gcc is special-cased + to an asm instruction, so is already as fast as it can be, and so + this setting has no effect. Similarly for Win32 under recent MS compilers. + (On most x86s, the asm version is only slightly faster than the C version.) + +malloc_getpagesize default: derive from system includes, or 4096. + The system page size. To the extent possible, this malloc manages + memory from the system in page-size units. This may be (and + usually is) a function rather than a constant. This is ignored + if WIN32, where page size is determined using getSystemInfo during + initialization. + +USE_DEV_RANDOM default: 0 (i.e., not used) + Causes malloc to use /dev/random to initialize secure magic seed for + stamping footers. Otherwise, the current time is used. + +NO_MALLINFO default: 0 + If defined, don't compile "mallinfo". This can be a simple way + of dealing with mismatches between system declarations and + those in this file. + +MALLINFO_FIELD_TYPE default: size_t + The type of the fields in the mallinfo struct. This was originally + defined as "int" in SVID etc, but is more usefully defined as + size_t. The value is used only if HAVE_USR_INCLUDE_MALLOC_H is not set + +REALLOC_ZERO_BYTES_FREES default: not defined + This should be set if a call to realloc with zero bytes should + be the same as a call to free. Some people think it should. Otherwise, + since this malloc returns a unique pointer for malloc(0), so does + realloc(p, 0). + +LACKS_UNISTD_H, LACKS_FCNTL_H, LACKS_SYS_PARAM_H, LACKS_SYS_MMAN_H +LACKS_STRINGS_H, LACKS_STRING_H, LACKS_SYS_TYPES_H, LACKS_ERRNO_H +LACKS_STDLIB_H default: NOT defined unless on WIN32 + Define these if your system does not have these header files. + You might need to manually insert some of the declarations they provide. + +DEFAULT_GRANULARITY default: page size if MORECORE_CONTIGUOUS, + system_info.dwAllocationGranularity in WIN32, + otherwise 64K. + Also settable using mallopt(M_GRANULARITY, x) + The unit for allocating and deallocating memory from the system. On + most systems with contiguous MORECORE, there is no reason to + make this more than a page. However, systems with MMAP tend to + either require or encourage larger granularities. You can increase + this value to prevent system allocation functions to be called so + often, especially if they are slow. The value must be at least one + page and must be a power of two. Setting to 0 causes initialization + to either page size or win32 region size. (Note: In previous + versions of malloc, the equivalent of this option was called + "TOP_PAD") + +DEFAULT_TRIM_THRESHOLD default: 2MB + Also settable using mallopt(M_TRIM_THRESHOLD, x) + The maximum amount of unused top-most memory to keep before + releasing via malloc_trim in free(). Automatic trimming is mainly + useful in long-lived programs using contiguous MORECORE. Because + trimming via sbrk can be slow on some systems, and can sometimes be + wasteful (in cases where programs immediately afterward allocate + more large chunks) the value should be high enough so that your + overall system performance would improve by releasing this much + memory. As a rough guide, you might set to a value close to the + average size of a process (program) running on your system. + Releasing this much memory would allow such a process to run in + memory. Generally, it is worth tuning trim thresholds when a + program undergoes phases where several large chunks are allocated + and released in ways that can reuse each other's storage, perhaps + mixed with phases where there are no such chunks at all. The trim + value must be greater than page size to have any useful effect. To + disable trimming completely, you can set to MAX_SIZE_T. Note that the trick + some people use of mallocing a huge space and then freeing it at + program startup, in an attempt to reserve system memory, doesn't + have the intended effect under automatic trimming, since that memory + will immediately be returned to the system. + +DEFAULT_MMAP_THRESHOLD default: 256K + Also settable using mallopt(M_MMAP_THRESHOLD, x) + The request size threshold for using MMAP to directly service a + request. Requests of at least this size that cannot be allocated + using already-existing space will be serviced via mmap. (If enough + normal freed space already exists it is used instead.) Using mmap + segregates relatively large chunks of memory so that they can be + individually obtained and released from the host system. A request + serviced through mmap is never reused by any other request (at least + not directly; the system may just so happen to remap successive + requests to the same locations). Segregating space in this way has + the benefits that: Mmapped space can always be individually released + back to the system, which helps keep the system level memory demands + of a long-lived program low. Also, mapped memory doesn't become + `locked' between other chunks, as can happen with normally allocated + chunks, which means that even trimming via malloc_trim would not + release them. However, it has the disadvantage that the space + cannot be reclaimed, consolidated, and then used to service later + requests, as happens with normal chunks. The advantages of mmap + nearly always outweigh disadvantages for "large" chunks, but the + value of "large" may vary across systems. The default is an + empirically derived value that works well in most systems. You can + disable mmap by setting to MAX_SIZE_T. + +MAX_RELEASE_CHECK_RATE default: 4095 unless not HAVE_MMAP + The number of consolidated frees between checks to release + unused segments when freeing. When using non-contiguous segments, + especially with multiple mspaces, checking only for topmost space + doesn't always suffice to trigger trimming. To compensate for this, + free() will, with a period of MAX_RELEASE_CHECK_RATE (or the + current number of segments, if greater) try to release unused + segments to the OS when freeing chunks that result in + consolidation. The best value for this parameter is a compromise + between slowing down frees with relatively costly checks that + rarely trigger versus holding on to unused memory. To effectively + disable, set to MAX_SIZE_T. This may lead to a very slight speed + improvement at the expense of carrying around more memory. +*/ + +/* Version identifier to allow people to support multiple versions */ +#ifndef DLMALLOC_VERSION +#define DLMALLOC_VERSION 20804 +#endif /* DLMALLOC_VERSION */ + +#ifndef WIN32 +#ifdef _WIN32 +#define WIN32 1 +#endif /* _WIN32 */ +#ifdef _WIN32_WCE +#define LACKS_FCNTL_H +#define WIN32 1 +#endif /* _WIN32_WCE */ +#endif /* WIN32 */ +#ifdef WIN32 +#define WIN32_LEAN_AND_MEAN +#define _WIN32_WINNT 0x403 +#include <windows.h> +#define HAVE_MMAP 1 +#define HAVE_MORECORE 0 +#define LACKS_UNISTD_H +#define LACKS_SYS_PARAM_H +#define LACKS_SYS_MMAN_H +#define LACKS_STRING_H +#define LACKS_STRINGS_H +#define LACKS_SYS_TYPES_H +#define LACKS_ERRNO_H +#ifndef MALLOC_FAILURE_ACTION +#define MALLOC_FAILURE_ACTION +#endif /* MALLOC_FAILURE_ACTION */ +#ifdef _WIN32_WCE /* WINCE reportedly does not clear */ +#define MMAP_CLEARS 0 +#else +#define MMAP_CLEARS 1 +#endif /* _WIN32_WCE */ +#endif /* WIN32 */ + +#if defined(DARWIN) || defined(_DARWIN) +/* Mac OSX docs advise not to use sbrk; it seems better to use mmap */ +#ifndef HAVE_MORECORE +#define HAVE_MORECORE 0 +#define HAVE_MMAP 1 +/* OSX allocators provide 16 byte alignment */ +#ifndef MALLOC_ALIGNMENT +#define MALLOC_ALIGNMENT ((size_t)16U) +#endif +#endif /* HAVE_MORECORE */ +#endif /* DARWIN */ + +#ifndef LACKS_SYS_TYPES_H +#include <sys/types.h> /* For size_t */ +#endif /* LACKS_SYS_TYPES_H */ + +/* The maximum possible size_t value has all bits set */ +#define MAX_SIZE_T (~(size_t)0) + +#ifndef ONLY_MSPACES +#define ONLY_MSPACES 0 /* define to a value */ +#else +#define ONLY_MSPACES 1 +#endif /* ONLY_MSPACES */ +#ifndef MSPACES +#if ONLY_MSPACES +#define MSPACES 1 +#else /* ONLY_MSPACES */ +#define MSPACES 0 +#endif /* ONLY_MSPACES */ +#endif /* MSPACES */ +#ifndef MALLOC_ALIGNMENT +#define MALLOC_ALIGNMENT ((size_t)8U) +#endif /* MALLOC_ALIGNMENT */ +#ifndef FOOTERS +#define FOOTERS 0 +#endif /* FOOTERS */ +#ifndef ABORT +#define ABORT abort() +#endif /* ABORT */ +#ifndef ABORT_ON_ASSERT_FAILURE +#define ABORT_ON_ASSERT_FAILURE 1 +#endif /* ABORT_ON_ASSERT_FAILURE */ +#ifndef PROCEED_ON_ERROR +#define PROCEED_ON_ERROR 0 +#endif /* PROCEED_ON_ERROR */ +#ifndef USE_LOCKS +#define USE_LOCKS 0 +#endif /* USE_LOCKS */ +#ifndef USE_SPIN_LOCKS +#if USE_LOCKS && (defined(__GNUC__) && ((defined(__i386__) || defined(__x86_64__)))) || (defined(_MSC_VER) && _MSC_VER>=1310) +#define USE_SPIN_LOCKS 1 +#else +#define USE_SPIN_LOCKS 0 +#endif /* USE_LOCKS && ... */ +#endif /* USE_SPIN_LOCKS */ +#ifndef INSECURE +#define INSECURE 0 +#endif /* INSECURE */ +#ifndef HAVE_MMAP +#define HAVE_MMAP 1 +#endif /* HAVE_MMAP */ +#ifndef MMAP_CLEARS +#define MMAP_CLEARS 1 +#endif /* MMAP_CLEARS */ +#ifndef HAVE_MREMAP +#ifdef linux +#define HAVE_MREMAP 1 +#else /* linux */ +#define HAVE_MREMAP 0 +#endif /* linux */ +#endif /* HAVE_MREMAP */ +#ifndef MALLOC_FAILURE_ACTION +#define MALLOC_FAILURE_ACTION errno = ENOMEM; +#endif /* MALLOC_FAILURE_ACTION */ +#ifndef HAVE_MORECORE +#if ONLY_MSPACES +#define HAVE_MORECORE 0 +#else /* ONLY_MSPACES */ +#define HAVE_MORECORE 1 +#endif /* ONLY_MSPACES */ +#endif /* HAVE_MORECORE */ +#if !HAVE_MORECORE +#define MORECORE_CONTIGUOUS 0 +#else /* !HAVE_MORECORE */ +#define MORECORE_DEFAULT sbrk +#ifndef MORECORE_CONTIGUOUS +#define MORECORE_CONTIGUOUS 1 +#endif /* MORECORE_CONTIGUOUS */ +#endif /* HAVE_MORECORE */ +#ifndef DEFAULT_GRANULARITY +#if (MORECORE_CONTIGUOUS || defined(WIN32)) +#define DEFAULT_GRANULARITY (0) /* 0 means to compute in init_mparams */ +#else /* MORECORE_CONTIGUOUS */ +#define DEFAULT_GRANULARITY ((size_t)64U * (size_t)1024U) +#endif /* MORECORE_CONTIGUOUS */ +#endif /* DEFAULT_GRANULARITY */ +#ifndef DEFAULT_TRIM_THRESHOLD +#ifndef MORECORE_CANNOT_TRIM +#define DEFAULT_TRIM_THRESHOLD ((size_t)2U * (size_t)1024U * (size_t)1024U) +#else /* MORECORE_CANNOT_TRIM */ +#define DEFAULT_TRIM_THRESHOLD MAX_SIZE_T +#endif /* MORECORE_CANNOT_TRIM */ +#endif /* DEFAULT_TRIM_THRESHOLD */ +#ifndef DEFAULT_MMAP_THRESHOLD +#if HAVE_MMAP +#define DEFAULT_MMAP_THRESHOLD ((size_t)256U * (size_t)1024U) +#else /* HAVE_MMAP */ +#define DEFAULT_MMAP_THRESHOLD MAX_SIZE_T +#endif /* HAVE_MMAP */ +#endif /* DEFAULT_MMAP_THRESHOLD */ +#ifndef MAX_RELEASE_CHECK_RATE +#if HAVE_MMAP +#define MAX_RELEASE_CHECK_RATE 4095 +#else +#define MAX_RELEASE_CHECK_RATE MAX_SIZE_T +#endif /* HAVE_MMAP */ +#endif /* MAX_RELEASE_CHECK_RATE */ +#ifndef USE_BUILTIN_FFS +#define USE_BUILTIN_FFS 0 +#endif /* USE_BUILTIN_FFS */ +#ifndef USE_DEV_RANDOM +#define USE_DEV_RANDOM 0 +#endif /* USE_DEV_RANDOM */ +#ifndef NO_MALLINFO +#define NO_MALLINFO 0 +#endif /* NO_MALLINFO */ +#ifndef MALLINFO_FIELD_TYPE +#define MALLINFO_FIELD_TYPE size_t +#endif /* MALLINFO_FIELD_TYPE */ +#ifndef NO_SEGMENT_TRAVERSAL +#define NO_SEGMENT_TRAVERSAL 0 +#endif /* NO_SEGMENT_TRAVERSAL */ + +/* + mallopt tuning options. SVID/XPG defines four standard parameter + numbers for mallopt, normally defined in malloc.h. None of these + are used in this malloc, so setting them has no effect. But this + malloc does support the following options. +*/ + +#define M_TRIM_THRESHOLD (-1) +#define M_GRANULARITY (-2) +#define M_MMAP_THRESHOLD (-3) + +/* ------------------------ Mallinfo declarations ------------------------ */ + +#if !NO_MALLINFO +/* + This version of malloc supports the standard SVID/XPG mallinfo + routine that returns a struct containing usage properties and + statistics. It should work on any system that has a + /usr/include/malloc.h defining struct mallinfo. The main + declaration needed is the mallinfo struct that is returned (by-copy) + by mallinfo(). The malloinfo struct contains a bunch of fields that + are not even meaningful in this version of malloc. These fields are + are instead filled by mallinfo() with other numbers that might be of + interest. + + HAVE_USR_INCLUDE_MALLOC_H should be set if you have a + /usr/include/malloc.h file that includes a declaration of struct + mallinfo. If so, it is included; else a compliant version is + declared below. These must be precisely the same for mallinfo() to + work. The original SVID version of this struct, defined on most + systems with mallinfo, declares all fields as ints. But some others + define as unsigned long. If your system defines the fields using a + type of different width than listed here, you MUST #include your + system version and #define HAVE_USR_INCLUDE_MALLOC_H. +*/ + +/* #define HAVE_USR_INCLUDE_MALLOC_H */ + +#ifdef HAVE_USR_INCLUDE_MALLOC_H +#include "/usr/include/malloc.h" +#else /* HAVE_USR_INCLUDE_MALLOC_H */ +#ifndef STRUCT_MALLINFO_DECLARED +#define STRUCT_MALLINFO_DECLARED 1 +struct mallinfo { + MALLINFO_FIELD_TYPE arena; /* non-mmapped space allocated from system */ + MALLINFO_FIELD_TYPE ordblks; /* number of free chunks */ + MALLINFO_FIELD_TYPE smblks; /* always 0 */ + MALLINFO_FIELD_TYPE hblks; /* always 0 */ + MALLINFO_FIELD_TYPE hblkhd; /* space in mmapped regions */ + MALLINFO_FIELD_TYPE usmblks; /* maximum total allocated space */ + MALLINFO_FIELD_TYPE fsmblks; /* always 0 */ + MALLINFO_FIELD_TYPE uordblks; /* total allocated space */ + MALLINFO_FIELD_TYPE fordblks; /* total free space */ + MALLINFO_FIELD_TYPE keepcost; /* releasable (via malloc_trim) space */ +}; +#endif /* STRUCT_MALLINFO_DECLARED */ +#endif /* HAVE_USR_INCLUDE_MALLOC_H */ +#endif /* NO_MALLINFO */ + +/* + Try to persuade compilers to inline. The most critical functions for + inlining are defined as macros, so these aren't used for them. +*/ + +#ifndef FORCEINLINE + #if defined(__GNUC__) +#define FORCEINLINE __inline __attribute__ ((always_inline)) + #elif defined(_MSC_VER) + #define FORCEINLINE __forceinline + #endif +#endif +#ifndef NOINLINE + #if defined(__GNUC__) + #define NOINLINE __attribute__ ((noinline)) + #elif defined(_MSC_VER) + #define NOINLINE __declspec(noinline) + #else + #define NOINLINE + #endif +#endif + +#ifdef __cplusplus +extern "C" { +#ifndef FORCEINLINE + #define FORCEINLINE inline +#endif +#endif /* __cplusplus */ +#ifndef FORCEINLINE + #define FORCEINLINE +#endif + +#if !ONLY_MSPACES + +/* ------------------- Declarations of public routines ------------------- */ + +#ifndef USE_DL_PREFIX +#define dlcalloc calloc +#define dlfree free +#define dlmalloc malloc +#define dlmemalign memalign +#define dlrealloc realloc +#define dlvalloc valloc +#define dlpvalloc pvalloc +#define dlmallinfo mallinfo +#define dlmallopt mallopt +#define dlmalloc_trim malloc_trim +#define dlmalloc_stats malloc_stats +#define dlmalloc_usable_size malloc_usable_size +#define dlmalloc_footprint malloc_footprint +#define dlmalloc_max_footprint malloc_max_footprint +#define dlindependent_calloc independent_calloc +#define dlindependent_comalloc independent_comalloc +#endif /* USE_DL_PREFIX */ + + +/* + malloc(size_t n) + Returns a pointer to a newly allocated chunk of at least n bytes, or + null if no space is available, in which case errno is set to ENOMEM + on ANSI C systems. + + If n is zero, malloc returns a minimum-sized chunk. (The minimum + size is 16 bytes on most 32bit systems, and 32 bytes on 64bit + systems.) Note that size_t is an unsigned type, so calls with + arguments that would be negative if signed are interpreted as + requests for huge amounts of space, which will often fail. The + maximum supported value of n differs across systems, but is in all + cases less than the maximum representable value of a size_t. +*/ +void* dlmalloc(size_t); + +/* + free(void* p) + Releases the chunk of memory pointed to by p, that had been previously + allocated using malloc or a related routine such as realloc. + It has no effect if p is null. If p was not malloced or already + freed, free(p) will by default cause the current program to abort. +*/ +void dlfree(void*); + +/* + calloc(size_t n_elements, size_t element_size); + Returns a pointer to n_elements * element_size bytes, with all locations + set to zero. +*/ +void* dlcalloc(size_t, size_t); + +/* + realloc(void* p, size_t n) + Returns a pointer to a chunk of size n that contains the same data + as does chunk p up to the minimum of (n, p's size) bytes, or null + if no space is available. + + The returned pointer may or may not be the same as p. The algorithm + prefers extending p in most cases when possible, otherwise it + employs the equivalent of a malloc-copy-free sequence. + + If p is null, realloc is equivalent to malloc. + + If space is not available, realloc returns null, errno is set (if on + ANSI) and p is NOT freed. + + if n is for fewer bytes than already held by p, the newly unused + space is lopped off and freed if possible. realloc with a size + argument of zero (re)allocates a minimum-sized chunk. + + The old unix realloc convention of allowing the last-free'd chunk + to be used as an argument to realloc is not supported. +*/ + +void* dlrealloc(void*, size_t); + +/* + memalign(size_t alignment, size_t n); + Returns a pointer to a newly allocated chunk of n bytes, aligned + in accord with the alignment argument. + + The alignment argument should be a power of two. If the argument is + not a power of two, the nearest greater power is used. + 8-byte alignment is guaranteed by normal malloc calls, so don't + bother calling memalign with an argument of 8 or less. + + Overreliance on memalign is a sure way to fragment space. +*/ +void* dlmemalign(size_t, size_t); + +/* + valloc(size_t n); + Equivalent to memalign(pagesize, n), where pagesize is the page + size of the system. If the pagesize is unknown, 4096 is used. +*/ +void* dlvalloc(size_t); + +/* + mallopt(int parameter_number, int parameter_value) + Sets tunable parameters The format is to provide a + (parameter-number, parameter-value) pair. mallopt then sets the + corresponding parameter to the argument value if it can (i.e., so + long as the value is meaningful), and returns 1 if successful else + 0. To workaround the fact that mallopt is specified to use int, + not size_t parameters, the value -1 is specially treated as the + maximum unsigned size_t value. + + SVID/XPG/ANSI defines four standard param numbers for mallopt, + normally defined in malloc.h. None of these are use in this malloc, + so setting them has no effect. But this malloc also supports other + options in mallopt. See below for details. Briefly, supported + parameters are as follows (listed defaults are for "typical" + configurations). + + Symbol param # default allowed param values + M_TRIM_THRESHOLD -1 2*1024*1024 any (-1 disables) + M_GRANULARITY -2 page size any power of 2 >= page size + M_MMAP_THRESHOLD -3 256*1024 any (or 0 if no MMAP support) +*/ +int dlmallopt(int, int); + +/* + malloc_footprint(); + Returns the number of bytes obtained from the system. The total + number of bytes allocated by malloc, realloc etc., is less than this + value. Unlike mallinfo, this function returns only a precomputed + result, so can be called frequently to monitor memory consumption. + Even if locks are otherwise defined, this function does not use them, + so results might not be up to date. +*/ +size_t dlmalloc_footprint(void); + +/* + malloc_max_footprint(); + Returns the maximum number of bytes obtained from the system. This + value will be greater than current footprint if deallocated space + has been reclaimed by the system. The peak number of bytes allocated + by malloc, realloc etc., is less than this value. Unlike mallinfo, + this function returns only a precomputed result, so can be called + frequently to monitor memory consumption. Even if locks are + otherwise defined, this function does not use them, so results might + not be up to date. +*/ +size_t dlmalloc_max_footprint(void); + +#if !NO_MALLINFO +/* + mallinfo() + Returns (by copy) a struct containing various summary statistics: + + arena: current total non-mmapped bytes allocated from system + ordblks: the number of free chunks + smblks: always zero. + hblks: current number of mmapped regions + hblkhd: total bytes held in mmapped regions + usmblks: the maximum total allocated space. This will be greater + than current total if trimming has occurred. + fsmblks: always zero + uordblks: current total allocated space (normal or mmapped) + fordblks: total free space + keepcost: the maximum number of bytes that could ideally be released + back to system via malloc_trim. ("ideally" means that + it ignores page restrictions etc.) + + Because these fields are ints, but internal bookkeeping may + be kept as longs, the reported values may wrap around zero and + thus be inaccurate. +*/ +struct mallinfo dlmallinfo(void); +#endif /* NO_MALLINFO */ + +/* + independent_calloc(size_t n_elements, size_t element_size, void* chunks[]); + + independent_calloc is similar to calloc, but instead of returning a + single cleared space, it returns an array of pointers to n_elements + independent elements that can hold contents of size elem_size, each + of which starts out cleared, and can be independently freed, + realloc'ed etc. The elements are guaranteed to be adjacently + allocated (this is not guaranteed to occur with multiple callocs or + mallocs), which may also improve cache locality in some + applications. + + The "chunks" argument is optional (i.e., may be null, which is + probably the most typical usage). If it is null, the returned array + is itself dynamically allocated and should also be freed when it is + no longer needed. Otherwise, the chunks array must be of at least + n_elements in length. It is filled in with the pointers to the + chunks. + + In either case, independent_calloc returns this pointer array, or + null if the allocation failed. If n_elements is zero and "chunks" + is null, it returns a chunk representing an array with zero elements + (which should be freed if not wanted). + + Each element must be individually freed when it is no longer + needed. If you'd like to instead be able to free all at once, you + should instead use regular calloc and assign pointers into this + space to represent elements. (In this case though, you cannot + independently free elements.) + + independent_calloc simplifies and speeds up implementations of many + kinds of pools. It may also be useful when constructing large data + structures that initially have a fixed number of fixed-sized nodes, + but the number is not known at compile time, and some of the nodes + may later need to be freed. For example: + + struct Node { int item; struct Node* next; }; + + struct Node* build_list() { + struct Node** pool; + int n = read_number_of_nodes_needed(); + if (n <= 0) return 0; + pool = (struct Node**)(independent_calloc(n, sizeof(struct Node), 0); + if (pool == 0) die(); + // organize into a linked list... + struct Node* first = pool[0]; + for (i = 0; i < n-1; ++i) + pool[i]->next = pool[i+1]; + free(pool); // Can now free the array (or not, if it is needed later) + return first; + } +*/ +void** dlindependent_calloc(size_t, size_t, void**); + +/* + independent_comalloc(size_t n_elements, size_t sizes[], void* chunks[]); + + independent_comalloc allocates, all at once, a set of n_elements + chunks with sizes indicated in the "sizes" array. It returns + an array of pointers to these elements, each of which can be + independently freed, realloc'ed etc. The elements are guaranteed to + be adjacently allocated (this is not guaranteed to occur with + multiple callocs or mallocs), which may also improve cache locality + in some applications. + + The "chunks" argument is optional (i.e., may be null). If it is null + the returned array is itself dynamically allocated and should also + be freed when it is no longer needed. Otherwise, the chunks array + must be of at least n_elements in length. It is filled in with the + pointers to the chunks. + + In either case, independent_comalloc returns this pointer array, or + null if the allocation failed. If n_elements is zero and chunks is + null, it returns a chunk representing an array with zero elements + (which should be freed if not wanted). + + Each element must be individually freed when it is no longer + needed. If you'd like to instead be able to free all at once, you + should instead use a single regular malloc, and assign pointers at + particular offsets in the aggregate space. (In this case though, you + cannot independently free elements.) + + independent_comallac differs from independent_calloc in that each + element may have a different size, and also that it does not + automatically clear elements. + + independent_comalloc can be used to speed up allocation in cases + where several structs or objects must always be allocated at the + same time. For example: + + struct Head { ... } + struct Foot { ... } + + void send_message(char* msg) { + int msglen = strlen(msg); + size_t sizes[3] = { sizeof(struct Head), msglen, sizeof(struct Foot) }; + void* chunks[3]; + if (independent_comalloc(3, sizes, chunks) == 0) + die(); + struct Head* head = (struct Head*)(chunks[0]); + char* body = (char*)(chunks[1]); + struct Foot* foot = (struct Foot*)(chunks[2]); + // ... + } + + In general though, independent_comalloc is worth using only for + larger values of n_elements. For small values, you probably won't + detect enough difference from series of malloc calls to bother. + + Overuse of independent_comalloc can increase overall memory usage, + since it cannot reuse existing noncontiguous small chunks that + might be available for some of the elements. +*/ +void** dlindependent_comalloc(size_t, size_t*, void**); + + +/* + pvalloc(size_t n); + Equivalent to valloc(minimum-page-that-holds(n)), that is, + round up n to nearest pagesize. + */ +void* dlpvalloc(size_t); + +/* + malloc_trim(size_t pad); + + If possible, gives memory back to the system (via negative arguments + to sbrk) if there is unused memory at the `high' end of the malloc + pool or in unused MMAP segments. You can call this after freeing + large blocks of memory to potentially reduce the system-level memory + requirements of a program. However, it cannot guarantee to reduce + memory. Under some allocation patterns, some large free blocks of + memory will be locked between two used chunks, so they cannot be + given back to the system. + + The `pad' argument to malloc_trim represents the amount of free + trailing space to leave untrimmed. If this argument is zero, only + the minimum amount of memory to maintain internal data structures + will be left. Non-zero arguments can be supplied to maintain enough + trailing space to service future expected allocations without having + to re-obtain memory from the system. + + Malloc_trim returns 1 if it actually released any memory, else 0. +*/ +int dlmalloc_trim(size_t); + +/* + malloc_stats(); + Prints on stderr the amount of space obtained from the system (both + via sbrk and mmap), the maximum amount (which may be more than + current if malloc_trim and/or munmap got called), and the current + number of bytes allocated via malloc (or realloc, etc) but not yet + freed. Note that this is the number of bytes allocated, not the + number requested. It will be larger than the number requested + because of alignment and bookkeeping overhead. Because it includes + alignment wastage as being in use, this figure may be greater than + zero even when no user-level chunks are allocated. + + The reported current and maximum system memory can be inaccurate if + a program makes other calls to system memory allocation functions + (normally sbrk) outside of malloc. + + malloc_stats prints only the most commonly interesting statistics. + More information can be obtained by calling mallinfo. +*/ +void dlmalloc_stats(void); + +#endif /* ONLY_MSPACES */ + +/* + malloc_usable_size(void* p); + + Returns the number of bytes you can actually use in + an allocated chunk, which may be more than you requested (although + often not) due to alignment and minimum size constraints. + You can use this many bytes without worrying about + overwriting other allocated objects. This is not a particularly great + programming practice. malloc_usable_size can be more useful in + debugging and assertions, for example: + + p = malloc(n); + assert(malloc_usable_size(p) >= 256); +*/ +size_t dlmalloc_usable_size(void*); + + +#if MSPACES + +/* + mspace is an opaque type representing an independent + region of space that supports mspace_malloc, etc. +*/ +typedef void* mspace; + +/* + create_mspace creates and returns a new independent space with the + given initial capacity, or, if 0, the default granularity size. It + returns null if there is no system memory available to create the + space. If argument locked is non-zero, the space uses a separate + lock to control access. The capacity of the space will grow + dynamically as needed to service mspace_malloc requests. You can + control the sizes of incremental increases of this space by + compiling with a different DEFAULT_GRANULARITY or dynamically + setting with mallopt(M_GRANULARITY, value). +*/ +mspace create_mspace(size_t capacity, int locked); + +/* + destroy_mspace destroys the given space, and attempts to return all + of its memory back to the system, returning the total number of + bytes freed. After destruction, the results of access to all memory + used by the space become undefined. +*/ +size_t destroy_mspace(mspace msp); + +/* + create_mspace_with_base uses the memory supplied as the initial base + of a new mspace. Part (less than 128*sizeof(size_t) bytes) of this + space is used for bookkeeping, so the capacity must be at least this + large. (Otherwise 0 is returned.) When this initial space is + exhausted, additional memory will be obtained from the system. + Destroying this space will deallocate all additionally allocated + space (if possible) but not the initial base. +*/ +mspace create_mspace_with_base(void* base, size_t capacity, int locked); + +/* + mspace_mmap_large_chunks controls whether requests for large chunks + are allocated in their own mmapped regions, separate from others in + this mspace. By default this is enabled, which reduces + fragmentation. However, such chunks are not necessarily released to + the system upon destroy_mspace. Disabling by setting to false may + increase fragmentation, but avoids leakage when relying on + destroy_mspace to release all memory allocated using this space. +*/ +int mspace_mmap_large_chunks(mspace msp, int enable); + + +/* + mspace_malloc behaves as malloc, but operates within + the given space. +*/ +void* mspace_malloc(mspace msp, size_t bytes); + +/* + mspace_free behaves as free, but operates within + the given space. + + If compiled with FOOTERS==1, mspace_free is not actually needed. + free may be called instead of mspace_free because freed chunks from + any space are handled by their originating spaces. +*/ +void mspace_free(mspace msp, void* mem); + +/* + mspace_realloc behaves as realloc, but operates within + the given space. + + If compiled with FOOTERS==1, mspace_realloc is not actually + needed. realloc may be called instead of mspace_realloc because + realloced chunks from any space are handled by their originating + spaces. +*/ +void* mspace_realloc(mspace msp, void* mem, size_t newsize); + +/* + mspace_calloc behaves as calloc, but operates within + the given space. +*/ +void* mspace_calloc(mspace msp, size_t n_elements, size_t elem_size); + +/* + mspace_memalign behaves as memalign, but operates within + the given space. +*/ +void* mspace_memalign(mspace msp, size_t alignment, size_t bytes); + +/* + mspace_independent_calloc behaves as independent_calloc, but + operates within the given space. +*/ +void** mspace_independent_calloc(mspace msp, size_t n_elements, + size_t elem_size, void* chunks[]); + +/* + mspace_independent_comalloc behaves as independent_comalloc, but + operates within the given space. +*/ +void** mspace_independent_comalloc(mspace msp, size_t n_elements, + size_t sizes[], void* chunks[]); + +/* + mspace_footprint() returns the number of bytes obtained from the + system for this space. +*/ +size_t mspace_footprint(mspace msp); + +/* + mspace_max_footprint() returns the peak number of bytes obtained from the + system for this space. +*/ +size_t mspace_max_footprint(mspace msp); + + +#if !NO_MALLINFO +/* + mspace_mallinfo behaves as mallinfo, but reports properties of + the given space. +*/ +struct mallinfo mspace_mallinfo(mspace msp); +#endif /* NO_MALLINFO */ + +/* + malloc_usable_size(void* p) behaves the same as malloc_usable_size; +*/ + size_t mspace_usable_size(void* mem); + +/* + mspace_malloc_stats behaves as malloc_stats, but reports + properties of the given space. +*/ +void mspace_malloc_stats(mspace msp); + +/* + mspace_trim behaves as malloc_trim, but + operates within the given space. +*/ +int mspace_trim(mspace msp, size_t pad); + +/* + An alias for mallopt. +*/ +int mspace_mallopt(int, int); + +#endif /* MSPACES */ + +#ifdef __cplusplus +}; /* end of extern "C" */ +#endif /* __cplusplus */ + +/* + ======================================================================== + To make a fully customizable malloc.h header file, cut everything + above this line, put into file malloc.h, edit to suit, and #include it + on the next line, as well as in programs that use this malloc. + ======================================================================== +*/ + +/* #include "malloc.h" */ + +/*------------------------------ internal #includes ---------------------- */ + +#ifdef WIN32 +#ifndef __GNUC__ +#pragma warning( disable : 4146 ) /* no "unsigned" warnings */ +#endif +#endif /* WIN32 */ + +#include <stdio.h> /* for printing in malloc_stats */ + +#ifndef LACKS_ERRNO_H +#include <errno.h> /* for MALLOC_FAILURE_ACTION */ +#endif /* LACKS_ERRNO_H */ +#if FOOTERS +#include <time.h> /* for magic initialization */ +#endif /* FOOTERS */ +#ifndef LACKS_STDLIB_H +#include <stdlib.h> /* for abort() */ +#endif /* LACKS_STDLIB_H */ +#ifdef DEBUG +#if ABORT_ON_ASSERT_FAILURE +#define assert(x) if(!(x)) ABORT +#else /* ABORT_ON_ASSERT_FAILURE */ +#include <assert.h> +#endif /* ABORT_ON_ASSERT_FAILURE */ +#else /* DEBUG */ +#ifndef assert +#define assert(x) +#endif +#define DEBUG 0 +#endif /* DEBUG */ +#ifndef LACKS_STRING_H +#include <string.h> /* for memset etc */ +#endif /* LACKS_STRING_H */ +#if USE_BUILTIN_FFS +#ifndef LACKS_STRINGS_H +#include <strings.h> /* for ffs */ +#endif /* LACKS_STRINGS_H */ +#endif /* USE_BUILTIN_FFS */ +#if HAVE_MMAP +#ifndef LACKS_SYS_MMAN_H +#include <sys/mman.h> /* for mmap */ +#endif /* LACKS_SYS_MMAN_H */ +#ifndef LACKS_FCNTL_H +#include <fcntl.h> +#endif /* LACKS_FCNTL_H */ +#endif /* HAVE_MMAP */ +#ifndef LACKS_UNISTD_H +#include <unistd.h> /* for sbrk, sysconf */ +#else /* LACKS_UNISTD_H */ +#if !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__NetBSD__) +extern void* sbrk(ptrdiff_t); +#endif /* FreeBSD etc */ +#endif /* LACKS_UNISTD_H */ + +/* Declarations for locking */ +#if USE_LOCKS +#ifndef WIN32 +#include <pthread.h> +#if defined (__SVR4) && defined (__sun) /* solaris */ +#include <thread.h> +#endif /* solaris */ +#else +#ifndef _M_AMD64 +/* These are already defined on AMD64 builds */ +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ +#ifndef __MINGW32__ +LONG __cdecl _InterlockedCompareExchange(LONG volatile *Dest, LONG Exchange, LONG Comp); +LONG __cdecl _InterlockedExchange(LONG volatile *Target, LONG Value); +#endif +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif /* _M_AMD64 */ +#ifndef __MINGW32__ +#pragma intrinsic (_InterlockedCompareExchange) +#pragma intrinsic (_InterlockedExchange) +#else + /* --[ start GCC compatibility ]---------------------------------------------- + * Compatibility <intrin_x86.h> header for GCC -- GCC equivalents of intrinsic + * Microsoft Visual C++ functions. Originally developed for the ReactOS + * (<http://www.reactos.org/>) and TinyKrnl (<http://www.tinykrnl.org/>) + * projects. + * + * Copyright (c) 2006 KJK::Hyperion <hackbunny@reactos.com> + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + + /*** Atomic operations ***/ + #if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) > 40100 + #define _ReadWriteBarrier() __sync_synchronize() + #else + static __inline__ __attribute__((always_inline)) long __sync_lock_test_and_set(volatile long * const Target, const long Value) + { + long res; + __asm__ __volatile__("xchg%z0 %2, %0" : "=g" (*(Target)), "=r" (res) : "1" (Value)); + return res; + } + static void __inline__ __attribute__((always_inline)) _MemoryBarrier(void) + { + __asm__ __volatile__("" : : : "memory"); + } + #define _ReadWriteBarrier() _MemoryBarrier() + #endif + /* BUGBUG: GCC only supports full barriers */ + static __inline__ __attribute__((always_inline)) long _InterlockedExchange(volatile long * const Target, const long Value) + { + /* NOTE: __sync_lock_test_and_set would be an acquire barrier, so we force a full barrier */ + _ReadWriteBarrier(); + return __sync_lock_test_and_set(Target, Value); + } + /* --[ end GCC compatibility ]---------------------------------------------- */ +#endif +#define interlockedcompareexchange _InterlockedCompareExchange +#define interlockedexchange _InterlockedExchange +#endif /* Win32 */ +#endif /* USE_LOCKS */ + +/* Declarations for bit scanning on win32 */ +#if defined(_MSC_VER) && _MSC_VER>=1300 +#ifndef BitScanForward /* Try to avoid pulling in WinNT.h */ +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ +unsigned char _BitScanForward(unsigned long *index, unsigned long mask); +unsigned char _BitScanReverse(unsigned long *index, unsigned long mask); +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#define BitScanForward _BitScanForward +#define BitScanReverse _BitScanReverse +#pragma intrinsic(_BitScanForward) +#pragma intrinsic(_BitScanReverse) +#endif /* BitScanForward */ +#endif /* defined(_MSC_VER) && _MSC_VER>=1300 */ + +#ifndef WIN32 +#ifndef malloc_getpagesize +# ifdef _SC_PAGESIZE /* some SVR4 systems omit an underscore */ +# ifndef _SC_PAGE_SIZE +# define _SC_PAGE_SIZE _SC_PAGESIZE +# endif +# endif +# ifdef _SC_PAGE_SIZE +# define malloc_getpagesize sysconf(_SC_PAGE_SIZE) +# else +# if defined(BSD) || defined(DGUX) || defined(HAVE_GETPAGESIZE) + extern size_t getpagesize(); +# define malloc_getpagesize getpagesize() +# else +# ifdef WIN32 /* use supplied emulation of getpagesize */ +# define malloc_getpagesize getpagesize() +# else +# ifndef LACKS_SYS_PARAM_H +# include <sys/param.h> +# endif +# ifdef EXEC_PAGESIZE +# define malloc_getpagesize EXEC_PAGESIZE +# else +# ifdef NBPG +# ifndef CLSIZE +# define malloc_getpagesize NBPG +# else +# define malloc_getpagesize (NBPG * CLSIZE) +# endif +# else +# ifdef NBPC +# define malloc_getpagesize NBPC +# else +# ifdef PAGESIZE +# define malloc_getpagesize PAGESIZE +# else /* just guess */ +# define malloc_getpagesize ((size_t)4096U) +# endif +# endif +# endif +# endif +# endif +# endif +# endif +#endif +#endif + + + +/* ------------------- size_t and alignment properties -------------------- */ + +/* The byte and bit size of a size_t */ +#define SIZE_T_SIZE (sizeof(size_t)) +#define SIZE_T_BITSIZE (sizeof(size_t) << 3) + +/* Some constants coerced to size_t */ +/* Annoying but necessary to avoid errors on some platforms */ +#define SIZE_T_ZERO ((size_t)0) +#define SIZE_T_ONE ((size_t)1) +#define SIZE_T_TWO ((size_t)2) +#define SIZE_T_FOUR ((size_t)4) +#define TWO_SIZE_T_SIZES (SIZE_T_SIZE<<1) +#define FOUR_SIZE_T_SIZES (SIZE_T_SIZE<<2) +#define SIX_SIZE_T_SIZES (FOUR_SIZE_T_SIZES+TWO_SIZE_T_SIZES) +#define HALF_MAX_SIZE_T (MAX_SIZE_T / 2U) + +/* The bit mask value corresponding to MALLOC_ALIGNMENT */ +#define CHUNK_ALIGN_MASK (MALLOC_ALIGNMENT - SIZE_T_ONE) + +/* True if address a has acceptable alignment */ +#define is_aligned(A) (((size_t)((A)) & (CHUNK_ALIGN_MASK)) == 0) + +/* the number of bytes to offset an address to align it */ +#define align_offset(A)\ + ((((size_t)(A) & CHUNK_ALIGN_MASK) == 0)? 0 :\ + ((MALLOC_ALIGNMENT - ((size_t)(A) & CHUNK_ALIGN_MASK)) & CHUNK_ALIGN_MASK)) + +/* -------------------------- MMAP preliminaries ------------------------- */ + +/* + If HAVE_MORECORE or HAVE_MMAP are false, we just define calls and + checks to fail so compiler optimizer can delete code rather than + using so many "#if"s. +*/ + + +/* MORECORE and MMAP must return MFAIL on failure */ +#define MFAIL ((void*)(MAX_SIZE_T)) +#define CMFAIL ((char*)(MFAIL)) /* defined for convenience */ + +#if HAVE_MMAP + +#ifndef WIN32 +#define MUNMAP_DEFAULT(a, s) munmap((a), (s)) +#define MMAP_PROT (PROT_READ|PROT_WRITE) +#if !defined(MAP_ANONYMOUS) && defined(MAP_ANON) +#define MAP_ANONYMOUS MAP_ANON +#endif /* MAP_ANON */ +#ifdef MAP_ANONYMOUS +#define MMAP_FLAGS (MAP_PRIVATE|MAP_ANONYMOUS) +#define MMAP_DEFAULT(s) mmap(0, (s), MMAP_PROT, MMAP_FLAGS, -1, 0) +#else /* MAP_ANONYMOUS */ +/* + Nearly all versions of mmap support MAP_ANONYMOUS, so the following + is unlikely to be needed, but is supplied just in case. +*/ +#define MMAP_FLAGS (MAP_PRIVATE) +static int dev_zero_fd = -1; /* Cached file descriptor for /dev/zero. */ +#define MMAP_DEFAULT(s) ((dev_zero_fd < 0) ? \ + (dev_zero_fd = open("/dev/zero", O_RDWR), \ + mmap(0, (s), MMAP_PROT, MMAP_FLAGS, dev_zero_fd, 0)) : \ + mmap(0, (s), MMAP_PROT, MMAP_FLAGS, dev_zero_fd, 0)) +#endif /* MAP_ANONYMOUS */ + +#define DIRECT_MMAP_DEFAULT(s) MMAP_DEFAULT(s) + +#else /* WIN32 */ + +/* Win32 MMAP via VirtualAlloc */ +static FORCEINLINE void* win32mmap(size_t size) { + void* ptr = VirtualAlloc(0, size, MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE); + return (ptr != 0)? ptr: MFAIL; +} + +/* For direct MMAP, use MEM_TOP_DOWN to minimize interference */ +static FORCEINLINE void* win32direct_mmap(size_t size) { + void* ptr = VirtualAlloc(0, size, MEM_RESERVE|MEM_COMMIT|MEM_TOP_DOWN, + PAGE_READWRITE); + return (ptr != 0)? ptr: MFAIL; +} + +/* This function supports releasing coalesed segments */ +static FORCEINLINE int win32munmap(void* ptr, size_t size) { + MEMORY_BASIC_INFORMATION minfo; + char* cptr = (char*)ptr; + while (size) { + if (VirtualQuery(cptr, &minfo, sizeof(minfo)) == 0) + return -1; + if (minfo.BaseAddress != cptr || minfo.AllocationBase != cptr || + minfo.State != MEM_COMMIT || minfo.RegionSize > size) + return -1; + if (VirtualFree(cptr, 0, MEM_RELEASE) == 0) + return -1; + cptr += minfo.RegionSize; + size -= minfo.RegionSize; + } + return 0; +} + +#define MMAP_DEFAULT(s) win32mmap(s) +#define MUNMAP_DEFAULT(a, s) win32munmap((a), (s)) +#define DIRECT_MMAP_DEFAULT(s) win32direct_mmap(s) +#endif /* WIN32 */ +#endif /* HAVE_MMAP */ + +#if HAVE_MREMAP +#ifndef WIN32 +#define MREMAP_DEFAULT(addr, osz, nsz, mv) mremap((addr), (osz), (nsz), (mv)) +#endif /* WIN32 */ +#endif /* HAVE_MREMAP */ + + +/** + * Define CALL_MORECORE + */ +#if HAVE_MORECORE + #ifdef MORECORE + #define CALL_MORECORE(S) MORECORE(S) + #else /* MORECORE */ + #define CALL_MORECORE(S) MORECORE_DEFAULT(S) + #endif /* MORECORE */ +#else /* HAVE_MORECORE */ + #define CALL_MORECORE(S) MFAIL +#endif /* HAVE_MORECORE */ + +/** + * Define CALL_MMAP/CALL_MUNMAP/CALL_DIRECT_MMAP + */ +#if HAVE_MMAP + #define IS_MMAPPED_BIT (SIZE_T_ONE) + #define USE_MMAP_BIT (SIZE_T_ONE) + + #ifdef MMAP + #define CALL_MMAP(s) MMAP(s) + #else /* MMAP */ + #define CALL_MMAP(s) MMAP_DEFAULT(s) + #endif /* MMAP */ + #ifdef MUNMAP + #define CALL_MUNMAP(a, s) MUNMAP((a), (s)) + #else /* MUNMAP */ + #define CALL_MUNMAP(a, s) MUNMAP_DEFAULT((a), (s)) + #endif /* MUNMAP */ + #ifdef DIRECT_MMAP + #define CALL_DIRECT_MMAP(s) DIRECT_MMAP(s) + #else /* DIRECT_MMAP */ + #define CALL_DIRECT_MMAP(s) DIRECT_MMAP_DEFAULT(s) + #endif /* DIRECT_MMAP */ +#else /* HAVE_MMAP */ + #define IS_MMAPPED_BIT (SIZE_T_ZERO) + #define USE_MMAP_BIT (SIZE_T_ZERO) + + #define MMAP(s) MFAIL + #define MUNMAP(a, s) (-1) + #define DIRECT_MMAP(s) MFAIL + #define CALL_DIRECT_MMAP(s) DIRECT_MMAP(s) + #define CALL_MMAP(s) MMAP(s) + #define CALL_MUNMAP(a, s) MUNMAP((a), (s)) +#endif /* HAVE_MMAP */ + +/** + * Define CALL_MREMAP + */ +#if HAVE_MMAP && HAVE_MREMAP + #ifdef MREMAP + #define CALL_MREMAP(addr, osz, nsz, mv) MREMAP((addr), (osz), (nsz), (mv)) + #else /* MREMAP */ + #define CALL_MREMAP(addr, osz, nsz, mv) MREMAP_DEFAULT((addr), (osz), (nsz), (mv)) + #endif /* MREMAP */ +#else /* HAVE_MMAP && HAVE_MREMAP */ + #define CALL_MREMAP(addr, osz, nsz, mv) MFAIL +#endif /* HAVE_MMAP && HAVE_MREMAP */ + +/* mstate bit set if continguous morecore disabled or failed */ +#define USE_NONCONTIGUOUS_BIT (4U) + +/* segment bit set in create_mspace_with_base */ +#define EXTERN_BIT (8U) + + +/* --------------------------- Lock preliminaries ------------------------ */ + +/* + When locks are defined, there is one global lock, plus + one per-mspace lock. + + The global lock_ensures that mparams.magic and other unique + mparams values are initialized only once. It also protects + sequences of calls to MORECORE. In many cases sys_alloc requires + two calls, that should not be interleaved with calls by other + threads. This does not protect against direct calls to MORECORE + by other threads not using this lock, so there is still code to + cope the best we can on interference. + + Per-mspace locks surround calls to malloc, free, etc. To enable use + in layered extensions, per-mspace locks are reentrant. + + Because lock-protected regions generally have bounded times, it is + OK to use the supplied simple spinlocks in the custom versions for + x86. + + If USE_LOCKS is > 1, the definitions of lock routines here are + bypassed, in which case you will need to define at least + INITIAL_LOCK, ACQUIRE_LOCK, RELEASE_LOCK and possibly TRY_LOCK + (which is not used in this malloc, but commonly needed in + extensions.) +*/ + +#if USE_LOCKS == 1 + +#if USE_SPIN_LOCKS +#ifndef WIN32 + +/* Custom pthread-style spin locks on x86 and x64 for gcc */ +struct pthread_mlock_t { + volatile unsigned int l; + volatile unsigned int c; + volatile pthread_t threadid; +}; +#define MLOCK_T struct pthread_mlock_t +#define CURRENT_THREAD pthread_self() +#define INITIAL_LOCK(sl) (memset(sl, 0, sizeof(MLOCK_T)), 0) +#define ACQUIRE_LOCK(sl) pthread_acquire_lock(sl) +#define RELEASE_LOCK(sl) pthread_release_lock(sl) +#define TRY_LOCK(sl) pthread_try_lock(sl) +#define SPINS_PER_YIELD 63 + +static MLOCK_T malloc_global_mutex = { 0, 0, 0}; + +static FORCEINLINE int pthread_acquire_lock (MLOCK_T *sl) { + int spins = 0; + volatile unsigned int* lp = &sl->l; + for (;;) { + if (*lp != 0) { + if (sl->threadid == CURRENT_THREAD) { + ++sl->c; + return 0; + } + } + else { + /* place args to cmpxchgl in locals to evade oddities in some gccs */ + int cmp = 0; + int val = 1; + int ret; + __asm__ __volatile__ ("lock; cmpxchgl %1, %2" + : "=a" (ret) + : "r" (val), "m" (*(lp)), "0"(cmp) + : "memory", "cc"); + if (!ret) { + assert(!sl->threadid); + sl->c = 1; + sl->threadid = CURRENT_THREAD; + return 0; + } + if ((++spins & SPINS_PER_YIELD) == 0) { +#if defined (__SVR4) && defined (__sun) /* solaris */ + thr_yield(); +#else +#if defined(__linux__) || defined(__FreeBSD__) || defined(__APPLE__) + sched_yield(); +#else /* no-op yield on unknown systems */ + ; +#endif /* __linux__ || __FreeBSD__ || __APPLE__ */ +#endif /* solaris */ + } + } + } +} + +static FORCEINLINE void pthread_release_lock (MLOCK_T *sl) { + assert(sl->l != 0); + assert(sl->threadid == CURRENT_THREAD); + if (--sl->c == 0) { + sl->threadid = 0; + volatile unsigned int* lp = &sl->l; + int prev = 0; + int ret; + __asm__ __volatile__ ("lock; xchgl %0, %1" + : "=r" (ret) + : "m" (*(lp)), "0"(prev) + : "memory"); + } +} + +static FORCEINLINE int pthread_try_lock (MLOCK_T *sl) { + volatile unsigned int* lp = &sl->l; + if (*lp != 0) { + if (sl->threadid == CURRENT_THREAD) { + ++sl->c; + return 1; + } + } + else { + int cmp = 0; + int val = 1; + int ret; + __asm__ __volatile__ ("lock; cmpxchgl %1, %2" + : "=a" (ret) + : "r" (val), "m" (*(lp)), "0"(cmp) + : "memory", "cc"); + if (!ret) { + assert(!sl->threadid); + sl->c = 1; + sl->threadid = CURRENT_THREAD; + return 1; + } + } + return 0; +} + + +#else /* WIN32 */ +/* Custom win32-style spin locks on x86 and x64 for MSC */ +struct win32_mlock_t +{ + volatile long l; + volatile unsigned int c; + volatile long threadid; +}; + +#define MLOCK_T struct win32_mlock_t +#define CURRENT_THREAD win32_getcurrentthreadid() +#define INITIAL_LOCK(sl) (memset(sl, 0, sizeof(MLOCK_T)), 0) +#define ACQUIRE_LOCK(sl) win32_acquire_lock(sl) +#define RELEASE_LOCK(sl) win32_release_lock(sl) +#define TRY_LOCK(sl) win32_try_lock(sl) +#define SPINS_PER_YIELD 63 + +static MLOCK_T malloc_global_mutex = { 0, 0, 0}; + +static FORCEINLINE long win32_getcurrentthreadid() { +#ifdef _MSC_VER +#if defined(_M_IX86) + long *threadstruct=(long *)__readfsdword(0x18); + long threadid=threadstruct[0x24/sizeof(long)]; + return threadid; +#elif defined(_M_X64) + /* todo */ + return GetCurrentThreadId(); +#else + return GetCurrentThreadId(); +#endif +#else + return GetCurrentThreadId(); +#endif +} + +static FORCEINLINE int win32_acquire_lock (MLOCK_T *sl) { + int spins = 0; + for (;;) { + if (sl->l != 0) { + if (sl->threadid == CURRENT_THREAD) { + ++sl->c; + return 0; + } + } + else { + if (!interlockedexchange(&sl->l, 1)) { + assert(!sl->threadid); + sl->c=CURRENT_THREAD; + sl->threadid = CURRENT_THREAD; + sl->c = 1; + return 0; + } + } + if ((++spins & SPINS_PER_YIELD) == 0) + SleepEx(0, FALSE); + } +} + +static FORCEINLINE void win32_release_lock (MLOCK_T *sl) { + assert(sl->threadid == CURRENT_THREAD); + assert(sl->l != 0); + if (--sl->c == 0) { + sl->threadid = 0; + interlockedexchange (&sl->l, 0); + } +} + +static FORCEINLINE int win32_try_lock (MLOCK_T *sl) { + if(sl->l != 0) { + if (sl->threadid == CURRENT_THREAD) { + ++sl->c; + return 1; + } + } + else { + if (!interlockedexchange(&sl->l, 1)){ + assert(!sl->threadid); + sl->threadid = CURRENT_THREAD; + sl->c = 1; + return 1; + } + } + return 0; +} + +#endif /* WIN32 */ +#else /* USE_SPIN_LOCKS */ + +#ifndef WIN32 +/* pthreads-based locks */ + +#define MLOCK_T pthread_mutex_t +#define CURRENT_THREAD pthread_self() +#define INITIAL_LOCK(sl) pthread_init_lock(sl) +#define ACQUIRE_LOCK(sl) pthread_mutex_lock(sl) +#define RELEASE_LOCK(sl) pthread_mutex_unlock(sl) +#define TRY_LOCK(sl) (!pthread_mutex_trylock(sl)) + +static MLOCK_T malloc_global_mutex = PTHREAD_MUTEX_INITIALIZER; + +/* Cope with old-style linux recursive lock initialization by adding */ +/* skipped internal declaration from pthread.h */ +#ifdef linux +#ifndef PTHREAD_MUTEX_RECURSIVE +extern int pthread_mutexattr_setkind_np __P ((pthread_mutexattr_t *__attr, + int __kind)); +#define PTHREAD_MUTEX_RECURSIVE PTHREAD_MUTEX_RECURSIVE_NP +#define pthread_mutexattr_settype(x,y) pthread_mutexattr_setkind_np(x,y) +#endif +#endif + +static int pthread_init_lock (MLOCK_T *sl) { + pthread_mutexattr_t attr; + if (pthread_mutexattr_init(&attr)) return 1; + if (pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE)) return 1; + if (pthread_mutex_init(sl, &attr)) return 1; + if (pthread_mutexattr_destroy(&attr)) return 1; + return 0; +} + +#else /* WIN32 */ +/* Win32 critical sections */ +#define MLOCK_T CRITICAL_SECTION +#define CURRENT_THREAD GetCurrentThreadId() +#define INITIAL_LOCK(s) (!InitializeCriticalSectionAndSpinCount((s), 0x80000000|4000)) +#define ACQUIRE_LOCK(s) (EnterCriticalSection(s), 0) +#define RELEASE_LOCK(s) LeaveCriticalSection(s) +#define TRY_LOCK(s) TryEnterCriticalSection(s) +#define NEED_GLOBAL_LOCK_INIT + +static MLOCK_T malloc_global_mutex; +static volatile long malloc_global_mutex_status; + +/* Use spin loop to initialize global lock */ +static void init_malloc_global_mutex() { + for (;;) { + long stat = malloc_global_mutex_status; + if (stat > 0) + return; + /* transition to < 0 while initializing, then to > 0) */ + if (stat == 0 && + interlockedcompareexchange(&malloc_global_mutex_status, -1, 0) == 0) { + InitializeCriticalSection(&malloc_global_mutex); + interlockedexchange(&malloc_global_mutex_status,1); + return; + } + SleepEx(0, FALSE); + } +} + +#endif /* WIN32 */ +#endif /* USE_SPIN_LOCKS */ +#endif /* USE_LOCKS == 1 */ + +/* ----------------------- User-defined locks ------------------------ */ + +#if USE_LOCKS > 1 +/* Define your own lock implementation here */ +/* #define INITIAL_LOCK(sl) ... */ +/* #define ACQUIRE_LOCK(sl) ... */ +/* #define RELEASE_LOCK(sl) ... */ +/* #define TRY_LOCK(sl) ... */ +/* static MLOCK_T malloc_global_mutex = ... */ +#endif /* USE_LOCKS > 1 */ + +/* ----------------------- Lock-based state ------------------------ */ + +#if USE_LOCKS +#define USE_LOCK_BIT (2U) +#else /* USE_LOCKS */ +#define USE_LOCK_BIT (0U) +#define INITIAL_LOCK(l) +#endif /* USE_LOCKS */ + +#if USE_LOCKS +#define ACQUIRE_MALLOC_GLOBAL_LOCK() ACQUIRE_LOCK(&malloc_global_mutex); +#define RELEASE_MALLOC_GLOBAL_LOCK() RELEASE_LOCK(&malloc_global_mutex); +#else /* USE_LOCKS */ +#define ACQUIRE_MALLOC_GLOBAL_LOCK() +#define RELEASE_MALLOC_GLOBAL_LOCK() +#endif /* USE_LOCKS */ + + +/* ----------------------- Chunk representations ------------------------ */ + +/* + (The following includes lightly edited explanations by Colin Plumb.) + + The malloc_chunk declaration below is misleading (but accurate and + necessary). It declares a "view" into memory allowing access to + necessary fields at known offsets from a given base. + + Chunks of memory are maintained using a `boundary tag' method as + originally described by Knuth. (See the paper by Paul Wilson + ftp://ftp.cs.utexas.edu/pub/garbage/allocsrv.ps for a survey of such + techniques.) Sizes of free chunks are stored both in the front of + each chunk and at the end. This makes consolidating fragmented + chunks into bigger chunks fast. The head fields also hold bits + representing whether chunks are free or in use. + + Here are some pictures to make it clearer. They are "exploded" to + show that the state of a chunk can be thought of as extending from + the high 31 bits of the head field of its header through the + prev_foot and PINUSE_BIT bit of the following chunk header. + + A chunk that's in use looks like: + + chunk-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Size of previous chunk (if P = 0) | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |P| + | Size of this chunk 1| +-+ + mem-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | | + +- -+ + | | + +- -+ + | : + +- size - sizeof(size_t) available payload bytes -+ + : | + chunk-> +- -+ + | | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |1| + | Size of next chunk (may or may not be in use) | +-+ + mem-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + + And if it's free, it looks like this: + + chunk-> +- -+ + | User payload (must be in use, or we would have merged!) | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |P| + | Size of this chunk 0| +-+ + mem-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Next pointer | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Prev pointer | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | : + +- size - sizeof(struct chunk) unused bytes -+ + : | + chunk-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Size of this chunk | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |0| + | Size of next chunk (must be in use, or we would have merged)| +-+ + mem-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | : + +- User payload -+ + : | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + |0| + +-+ + Note that since we always merge adjacent free chunks, the chunks + adjacent to a free chunk must be in use. + + Given a pointer to a chunk (which can be derived trivially from the + payload pointer) we can, in O(1) time, find out whether the adjacent + chunks are free, and if so, unlink them from the lists that they + are on and merge them with the current chunk. + + Chunks always begin on even word boundaries, so the mem portion + (which is returned to the user) is also on an even word boundary, and + thus at least double-word aligned. + + The P (PINUSE_BIT) bit, stored in the unused low-order bit of the + chunk size (which is always a multiple of two words), is an in-use + bit for the *previous* chunk. If that bit is *clear*, then the + word before the current chunk size contains the previous chunk + size, and can be used to find the front of the previous chunk. + The very first chunk allocated always has this bit set, preventing + access to non-existent (or non-owned) memory. If pinuse is set for + any given chunk, then you CANNOT determine the size of the + previous chunk, and might even get a memory addressing fault when + trying to do so. + + The C (CINUSE_BIT) bit, stored in the unused second-lowest bit of + the chunk size redundantly records whether the current chunk is + inuse. This redundancy enables usage checks within free and realloc, + and reduces indirection when freeing and consolidating chunks. + + Each freshly allocated chunk must have both cinuse and pinuse set. + That is, each allocated chunk borders either a previously allocated + and still in-use chunk, or the base of its memory arena. This is + ensured by making all allocations from the the `lowest' part of any + found chunk. Further, no free chunk physically borders another one, + so each free chunk is known to be preceded and followed by either + inuse chunks or the ends of memory. + + Note that the `foot' of the current chunk is actually represented + as the prev_foot of the NEXT chunk. This makes it easier to + deal with alignments etc but can be very confusing when trying + to extend or adapt this code. + + The exceptions to all this are + + 1. The special chunk `top' is the top-most available chunk (i.e., + the one bordering the end of available memory). It is treated + specially. Top is never included in any bin, is used only if + no other chunk is available, and is released back to the + system if it is very large (see M_TRIM_THRESHOLD). In effect, + the top chunk is treated as larger (and thus less well + fitting) than any other available chunk. The top chunk + doesn't update its trailing size field since there is no next + contiguous chunk that would have to index off it. However, + space is still allocated for it (TOP_FOOT_SIZE) to enable + separation or merging when space is extended. + + 3. Chunks allocated via mmap, which have the lowest-order bit + (IS_MMAPPED_BIT) set in their prev_foot fields, and do not set + PINUSE_BIT in their head fields. Because they are allocated + one-by-one, each must carry its own prev_foot field, which is + also used to hold the offset this chunk has within its mmapped + region, which is needed to preserve alignment. Each mmapped + chunk is trailed by the first two fields of a fake next-chunk + for sake of usage checks. + +*/ + +struct malloc_chunk { + size_t prev_foot; /* Size of previous chunk (if free). */ + size_t head; /* Size and inuse bits. */ + struct malloc_chunk* fd; /* double links -- used only if free. */ + struct malloc_chunk* bk; +}; + +typedef struct malloc_chunk mchunk; +typedef struct malloc_chunk* mchunkptr; +typedef struct malloc_chunk* sbinptr; /* The type of bins of chunks */ +typedef unsigned int bindex_t; /* Described below */ +typedef unsigned int binmap_t; /* Described below */ +typedef unsigned int flag_t; /* The type of various bit flag sets */ + +/* ------------------- Chunks sizes and alignments ----------------------- */ + +#define MCHUNK_SIZE (sizeof(mchunk)) + +#if FOOTERS +#define CHUNK_OVERHEAD (TWO_SIZE_T_SIZES) +#else /* FOOTERS */ +#define CHUNK_OVERHEAD (SIZE_T_SIZE) +#endif /* FOOTERS */ + +/* MMapped chunks need a second word of overhead ... */ +#define MMAP_CHUNK_OVERHEAD (TWO_SIZE_T_SIZES) +/* ... and additional padding for fake next-chunk at foot */ +#define MMAP_FOOT_PAD (FOUR_SIZE_T_SIZES) + +/* The smallest size we can malloc is an aligned minimal chunk */ +#define MIN_CHUNK_SIZE\ + ((MCHUNK_SIZE + CHUNK_ALIGN_MASK) & ~CHUNK_ALIGN_MASK) + +/* conversion from malloc headers to user pointers, and back */ +#define chunk2mem(p) ((void*)((char*)(p) + TWO_SIZE_T_SIZES)) +#define mem2chunk(mem) ((mchunkptr)((char*)(mem) - TWO_SIZE_T_SIZES)) +/* chunk associated with aligned address A */ +#define align_as_chunk(A) (mchunkptr)((A) + align_offset(chunk2mem(A))) + +/* Bounds on request (not chunk) sizes. */ +#define MAX_REQUEST ((-MIN_CHUNK_SIZE) << 2) +#define MIN_REQUEST (MIN_CHUNK_SIZE - CHUNK_OVERHEAD - SIZE_T_ONE) + +/* pad request bytes into a usable size */ +#define pad_request(req) \ + (((req) + CHUNK_OVERHEAD + CHUNK_ALIGN_MASK) & ~CHUNK_ALIGN_MASK) + +/* pad request, checking for minimum (but not maximum) */ +#define request2size(req) \ + (((req) < MIN_REQUEST)? MIN_CHUNK_SIZE : pad_request(req)) + + +/* ------------------ Operations on head and foot fields ----------------- */ + +/* + The head field of a chunk is or'ed with PINUSE_BIT when previous + adjacent chunk in use, and or'ed with CINUSE_BIT if this chunk is in + use. If the chunk was obtained with mmap, the prev_foot field has + IS_MMAPPED_BIT set, otherwise holding the offset of the base of the + mmapped region to the base of the chunk. + + FLAG4_BIT is not used by this malloc, but might be useful in extensions. +*/ + +#define PINUSE_BIT (SIZE_T_ONE) +#define CINUSE_BIT (SIZE_T_TWO) +#define FLAG4_BIT (SIZE_T_FOUR) +#define INUSE_BITS (PINUSE_BIT|CINUSE_BIT) +#define FLAG_BITS (PINUSE_BIT|CINUSE_BIT|FLAG4_BIT) + +/* Head value for fenceposts */ +#define FENCEPOST_HEAD (INUSE_BITS|SIZE_T_SIZE) + +/* extraction of fields from head words */ +#define cinuse(p) ((p)->head & CINUSE_BIT) +#define pinuse(p) ((p)->head & PINUSE_BIT) +#define chunksize(p) ((p)->head & ~(FLAG_BITS)) + +#define clear_pinuse(p) ((p)->head &= ~PINUSE_BIT) +#define clear_cinuse(p) ((p)->head &= ~CINUSE_BIT) + +/* Treat space at ptr +/- offset as a chunk */ +#define chunk_plus_offset(p, s) ((mchunkptr)(((char*)(p)) + (s))) +#define chunk_minus_offset(p, s) ((mchunkptr)(((char*)(p)) - (s))) + +/* Ptr to next or previous physical malloc_chunk. */ +#define next_chunk(p) ((mchunkptr)( ((char*)(p)) + ((p)->head & ~FLAG_BITS))) +#define prev_chunk(p) ((mchunkptr)( ((char*)(p)) - ((p)->prev_foot) )) + +/* extract next chunk's pinuse bit */ +#define next_pinuse(p) ((next_chunk(p)->head) & PINUSE_BIT) + +/* Get/set size at footer */ +#define get_foot(p, s) (((mchunkptr)((char*)(p) + (s)))->prev_foot) +#define set_foot(p, s) (((mchunkptr)((char*)(p) + (s)))->prev_foot = (s)) + +/* Set size, pinuse bit, and foot */ +#define set_size_and_pinuse_of_free_chunk(p, s)\ + ((p)->head = (s|PINUSE_BIT), set_foot(p, s)) + +/* Set size, pinuse bit, foot, and clear next pinuse */ +#define set_free_with_pinuse(p, s, n)\ + (clear_pinuse(n), set_size_and_pinuse_of_free_chunk(p, s)) + +#define is_mmapped(p)\ + (!((p)->head & PINUSE_BIT) && ((p)->prev_foot & IS_MMAPPED_BIT)) + +/* Get the internal overhead associated with chunk p */ +#define overhead_for(p)\ + (is_mmapped(p)? MMAP_CHUNK_OVERHEAD : CHUNK_OVERHEAD) + +/* Return true if malloced space is not necessarily cleared */ +#if MMAP_CLEARS +#define calloc_must_clear(p) (!is_mmapped(p)) +#else /* MMAP_CLEARS */ +#define calloc_must_clear(p) (1) +#endif /* MMAP_CLEARS */ + +/* ---------------------- Overlaid data structures ----------------------- */ + +/* + When chunks are not in use, they are treated as nodes of either + lists or trees. + + "Small" chunks are stored in circular doubly-linked lists, and look + like this: + + chunk-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Size of previous chunk | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + `head:' | Size of chunk, in bytes |P| + mem-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Forward pointer to next chunk in list | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Back pointer to previous chunk in list | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Unused space (may be 0 bytes long) . + . . + . | +nextchunk-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + `foot:' | Size of chunk, in bytes | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + + Larger chunks are kept in a form of bitwise digital trees (aka + tries) keyed on chunksizes. Because malloc_tree_chunks are only for + free chunks greater than 256 bytes, their size doesn't impose any + constraints on user chunk sizes. Each node looks like: + + chunk-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Size of previous chunk | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + `head:' | Size of chunk, in bytes |P| + mem-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Forward pointer to next chunk of same size | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Back pointer to previous chunk of same size | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Pointer to left child (child[0]) | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Pointer to right child (child[1]) | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Pointer to parent | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | bin index of this chunk | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Unused space . + . | +nextchunk-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + `foot:' | Size of chunk, in bytes | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + + Each tree holding treenodes is a tree of unique chunk sizes. Chunks + of the same size are arranged in a circularly-linked list, with only + the oldest chunk (the next to be used, in our FIFO ordering) + actually in the tree. (Tree members are distinguished by a non-null + parent pointer.) If a chunk with the same size an an existing node + is inserted, it is linked off the existing node using pointers that + work in the same way as fd/bk pointers of small chunks. + + Each tree contains a power of 2 sized range of chunk sizes (the + smallest is 0x100 <= x < 0x180), which is is divided in half at each + tree level, with the chunks in the smaller half of the range (0x100 + <= x < 0x140 for the top nose) in the left subtree and the larger + half (0x140 <= x < 0x180) in the right subtree. This is, of course, + done by inspecting individual bits. + + Using these rules, each node's left subtree contains all smaller + sizes than its right subtree. However, the node at the root of each + subtree has no particular ordering relationship to either. (The + dividing line between the subtree sizes is based on trie relation.) + If we remove the last chunk of a given size from the interior of the + tree, we need to replace it with a leaf node. The tree ordering + rules permit a node to be replaced by any leaf below it. + + The smallest chunk in a tree (a common operation in a best-fit + allocator) can be found by walking a path to the leftmost leaf in + the tree. Unlike a usual binary tree, where we follow left child + pointers until we reach a null, here we follow the right child + pointer any time the left one is null, until we reach a leaf with + both child pointers null. The smallest chunk in the tree will be + somewhere along that path. + + The worst case number of steps to add, find, or remove a node is + bounded by the number of bits differentiating chunks within + bins. Under current bin calculations, this ranges from 6 up to 21 + (for 32 bit sizes) or up to 53 (for 64 bit sizes). The typical case + is of course much better. +*/ + +struct malloc_tree_chunk { + /* The first four fields must be compatible with malloc_chunk */ + size_t prev_foot; + size_t head; + struct malloc_tree_chunk* fd; + struct malloc_tree_chunk* bk; + + struct malloc_tree_chunk* child[2]; + struct malloc_tree_chunk* parent; + bindex_t index; +}; + +typedef struct malloc_tree_chunk tchunk; +typedef struct malloc_tree_chunk* tchunkptr; +typedef struct malloc_tree_chunk* tbinptr; /* The type of bins of trees */ + +/* A little helper macro for trees */ +#define leftmost_child(t) ((t)->child[0] != 0? (t)->child[0] : (t)->child[1]) + +/* ----------------------------- Segments -------------------------------- */ + +/* + Each malloc space may include non-contiguous segments, held in a + list headed by an embedded malloc_segment record representing the + top-most space. Segments also include flags holding properties of + the space. Large chunks that are directly allocated by mmap are not + included in this list. They are instead independently created and + destroyed without otherwise keeping track of them. + + Segment management mainly comes into play for spaces allocated by + MMAP. Any call to MMAP might or might not return memory that is + adjacent to an existing segment. MORECORE normally contiguously + extends the current space, so this space is almost always adjacent, + which is simpler and faster to deal with. (This is why MORECORE is + used preferentially to MMAP when both are available -- see + sys_alloc.) When allocating using MMAP, we don't use any of the + hinting mechanisms (inconsistently) supported in various + implementations of unix mmap, or distinguish reserving from + committing memory. Instead, we just ask for space, and exploit + contiguity when we get it. It is probably possible to do + better than this on some systems, but no general scheme seems + to be significantly better. + + Management entails a simpler variant of the consolidation scheme + used for chunks to reduce fragmentation -- new adjacent memory is + normally prepended or appended to an existing segment. However, + there are limitations compared to chunk consolidation that mostly + reflect the fact that segment processing is relatively infrequent + (occurring only when getting memory from system) and that we + don't expect to have huge numbers of segments: + + * Segments are not indexed, so traversal requires linear scans. (It + would be possible to index these, but is not worth the extra + overhead and complexity for most programs on most platforms.) + * New segments are only appended to old ones when holding top-most + memory; if they cannot be prepended to others, they are held in + different segments. + + Except for the top-most segment of an mstate, each segment record + is kept at the tail of its segment. Segments are added by pushing + segment records onto the list headed by &mstate.seg for the + containing mstate. + + Segment flags control allocation/merge/deallocation policies: + * If EXTERN_BIT set, then we did not allocate this segment, + and so should not try to deallocate or merge with others. + (This currently holds only for the initial segment passed + into create_mspace_with_base.) + * If IS_MMAPPED_BIT set, the segment may be merged with + other surrounding mmapped segments and trimmed/de-allocated + using munmap. + * If neither bit is set, then the segment was obtained using + MORECORE so can be merged with surrounding MORECORE'd segments + and deallocated/trimmed using MORECORE with negative arguments. +*/ + +struct malloc_segment { + char* base; /* base address */ + size_t size; /* allocated size */ + struct malloc_segment* next; /* ptr to next segment */ + flag_t sflags; /* mmap and extern flag */ +}; + +#define is_mmapped_segment(S) ((S)->sflags & IS_MMAPPED_BIT) +#define is_extern_segment(S) ((S)->sflags & EXTERN_BIT) + +typedef struct malloc_segment msegment; +typedef struct malloc_segment* msegmentptr; + +/* ---------------------------- malloc_state ----------------------------- */ + +/* + A malloc_state holds all of the bookkeeping for a space. + The main fields are: + + Top + The topmost chunk of the currently active segment. Its size is + cached in topsize. The actual size of topmost space is + topsize+TOP_FOOT_SIZE, which includes space reserved for adding + fenceposts and segment records if necessary when getting more + space from the system. The size at which to autotrim top is + cached from mparams in trim_check, except that it is disabled if + an autotrim fails. + + Designated victim (dv) + This is the preferred chunk for servicing small requests that + don't have exact fits. It is normally the chunk split off most + recently to service another small request. Its size is cached in + dvsize. The link fields of this chunk are not maintained since it + is not kept in a bin. + + SmallBins + An array of bin headers for free chunks. These bins hold chunks + with sizes less than MIN_LARGE_SIZE bytes. Each bin contains + chunks of all the same size, spaced 8 bytes apart. To simplify + use in double-linked lists, each bin header acts as a malloc_chunk + pointing to the real first node, if it exists (else pointing to + itself). This avoids special-casing for headers. But to avoid + waste, we allocate only the fd/bk pointers of bins, and then use + repositioning tricks to treat these as the fields of a chunk. + + TreeBins + Treebins are pointers to the roots of trees holding a range of + sizes. There are 2 equally spaced treebins for each power of two + from TREE_SHIFT to TREE_SHIFT+16. The last bin holds anything + larger. + + Bin maps + There is one bit map for small bins ("smallmap") and one for + treebins ("treemap). Each bin sets its bit when non-empty, and + clears the bit when empty. Bit operations are then used to avoid + bin-by-bin searching -- nearly all "search" is done without ever + looking at bins that won't be selected. The bit maps + conservatively use 32 bits per map word, even if on 64bit system. + For a good description of some of the bit-based techniques used + here, see Henry S. Warren Jr's book "Hacker's Delight" (and + supplement at http://hackersdelight.org/). Many of these are + intended to reduce the branchiness of paths through malloc etc, as + well as to reduce the number of memory locations read or written. + + Segments + A list of segments headed by an embedded malloc_segment record + representing the initial space. + + Address check support + The least_addr field is the least address ever obtained from + MORECORE or MMAP. Attempted frees and reallocs of any address less + than this are trapped (unless INSECURE is defined). + + Magic tag + A cross-check field that should always hold same value as mparams.magic. + + Flags + Bits recording whether to use MMAP, locks, or contiguous MORECORE + + Statistics + Each space keeps track of current and maximum system memory + obtained via MORECORE or MMAP. + + Trim support + Fields holding the amount of unused topmost memory that should trigger + timming, and a counter to force periodic scanning to release unused + non-topmost segments. + + Locking + If USE_LOCKS is defined, the "mutex" lock is acquired and released + around every public call using this mspace. + + Extension support + A void* pointer and a size_t field that can be used to help implement + extensions to this malloc. +*/ + +/* Bin types, widths and sizes */ +#define NSMALLBINS (32U) +#define NTREEBINS (32U) +#define SMALLBIN_SHIFT (3U) +#define SMALLBIN_WIDTH (SIZE_T_ONE << SMALLBIN_SHIFT) +#define TREEBIN_SHIFT (8U) +#define MIN_LARGE_SIZE (SIZE_T_ONE << TREEBIN_SHIFT) +#define MAX_SMALL_SIZE (MIN_LARGE_SIZE - SIZE_T_ONE) +#define MAX_SMALL_REQUEST (MAX_SMALL_SIZE - CHUNK_ALIGN_MASK - CHUNK_OVERHEAD) + +struct malloc_state { + binmap_t smallmap; + binmap_t treemap; + size_t dvsize; + size_t topsize; + char* least_addr; + mchunkptr dv; + mchunkptr top; + size_t trim_check; + size_t release_checks; + size_t magic; + mchunkptr smallbins[(NSMALLBINS+1)*2]; + tbinptr treebins[NTREEBINS]; + size_t footprint; + size_t max_footprint; + flag_t mflags; +#if USE_LOCKS + MLOCK_T mutex; /* locate lock among fields that rarely change */ +#endif /* USE_LOCKS */ + msegment seg; + void* extp; /* Unused but available for extensions */ + size_t exts; +}; + +typedef struct malloc_state* mstate; + +/* ------------- Global malloc_state and malloc_params ------------------- */ + +/* + malloc_params holds global properties, including those that can be + dynamically set using mallopt. There is a single instance, mparams, + initialized in init_mparams. Note that the non-zeroness of "magic" + also serves as an initialization flag. +*/ + +struct malloc_params { + volatile size_t magic; + size_t page_size; + size_t granularity; + size_t mmap_threshold; + size_t trim_threshold; + flag_t default_mflags; +}; + +static struct malloc_params mparams; + +/* Ensure mparams initialized */ +#define ensure_initialization() ((void)(mparams.magic != 0 || init_mparams())) + +#if !ONLY_MSPACES + +/* The global malloc_state used for all non-"mspace" calls */ +static struct malloc_state _gm_; +#define gm (&_gm_) +#define is_global(M) ((M) == &_gm_) + +#endif /* !ONLY_MSPACES */ + +#define is_initialized(M) ((M)->top != 0) + +/* -------------------------- system alloc setup ------------------------- */ + +/* Operations on mflags */ + +#define use_lock(M) ((M)->mflags & USE_LOCK_BIT) +#define enable_lock(M) ((M)->mflags |= USE_LOCK_BIT) +#define disable_lock(M) ((M)->mflags &= ~USE_LOCK_BIT) + +#define use_mmap(M) ((M)->mflags & USE_MMAP_BIT) +#define enable_mmap(M) ((M)->mflags |= USE_MMAP_BIT) +#define disable_mmap(M) ((M)->mflags &= ~USE_MMAP_BIT) + +#define use_noncontiguous(M) ((M)->mflags & USE_NONCONTIGUOUS_BIT) +#define disable_contiguous(M) ((M)->mflags |= USE_NONCONTIGUOUS_BIT) + +#define set_lock(M,L)\ + ((M)->mflags = (L)?\ + ((M)->mflags | USE_LOCK_BIT) :\ + ((M)->mflags & ~USE_LOCK_BIT)) + +/* page-align a size */ +#define page_align(S)\ + (((S) + (mparams.page_size - SIZE_T_ONE)) & ~(mparams.page_size - SIZE_T_ONE)) + +/* granularity-align a size */ +#define granularity_align(S)\ + (((S) + (mparams.granularity - SIZE_T_ONE))\ + & ~(mparams.granularity - SIZE_T_ONE)) + + +/* For mmap, use granularity alignment on windows, else page-align */ +#ifdef WIN32 +#define mmap_align(S) granularity_align(S) +#else +#define mmap_align(S) page_align(S) +#endif + +/* For sys_alloc, enough padding to ensure can malloc request on success */ +#define SYS_ALLOC_PADDING (TOP_FOOT_SIZE + MALLOC_ALIGNMENT) + +#define is_page_aligned(S)\ + (((size_t)(S) & (mparams.page_size - SIZE_T_ONE)) == 0) +#define is_granularity_aligned(S)\ + (((size_t)(S) & (mparams.granularity - SIZE_T_ONE)) == 0) + +/* True if segment S holds address A */ +#define segment_holds(S, A)\ + ((char*)(A) >= S->base && (char*)(A) < S->base + S->size) + +/* Return segment holding given address */ +static msegmentptr segment_holding(mstate m, char* addr) { + msegmentptr sp = &m->seg; + for (;;) { + if (addr >= sp->base && addr < sp->base + sp->size) + return sp; + if ((sp = sp->next) == 0) + return 0; + } +} + +/* Return true if segment contains a segment link */ +static int has_segment_link(mstate m, msegmentptr ss) { + msegmentptr sp = &m->seg; + for (;;) { + if ((char*)sp >= ss->base && (char*)sp < ss->base + ss->size) + return 1; + if ((sp = sp->next) == 0) + return 0; + } +} + +#ifndef MORECORE_CANNOT_TRIM +#define should_trim(M,s) ((s) > (M)->trim_check) +#else /* MORECORE_CANNOT_TRIM */ +#define should_trim(M,s) (0) +#endif /* MORECORE_CANNOT_TRIM */ + +/* + TOP_FOOT_SIZE is padding at the end of a segment, including space + that may be needed to place segment records and fenceposts when new + noncontiguous segments are added. +*/ +#define TOP_FOOT_SIZE\ + (align_offset(chunk2mem(0))+pad_request(sizeof(struct malloc_segment))+MIN_CHUNK_SIZE) + + +/* ------------------------------- Hooks -------------------------------- */ + +/* + PREACTION should be defined to return 0 on success, and nonzero on + failure. If you are not using locking, you can redefine these to do + anything you like. +*/ + +#if USE_LOCKS + +#define PREACTION(M) ((use_lock(M))? ACQUIRE_LOCK(&(M)->mutex) : 0) +#define POSTACTION(M) { if (use_lock(M)) RELEASE_LOCK(&(M)->mutex); } +#else /* USE_LOCKS */ + +#ifndef PREACTION +#define PREACTION(M) (0) +#endif /* PREACTION */ + +#ifndef POSTACTION +#define POSTACTION(M) +#endif /* POSTACTION */ + +#endif /* USE_LOCKS */ + +/* + CORRUPTION_ERROR_ACTION is triggered upon detected bad addresses. + USAGE_ERROR_ACTION is triggered on detected bad frees and + reallocs. The argument p is an address that might have triggered the + fault. It is ignored by the two predefined actions, but might be + useful in custom actions that try to help diagnose errors. +*/ + +#if PROCEED_ON_ERROR + +/* A count of the number of corruption errors causing resets */ +int malloc_corruption_error_count; + +/* default corruption action */ +static void reset_on_error(mstate m); + +#define CORRUPTION_ERROR_ACTION(m) reset_on_error(m) +#define USAGE_ERROR_ACTION(m, p) + +#else /* PROCEED_ON_ERROR */ + +#ifndef CORRUPTION_ERROR_ACTION +#define CORRUPTION_ERROR_ACTION(m) ABORT +#endif /* CORRUPTION_ERROR_ACTION */ + +#ifndef USAGE_ERROR_ACTION +#define USAGE_ERROR_ACTION(m,p) ABORT +#endif /* USAGE_ERROR_ACTION */ + +#endif /* PROCEED_ON_ERROR */ + +/* -------------------------- Debugging setup ---------------------------- */ + +#if ! DEBUG + +#define check_free_chunk(M,P) +#define check_inuse_chunk(M,P) +#define check_malloced_chunk(M,P,N) +#define check_mmapped_chunk(M,P) +#define check_malloc_state(M) +#define check_top_chunk(M,P) + +#else /* DEBUG */ +#define check_free_chunk(M,P) do_check_free_chunk(M,P) +#define check_inuse_chunk(M,P) do_check_inuse_chunk(M,P) +#define check_top_chunk(M,P) do_check_top_chunk(M,P) +#define check_malloced_chunk(M,P,N) do_check_malloced_chunk(M,P,N) +#define check_mmapped_chunk(M,P) do_check_mmapped_chunk(M,P) +#define check_malloc_state(M) do_check_malloc_state(M) + +static void do_check_any_chunk(mstate m, mchunkptr p); +static void do_check_top_chunk(mstate m, mchunkptr p); +static void do_check_mmapped_chunk(mstate m, mchunkptr p); +static void do_check_inuse_chunk(mstate m, mchunkptr p); +static void do_check_free_chunk(mstate m, mchunkptr p); +static void do_check_malloced_chunk(mstate m, void* mem, size_t s); +static void do_check_tree(mstate m, tchunkptr t); +static void do_check_treebin(mstate m, bindex_t i); +static void do_check_smallbin(mstate m, bindex_t i); +static void do_check_malloc_state(mstate m); +static int bin_find(mstate m, mchunkptr x); +static size_t traverse_and_check(mstate m); +#endif /* DEBUG */ + +/* ---------------------------- Indexing Bins ---------------------------- */ + +#define is_small(s) (((s) >> SMALLBIN_SHIFT) < NSMALLBINS) +#define small_index(s) ((s) >> SMALLBIN_SHIFT) +#define small_index2size(i) ((i) << SMALLBIN_SHIFT) +#define MIN_SMALL_INDEX (small_index(MIN_CHUNK_SIZE)) + +/* addressing by index. See above about smallbin repositioning */ +#define smallbin_at(M, i) ((sbinptr)((char*)&((M)->smallbins[(i)<<1]))) +#define treebin_at(M,i) (&((M)->treebins[i])) + +/* assign tree index for size S to variable I. Use x86 asm if possible */ +#if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__)) +#define compute_tree_index(S, I)\ +{\ + unsigned int X = S >> TREEBIN_SHIFT;\ + if (X == 0)\ + I = 0;\ + else if (X > 0xFFFF)\ + I = NTREEBINS-1;\ + else {\ + unsigned int K;\ + __asm__("bsrl\t%1, %0\n\t" : "=r" (K) : "rm" (X));\ + I = (bindex_t)((K << 1) + ((S >> (K + (TREEBIN_SHIFT-1)) & 1)));\ + }\ +} + +#elif defined (__INTEL_COMPILER) +#define compute_tree_index(S, I)\ +{\ + size_t X = S >> TREEBIN_SHIFT;\ + if (X == 0)\ + I = 0;\ + else if (X > 0xFFFF)\ + I = NTREEBINS-1;\ + else {\ + unsigned int K = _bit_scan_reverse (X); \ + I = (bindex_t)((K << 1) + ((S >> (K + (TREEBIN_SHIFT-1)) & 1)));\ + }\ +} + +#elif defined(_MSC_VER) && _MSC_VER>=1300 +#define compute_tree_index(S, I)\ +{\ + size_t X = S >> TREEBIN_SHIFT;\ + if (X == 0)\ + I = 0;\ + else if (X > 0xFFFF)\ + I = NTREEBINS-1;\ + else {\ + unsigned int K;\ + _BitScanReverse((DWORD *) &K, X);\ + I = (bindex_t)((K << 1) + ((S >> (K + (TREEBIN_SHIFT-1)) & 1)));\ + }\ +} + +#else /* GNUC */ +#define compute_tree_index(S, I)\ +{\ + size_t X = S >> TREEBIN_SHIFT;\ + if (X == 0)\ + I = 0;\ + else if (X > 0xFFFF)\ + I = NTREEBINS-1;\ + else {\ + unsigned int Y = (unsigned int)X;\ + unsigned int N = ((Y - 0x100) >> 16) & 8;\ + unsigned int K = (((Y <<= N) - 0x1000) >> 16) & 4;\ + N += K;\ + N += K = (((Y <<= K) - 0x4000) >> 16) & 2;\ + K = 14 - N + ((Y <<= K) >> 15);\ + I = (K << 1) + ((S >> (K + (TREEBIN_SHIFT-1)) & 1));\ + }\ +} +#endif /* GNUC */ + +/* Bit representing maximum resolved size in a treebin at i */ +#define bit_for_tree_index(i) \ + (i == NTREEBINS-1)? (SIZE_T_BITSIZE-1) : (((i) >> 1) + TREEBIN_SHIFT - 2) + +/* Shift placing maximum resolved bit in a treebin at i as sign bit */ +#define leftshift_for_tree_index(i) \ + ((i == NTREEBINS-1)? 0 : \ + ((SIZE_T_BITSIZE-SIZE_T_ONE) - (((i) >> 1) + TREEBIN_SHIFT - 2))) + +/* The size of the smallest chunk held in bin with index i */ +#define minsize_for_tree_index(i) \ + ((SIZE_T_ONE << (((i) >> 1) + TREEBIN_SHIFT)) | \ + (((size_t)((i) & SIZE_T_ONE)) << (((i) >> 1) + TREEBIN_SHIFT - 1))) + + +/* ------------------------ Operations on bin maps ----------------------- */ + +/* bit corresponding to given index */ +#define idx2bit(i) ((binmap_t)(1) << (i)) + +/* Mark/Clear bits with given index */ +#define mark_smallmap(M,i) ((M)->smallmap |= idx2bit(i)) +#define clear_smallmap(M,i) ((M)->smallmap &= ~idx2bit(i)) +#define smallmap_is_marked(M,i) ((M)->smallmap & idx2bit(i)) + +#define mark_treemap(M,i) ((M)->treemap |= idx2bit(i)) +#define clear_treemap(M,i) ((M)->treemap &= ~idx2bit(i)) +#define treemap_is_marked(M,i) ((M)->treemap & idx2bit(i)) + +/* isolate the least set bit of a bitmap */ +#define least_bit(x) ((x) & -(x)) + +/* mask with all bits to left of least bit of x on */ +#define left_bits(x) ((x<<1) | -(x<<1)) + +/* mask with all bits to left of or equal to least bit of x on */ +#define same_or_left_bits(x) ((x) | -(x)) + +/* index corresponding to given bit. Use x86 asm if possible */ + +#if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__)) +#define compute_bit2idx(X, I)\ +{\ + unsigned int J;\ + __asm__("bsfl\t%1, %0\n\t" : "=r" (J) : "rm" (X));\ + I = (bindex_t)J;\ +} + +#elif defined (__INTEL_COMPILER) +#define compute_bit2idx(X, I)\ +{\ + unsigned int J;\ + J = _bit_scan_forward (X); \ + I = (bindex_t)J;\ +} + +#elif defined(_MSC_VER) && _MSC_VER>=1300 +#define compute_bit2idx(X, I)\ +{\ + unsigned int J;\ + _BitScanForward((DWORD *) &J, X);\ + I = (bindex_t)J;\ +} + +#elif USE_BUILTIN_FFS +#define compute_bit2idx(X, I) I = ffs(X)-1 + +#else +#define compute_bit2idx(X, I)\ +{\ + unsigned int Y = X - 1;\ + unsigned int K = Y >> (16-4) & 16;\ + unsigned int N = K; Y >>= K;\ + N += K = Y >> (8-3) & 8; Y >>= K;\ + N += K = Y >> (4-2) & 4; Y >>= K;\ + N += K = Y >> (2-1) & 2; Y >>= K;\ + N += K = Y >> (1-0) & 1; Y >>= K;\ + I = (bindex_t)(N + Y);\ +} +#endif /* GNUC */ + + +/* ----------------------- Runtime Check Support ------------------------- */ + +/* + For security, the main invariant is that malloc/free/etc never + writes to a static address other than malloc_state, unless static + malloc_state itself has been corrupted, which cannot occur via + malloc (because of these checks). In essence this means that we + believe all pointers, sizes, maps etc held in malloc_state, but + check all of those linked or offsetted from other embedded data + structures. These checks are interspersed with main code in a way + that tends to minimize their run-time cost. + + When FOOTERS is defined, in addition to range checking, we also + verify footer fields of inuse chunks, which can be used guarantee + that the mstate controlling malloc/free is intact. This is a + streamlined version of the approach described by William Robertson + et al in "Run-time Detection of Heap-based Overflows" LISA'03 + http://www.usenix.org/events/lisa03/tech/robertson.html The footer + of an inuse chunk holds the xor of its mstate and a random seed, + that is checked upon calls to free() and realloc(). This is + (probablistically) unguessable from outside the program, but can be + computed by any code successfully malloc'ing any chunk, so does not + itself provide protection against code that has already broken + security through some other means. Unlike Robertson et al, we + always dynamically check addresses of all offset chunks (previous, + next, etc). This turns out to be cheaper than relying on hashes. +*/ + +#if !INSECURE +/* Check if address a is at least as high as any from MORECORE or MMAP */ +#define ok_address(M, a) ((char*)(a) >= (M)->least_addr) +/* Check if address of next chunk n is higher than base chunk p */ +#define ok_next(p, n) ((char*)(p) < (char*)(n)) +/* Check if p has its cinuse bit on */ +#define ok_cinuse(p) cinuse(p) +/* Check if p has its pinuse bit on */ +#define ok_pinuse(p) pinuse(p) + +#else /* !INSECURE */ +#define ok_address(M, a) (1) +#define ok_next(b, n) (1) +#define ok_cinuse(p) (1) +#define ok_pinuse(p) (1) +#endif /* !INSECURE */ + +#if (FOOTERS && !INSECURE) +/* Check if (alleged) mstate m has expected magic field */ +#define ok_magic(M) ((M)->magic == mparams.magic) +#else /* (FOOTERS && !INSECURE) */ +#define ok_magic(M) (1) +#endif /* (FOOTERS && !INSECURE) */ + + +/* In gcc, use __builtin_expect to minimize impact of checks */ +#if !INSECURE +#if defined(__GNUC__) && __GNUC__ >= 3 +#define RTCHECK(e) __builtin_expect(e, 1) +#else /* GNUC */ +#define RTCHECK(e) (e) +#endif /* GNUC */ +#else /* !INSECURE */ +#define RTCHECK(e) (1) +#endif /* !INSECURE */ + +/* macros to set up inuse chunks with or without footers */ + +#if !FOOTERS + +#define mark_inuse_foot(M,p,s) + +/* Set cinuse bit and pinuse bit of next chunk */ +#define set_inuse(M,p,s)\ + ((p)->head = (((p)->head & PINUSE_BIT)|s|CINUSE_BIT),\ + ((mchunkptr)(((char*)(p)) + (s)))->head |= PINUSE_BIT) + +/* Set cinuse and pinuse of this chunk and pinuse of next chunk */ +#define set_inuse_and_pinuse(M,p,s)\ + ((p)->head = (s|PINUSE_BIT|CINUSE_BIT),\ + ((mchunkptr)(((char*)(p)) + (s)))->head |= PINUSE_BIT) + +/* Set size, cinuse and pinuse bit of this chunk */ +#define set_size_and_pinuse_of_inuse_chunk(M, p, s)\ + ((p)->head = (s|PINUSE_BIT|CINUSE_BIT)) + +#else /* FOOTERS */ + +/* Set foot of inuse chunk to be xor of mstate and seed */ +#define mark_inuse_foot(M,p,s)\ + (((mchunkptr)((char*)(p) + (s)))->prev_foot = ((size_t)(M) ^ mparams.magic)) + +#define get_mstate_for(p)\ + ((mstate)(((mchunkptr)((char*)(p) +\ + (chunksize(p))))->prev_foot ^ mparams.magic)) + +#define set_inuse(M,p,s)\ + ((p)->head = (((p)->head & PINUSE_BIT)|s|CINUSE_BIT),\ + (((mchunkptr)(((char*)(p)) + (s)))->head |= PINUSE_BIT), \ + mark_inuse_foot(M,p,s)) + +#define set_inuse_and_pinuse(M,p,s)\ + ((p)->head = (s|PINUSE_BIT|CINUSE_BIT),\ + (((mchunkptr)(((char*)(p)) + (s)))->head |= PINUSE_BIT),\ + mark_inuse_foot(M,p,s)) + +#define set_size_and_pinuse_of_inuse_chunk(M, p, s)\ + ((p)->head = (s|PINUSE_BIT|CINUSE_BIT),\ + mark_inuse_foot(M, p, s)) + +#endif /* !FOOTERS */ + +/* ---------------------------- setting mparams -------------------------- */ + +/* Initialize mparams */ +static int init_mparams(void) { +#ifdef NEED_GLOBAL_LOCK_INIT + if (malloc_global_mutex_status <= 0) + init_malloc_global_mutex(); +#endif + + ACQUIRE_MALLOC_GLOBAL_LOCK(); + if (mparams.magic == 0) { + size_t magic; + size_t psize; + size_t gsize; + +#ifndef WIN32 + psize = malloc_getpagesize; + gsize = ((DEFAULT_GRANULARITY != 0)? DEFAULT_GRANULARITY : psize); +#else /* WIN32 */ + { + SYSTEM_INFO system_info; + GetSystemInfo(&system_info); + psize = system_info.dwPageSize; + gsize = ((DEFAULT_GRANULARITY != 0)? + DEFAULT_GRANULARITY : system_info.dwAllocationGranularity); + } +#endif /* WIN32 */ + + /* Sanity-check configuration: + size_t must be unsigned and as wide as pointer type. + ints must be at least 4 bytes. + alignment must be at least 8. + Alignment, min chunk size, and page size must all be powers of 2. + */ + if ((sizeof(size_t) != sizeof(char*)) || + (MAX_SIZE_T < MIN_CHUNK_SIZE) || + (sizeof(int) < 4) || + (MALLOC_ALIGNMENT < (size_t)8U) || + ((MALLOC_ALIGNMENT & (MALLOC_ALIGNMENT-SIZE_T_ONE)) != 0) || + ((MCHUNK_SIZE & (MCHUNK_SIZE-SIZE_T_ONE)) != 0) || + ((gsize & (gsize-SIZE_T_ONE)) != 0) || + ((psize & (psize-SIZE_T_ONE)) != 0)) + ABORT; + + mparams.granularity = gsize; + mparams.page_size = psize; + mparams.mmap_threshold = DEFAULT_MMAP_THRESHOLD; + mparams.trim_threshold = DEFAULT_TRIM_THRESHOLD; +#if MORECORE_CONTIGUOUS + mparams.default_mflags = USE_LOCK_BIT|USE_MMAP_BIT; +#else /* MORECORE_CONTIGUOUS */ + mparams.default_mflags = USE_LOCK_BIT|USE_MMAP_BIT|USE_NONCONTIGUOUS_BIT; +#endif /* MORECORE_CONTIGUOUS */ + +#if !ONLY_MSPACES + /* Set up lock for main malloc area */ + gm->mflags = mparams.default_mflags; + INITIAL_LOCK(&gm->mutex); +#endif + +#if (FOOTERS && !INSECURE) + { +#if USE_DEV_RANDOM + int fd; + unsigned char buf[sizeof(size_t)]; + /* Try to use /dev/urandom, else fall back on using time */ + if ((fd = open("/dev/urandom", O_RDONLY)) >= 0 && + read(fd, buf, sizeof(buf)) == sizeof(buf)) { + magic = *((size_t *) buf); + close(fd); + } + else +#endif /* USE_DEV_RANDOM */ +#ifdef WIN32 + magic = (size_t)(GetTickCount() ^ (size_t)0x55555555U); +#else + magic = (size_t)(time(0) ^ (size_t)0x55555555U); +#endif + magic |= (size_t)8U; /* ensure nonzero */ + magic &= ~(size_t)7U; /* improve chances of fault for bad values */ + } +#else /* (FOOTERS && !INSECURE) */ + magic = (size_t)0x58585858U; +#endif /* (FOOTERS && !INSECURE) */ + + mparams.magic = magic; + } + + RELEASE_MALLOC_GLOBAL_LOCK(); + return 1; +} + +/* support for mallopt */ +static int change_mparam(int param_number, int value) { + size_t val = (value == -1)? MAX_SIZE_T : (size_t)value; + ensure_initialization(); + switch(param_number) { + case M_TRIM_THRESHOLD: + mparams.trim_threshold = val; + return 1; + case M_GRANULARITY: + if (val >= mparams.page_size && ((val & (val-1)) == 0)) { + mparams.granularity = val; + return 1; + } + else + return 0; + case M_MMAP_THRESHOLD: + mparams.mmap_threshold = val; + return 1; + default: + return 0; + } +} + +#if DEBUG +/* ------------------------- Debugging Support --------------------------- */ + +/* Check properties of any chunk, whether free, inuse, mmapped etc */ +static void do_check_any_chunk(mstate m, mchunkptr p) { + assert((is_aligned(chunk2mem(p))) || (p->head == FENCEPOST_HEAD)); + assert(ok_address(m, p)); +} + +/* Check properties of top chunk */ +static void do_check_top_chunk(mstate m, mchunkptr p) { + msegmentptr sp = segment_holding(m, (char*)p); + size_t sz = p->head & ~INUSE_BITS; /* third-lowest bit can be set! */ + assert(sp != 0); + assert((is_aligned(chunk2mem(p))) || (p->head == FENCEPOST_HEAD)); + assert(ok_address(m, p)); + assert(sz == m->topsize); + assert(sz > 0); + assert(sz == ((sp->base + sp->size) - (char*)p) - TOP_FOOT_SIZE); + assert(pinuse(p)); + assert(!pinuse(chunk_plus_offset(p, sz))); +} + +/* Check properties of (inuse) mmapped chunks */ +static void do_check_mmapped_chunk(mstate m, mchunkptr p) { + size_t sz = chunksize(p); + size_t len = (sz + (p->prev_foot & ~IS_MMAPPED_BIT) + MMAP_FOOT_PAD); + assert(is_mmapped(p)); + assert(use_mmap(m)); + assert((is_aligned(chunk2mem(p))) || (p->head == FENCEPOST_HEAD)); + assert(ok_address(m, p)); + assert(!is_small(sz)); + assert((len & (mparams.page_size-SIZE_T_ONE)) == 0); + assert(chunk_plus_offset(p, sz)->head == FENCEPOST_HEAD); + assert(chunk_plus_offset(p, sz+SIZE_T_SIZE)->head == 0); +} + +/* Check properties of inuse chunks */ +static void do_check_inuse_chunk(mstate m, mchunkptr p) { + do_check_any_chunk(m, p); + assert(cinuse(p)); + assert(next_pinuse(p)); + /* If not pinuse and not mmapped, previous chunk has OK offset */ + assert(is_mmapped(p) || pinuse(p) || next_chunk(prev_chunk(p)) == p); + if (is_mmapped(p)) + do_check_mmapped_chunk(m, p); +} + +/* Check properties of free chunks */ +static void do_check_free_chunk(mstate m, mchunkptr p) { + size_t sz = chunksize(p); + mchunkptr next = chunk_plus_offset(p, sz); + do_check_any_chunk(m, p); + assert(!cinuse(p)); + assert(!next_pinuse(p)); + assert (!is_mmapped(p)); + if (p != m->dv && p != m->top) { + if (sz >= MIN_CHUNK_SIZE) { + assert((sz & CHUNK_ALIGN_MASK) == 0); + assert(is_aligned(chunk2mem(p))); + assert(next->prev_foot == sz); + assert(pinuse(p)); + assert (next == m->top || cinuse(next)); + assert(p->fd->bk == p); + assert(p->bk->fd == p); + } + else /* markers are always of size SIZE_T_SIZE */ + assert(sz == SIZE_T_SIZE); + } +} + +/* Check properties of malloced chunks at the point they are malloced */ +static void do_check_malloced_chunk(mstate m, void* mem, size_t s) { + if (mem != 0) { + mchunkptr p = mem2chunk(mem); + size_t sz = p->head & ~(PINUSE_BIT|CINUSE_BIT); + do_check_inuse_chunk(m, p); + assert((sz & CHUNK_ALIGN_MASK) == 0); + assert(sz >= MIN_CHUNK_SIZE); + assert(sz >= s); + /* unless mmapped, size is less than MIN_CHUNK_SIZE more than request */ + assert(is_mmapped(p) || sz < (s + MIN_CHUNK_SIZE)); + } +} + +/* Check a tree and its subtrees. */ +static void do_check_tree(mstate m, tchunkptr t) { + tchunkptr head = 0; + tchunkptr u = t; + bindex_t tindex = t->index; + size_t tsize = chunksize(t); + bindex_t idx; + compute_tree_index(tsize, idx); + assert(tindex == idx); + assert(tsize >= MIN_LARGE_SIZE); + assert(tsize >= minsize_for_tree_index(idx)); + assert((idx == NTREEBINS-1) || (tsize < minsize_for_tree_index((idx+1)))); + + do { /* traverse through chain of same-sized nodes */ + do_check_any_chunk(m, ((mchunkptr)u)); + assert(u->index == tindex); + assert(chunksize(u) == tsize); + assert(!cinuse(u)); + assert(!next_pinuse(u)); + assert(u->fd->bk == u); + assert(u->bk->fd == u); + if (u->parent == 0) { + assert(u->child[0] == 0); + assert(u->child[1] == 0); + } + else { + assert(head == 0); /* only one node on chain has parent */ + head = u; + assert(u->parent != u); + assert (u->parent->child[0] == u || + u->parent->child[1] == u || + *((tbinptr*)(u->parent)) == u); + if (u->child[0] != 0) { + assert(u->child[0]->parent == u); + assert(u->child[0] != u); + do_check_tree(m, u->child[0]); + } + if (u->child[1] != 0) { + assert(u->child[1]->parent == u); + assert(u->child[1] != u); + do_check_tree(m, u->child[1]); + } + if (u->child[0] != 0 && u->child[1] != 0) { + assert(chunksize(u->child[0]) < chunksize(u->child[1])); + } + } + u = u->fd; + } while (u != t); + assert(head != 0); +} + +/* Check all the chunks in a treebin. */ +static void do_check_treebin(mstate m, bindex_t i) { + tbinptr* tb = treebin_at(m, i); + tchunkptr t = *tb; + int empty = (m->treemap & (1U << i)) == 0; + if (t == 0) + assert(empty); + if (!empty) + do_check_tree(m, t); +} + +/* Check all the chunks in a smallbin. */ +static void do_check_smallbin(mstate m, bindex_t i) { + sbinptr b = smallbin_at(m, i); + mchunkptr p = b->bk; + unsigned int empty = (m->smallmap & (1U << i)) == 0; + if (p == b) + assert(empty); + if (!empty) { + for (; p != b; p = p->bk) { + size_t size = chunksize(p); + mchunkptr q; + /* each chunk claims to be free */ + do_check_free_chunk(m, p); + /* chunk belongs in bin */ + assert(small_index(size) == i); + assert(p->bk == b || chunksize(p->bk) == chunksize(p)); + /* chunk is followed by an inuse chunk */ + q = next_chunk(p); + if (q->head != FENCEPOST_HEAD) + do_check_inuse_chunk(m, q); + } + } +} + +/* Find x in a bin. Used in other check functions. */ +static int bin_find(mstate m, mchunkptr x) { + size_t size = chunksize(x); + if (is_small(size)) { + bindex_t sidx = small_index(size); + sbinptr b = smallbin_at(m, sidx); + if (smallmap_is_marked(m, sidx)) { + mchunkptr p = b; + do { + if (p == x) + return 1; + } while ((p = p->fd) != b); + } + } + else { + bindex_t tidx; + compute_tree_index(size, tidx); + if (treemap_is_marked(m, tidx)) { + tchunkptr t = *treebin_at(m, tidx); + size_t sizebits = size << leftshift_for_tree_index(tidx); + while (t != 0 && chunksize(t) != size) { + t = t->child[(sizebits >> (SIZE_T_BITSIZE-SIZE_T_ONE)) & 1]; + sizebits <<= 1; + } + if (t != 0) { + tchunkptr u = t; + do { + if (u == (tchunkptr)x) + return 1; + } while ((u = u->fd) != t); + } + } + } + return 0; +} + +/* Traverse each chunk and check it; return total */ +static size_t traverse_and_check(mstate m) { + size_t sum = 0; + if (is_initialized(m)) { + msegmentptr s = &m->seg; + sum += m->topsize + TOP_FOOT_SIZE; + while (s != 0) { + mchunkptr q = align_as_chunk(s->base); + mchunkptr lastq = 0; + assert(pinuse(q)); + while (segment_holds(s, q) && + q != m->top && q->head != FENCEPOST_HEAD) { + sum += chunksize(q); + if (cinuse(q)) { + assert(!bin_find(m, q)); + do_check_inuse_chunk(m, q); + } + else { + assert(q == m->dv || bin_find(m, q)); + assert(lastq == 0 || cinuse(lastq)); /* Not 2 consecutive free */ + do_check_free_chunk(m, q); + } + lastq = q; + q = next_chunk(q); + } + s = s->next; + } + } + return sum; +} + +/* Check all properties of malloc_state. */ +static void do_check_malloc_state(mstate m) { + bindex_t i; + size_t total; + /* check bins */ + for (i = 0; i < NSMALLBINS; ++i) + do_check_smallbin(m, i); + for (i = 0; i < NTREEBINS; ++i) + do_check_treebin(m, i); + + if (m->dvsize != 0) { /* check dv chunk */ + do_check_any_chunk(m, m->dv); + assert(m->dvsize == chunksize(m->dv)); + assert(m->dvsize >= MIN_CHUNK_SIZE); + assert(bin_find(m, m->dv) == 0); + } + + if (m->top != 0) { /* check top chunk */ + do_check_top_chunk(m, m->top); + /*assert(m->topsize == chunksize(m->top)); redundant */ + assert(m->topsize > 0); + assert(bin_find(m, m->top) == 0); + } + + total = traverse_and_check(m); + assert(total <= m->footprint); + assert(m->footprint <= m->max_footprint); +} +#endif /* DEBUG */ + +/* ----------------------------- statistics ------------------------------ */ + +#if !NO_MALLINFO +static struct mallinfo internal_mallinfo(mstate m) { + struct mallinfo nm = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + ensure_initialization(); + if (!PREACTION(m)) { + check_malloc_state(m); + if (is_initialized(m)) { + size_t nfree = SIZE_T_ONE; /* top always free */ + size_t mfree = m->topsize + TOP_FOOT_SIZE; + size_t sum = mfree; + msegmentptr s = &m->seg; + while (s != 0) { + mchunkptr q = align_as_chunk(s->base); + while (segment_holds(s, q) && + q != m->top && q->head != FENCEPOST_HEAD) { + size_t sz = chunksize(q); + sum += sz; + if (!cinuse(q)) { + mfree += sz; + ++nfree; + } + q = next_chunk(q); + } + s = s->next; + } + + nm.arena = sum; + nm.ordblks = nfree; + nm.hblkhd = m->footprint - sum; + nm.usmblks = m->max_footprint; + nm.uordblks = m->footprint - mfree; + nm.fordblks = mfree; + nm.keepcost = m->topsize; + } + + POSTACTION(m); + } + return nm; +} +#endif /* !NO_MALLINFO */ + +static void internal_malloc_stats(mstate m) { + ensure_initialization(); + if (!PREACTION(m)) { + size_t maxfp = 0; + size_t fp = 0; + size_t used = 0; + check_malloc_state(m); + if (is_initialized(m)) { + msegmentptr s = &m->seg; + maxfp = m->max_footprint; + fp = m->footprint; + used = fp - (m->topsize + TOP_FOOT_SIZE); + + while (s != 0) { + mchunkptr q = align_as_chunk(s->base); + while (segment_holds(s, q) && + q != m->top && q->head != FENCEPOST_HEAD) { + if (!cinuse(q)) + used -= chunksize(q); + q = next_chunk(q); + } + s = s->next; + } + } + + fprintf(stderr, "max system bytes = %10lu\n", (unsigned long)(maxfp)); + fprintf(stderr, "system bytes = %10lu\n", (unsigned long)(fp)); + fprintf(stderr, "in use bytes = %10lu\n", (unsigned long)(used)); + + POSTACTION(m); + } +} + +/* ----------------------- Operations on smallbins ----------------------- */ + +/* + Various forms of linking and unlinking are defined as macros. Even + the ones for trees, which are very long but have very short typical + paths. This is ugly but reduces reliance on inlining support of + compilers. +*/ + +/* Link a free chunk into a smallbin */ +#define insert_small_chunk(M, P, S) {\ + bindex_t I = small_index(S);\ + mchunkptr B = smallbin_at(M, I);\ + mchunkptr F = B;\ + assert(S >= MIN_CHUNK_SIZE);\ + if (!smallmap_is_marked(M, I))\ + mark_smallmap(M, I);\ + else if (RTCHECK(ok_address(M, B->fd)))\ + F = B->fd;\ + else {\ + CORRUPTION_ERROR_ACTION(M);\ + }\ + B->fd = P;\ + F->bk = P;\ + P->fd = F;\ + P->bk = B;\ +} + +/* Unlink a chunk from a smallbin */ +#define unlink_small_chunk(M, P, S) {\ + mchunkptr F = P->fd;\ + mchunkptr B = P->bk;\ + bindex_t I = small_index(S);\ + assert(P != B);\ + assert(P != F);\ + assert(chunksize(P) == small_index2size(I));\ + if (F == B)\ + clear_smallmap(M, I);\ + else if (RTCHECK((F == smallbin_at(M,I) || ok_address(M, F)) &&\ + (B == smallbin_at(M,I) || ok_address(M, B)))) {\ + F->bk = B;\ + B->fd = F;\ + }\ + else {\ + CORRUPTION_ERROR_ACTION(M);\ + }\ +} + +/* Unlink the first chunk from a smallbin */ +#define unlink_first_small_chunk(M, B, P, I) {\ + mchunkptr F = P->fd;\ + assert(P != B);\ + assert(P != F);\ + assert(chunksize(P) == small_index2size(I));\ + if (B == F)\ + clear_smallmap(M, I);\ + else if (RTCHECK(ok_address(M, F))) {\ + B->fd = F;\ + F->bk = B;\ + }\ + else {\ + CORRUPTION_ERROR_ACTION(M);\ + }\ +} + + + +/* Replace dv node, binning the old one */ +/* Used only when dvsize known to be small */ +#define replace_dv(M, P, S) {\ + size_t DVS = M->dvsize;\ + if (DVS != 0) {\ + mchunkptr DV = M->dv;\ + assert(is_small(DVS));\ + insert_small_chunk(M, DV, DVS);\ + }\ + M->dvsize = S;\ + M->dv = P;\ +} + +/* ------------------------- Operations on trees ------------------------- */ + +/* Insert chunk into tree */ +#define insert_large_chunk(M, X, S) {\ + tbinptr* H;\ + bindex_t I;\ + compute_tree_index(S, I);\ + H = treebin_at(M, I);\ + X->index = I;\ + X->child[0] = X->child[1] = 0;\ + if (!treemap_is_marked(M, I)) {\ + mark_treemap(M, I);\ + *H = X;\ + X->parent = (tchunkptr)H;\ + X->fd = X->bk = X;\ + }\ + else {\ + tchunkptr T = *H;\ + size_t K = S << leftshift_for_tree_index(I);\ + for (;;) {\ + if (chunksize(T) != S) {\ + tchunkptr* C = &(T->child[(K >> (SIZE_T_BITSIZE-SIZE_T_ONE)) & 1]);\ + K <<= 1;\ + if (*C != 0)\ + T = *C;\ + else if (RTCHECK(ok_address(M, C))) {\ + *C = X;\ + X->parent = T;\ + X->fd = X->bk = X;\ + break;\ + }\ + else {\ + CORRUPTION_ERROR_ACTION(M);\ + break;\ + }\ + }\ + else {\ + tchunkptr F = T->fd;\ + if (RTCHECK(ok_address(M, T) && ok_address(M, F))) {\ + T->fd = F->bk = X;\ + X->fd = F;\ + X->bk = T;\ + X->parent = 0;\ + break;\ + }\ + else {\ + CORRUPTION_ERROR_ACTION(M);\ + break;\ + }\ + }\ + }\ + }\ +} + +/* + Unlink steps: + + 1. If x is a chained node, unlink it from its same-sized fd/bk links + and choose its bk node as its replacement. + 2. If x was the last node of its size, but not a leaf node, it must + be replaced with a leaf node (not merely one with an open left or + right), to make sure that lefts and rights of descendents + correspond properly to bit masks. We use the rightmost descendent + of x. We could use any other leaf, but this is easy to locate and + tends to counteract removal of leftmosts elsewhere, and so keeps + paths shorter than minimally guaranteed. This doesn't loop much + because on average a node in a tree is near the bottom. + 3. If x is the base of a chain (i.e., has parent links) relink + x's parent and children to x's replacement (or null if none). +*/ + +#define unlink_large_chunk(M, X) {\ + tchunkptr XP = X->parent;\ + tchunkptr R;\ + if (X->bk != X) {\ + tchunkptr F = X->fd;\ + R = X->bk;\ + if (RTCHECK(ok_address(M, F))) {\ + F->bk = R;\ + R->fd = F;\ + }\ + else {\ + CORRUPTION_ERROR_ACTION(M);\ + }\ + }\ + else {\ + tchunkptr* RP;\ + if (((R = *(RP = &(X->child[1]))) != 0) ||\ + ((R = *(RP = &(X->child[0]))) != 0)) {\ + tchunkptr* CP;\ + while ((*(CP = &(R->child[1])) != 0) ||\ + (*(CP = &(R->child[0])) != 0)) {\ + R = *(RP = CP);\ + }\ + if (RTCHECK(ok_address(M, RP)))\ + *RP = 0;\ + else {\ + CORRUPTION_ERROR_ACTION(M);\ + }\ + }\ + }\ + if (XP != 0) {\ + tbinptr* H = treebin_at(M, X->index);\ + if (X == *H) {\ + if ((*H = R) == 0) \ + clear_treemap(M, X->index);\ + }\ + else if (RTCHECK(ok_address(M, XP))) {\ + if (XP->child[0] == X) \ + XP->child[0] = R;\ + else \ + XP->child[1] = R;\ + }\ + else\ + CORRUPTION_ERROR_ACTION(M);\ + if (R != 0) {\ + if (RTCHECK(ok_address(M, R))) {\ + tchunkptr C0, C1;\ + R->parent = XP;\ + if ((C0 = X->child[0]) != 0) {\ + if (RTCHECK(ok_address(M, C0))) {\ + R->child[0] = C0;\ + C0->parent = R;\ + }\ + else\ + CORRUPTION_ERROR_ACTION(M);\ + }\ + if ((C1 = X->child[1]) != 0) {\ + if (RTCHECK(ok_address(M, C1))) {\ + R->child[1] = C1;\ + C1->parent = R;\ + }\ + else\ + CORRUPTION_ERROR_ACTION(M);\ + }\ + }\ + else\ + CORRUPTION_ERROR_ACTION(M);\ + }\ + }\ +} + +/* Relays to large vs small bin operations */ + +#define insert_chunk(M, P, S)\ + if (is_small(S)) insert_small_chunk(M, P, S)\ + else { tchunkptr TP = (tchunkptr)(P); insert_large_chunk(M, TP, S); } + +#define unlink_chunk(M, P, S)\ + if (is_small(S)) unlink_small_chunk(M, P, S)\ + else { tchunkptr TP = (tchunkptr)(P); unlink_large_chunk(M, TP); } + + +/* Relays to internal calls to malloc/free from realloc, memalign etc */ + +#if ONLY_MSPACES +#define internal_malloc(m, b) mspace_malloc(m, b) +#define internal_free(m, mem) mspace_free(m,mem); +#else /* ONLY_MSPACES */ +#if MSPACES +#define internal_malloc(m, b)\ + (m == gm)? dlmalloc(b) : mspace_malloc(m, b) +#define internal_free(m, mem)\ + if (m == gm) dlfree(mem); else mspace_free(m,mem); +#else /* MSPACES */ +#define internal_malloc(m, b) dlmalloc(b) +#define internal_free(m, mem) dlfree(mem) +#endif /* MSPACES */ +#endif /* ONLY_MSPACES */ + +/* ----------------------- Direct-mmapping chunks ----------------------- */ + +/* + Directly mmapped chunks are set up with an offset to the start of + the mmapped region stored in the prev_foot field of the chunk. This + allows reconstruction of the required argument to MUNMAP when freed, + and also allows adjustment of the returned chunk to meet alignment + requirements (especially in memalign). There is also enough space + allocated to hold a fake next chunk of size SIZE_T_SIZE to maintain + the PINUSE bit so frees can be checked. +*/ + +/* Malloc using mmap */ +static void* mmap_alloc(mstate m, size_t nb) { + size_t mmsize = mmap_align(nb + SIX_SIZE_T_SIZES + CHUNK_ALIGN_MASK); + if (mmsize > nb) { /* Check for wrap around 0 */ + char* mm = (char*)(CALL_DIRECT_MMAP(mmsize)); + if (mm != CMFAIL) { + size_t offset = align_offset(chunk2mem(mm)); + size_t psize = mmsize - offset - MMAP_FOOT_PAD; + mchunkptr p = (mchunkptr)(mm + offset); + p->prev_foot = offset | IS_MMAPPED_BIT; + (p)->head = (psize|CINUSE_BIT); + mark_inuse_foot(m, p, psize); + chunk_plus_offset(p, psize)->head = FENCEPOST_HEAD; + chunk_plus_offset(p, psize+SIZE_T_SIZE)->head = 0; + + if (mm < m->least_addr) + m->least_addr = mm; + if ((m->footprint += mmsize) > m->max_footprint) + m->max_footprint = m->footprint; + assert(is_aligned(chunk2mem(p))); + check_mmapped_chunk(m, p); + return chunk2mem(p); + } + } + return 0; +} + +/* Realloc using mmap */ +static mchunkptr mmap_resize(mstate m, mchunkptr oldp, size_t nb) { + size_t oldsize = chunksize(oldp); + if (is_small(nb)) /* Can't shrink mmap regions below small size */ + return 0; + /* Keep old chunk if big enough but not too big */ + if (oldsize >= nb + SIZE_T_SIZE && + (oldsize - nb) <= (mparams.granularity << 1)) + return oldp; + else { + size_t offset = oldp->prev_foot & ~IS_MMAPPED_BIT; + size_t oldmmsize = oldsize + offset + MMAP_FOOT_PAD; + size_t newmmsize = mmap_align(nb + SIX_SIZE_T_SIZES + CHUNK_ALIGN_MASK); + char* cp = (char*)CALL_MREMAP((char*)oldp - offset, + oldmmsize, newmmsize, 1); + if (cp != CMFAIL) { + mchunkptr newp = (mchunkptr)(cp + offset); + size_t psize = newmmsize - offset - MMAP_FOOT_PAD; + newp->head = (psize|CINUSE_BIT); + mark_inuse_foot(m, newp, psize); + chunk_plus_offset(newp, psize)->head = FENCEPOST_HEAD; + chunk_plus_offset(newp, psize+SIZE_T_SIZE)->head = 0; + + if (cp < m->least_addr) + m->least_addr = cp; + if ((m->footprint += newmmsize - oldmmsize) > m->max_footprint) + m->max_footprint = m->footprint; + check_mmapped_chunk(m, newp); + return newp; + } + } + return 0; +} + +/* -------------------------- mspace management -------------------------- */ + +/* Initialize top chunk and its size */ +static void init_top(mstate m, mchunkptr p, size_t psize) { + /* Ensure alignment */ + size_t offset = align_offset(chunk2mem(p)); + p = (mchunkptr)((char*)p + offset); + psize -= offset; + + m->top = p; + m->topsize = psize; + p->head = psize | PINUSE_BIT; + /* set size of fake trailing chunk holding overhead space only once */ + chunk_plus_offset(p, psize)->head = TOP_FOOT_SIZE; + m->trim_check = mparams.trim_threshold; /* reset on each update */ +} + +/* Initialize bins for a new mstate that is otherwise zeroed out */ +static void init_bins(mstate m) { + /* Establish circular links for smallbins */ + bindex_t i; + for (i = 0; i < NSMALLBINS; ++i) { + sbinptr bin = smallbin_at(m,i); + bin->fd = bin->bk = bin; + } +} + +#if PROCEED_ON_ERROR + +/* default corruption action */ +static void reset_on_error(mstate m) { + int i; + ++malloc_corruption_error_count; + /* Reinitialize fields to forget about all memory */ + m->smallbins = m->treebins = 0; + m->dvsize = m->topsize = 0; + m->seg.base = 0; + m->seg.size = 0; + m->seg.next = 0; + m->top = m->dv = 0; + for (i = 0; i < NTREEBINS; ++i) + *treebin_at(m, i) = 0; + init_bins(m); +} +#endif /* PROCEED_ON_ERROR */ + +/* Allocate chunk and prepend remainder with chunk in successor base. */ +static void* prepend_alloc(mstate m, char* newbase, char* oldbase, + size_t nb) { + mchunkptr p = align_as_chunk(newbase); + mchunkptr oldfirst = align_as_chunk(oldbase); + size_t psize = (char*)oldfirst - (char*)p; + mchunkptr q = chunk_plus_offset(p, nb); + size_t qsize = psize - nb; + set_size_and_pinuse_of_inuse_chunk(m, p, nb); + + assert((char*)oldfirst > (char*)q); + assert(pinuse(oldfirst)); + assert(qsize >= MIN_CHUNK_SIZE); + + /* consolidate remainder with first chunk of old base */ + if (oldfirst == m->top) { + size_t tsize = m->topsize += qsize; + m->top = q; + q->head = tsize | PINUSE_BIT; + check_top_chunk(m, q); + } + else if (oldfirst == m->dv) { + size_t dsize = m->dvsize += qsize; + m->dv = q; + set_size_and_pinuse_of_free_chunk(q, dsize); + } + else { + if (!cinuse(oldfirst)) { + size_t nsize = chunksize(oldfirst); + unlink_chunk(m, oldfirst, nsize); + oldfirst = chunk_plus_offset(oldfirst, nsize); + qsize += nsize; + } + set_free_with_pinuse(q, qsize, oldfirst); + insert_chunk(m, q, qsize); + check_free_chunk(m, q); + } + + check_malloced_chunk(m, chunk2mem(p), nb); + return chunk2mem(p); +} + +/* Add a segment to hold a new noncontiguous region */ +static void add_segment(mstate m, char* tbase, size_t tsize, flag_t mmapped) { + /* Determine locations and sizes of segment, fenceposts, old top */ + char* old_top = (char*)m->top; + msegmentptr oldsp = segment_holding(m, old_top); + char* old_end = oldsp->base + oldsp->size; + size_t ssize = pad_request(sizeof(struct malloc_segment)); + char* rawsp = old_end - (ssize + FOUR_SIZE_T_SIZES + CHUNK_ALIGN_MASK); + size_t offset = align_offset(chunk2mem(rawsp)); + char* asp = rawsp + offset; + char* csp = (asp < (old_top + MIN_CHUNK_SIZE))? old_top : asp; + mchunkptr sp = (mchunkptr)csp; + msegmentptr ss = (msegmentptr)(chunk2mem(sp)); + mchunkptr tnext = chunk_plus_offset(sp, ssize); + mchunkptr p = tnext; + int nfences = 0; + + /* reset top to new space */ + init_top(m, (mchunkptr)tbase, tsize - TOP_FOOT_SIZE); + + /* Set up segment record */ + assert(is_aligned(ss)); + set_size_and_pinuse_of_inuse_chunk(m, sp, ssize); + *ss = m->seg; /* Push current record */ + m->seg.base = tbase; + m->seg.size = tsize; + m->seg.sflags = mmapped; + m->seg.next = ss; + + /* Insert trailing fenceposts */ + for (;;) { + mchunkptr nextp = chunk_plus_offset(p, SIZE_T_SIZE); + p->head = FENCEPOST_HEAD; + ++nfences; + if ((char*)(&(nextp->head)) < old_end) + p = nextp; + else + break; + } + assert(nfences >= 2); + + /* Insert the rest of old top into a bin as an ordinary free chunk */ + if (csp != old_top) { + mchunkptr q = (mchunkptr)old_top; + size_t psize = csp - old_top; + mchunkptr tn = chunk_plus_offset(q, psize); + set_free_with_pinuse(q, psize, tn); + insert_chunk(m, q, psize); + } + + check_top_chunk(m, m->top); +} + +/* -------------------------- System allocation -------------------------- */ + +/* Get memory from system using MORECORE or MMAP */ +static void* sys_alloc(mstate m, size_t nb) { + char* tbase = CMFAIL; + size_t tsize = 0; + flag_t mmap_flag = 0; + + ensure_initialization(); + + /* Directly map large chunks */ + if (use_mmap(m) && nb >= mparams.mmap_threshold) { + void* mem = mmap_alloc(m, nb); + if (mem != 0) + return mem; + } + + /* + Try getting memory in any of three ways (in most-preferred to + least-preferred order): + 1. A call to MORECORE that can normally contiguously extend memory. + (disabled if not MORECORE_CONTIGUOUS or not HAVE_MORECORE or + or main space is mmapped or a previous contiguous call failed) + 2. A call to MMAP new space (disabled if not HAVE_MMAP). + Note that under the default settings, if MORECORE is unable to + fulfill a request, and HAVE_MMAP is true, then mmap is + used as a noncontiguous system allocator. This is a useful backup + strategy for systems with holes in address spaces -- in this case + sbrk cannot contiguously expand the heap, but mmap may be able to + find space. + 3. A call to MORECORE that cannot usually contiguously extend memory. + (disabled if not HAVE_MORECORE) + + In all cases, we need to request enough bytes from system to ensure + we can malloc nb bytes upon success, so pad with enough space for + top_foot, plus alignment-pad to make sure we don't lose bytes if + not on boundary, and round this up to a granularity unit. + */ + + if (MORECORE_CONTIGUOUS && !use_noncontiguous(m)) { + char* br = CMFAIL; + msegmentptr ss = (m->top == 0)? 0 : segment_holding(m, (char*)m->top); + size_t asize = 0; + ACQUIRE_MALLOC_GLOBAL_LOCK(); + + if (ss == 0) { /* First time through or recovery */ + char* base = (char*)CALL_MORECORE(0); + if (base != CMFAIL) { + asize = granularity_align(nb + SYS_ALLOC_PADDING); + /* Adjust to end on a page boundary */ + if (!is_page_aligned(base)) + asize += (page_align((size_t)base) - (size_t)base); + /* Can't call MORECORE if size is negative when treated as signed */ + if (asize < HALF_MAX_SIZE_T && + (br = (char*)(CALL_MORECORE(asize))) == base) { + tbase = base; + tsize = asize; + } + } + } + else { + /* Subtract out existing available top space from MORECORE request. */ + asize = granularity_align(nb - m->topsize + SYS_ALLOC_PADDING); + /* Use mem here only if it did continuously extend old space */ + if (asize < HALF_MAX_SIZE_T && + (br = (char*)(CALL_MORECORE(asize))) == ss->base+ss->size) { + tbase = br; + tsize = asize; + } + } + + if (tbase == CMFAIL) { /* Cope with partial failure */ + if (br != CMFAIL) { /* Try to use/extend the space we did get */ + if (asize < HALF_MAX_SIZE_T && + asize < nb + SYS_ALLOC_PADDING) { + size_t esize = granularity_align(nb + SYS_ALLOC_PADDING - asize); + if (esize < HALF_MAX_SIZE_T) { + char* end = (char*)CALL_MORECORE(esize); + if (end != CMFAIL) + asize += esize; + else { /* Can't use; try to release */ + (void) CALL_MORECORE(-asize); + br = CMFAIL; + } + } + } + } + if (br != CMFAIL) { /* Use the space we did get */ + tbase = br; + tsize = asize; + } + else + disable_contiguous(m); /* Don't try contiguous path in the future */ + } + + RELEASE_MALLOC_GLOBAL_LOCK(); + } + + if (HAVE_MMAP && tbase == CMFAIL) { /* Try MMAP */ + size_t rsize = granularity_align(nb + SYS_ALLOC_PADDING); + if (rsize > nb) { /* Fail if wraps around zero */ + char* mp = (char*)(CALL_MMAP(rsize)); + if (mp != CMFAIL) { + tbase = mp; + tsize = rsize; + mmap_flag = IS_MMAPPED_BIT; + } + } + } + + if (HAVE_MORECORE && tbase == CMFAIL) { /* Try noncontiguous MORECORE */ + size_t asize = granularity_align(nb + SYS_ALLOC_PADDING); + if (asize < HALF_MAX_SIZE_T) { + char* br = CMFAIL; + char* end = CMFAIL; + ACQUIRE_MALLOC_GLOBAL_LOCK(); + br = (char*)(CALL_MORECORE(asize)); + end = (char*)(CALL_MORECORE(0)); + RELEASE_MALLOC_GLOBAL_LOCK(); + if (br != CMFAIL && end != CMFAIL && br < end) { + size_t ssize = end - br; + if (ssize > nb + TOP_FOOT_SIZE) { + tbase = br; + tsize = ssize; + } + } + } + } + + if (tbase != CMFAIL) { + + if ((m->footprint += tsize) > m->max_footprint) + m->max_footprint = m->footprint; + + if (!is_initialized(m)) { /* first-time initialization */ + m->seg.base = m->least_addr = tbase; + m->seg.size = tsize; + m->seg.sflags = mmap_flag; + m->magic = mparams.magic; + m->release_checks = MAX_RELEASE_CHECK_RATE; + init_bins(m); +#if !ONLY_MSPACES + if (is_global(m)) + init_top(m, (mchunkptr)tbase, tsize - TOP_FOOT_SIZE); + else +#endif + { + /* Offset top by embedded malloc_state */ + mchunkptr mn = next_chunk(mem2chunk(m)); + init_top(m, mn, (size_t)((tbase + tsize) - (char*)mn) -TOP_FOOT_SIZE); + } + } + + else { + /* Try to merge with an existing segment */ + msegmentptr sp = &m->seg; + /* Only consider most recent segment if traversal suppressed */ + while (sp != 0 && tbase != sp->base + sp->size) + sp = (NO_SEGMENT_TRAVERSAL) ? 0 : sp->next; + if (sp != 0 && + !is_extern_segment(sp) && + (sp->sflags & IS_MMAPPED_BIT) == mmap_flag && + segment_holds(sp, m->top)) { /* append */ + sp->size += tsize; + init_top(m, m->top, m->topsize + tsize); + } + else { + if (tbase < m->least_addr) + m->least_addr = tbase; + sp = &m->seg; + while (sp != 0 && sp->base != tbase + tsize) + sp = (NO_SEGMENT_TRAVERSAL) ? 0 : sp->next; + if (sp != 0 && + !is_extern_segment(sp) && + (sp->sflags & IS_MMAPPED_BIT) == mmap_flag) { + char* oldbase = sp->base; + sp->base = tbase; + sp->size += tsize; + return prepend_alloc(m, tbase, oldbase, nb); + } + else + add_segment(m, tbase, tsize, mmap_flag); + } + } + + if (nb < m->topsize) { /* Allocate from new or extended top space */ + size_t rsize = m->topsize -= nb; + mchunkptr p = m->top; + mchunkptr r = m->top = chunk_plus_offset(p, nb); + r->head = rsize | PINUSE_BIT; + set_size_and_pinuse_of_inuse_chunk(m, p, nb); + check_top_chunk(m, m->top); + check_malloced_chunk(m, chunk2mem(p), nb); + return chunk2mem(p); + } + } + + MALLOC_FAILURE_ACTION; + return 0; +} + +/* ----------------------- system deallocation -------------------------- */ + +/* Unmap and unlink any mmapped segments that don't contain used chunks */ +static size_t release_unused_segments(mstate m) { + size_t released = 0; + int nsegs = 0; + msegmentptr pred = &m->seg; + msegmentptr sp = pred->next; + while (sp != 0) { + char* base = sp->base; + size_t size = sp->size; + msegmentptr next = sp->next; + ++nsegs; + if (is_mmapped_segment(sp) && !is_extern_segment(sp)) { + mchunkptr p = align_as_chunk(base); + size_t psize = chunksize(p); + /* Can unmap if first chunk holds entire segment and not pinned */ + if (!cinuse(p) && (char*)p + psize >= base + size - TOP_FOOT_SIZE) { + tchunkptr tp = (tchunkptr)p; + assert(segment_holds(sp, (char*)sp)); + if (p == m->dv) { + m->dv = 0; + m->dvsize = 0; + } + else { + unlink_large_chunk(m, tp); + } + if (CALL_MUNMAP(base, size) == 0) { + released += size; + m->footprint -= size; + /* unlink obsoleted record */ + sp = pred; + sp->next = next; + } + else { /* back out if cannot unmap */ + insert_large_chunk(m, tp, psize); + } + } + } + if (NO_SEGMENT_TRAVERSAL) /* scan only first segment */ + break; + pred = sp; + sp = next; + } + /* Reset check counter */ + m->release_checks = ((nsegs > MAX_RELEASE_CHECK_RATE)? + nsegs : MAX_RELEASE_CHECK_RATE); + return released; +} + +static int sys_trim(mstate m, size_t pad) { + size_t released = 0; + ensure_initialization(); + if (pad < MAX_REQUEST && is_initialized(m)) { + pad += TOP_FOOT_SIZE; /* ensure enough room for segment overhead */ + + if (m->topsize > pad) { + /* Shrink top space in granularity-size units, keeping at least one */ + size_t unit = mparams.granularity; + size_t extra = ((m->topsize - pad + (unit - SIZE_T_ONE)) / unit - + SIZE_T_ONE) * unit; + msegmentptr sp = segment_holding(m, (char*)m->top); + + if (!is_extern_segment(sp)) { + if (is_mmapped_segment(sp)) { + if (HAVE_MMAP && + sp->size >= extra && + !has_segment_link(m, sp)) { /* can't shrink if pinned */ + size_t newsize = sp->size - extra; + /* Prefer mremap, fall back to munmap */ + if ((CALL_MREMAP(sp->base, sp->size, newsize, 0) != MFAIL) || + (CALL_MUNMAP(sp->base + newsize, extra) == 0)) { + released = extra; + } + } + } + else if (HAVE_MORECORE) { + if (extra >= HALF_MAX_SIZE_T) /* Avoid wrapping negative */ + extra = (HALF_MAX_SIZE_T) + SIZE_T_ONE - unit; + ACQUIRE_MALLOC_GLOBAL_LOCK(); + { + /* Make sure end of memory is where we last set it. */ + char* old_br = (char*)(CALL_MORECORE(0)); + if (old_br == sp->base + sp->size) { + char* rel_br = (char*)(CALL_MORECORE(-extra)); + char* new_br = (char*)(CALL_MORECORE(0)); + if (rel_br != CMFAIL && new_br < old_br) + released = old_br - new_br; + } + } + RELEASE_MALLOC_GLOBAL_LOCK(); + } + } + + if (released != 0) { + sp->size -= released; + m->footprint -= released; + init_top(m, m->top, m->topsize - released); + check_top_chunk(m, m->top); + } + } + + /* Unmap any unused mmapped segments */ + if (HAVE_MMAP) + released += release_unused_segments(m); + + /* On failure, disable autotrim to avoid repeated failed future calls */ + if (released == 0 && m->topsize > m->trim_check) + m->trim_check = MAX_SIZE_T; + } + + return (released != 0)? 1 : 0; +} + + +/* ---------------------------- malloc support --------------------------- */ + +/* allocate a large request from the best fitting chunk in a treebin */ +static void* tmalloc_large(mstate m, size_t nb) { + tchunkptr v = 0; + size_t rsize = -nb; /* Unsigned negation */ + tchunkptr t; + bindex_t idx; + compute_tree_index(nb, idx); + if ((t = *treebin_at(m, idx)) != 0) { + /* Traverse tree for this bin looking for node with size == nb */ + size_t sizebits = nb << leftshift_for_tree_index(idx); + tchunkptr rst = 0; /* The deepest untaken right subtree */ + for (;;) { + tchunkptr rt; + size_t trem = chunksize(t) - nb; + if (trem < rsize) { + v = t; + if ((rsize = trem) == 0) + break; + } + rt = t->child[1]; + t = t->child[(sizebits >> (SIZE_T_BITSIZE-SIZE_T_ONE)) & 1]; + if (rt != 0 && rt != t) + rst = rt; + if (t == 0) { + t = rst; /* set t to least subtree holding sizes > nb */ + break; + } + sizebits <<= 1; + } + } + if (t == 0 && v == 0) { /* set t to root of next non-empty treebin */ + binmap_t leftbits = left_bits(idx2bit(idx)) & m->treemap; + if (leftbits != 0) { + bindex_t i; + binmap_t leastbit = least_bit(leftbits); + compute_bit2idx(leastbit, i); + t = *treebin_at(m, i); + } + } + + while (t != 0) { /* find smallest of tree or subtree */ + size_t trem = chunksize(t) - nb; + if (trem < rsize) { + rsize = trem; + v = t; + } + t = leftmost_child(t); + } + + /* If dv is a better fit, return 0 so malloc will use it */ + if (v != 0 && rsize < (size_t)(m->dvsize - nb)) { + if (RTCHECK(ok_address(m, v))) { /* split */ + mchunkptr r = chunk_plus_offset(v, nb); + assert(chunksize(v) == rsize + nb); + if (RTCHECK(ok_next(v, r))) { + unlink_large_chunk(m, v); + if (rsize < MIN_CHUNK_SIZE) + set_inuse_and_pinuse(m, v, (rsize + nb)); + else { + set_size_and_pinuse_of_inuse_chunk(m, v, nb); + set_size_and_pinuse_of_free_chunk(r, rsize); + insert_chunk(m, r, rsize); + } + return chunk2mem(v); + } + } + CORRUPTION_ERROR_ACTION(m); + } + return 0; +} + +/* allocate a small request from the best fitting chunk in a treebin */ +static void* tmalloc_small(mstate m, size_t nb) { + tchunkptr t, v; + size_t rsize; + bindex_t i; + binmap_t leastbit = least_bit(m->treemap); + compute_bit2idx(leastbit, i); + v = t = *treebin_at(m, i); + rsize = chunksize(t) - nb; + + while ((t = leftmost_child(t)) != 0) { + size_t trem = chunksize(t) - nb; + if (trem < rsize) { + rsize = trem; + v = t; + } + } + + if (RTCHECK(ok_address(m, v))) { + mchunkptr r = chunk_plus_offset(v, nb); + assert(chunksize(v) == rsize + nb); + if (RTCHECK(ok_next(v, r))) { + unlink_large_chunk(m, v); + if (rsize < MIN_CHUNK_SIZE) + set_inuse_and_pinuse(m, v, (rsize + nb)); + else { + set_size_and_pinuse_of_inuse_chunk(m, v, nb); + set_size_and_pinuse_of_free_chunk(r, rsize); + replace_dv(m, r, rsize); + } + return chunk2mem(v); + } + } + + CORRUPTION_ERROR_ACTION(m); + return 0; +} + +/* --------------------------- realloc support --------------------------- */ + +static void* internal_realloc(mstate m, void* oldmem, size_t bytes) { + if (bytes >= MAX_REQUEST) { + MALLOC_FAILURE_ACTION; + return 0; + } + if (!PREACTION(m)) { + mchunkptr oldp = mem2chunk(oldmem); + size_t oldsize = chunksize(oldp); + mchunkptr next = chunk_plus_offset(oldp, oldsize); + mchunkptr newp = 0; + void* extra = 0; + + /* Try to either shrink or extend into top. Else malloc-copy-free */ + + if (RTCHECK(ok_address(m, oldp) && ok_cinuse(oldp) && + ok_next(oldp, next) && ok_pinuse(next))) { + size_t nb = request2size(bytes); + if (is_mmapped(oldp)) + newp = mmap_resize(m, oldp, nb); + else if (oldsize >= nb) { /* already big enough */ + size_t rsize = oldsize - nb; + newp = oldp; + if (rsize >= MIN_CHUNK_SIZE) { + mchunkptr remainder = chunk_plus_offset(newp, nb); + set_inuse(m, newp, nb); + set_inuse(m, remainder, rsize); + extra = chunk2mem(remainder); + } + } + else if (next == m->top && oldsize + m->topsize > nb) { + /* Expand into top */ + size_t newsize = oldsize + m->topsize; + size_t newtopsize = newsize - nb; + mchunkptr newtop = chunk_plus_offset(oldp, nb); + set_inuse(m, oldp, nb); + newtop->head = newtopsize |PINUSE_BIT; + m->top = newtop; + m->topsize = newtopsize; + newp = oldp; + } + } + else { + USAGE_ERROR_ACTION(m, oldmem); + POSTACTION(m); + return 0; + } + + POSTACTION(m); + + if (newp != 0) { + if (extra != 0) { + internal_free(m, extra); + } + check_inuse_chunk(m, newp); + return chunk2mem(newp); + } + else { + void* newmem = internal_malloc(m, bytes); + if (newmem != 0) { + size_t oc = oldsize - overhead_for(oldp); + memcpy(newmem, oldmem, (oc < bytes)? oc : bytes); + internal_free(m, oldmem); + } + return newmem; + } + } + return 0; +} + +/* --------------------------- memalign support -------------------------- */ + +static void* internal_memalign(mstate m, size_t alignment, size_t bytes) { + if (alignment <= MALLOC_ALIGNMENT) /* Can just use malloc */ + return internal_malloc(m, bytes); + if (alignment < MIN_CHUNK_SIZE) /* must be at least a minimum chunk size */ + alignment = MIN_CHUNK_SIZE; + if ((alignment & (alignment-SIZE_T_ONE)) != 0) {/* Ensure a power of 2 */ + size_t a = MALLOC_ALIGNMENT << 1; + while (a < alignment) a <<= 1; + alignment = a; + } + + if (bytes >= MAX_REQUEST - alignment) { + if (m != 0) { /* Test isn't needed but avoids compiler warning */ + MALLOC_FAILURE_ACTION; + } + } + else { + size_t nb = request2size(bytes); + size_t req = nb + alignment + MIN_CHUNK_SIZE - CHUNK_OVERHEAD; + char* mem = (char*)internal_malloc(m, req); + if (mem != 0) { + void* leader = 0; + void* trailer = 0; + mchunkptr p = mem2chunk(mem); + + if (PREACTION(m)) return 0; + if ((((size_t)(mem)) % alignment) != 0) { /* misaligned */ + /* + Find an aligned spot inside chunk. Since we need to give + back leading space in a chunk of at least MIN_CHUNK_SIZE, if + the first calculation places us at a spot with less than + MIN_CHUNK_SIZE leader, we can move to the next aligned spot. + We've allocated enough total room so that this is always + possible. + */ + char* br = (char*)mem2chunk((size_t)(((size_t)(mem + + alignment - + SIZE_T_ONE)) & + -alignment)); + char* pos = ((size_t)(br - (char*)(p)) >= MIN_CHUNK_SIZE)? + br : br+alignment; + mchunkptr newp = (mchunkptr)pos; + size_t leadsize = pos - (char*)(p); + size_t newsize = chunksize(p) - leadsize; + + if (is_mmapped(p)) { /* For mmapped chunks, just adjust offset */ + newp->prev_foot = p->prev_foot + leadsize; + newp->head = (newsize|CINUSE_BIT); + } + else { /* Otherwise, give back leader, use the rest */ + set_inuse(m, newp, newsize); + set_inuse(m, p, leadsize); + leader = chunk2mem(p); + } + p = newp; + } + + /* Give back spare room at the end */ + if (!is_mmapped(p)) { + size_t size = chunksize(p); + if (size > nb + MIN_CHUNK_SIZE) { + size_t remainder_size = size - nb; + mchunkptr remainder = chunk_plus_offset(p, nb); + set_inuse(m, p, nb); + set_inuse(m, remainder, remainder_size); + trailer = chunk2mem(remainder); + } + } + + assert (chunksize(p) >= nb); + assert((((size_t)(chunk2mem(p))) % alignment) == 0); + check_inuse_chunk(m, p); + POSTACTION(m); + if (leader != 0) { + internal_free(m, leader); + } + if (trailer != 0) { + internal_free(m, trailer); + } + return chunk2mem(p); + } + } + return 0; +} + +/* ------------------------ comalloc/coalloc support --------------------- */ + +static void** ialloc(mstate m, + size_t n_elements, + size_t* sizes, + int opts, + void* chunks[]) { + /* + This provides common support for independent_X routines, handling + all of the combinations that can result. + + The opts arg has: + bit 0 set if all elements are same size (using sizes[0]) + bit 1 set if elements should be zeroed + */ + + size_t element_size; /* chunksize of each element, if all same */ + size_t contents_size; /* total size of elements */ + size_t array_size; /* request size of pointer array */ + void* mem; /* malloced aggregate space */ + mchunkptr p; /* corresponding chunk */ + size_t remainder_size; /* remaining bytes while splitting */ + void** marray; /* either "chunks" or malloced ptr array */ + mchunkptr array_chunk; /* chunk for malloced ptr array */ + flag_t was_enabled; /* to disable mmap */ + size_t size; + size_t i; + + ensure_initialization(); + /* compute array length, if needed */ + if (chunks != 0) { + if (n_elements == 0) + return chunks; /* nothing to do */ + marray = chunks; + array_size = 0; + } + else { + /* if empty req, must still return chunk representing empty array */ + if (n_elements == 0) + return (void**)internal_malloc(m, 0); + marray = 0; + array_size = request2size(n_elements * (sizeof(void*))); + } + + /* compute total element size */ + if (opts & 0x1) { /* all-same-size */ + element_size = request2size(*sizes); + contents_size = n_elements * element_size; + } + else { /* add up all the sizes */ + element_size = 0; + contents_size = 0; + for (i = 0; i != n_elements; ++i) + contents_size += request2size(sizes[i]); + } + + size = contents_size + array_size; + + /* + Allocate the aggregate chunk. First disable direct-mmapping so + malloc won't use it, since we would not be able to later + free/realloc space internal to a segregated mmap region. + */ + was_enabled = use_mmap(m); + disable_mmap(m); + mem = internal_malloc(m, size - CHUNK_OVERHEAD); + if (was_enabled) + enable_mmap(m); + if (mem == 0) + return 0; + + if (PREACTION(m)) return 0; + p = mem2chunk(mem); + remainder_size = chunksize(p); + + assert(!is_mmapped(p)); + + if (opts & 0x2) { /* optionally clear the elements */ + memset((size_t*)mem, 0, remainder_size - SIZE_T_SIZE - array_size); + } + + /* If not provided, allocate the pointer array as final part of chunk */ + if (marray == 0) { + size_t array_chunk_size; + array_chunk = chunk_plus_offset(p, contents_size); + array_chunk_size = remainder_size - contents_size; + marray = (void**) (chunk2mem(array_chunk)); + set_size_and_pinuse_of_inuse_chunk(m, array_chunk, array_chunk_size); + remainder_size = contents_size; + } + + /* split out elements */ + for (i = 0; ; ++i) { + marray[i] = chunk2mem(p); + if (i != n_elements-1) { + if (element_size != 0) + size = element_size; + else + size = request2size(sizes[i]); + remainder_size -= size; + set_size_and_pinuse_of_inuse_chunk(m, p, size); + p = chunk_plus_offset(p, size); + } + else { /* the final element absorbs any overallocation slop */ + set_size_and_pinuse_of_inuse_chunk(m, p, remainder_size); + break; + } + } + +#if DEBUG + if (marray != chunks) { + /* final element must have exactly exhausted chunk */ + if (element_size != 0) { + assert(remainder_size == element_size); + } + else { + assert(remainder_size == request2size(sizes[i])); + } + check_inuse_chunk(m, mem2chunk(marray)); + } + for (i = 0; i != n_elements; ++i) + check_inuse_chunk(m, mem2chunk(marray[i])); + +#endif /* DEBUG */ + + POSTACTION(m); + return marray; +} + + +/* -------------------------- public routines ---------------------------- */ + +#if !ONLY_MSPACES + +void* dlmalloc(size_t bytes) { + /* + Basic algorithm: + If a small request (< 256 bytes minus per-chunk overhead): + 1. If one exists, use a remainderless chunk in associated smallbin. + (Remainderless means that there are too few excess bytes to + represent as a chunk.) + 2. If it is big enough, use the dv chunk, which is normally the + chunk adjacent to the one used for the most recent small request. + 3. If one exists, split the smallest available chunk in a bin, + saving remainder in dv. + 4. If it is big enough, use the top chunk. + 5. If available, get memory from system and use it + Otherwise, for a large request: + 1. Find the smallest available binned chunk that fits, and use it + if it is better fitting than dv chunk, splitting if necessary. + 2. If better fitting than any binned chunk, use the dv chunk. + 3. If it is big enough, use the top chunk. + 4. If request size >= mmap threshold, try to directly mmap this chunk. + 5. If available, get memory from system and use it + + The ugly goto's here ensure that postaction occurs along all paths. + */ + +#if USE_LOCKS + ensure_initialization(); /* initialize in sys_alloc if not using locks */ +#endif + + if (!PREACTION(gm)) { + void* mem; + size_t nb; + if (bytes <= MAX_SMALL_REQUEST) { + bindex_t idx; + binmap_t smallbits; + nb = (bytes < MIN_REQUEST)? MIN_CHUNK_SIZE : pad_request(bytes); + idx = small_index(nb); + smallbits = gm->smallmap >> idx; + + if ((smallbits & 0x3U) != 0) { /* Remainderless fit to a smallbin. */ + mchunkptr b, p; + idx += ~smallbits & 1; /* Uses next bin if idx empty */ + b = smallbin_at(gm, idx); + p = b->fd; + assert(chunksize(p) == small_index2size(idx)); + unlink_first_small_chunk(gm, b, p, idx); + set_inuse_and_pinuse(gm, p, small_index2size(idx)); + mem = chunk2mem(p); + check_malloced_chunk(gm, mem, nb); + goto postaction; + } + + else if (nb > gm->dvsize) { + if (smallbits != 0) { /* Use chunk in next nonempty smallbin */ + mchunkptr b, p, r; + size_t rsize; + bindex_t i; + binmap_t leftbits = (smallbits << idx) & left_bits(idx2bit(idx)); + binmap_t leastbit = least_bit(leftbits); + compute_bit2idx(leastbit, i); + b = smallbin_at(gm, i); + p = b->fd; + assert(chunksize(p) == small_index2size(i)); + unlink_first_small_chunk(gm, b, p, i); + rsize = small_index2size(i) - nb; + /* Fit here cannot be remainderless if 4byte sizes */ + if (SIZE_T_SIZE != 4 && rsize < MIN_CHUNK_SIZE) + set_inuse_and_pinuse(gm, p, small_index2size(i)); + else { + set_size_and_pinuse_of_inuse_chunk(gm, p, nb); + r = chunk_plus_offset(p, nb); + set_size_and_pinuse_of_free_chunk(r, rsize); + replace_dv(gm, r, rsize); + } + mem = chunk2mem(p); + check_malloced_chunk(gm, mem, nb); + goto postaction; + } + + else if (gm->treemap != 0 && (mem = tmalloc_small(gm, nb)) != 0) { + check_malloced_chunk(gm, mem, nb); + goto postaction; + } + } + } + else if (bytes >= MAX_REQUEST) + nb = MAX_SIZE_T; /* Too big to allocate. Force failure (in sys alloc) */ + else { + nb = pad_request(bytes); + if (gm->treemap != 0 && (mem = tmalloc_large(gm, nb)) != 0) { + check_malloced_chunk(gm, mem, nb); + goto postaction; + } + } + + if (nb <= gm->dvsize) { + size_t rsize = gm->dvsize - nb; + mchunkptr p = gm->dv; + if (rsize >= MIN_CHUNK_SIZE) { /* split dv */ + mchunkptr r = gm->dv = chunk_plus_offset(p, nb); + gm->dvsize = rsize; + set_size_and_pinuse_of_free_chunk(r, rsize); + set_size_and_pinuse_of_inuse_chunk(gm, p, nb); + } + else { /* exhaust dv */ + size_t dvs = gm->dvsize; + gm->dvsize = 0; + gm->dv = 0; + set_inuse_and_pinuse(gm, p, dvs); + } + mem = chunk2mem(p); + check_malloced_chunk(gm, mem, nb); + goto postaction; + } + + else if (nb < gm->topsize) { /* Split top */ + size_t rsize = gm->topsize -= nb; + mchunkptr p = gm->top; + mchunkptr r = gm->top = chunk_plus_offset(p, nb); + r->head = rsize | PINUSE_BIT; + set_size_and_pinuse_of_inuse_chunk(gm, p, nb); + mem = chunk2mem(p); + check_top_chunk(gm, gm->top); + check_malloced_chunk(gm, mem, nb); + goto postaction; + } + + mem = sys_alloc(gm, nb); + + postaction: + POSTACTION(gm); + return mem; + } + + return 0; +} + +void dlfree(void* mem) { + /* + Consolidate freed chunks with preceeding or succeeding bordering + free chunks, if they exist, and then place in a bin. Intermixed + with special cases for top, dv, mmapped chunks, and usage errors. + */ + + if (mem != 0) { + mchunkptr p = mem2chunk(mem); +#if FOOTERS + mstate fm = get_mstate_for(p); + if (!ok_magic(fm)) { + USAGE_ERROR_ACTION(fm, p); + return; + } +#else /* FOOTERS */ +#define fm gm +#endif /* FOOTERS */ + if (!PREACTION(fm)) { + check_inuse_chunk(fm, p); + if (RTCHECK(ok_address(fm, p) && ok_cinuse(p))) { + size_t psize = chunksize(p); + mchunkptr next = chunk_plus_offset(p, psize); + if (!pinuse(p)) { + size_t prevsize = p->prev_foot; + if ((prevsize & IS_MMAPPED_BIT) != 0) { + prevsize &= ~IS_MMAPPED_BIT; + psize += prevsize + MMAP_FOOT_PAD; + if (CALL_MUNMAP((char*)p - prevsize, psize) == 0) + fm->footprint -= psize; + goto postaction; + } + else { + mchunkptr prev = chunk_minus_offset(p, prevsize); + psize += prevsize; + p = prev; + if (RTCHECK(ok_address(fm, prev))) { /* consolidate backward */ + if (p != fm->dv) { + unlink_chunk(fm, p, prevsize); + } + else if ((next->head & INUSE_BITS) == INUSE_BITS) { + fm->dvsize = psize; + set_free_with_pinuse(p, psize, next); + goto postaction; + } + } + else + goto erroraction; + } + } + + if (RTCHECK(ok_next(p, next) && ok_pinuse(next))) { + if (!cinuse(next)) { /* consolidate forward */ + if (next == fm->top) { + size_t tsize = fm->topsize += psize; + fm->top = p; + p->head = tsize | PINUSE_BIT; + if (p == fm->dv) { + fm->dv = 0; + fm->dvsize = 0; + } + if (should_trim(fm, tsize)) + sys_trim(fm, 0); + goto postaction; + } + else if (next == fm->dv) { + size_t dsize = fm->dvsize += psize; + fm->dv = p; + set_size_and_pinuse_of_free_chunk(p, dsize); + goto postaction; + } + else { + size_t nsize = chunksize(next); + psize += nsize; + unlink_chunk(fm, next, nsize); + set_size_and_pinuse_of_free_chunk(p, psize); + if (p == fm->dv) { + fm->dvsize = psize; + goto postaction; + } + } + } + else + set_free_with_pinuse(p, psize, next); + + if (is_small(psize)) { + insert_small_chunk(fm, p, psize); + check_free_chunk(fm, p); + } + else { + tchunkptr tp = (tchunkptr)p; + insert_large_chunk(fm, tp, psize); + check_free_chunk(fm, p); + if (--fm->release_checks == 0) + release_unused_segments(fm); + } + goto postaction; + } + } + erroraction: + USAGE_ERROR_ACTION(fm, p); + postaction: + POSTACTION(fm); + } + } +#if !FOOTERS +#undef fm +#endif /* FOOTERS */ +} + +void* dlcalloc(size_t n_elements, size_t elem_size) { + void* mem; + size_t req = 0; + if (n_elements != 0) { + req = n_elements * elem_size; + if (((n_elements | elem_size) & ~(size_t)0xffff) && + (req / n_elements != elem_size)) + req = MAX_SIZE_T; /* force downstream failure on overflow */ + } + mem = dlmalloc(req); + if (mem != 0 && calloc_must_clear(mem2chunk(mem))) + memset(mem, 0, req); + return mem; +} + +void* dlrealloc(void* oldmem, size_t bytes) { + if (oldmem == 0) + return dlmalloc(bytes); +#ifdef REALLOC_ZERO_BYTES_FREES + if (bytes == 0) { + dlfree(oldmem); + return 0; + } +#endif /* REALLOC_ZERO_BYTES_FREES */ + else { +#if ! FOOTERS + mstate m = gm; +#else /* FOOTERS */ + mstate m = get_mstate_for(mem2chunk(oldmem)); + if (!ok_magic(m)) { + USAGE_ERROR_ACTION(m, oldmem); + return 0; + } +#endif /* FOOTERS */ + return internal_realloc(m, oldmem, bytes); + } +} + +void* dlmemalign(size_t alignment, size_t bytes) { + return internal_memalign(gm, alignment, bytes); +} + +void** dlindependent_calloc(size_t n_elements, size_t elem_size, + void* chunks[]) { + size_t sz = elem_size; /* serves as 1-element array */ + return ialloc(gm, n_elements, &sz, 3, chunks); +} + +void** dlindependent_comalloc(size_t n_elements, size_t sizes[], + void* chunks[]) { + return ialloc(gm, n_elements, sizes, 0, chunks); +} + +void* dlvalloc(size_t bytes) { + size_t pagesz; + ensure_initialization(); + pagesz = mparams.page_size; + return dlmemalign(pagesz, bytes); +} + +void* dlpvalloc(size_t bytes) { + size_t pagesz; + ensure_initialization(); + pagesz = mparams.page_size; + return dlmemalign(pagesz, (bytes + pagesz - SIZE_T_ONE) & ~(pagesz - SIZE_T_ONE)); +} + +int dlmalloc_trim(size_t pad) { + ensure_initialization(); + int result = 0; + if (!PREACTION(gm)) { + result = sys_trim(gm, pad); + POSTACTION(gm); + } + return result; +} + +size_t dlmalloc_footprint(void) { + return gm->footprint; +} + +size_t dlmalloc_max_footprint(void) { + return gm->max_footprint; +} + +#if !NO_MALLINFO +struct mallinfo dlmallinfo(void) { + return internal_mallinfo(gm); +} +#endif /* NO_MALLINFO */ + +void dlmalloc_stats() { + internal_malloc_stats(gm); +} + +int dlmallopt(int param_number, int value) { + return change_mparam(param_number, value); +} + +#endif /* !ONLY_MSPACES */ + +size_t dlmalloc_usable_size(void* mem) { + if (mem != 0) { + mchunkptr p = mem2chunk(mem); + if (cinuse(p)) + return chunksize(p) - overhead_for(p); + } + return 0; +} + +/* ----------------------------- user mspaces ---------------------------- */ + +#if MSPACES + +static mstate init_user_mstate(char* tbase, size_t tsize) { + size_t msize = pad_request(sizeof(struct malloc_state)); + mchunkptr mn; + mchunkptr msp = align_as_chunk(tbase); + mstate m = (mstate)(chunk2mem(msp)); + memset(m, 0, msize); + INITIAL_LOCK(&m->mutex); + msp->head = (msize|PINUSE_BIT|CINUSE_BIT); + m->seg.base = m->least_addr = tbase; + m->seg.size = m->footprint = m->max_footprint = tsize; + m->magic = mparams.magic; + m->release_checks = MAX_RELEASE_CHECK_RATE; + m->mflags = mparams.default_mflags; + m->extp = 0; + m->exts = 0; + disable_contiguous(m); + init_bins(m); + mn = next_chunk(mem2chunk(m)); + init_top(m, mn, (size_t)((tbase + tsize) - (char*)mn) - TOP_FOOT_SIZE); + check_top_chunk(m, m->top); + return m; +} + +mspace create_mspace(size_t capacity, int locked) { + mstate m = 0; + size_t msize; + ensure_initialization(); + msize = pad_request(sizeof(struct malloc_state)); + if (capacity < (size_t) -(msize + TOP_FOOT_SIZE + mparams.page_size)) { + size_t rs = ((capacity == 0)? mparams.granularity : + (capacity + TOP_FOOT_SIZE + msize)); + size_t tsize = granularity_align(rs); + char* tbase = (char*)(CALL_MMAP(tsize)); + if (tbase != CMFAIL) { + m = init_user_mstate(tbase, tsize); + m->seg.sflags = IS_MMAPPED_BIT; + set_lock(m, locked); + } + } + return (mspace)m; +} + +mspace create_mspace_with_base(void* base, size_t capacity, int locked) { + mstate m = 0; + size_t msize; + ensure_initialization(); + msize = pad_request(sizeof(struct malloc_state)); + if (capacity > msize + TOP_FOOT_SIZE && + capacity < (size_t) -(msize + TOP_FOOT_SIZE + mparams.page_size)) { + m = init_user_mstate((char*)base, capacity); + m->seg.sflags = EXTERN_BIT; + set_lock(m, locked); + } + return (mspace)m; +} + +int mspace_mmap_large_chunks(mspace msp, int enable) { + int ret = 0; + mstate ms = (mstate)msp; + if (!PREACTION(ms)) { + if (use_mmap(ms)) + ret = 1; + if (enable) + enable_mmap(ms); + else + disable_mmap(ms); + POSTACTION(ms); + } + return ret; +} + +size_t destroy_mspace(mspace msp) { + size_t freed = 0; + mstate ms = (mstate)msp; + if (ok_magic(ms)) { + msegmentptr sp = &ms->seg; + while (sp != 0) { + char* base = sp->base; + size_t size = sp->size; + flag_t flag = sp->sflags; + sp = sp->next; + if ((flag & IS_MMAPPED_BIT) && !(flag & EXTERN_BIT) && + CALL_MUNMAP(base, size) == 0) + freed += size; + } + } + else { + USAGE_ERROR_ACTION(ms,ms); + } + return freed; +} + +/* + mspace versions of routines are near-clones of the global + versions. This is not so nice but better than the alternatives. +*/ + + +void* mspace_malloc(mspace msp, size_t bytes) { + mstate ms = (mstate)msp; + if (!ok_magic(ms)) { + USAGE_ERROR_ACTION(ms,ms); + return 0; + } + if (!PREACTION(ms)) { + void* mem; + size_t nb; + if (bytes <= MAX_SMALL_REQUEST) { + bindex_t idx; + binmap_t smallbits; + nb = (bytes < MIN_REQUEST)? MIN_CHUNK_SIZE : pad_request(bytes); + idx = small_index(nb); + smallbits = ms->smallmap >> idx; + + if ((smallbits & 0x3U) != 0) { /* Remainderless fit to a smallbin. */ + mchunkptr b, p; + idx += ~smallbits & 1; /* Uses next bin if idx empty */ + b = smallbin_at(ms, idx); + p = b->fd; + assert(chunksize(p) == small_index2size(idx)); + unlink_first_small_chunk(ms, b, p, idx); + set_inuse_and_pinuse(ms, p, small_index2size(idx)); + mem = chunk2mem(p); + check_malloced_chunk(ms, mem, nb); + goto postaction; + } + + else if (nb > ms->dvsize) { + if (smallbits != 0) { /* Use chunk in next nonempty smallbin */ + mchunkptr b, p, r; + size_t rsize; + bindex_t i; + binmap_t leftbits = (smallbits << idx) & left_bits(idx2bit(idx)); + binmap_t leastbit = least_bit(leftbits); + compute_bit2idx(leastbit, i); + b = smallbin_at(ms, i); + p = b->fd; + assert(chunksize(p) == small_index2size(i)); + unlink_first_small_chunk(ms, b, p, i); + rsize = small_index2size(i) - nb; + /* Fit here cannot be remainderless if 4byte sizes */ + if (SIZE_T_SIZE != 4 && rsize < MIN_CHUNK_SIZE) + set_inuse_and_pinuse(ms, p, small_index2size(i)); + else { + set_size_and_pinuse_of_inuse_chunk(ms, p, nb); + r = chunk_plus_offset(p, nb); + set_size_and_pinuse_of_free_chunk(r, rsize); + replace_dv(ms, r, rsize); + } + mem = chunk2mem(p); + check_malloced_chunk(ms, mem, nb); + goto postaction; + } + + else if (ms->treemap != 0 && (mem = tmalloc_small(ms, nb)) != 0) { + check_malloced_chunk(ms, mem, nb); + goto postaction; + } + } + } + else if (bytes >= MAX_REQUEST) + nb = MAX_SIZE_T; /* Too big to allocate. Force failure (in sys alloc) */ + else { + nb = pad_request(bytes); + if (ms->treemap != 0 && (mem = tmalloc_large(ms, nb)) != 0) { + check_malloced_chunk(ms, mem, nb); + goto postaction; + } + } + + if (nb <= ms->dvsize) { + size_t rsize = ms->dvsize - nb; + mchunkptr p = ms->dv; + if (rsize >= MIN_CHUNK_SIZE) { /* split dv */ + mchunkptr r = ms->dv = chunk_plus_offset(p, nb); + ms->dvsize = rsize; + set_size_and_pinuse_of_free_chunk(r, rsize); + set_size_and_pinuse_of_inuse_chunk(ms, p, nb); + } + else { /* exhaust dv */ + size_t dvs = ms->dvsize; + ms->dvsize = 0; + ms->dv = 0; + set_inuse_and_pinuse(ms, p, dvs); + } + mem = chunk2mem(p); + check_malloced_chunk(ms, mem, nb); + goto postaction; + } + + else if (nb < ms->topsize) { /* Split top */ + size_t rsize = ms->topsize -= nb; + mchunkptr p = ms->top; + mchunkptr r = ms->top = chunk_plus_offset(p, nb); + r->head = rsize | PINUSE_BIT; + set_size_and_pinuse_of_inuse_chunk(ms, p, nb); + mem = chunk2mem(p); + check_top_chunk(ms, ms->top); + check_malloced_chunk(ms, mem, nb); + goto postaction; + } + + mem = sys_alloc(ms, nb); + + postaction: + POSTACTION(ms); + return mem; + } + + return 0; +} + +void mspace_free(mspace msp, void* mem) { + if (mem != 0) { + mchunkptr p = mem2chunk(mem); +#if FOOTERS + mstate fm = get_mstate_for(p); +#else /* FOOTERS */ + mstate fm = (mstate)msp; +#endif /* FOOTERS */ + if (!ok_magic(fm)) { + USAGE_ERROR_ACTION(fm, p); + return; + } + if (!PREACTION(fm)) { + check_inuse_chunk(fm, p); + if (RTCHECK(ok_address(fm, p) && ok_cinuse(p))) { + size_t psize = chunksize(p); + mchunkptr next = chunk_plus_offset(p, psize); + if (!pinuse(p)) { + size_t prevsize = p->prev_foot; + if ((prevsize & IS_MMAPPED_BIT) != 0) { + prevsize &= ~IS_MMAPPED_BIT; + psize += prevsize + MMAP_FOOT_PAD; + if (CALL_MUNMAP((char*)p - prevsize, psize) == 0) + fm->footprint -= psize; + goto postaction; + } + else { + mchunkptr prev = chunk_minus_offset(p, prevsize); + psize += prevsize; + p = prev; + if (RTCHECK(ok_address(fm, prev))) { /* consolidate backward */ + if (p != fm->dv) { + unlink_chunk(fm, p, prevsize); + } + else if ((next->head & INUSE_BITS) == INUSE_BITS) { + fm->dvsize = psize; + set_free_with_pinuse(p, psize, next); + goto postaction; + } + } + else + goto erroraction; + } + } + + if (RTCHECK(ok_next(p, next) && ok_pinuse(next))) { + if (!cinuse(next)) { /* consolidate forward */ + if (next == fm->top) { + size_t tsize = fm->topsize += psize; + fm->top = p; + p->head = tsize | PINUSE_BIT; + if (p == fm->dv) { + fm->dv = 0; + fm->dvsize = 0; + } + if (should_trim(fm, tsize)) + sys_trim(fm, 0); + goto postaction; + } + else if (next == fm->dv) { + size_t dsize = fm->dvsize += psize; + fm->dv = p; + set_size_and_pinuse_of_free_chunk(p, dsize); + goto postaction; + } + else { + size_t nsize = chunksize(next); + psize += nsize; + unlink_chunk(fm, next, nsize); + set_size_and_pinuse_of_free_chunk(p, psize); + if (p == fm->dv) { + fm->dvsize = psize; + goto postaction; + } + } + } + else + set_free_with_pinuse(p, psize, next); + + if (is_small(psize)) { + insert_small_chunk(fm, p, psize); + check_free_chunk(fm, p); + } + else { + tchunkptr tp = (tchunkptr)p; + insert_large_chunk(fm, tp, psize); + check_free_chunk(fm, p); + if (--fm->release_checks == 0) + release_unused_segments(fm); + } + goto postaction; + } + } + erroraction: + USAGE_ERROR_ACTION(fm, p); + postaction: + POSTACTION(fm); + } + } +} + +void* mspace_calloc(mspace msp, size_t n_elements, size_t elem_size) { + void* mem; + size_t req = 0; + mstate ms = (mstate)msp; + if (!ok_magic(ms)) { + USAGE_ERROR_ACTION(ms,ms); + return 0; + } + if (n_elements != 0) { + req = n_elements * elem_size; + if (((n_elements | elem_size) & ~(size_t)0xffff) && + (req / n_elements != elem_size)) + req = MAX_SIZE_T; /* force downstream failure on overflow */ + } + mem = internal_malloc(ms, req); + if (mem != 0 && calloc_must_clear(mem2chunk(mem))) + memset(mem, 0, req); + return mem; +} + +void* mspace_realloc(mspace msp, void* oldmem, size_t bytes) { + if (oldmem == 0) + return mspace_malloc(msp, bytes); +#ifdef REALLOC_ZERO_BYTES_FREES + if (bytes == 0) { + mspace_free(msp, oldmem); + return 0; + } +#endif /* REALLOC_ZERO_BYTES_FREES */ + else { +#if FOOTERS + mchunkptr p = mem2chunk(oldmem); + mstate ms = get_mstate_for(p); +#else /* FOOTERS */ + mstate ms = (mstate)msp; +#endif /* FOOTERS */ + if (!ok_magic(ms)) { + USAGE_ERROR_ACTION(ms,ms); + return 0; + } + return internal_realloc(ms, oldmem, bytes); + } +} + +void* mspace_memalign(mspace msp, size_t alignment, size_t bytes) { + mstate ms = (mstate)msp; + if (!ok_magic(ms)) { + USAGE_ERROR_ACTION(ms,ms); + return 0; + } + return internal_memalign(ms, alignment, bytes); +} + +void** mspace_independent_calloc(mspace msp, size_t n_elements, + size_t elem_size, void* chunks[]) { + size_t sz = elem_size; /* serves as 1-element array */ + mstate ms = (mstate)msp; + if (!ok_magic(ms)) { + USAGE_ERROR_ACTION(ms,ms); + return 0; + } + return ialloc(ms, n_elements, &sz, 3, chunks); +} + +void** mspace_independent_comalloc(mspace msp, size_t n_elements, + size_t sizes[], void* chunks[]) { + mstate ms = (mstate)msp; + if (!ok_magic(ms)) { + USAGE_ERROR_ACTION(ms,ms); + return 0; + } + return ialloc(ms, n_elements, sizes, 0, chunks); +} + +int mspace_trim(mspace msp, size_t pad) { + int result = 0; + mstate ms = (mstate)msp; + if (ok_magic(ms)) { + if (!PREACTION(ms)) { + result = sys_trim(ms, pad); + POSTACTION(ms); + } + } + else { + USAGE_ERROR_ACTION(ms,ms); + } + return result; +} + +void mspace_malloc_stats(mspace msp) { + mstate ms = (mstate)msp; + if (ok_magic(ms)) { + internal_malloc_stats(ms); + } + else { + USAGE_ERROR_ACTION(ms,ms); + } +} + +size_t mspace_footprint(mspace msp) { + size_t result = 0; + mstate ms = (mstate)msp; + if (ok_magic(ms)) { + result = ms->footprint; + } + else { + USAGE_ERROR_ACTION(ms,ms); + } + return result; +} + + +size_t mspace_max_footprint(mspace msp) { + size_t result = 0; + mstate ms = (mstate)msp; + if (ok_magic(ms)) { + result = ms->max_footprint; + } + else { + USAGE_ERROR_ACTION(ms,ms); + } + return result; +} + + +#if !NO_MALLINFO +struct mallinfo mspace_mallinfo(mspace msp) { + mstate ms = (mstate)msp; + if (!ok_magic(ms)) { + USAGE_ERROR_ACTION(ms,ms); + } + return internal_mallinfo(ms); +} +#endif /* NO_MALLINFO */ + +size_t mspace_usable_size(void* mem) { + if (mem != 0) { + mchunkptr p = mem2chunk(mem); + if (cinuse(p)) + return chunksize(p) - overhead_for(p); + } + return 0; +} + +int mspace_mallopt(int param_number, int value) { + return change_mparam(param_number, value); +} + +#endif /* MSPACES */ + +/* -------------------- Alternative MORECORE functions ------------------- */ + +/* + Guidelines for creating a custom version of MORECORE: + + * For best performance, MORECORE should allocate in multiples of pagesize. + * MORECORE may allocate more memory than requested. (Or even less, + but this will usually result in a malloc failure.) + * MORECORE must not allocate memory when given argument zero, but + instead return one past the end address of memory from previous + nonzero call. + * For best performance, consecutive calls to MORECORE with positive + arguments should return increasing addresses, indicating that + space has been contiguously extended. + * Even though consecutive calls to MORECORE need not return contiguous + addresses, it must be OK for malloc'ed chunks to span multiple + regions in those cases where they do happen to be contiguous. + * MORECORE need not handle negative arguments -- it may instead + just return MFAIL when given negative arguments. + Negative arguments are always multiples of pagesize. MORECORE + must not misinterpret negative args as large positive unsigned + args. You can suppress all such calls from even occurring by defining + MORECORE_CANNOT_TRIM, + + As an example alternative MORECORE, here is a custom allocator + kindly contributed for pre-OSX macOS. It uses virtually but not + necessarily physically contiguous non-paged memory (locked in, + present and won't get swapped out). You can use it by uncommenting + this section, adding some #includes, and setting up the appropriate + defines above: + + #define MORECORE osMoreCore + + There is also a shutdown routine that should somehow be called for + cleanup upon program exit. + + #define MAX_POOL_ENTRIES 100 + #define MINIMUM_MORECORE_SIZE (64 * 1024U) + static int next_os_pool; + void *our_os_pools[MAX_POOL_ENTRIES]; + + void *osMoreCore(int size) + { + void *ptr = 0; + static void *sbrk_top = 0; + + if (size > 0) + { + if (size < MINIMUM_MORECORE_SIZE) + size = MINIMUM_MORECORE_SIZE; + if (CurrentExecutionLevel() == kTaskLevel) + ptr = PoolAllocateResident(size + RM_PAGE_SIZE, 0); + if (ptr == 0) + { + return (void *) MFAIL; + } + // save ptrs so they can be freed during cleanup + our_os_pools[next_os_pool] = ptr; + next_os_pool++; + ptr = (void *) ((((size_t) ptr) + RM_PAGE_MASK) & ~RM_PAGE_MASK); + sbrk_top = (char *) ptr + size; + return ptr; + } + else if (size < 0) + { + // we don't currently support shrink behavior + return (void *) MFAIL; + } + else + { + return sbrk_top; + } + } + + // cleanup any allocated memory pools + // called as last thing before shutting down driver + + void osCleanupMem(void) + { + void **ptr; + + for (ptr = our_os_pools; ptr < &our_os_pools[MAX_POOL_ENTRIES]; ptr++) + if (*ptr) + { + PoolDeallocate(*ptr); + *ptr = 0; + } + } + +*/ + + +/* ----------------------------------------------------------------------- +History: + V2.8.4 (not yet released) + * Add mspace_mmap_large_chunks; thanks to Jean Brouwers + * Fix insufficient sys_alloc padding when using 16byte alignment + * Fix bad error check in mspace_footprint + * Adaptations for ptmalloc, courtesy of Wolfram Gloger. + * Reentrant spin locks, courtesy of Earl Chew and others + * Win32 improvements, courtesy of Niall Douglas and Earl Chew + * Add NO_SEGMENT_TRAVERSAL and MAX_RELEASE_CHECK_RATE options + * Extension hook in malloc_state + * Various small adjustments to reduce warnings on some compilers + * Various configuration extensions/changes for more platforms. Thanks + to all who contributed these. + + V2.8.3 Thu Sep 22 11:16:32 2005 Doug Lea (dl at gee) + * Add max_footprint functions + * Ensure all appropriate literals are size_t + * Fix conditional compilation problem for some #define settings + * Avoid concatenating segments with the one provided + in create_mspace_with_base + * Rename some variables to avoid compiler shadowing warnings + * Use explicit lock initialization. + * Better handling of sbrk interference. + * Simplify and fix segment insertion, trimming and mspace_destroy + * Reinstate REALLOC_ZERO_BYTES_FREES option from 2.7.x + * Thanks especially to Dennis Flanagan for help on these. + + V2.8.2 Sun Jun 12 16:01:10 2005 Doug Lea (dl at gee) + * Fix memalign brace error. + + V2.8.1 Wed Jun 8 16:11:46 2005 Doug Lea (dl at gee) + * Fix improper #endif nesting in C++ + * Add explicit casts needed for C++ + + V2.8.0 Mon May 30 14:09:02 2005 Doug Lea (dl at gee) + * Use trees for large bins + * Support mspaces + * Use segments to unify sbrk-based and mmap-based system allocation, + removing need for emulation on most platforms without sbrk. + * Default safety checks + * Optional footer checks. Thanks to William Robertson for the idea. + * Internal code refactoring + * Incorporate suggestions and platform-specific changes. + Thanks to Dennis Flanagan, Colin Plumb, Niall Douglas, + Aaron Bachmann, Emery Berger, and others. + * Speed up non-fastbin processing enough to remove fastbins. + * Remove useless cfree() to avoid conflicts with other apps. + * Remove internal memcpy, memset. Compilers handle builtins better. + * Remove some options that no one ever used and rename others. + + V2.7.2 Sat Aug 17 09:07:30 2002 Doug Lea (dl at gee) + * Fix malloc_state bitmap array misdeclaration + + V2.7.1 Thu Jul 25 10:58:03 2002 Doug Lea (dl at gee) + * Allow tuning of FIRST_SORTED_BIN_SIZE + * Use PTR_UINT as type for all ptr->int casts. Thanks to John Belmonte. + * Better detection and support for non-contiguousness of MORECORE. + Thanks to Andreas Mueller, Conal Walsh, and Wolfram Gloger + * Bypass most of malloc if no frees. Thanks To Emery Berger. + * Fix freeing of old top non-contiguous chunk im sysmalloc. + * Raised default trim and map thresholds to 256K. + * Fix mmap-related #defines. Thanks to Lubos Lunak. + * Fix copy macros; added LACKS_FCNTL_H. Thanks to Neal Walfield. + * Branch-free bin calculation + * Default trim and mmap thresholds now 256K. + + V2.7.0 Sun Mar 11 14:14:06 2001 Doug Lea (dl at gee) + * Introduce independent_comalloc and independent_calloc. + Thanks to Michael Pachos for motivation and help. + * Make optional .h file available + * Allow > 2GB requests on 32bit systems. + * new WIN32 sbrk, mmap, munmap, lock code from <Walter@GeNeSys-e.de>. + Thanks also to Andreas Mueller <a.mueller at paradatec.de>, + and Anonymous. + * Allow override of MALLOC_ALIGNMENT (Thanks to Ruud Waij for + helping test this.) + * memalign: check alignment arg + * realloc: don't try to shift chunks backwards, since this + leads to more fragmentation in some programs and doesn't + seem to help in any others. + * Collect all cases in malloc requiring system memory into sysmalloc + * Use mmap as backup to sbrk + * Place all internal state in malloc_state + * Introduce fastbins (although similar to 2.5.1) + * Many minor tunings and cosmetic improvements + * Introduce USE_PUBLIC_MALLOC_WRAPPERS, USE_MALLOC_LOCK + * Introduce MALLOC_FAILURE_ACTION, MORECORE_CONTIGUOUS + Thanks to Tony E. Bennett <tbennett@nvidia.com> and others. + * Include errno.h to support default failure action. + + V2.6.6 Sun Dec 5 07:42:19 1999 Doug Lea (dl at gee) + * return null for negative arguments + * Added Several WIN32 cleanups from Martin C. Fong <mcfong at yahoo.com> + * Add 'LACKS_SYS_PARAM_H' for those systems without 'sys/param.h' + (e.g. WIN32 platforms) + * Cleanup header file inclusion for WIN32 platforms + * Cleanup code to avoid Microsoft Visual C++ compiler complaints + * Add 'USE_DL_PREFIX' to quickly allow co-existence with existing + memory allocation routines + * Set 'malloc_getpagesize' for WIN32 platforms (needs more work) + * Use 'assert' rather than 'ASSERT' in WIN32 code to conform to + usage of 'assert' in non-WIN32 code + * Improve WIN32 'sbrk()' emulation's 'findRegion()' routine to + avoid infinite loop + * Always call 'fREe()' rather than 'free()' + + V2.6.5 Wed Jun 17 15:57:31 1998 Doug Lea (dl at gee) + * Fixed ordering problem with boundary-stamping + + V2.6.3 Sun May 19 08:17:58 1996 Doug Lea (dl at gee) + * Added pvalloc, as recommended by H.J. Liu + * Added 64bit pointer support mainly from Wolfram Gloger + * Added anonymously donated WIN32 sbrk emulation + * Malloc, calloc, getpagesize: add optimizations from Raymond Nijssen + * malloc_extend_top: fix mask error that caused wastage after + foreign sbrks + * Add linux mremap support code from HJ Liu + + V2.6.2 Tue Dec 5 06:52:55 1995 Doug Lea (dl at gee) + * Integrated most documentation with the code. + * Add support for mmap, with help from + Wolfram Gloger (Gloger@lrz.uni-muenchen.de). + * Use last_remainder in more cases. + * Pack bins using idea from colin@nyx10.cs.du.edu + * Use ordered bins instead of best-fit threshhold + * Eliminate block-local decls to simplify tracing and debugging. + * Support another case of realloc via move into top + * Fix error occuring when initial sbrk_base not word-aligned. + * Rely on page size for units instead of SBRK_UNIT to + avoid surprises about sbrk alignment conventions. + * Add mallinfo, mallopt. Thanks to Raymond Nijssen + (raymond@es.ele.tue.nl) for the suggestion. + * Add `pad' argument to malloc_trim and top_pad mallopt parameter. + * More precautions for cases where other routines call sbrk, + courtesy of Wolfram Gloger (Gloger@lrz.uni-muenchen.de). + * Added macros etc., allowing use in linux libc from + H.J. Lu (hjl@gnu.ai.mit.edu) + * Inverted this history list + + V2.6.1 Sat Dec 2 14:10:57 1995 Doug Lea (dl at gee) + * Re-tuned and fixed to behave more nicely with V2.6.0 changes. + * Removed all preallocation code since under current scheme + the work required to undo bad preallocations exceeds + the work saved in good cases for most test programs. + * No longer use return list or unconsolidated bins since + no scheme using them consistently outperforms those that don't + given above changes. + * Use best fit for very large chunks to prevent some worst-cases. + * Added some support for debugging + + V2.6.0 Sat Nov 4 07:05:23 1995 Doug Lea (dl at gee) + * Removed footers when chunks are in use. Thanks to + Paul Wilson (wilson@cs.texas.edu) for the suggestion. + + V2.5.4 Wed Nov 1 07:54:51 1995 Doug Lea (dl at gee) + * Added malloc_trim, with help from Wolfram Gloger + (wmglo@Dent.MED.Uni-Muenchen.DE). + + V2.5.3 Tue Apr 26 10:16:01 1994 Doug Lea (dl at g) + + V2.5.2 Tue Apr 5 16:20:40 1994 Doug Lea (dl at g) + * realloc: try to expand in both directions + * malloc: swap order of clean-bin strategy; + * realloc: only conditionally expand backwards + * Try not to scavenge used bins + * Use bin counts as a guide to preallocation + * Occasionally bin return list chunks in first scan + * Add a few optimizations from colin@nyx10.cs.du.edu + + V2.5.1 Sat Aug 14 15:40:43 1993 Doug Lea (dl at g) + * faster bin computation & slightly different binning + * merged all consolidations to one part of malloc proper + (eliminating old malloc_find_space & malloc_clean_bin) + * Scan 2 returns chunks (not just 1) + * Propagate failure in realloc if malloc returns 0 + * Add stuff to allow compilation on non-ANSI compilers + from kpv@research.att.com + + V2.5 Sat Aug 7 07:41:59 1993 Doug Lea (dl at g.oswego.edu) + * removed potential for odd address access in prev_chunk + * removed dependency on getpagesize.h + * misc cosmetics and a bit more internal documentation + * anticosmetics: mangled names in macros to evade debugger strangeness + * tested on sparc, hp-700, dec-mips, rs6000 + with gcc & native cc (hp, dec only) allowing + Detlefs & Zorn comparison study (in SIGPLAN Notices.) + + Trial version Fri Aug 28 13:14:29 1992 Doug Lea (dl at g.oswego.edu) + * Based loosely on libg++-1.2X malloc. (It retains some of the overall + structure of old version, but most details differ.) + +*/ + + diff --git a/compat/nedmalloc/nedmalloc.c b/compat/nedmalloc/nedmalloc.c new file mode 100644 index 0000000000..d9a17a8057 --- /dev/null +++ b/compat/nedmalloc/nedmalloc.c @@ -0,0 +1,966 @@ +/* Alternative malloc implementation for multiple threads without +lock contention based on dlmalloc. (C) 2005-2006 Niall Douglas + +Boost Software License - Version 1.0 - August 17th, 2003 + +Permission is hereby granted, free of charge, to any person or organization +obtaining a copy of the software and accompanying documentation covered by +this license (the "Software") to use, reproduce, display, distribute, +execute, and transmit the Software, and to prepare derivative works of the +Software, and to permit third-parties to whom the Software is furnished to +do so, all subject to the following: + +The copyright notices in the Software and this entire statement, including +the above license grant, this restriction and the following disclaimer, +must be included in all copies of the Software, in whole or in part, and +all derivative works of the Software, unless such copies or derivative +works are solely in the form of machine-executable object code generated by +a source language processor. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. +*/ + +#ifdef _MSC_VER +/* Enable full aliasing on MSVC */ +/*#pragma optimize("a", on)*/ +#endif + +/*#define FULLSANITYCHECKS*/ + +#include "nedmalloc.h" +#if defined(WIN32) + #include <malloc.h> +#endif +#define MSPACES 1 +#define ONLY_MSPACES 1 +#ifndef USE_LOCKS + #define USE_LOCKS 1 +#endif +#define FOOTERS 1 /* Need to enable footers so frees lock the right mspace */ +#undef DEBUG /* dlmalloc wants DEBUG either 0 or 1 */ +#ifdef _DEBUG + #define DEBUG 1 +#else + #define DEBUG 0 +#endif +#ifdef NDEBUG /* Disable assert checking on release builds */ + #undef DEBUG +#endif +/* The default of 64Kb means we spend too much time kernel-side */ +#ifndef DEFAULT_GRANULARITY +#define DEFAULT_GRANULARITY (1*1024*1024) +#endif +/*#define USE_SPIN_LOCKS 0*/ + + +/*#define FORCEINLINE*/ +#include "malloc.c.h" +#ifdef NDEBUG /* Disable assert checking on release builds */ + #undef DEBUG +#endif + +/* The maximum concurrent threads in a pool possible */ +#ifndef MAXTHREADSINPOOL +#define MAXTHREADSINPOOL 16 +#endif +/* The maximum number of threadcaches which can be allocated */ +#ifndef THREADCACHEMAXCACHES +#define THREADCACHEMAXCACHES 256 +#endif +/* The maximum size to be allocated from the thread cache */ +#ifndef THREADCACHEMAX +#define THREADCACHEMAX 8192 +#endif +#if 0 +/* The number of cache entries for finer grained bins. This is (topbitpos(THREADCACHEMAX)-4)*2 */ +#define THREADCACHEMAXBINS ((13-4)*2) +#else +/* The number of cache entries. This is (topbitpos(THREADCACHEMAX)-4) */ +#define THREADCACHEMAXBINS (13-4) +#endif +/* Point at which the free space in a thread cache is garbage collected */ +#ifndef THREADCACHEMAXFREESPACE +#define THREADCACHEMAXFREESPACE (512*1024) +#endif + + +#ifdef WIN32 + #define TLSVAR DWORD + #define TLSALLOC(k) (*(k)=TlsAlloc(), TLS_OUT_OF_INDEXES==*(k)) + #define TLSFREE(k) (!TlsFree(k)) + #define TLSGET(k) TlsGetValue(k) + #define TLSSET(k, a) (!TlsSetValue(k, a)) + #ifdef DEBUG +static LPVOID ChkedTlsGetValue(DWORD idx) +{ + LPVOID ret=TlsGetValue(idx); + assert(S_OK==GetLastError()); + return ret; +} + #undef TLSGET + #define TLSGET(k) ChkedTlsGetValue(k) + #endif +#else + #define TLSVAR pthread_key_t + #define TLSALLOC(k) pthread_key_create(k, 0) + #define TLSFREE(k) pthread_key_delete(k) + #define TLSGET(k) pthread_getspecific(k) + #define TLSSET(k, a) pthread_setspecific(k, a) +#endif + +#if 0 +/* Only enable if testing with valgrind. Causes misoperation */ +#define mspace_malloc(p, s) malloc(s) +#define mspace_realloc(p, m, s) realloc(m, s) +#define mspace_calloc(p, n, s) calloc(n, s) +#define mspace_free(p, m) free(m) +#endif + + +#if defined(__cplusplus) +#if !defined(NO_NED_NAMESPACE) +namespace nedalloc { +#else +extern "C" { +#endif +#endif + +size_t nedblksize(void *mem) THROWSPEC +{ +#if 0 + /* Only enable if testing with valgrind. Causes misoperation */ + return THREADCACHEMAX; +#else + if(mem) + { + mchunkptr p=mem2chunk(mem); + assert(cinuse(p)); /* If this fails, someone tried to free a block twice */ + if(cinuse(p)) + return chunksize(p)-overhead_for(p); + } + return 0; +#endif +} + +void nedsetvalue(void *v) THROWSPEC { nedpsetvalue(0, v); } +void * nedmalloc(size_t size) THROWSPEC { return nedpmalloc(0, size); } +void * nedcalloc(size_t no, size_t size) THROWSPEC { return nedpcalloc(0, no, size); } +void * nedrealloc(void *mem, size_t size) THROWSPEC { return nedprealloc(0, mem, size); } +void nedfree(void *mem) THROWSPEC { nedpfree(0, mem); } +void * nedmemalign(size_t alignment, size_t bytes) THROWSPEC { return nedpmemalign(0, alignment, bytes); } +#if !NO_MALLINFO +struct mallinfo nedmallinfo(void) THROWSPEC { return nedpmallinfo(0); } +#endif +int nedmallopt(int parno, int value) THROWSPEC { return nedpmallopt(0, parno, value); } +int nedmalloc_trim(size_t pad) THROWSPEC { return nedpmalloc_trim(0, pad); } +void nedmalloc_stats() THROWSPEC { nedpmalloc_stats(0); } +size_t nedmalloc_footprint() THROWSPEC { return nedpmalloc_footprint(0); } +void **nedindependent_calloc(size_t elemsno, size_t elemsize, void **chunks) THROWSPEC { return nedpindependent_calloc(0, elemsno, elemsize, chunks); } +void **nedindependent_comalloc(size_t elems, size_t *sizes, void **chunks) THROWSPEC { return nedpindependent_comalloc(0, elems, sizes, chunks); } + +struct threadcacheblk_t; +typedef struct threadcacheblk_t threadcacheblk; +struct threadcacheblk_t +{ /* Keep less than 16 bytes on 32 bit systems and 32 bytes on 64 bit systems */ +#ifdef FULLSANITYCHECKS + unsigned int magic; +#endif + unsigned int lastUsed, size; + threadcacheblk *next, *prev; +}; +typedef struct threadcache_t +{ +#ifdef FULLSANITYCHECKS + unsigned int magic1; +#endif + int mymspace; /* Last mspace entry this thread used */ + long threadid; + unsigned int mallocs, frees, successes; + size_t freeInCache; /* How much free space is stored in this cache */ + threadcacheblk *bins[(THREADCACHEMAXBINS+1)*2]; +#ifdef FULLSANITYCHECKS + unsigned int magic2; +#endif +} threadcache; +struct nedpool_t +{ + MLOCK_T mutex; + void *uservalue; + int threads; /* Max entries in m to use */ + threadcache *caches[THREADCACHEMAXCACHES]; + TLSVAR mycache; /* Thread cache for this thread. 0 for unset, negative for use mspace-1 directly, otherwise is cache-1 */ + mstate m[MAXTHREADSINPOOL+1]; /* mspace entries for this pool */ +}; +static nedpool syspool; + +static FORCEINLINE unsigned int size2binidx(size_t _size) THROWSPEC +{ /* 8=1000 16=10000 20=10100 24=11000 32=100000 48=110000 4096=1000000000000 */ + unsigned int topbit, size=(unsigned int)(_size>>4); + /* 16=1 20=1 24=1 32=10 48=11 64=100 96=110 128=1000 4096=100000000 */ + +#if defined(__GNUC__) + topbit = sizeof(size)*__CHAR_BIT__ - 1 - __builtin_clz(size); +#elif defined(_MSC_VER) && _MSC_VER>=1300 + { + unsigned long bsrTopBit; + + _BitScanReverse(&bsrTopBit, size); + + topbit = bsrTopBit; + } +#else +#if 0 + union { + unsigned asInt[2]; + double asDouble; + }; + int n; + + asDouble = (double)size + 0.5; + topbit = (asInt[!FOX_BIGENDIAN] >> 20) - 1023; +#else + { + unsigned int x=size; + x = x | (x >> 1); + x = x | (x >> 2); + x = x | (x >> 4); + x = x | (x >> 8); + x = x | (x >>16); + x = ~x; + x = x - ((x >> 1) & 0x55555555); + x = (x & 0x33333333) + ((x >> 2) & 0x33333333); + x = (x + (x >> 4)) & 0x0F0F0F0F; + x = x + (x << 8); + x = x + (x << 16); + topbit=31 - (x >> 24); + } +#endif +#endif + return topbit; +} + + +#ifdef FULLSANITYCHECKS +static void tcsanitycheck(threadcacheblk **ptr) THROWSPEC +{ + assert((ptr[0] && ptr[1]) || (!ptr[0] && !ptr[1])); + if(ptr[0] && ptr[1]) + { + assert(nedblksize(ptr[0])>=sizeof(threadcacheblk)); + assert(nedblksize(ptr[1])>=sizeof(threadcacheblk)); + assert(*(unsigned int *) "NEDN"==ptr[0]->magic); + assert(*(unsigned int *) "NEDN"==ptr[1]->magic); + assert(!ptr[0]->prev); + assert(!ptr[1]->next); + if(ptr[0]==ptr[1]) + { + assert(!ptr[0]->next); + assert(!ptr[1]->prev); + } + } +} +static void tcfullsanitycheck(threadcache *tc) THROWSPEC +{ + threadcacheblk **tcbptr=tc->bins; + int n; + for(n=0; n<=THREADCACHEMAXBINS; n++, tcbptr+=2) + { + threadcacheblk *b, *ob=0; + tcsanitycheck(tcbptr); + for(b=tcbptr[0]; b; ob=b, b=b->next) + { + assert(*(unsigned int *) "NEDN"==b->magic); + assert(!ob || ob->next==b); + assert(!ob || b->prev==ob); + } + } +} +#endif + +static NOINLINE void RemoveCacheEntries(nedpool *p, threadcache *tc, unsigned int age) THROWSPEC +{ +#ifdef FULLSANITYCHECKS + tcfullsanitycheck(tc); +#endif + if(tc->freeInCache) + { + threadcacheblk **tcbptr=tc->bins; + int n; + for(n=0; n<=THREADCACHEMAXBINS; n++, tcbptr+=2) + { + threadcacheblk **tcb=tcbptr+1; /* come from oldest end of list */ + /*tcsanitycheck(tcbptr);*/ + for(; *tcb && tc->frees-(*tcb)->lastUsed>=age; ) + { + threadcacheblk *f=*tcb; + size_t blksize=f->size; /*nedblksize(f);*/ + assert(blksize<=nedblksize(f)); + assert(blksize); +#ifdef FULLSANITYCHECKS + assert(*(unsigned int *) "NEDN"==(*tcb)->magic); +#endif + *tcb=(*tcb)->prev; + if(*tcb) + (*tcb)->next=0; + else + *tcbptr=0; + tc->freeInCache-=blksize; + assert((long) tc->freeInCache>=0); + mspace_free(0, f); + /*tcsanitycheck(tcbptr);*/ + } + } + } +#ifdef FULLSANITYCHECKS + tcfullsanitycheck(tc); +#endif +} +static void DestroyCaches(nedpool *p) THROWSPEC +{ + if(p->caches) + { + threadcache *tc; + int n; + for(n=0; n<THREADCACHEMAXCACHES; n++) + { + if((tc=p->caches[n])) + { + tc->frees++; + RemoveCacheEntries(p, tc, 0); + assert(!tc->freeInCache); + tc->mymspace=-1; + tc->threadid=0; + mspace_free(0, tc); + p->caches[n]=0; + } + } + } +} + +static NOINLINE threadcache *AllocCache(nedpool *p) THROWSPEC +{ + threadcache *tc=0; + int n, end; + ACQUIRE_LOCK(&p->mutex); + for(n=0; n<THREADCACHEMAXCACHES && p->caches[n]; n++); + if(THREADCACHEMAXCACHES==n) + { /* List exhausted, so disable for this thread */ + RELEASE_LOCK(&p->mutex); + return 0; + } + tc=p->caches[n]=(threadcache *) mspace_calloc(p->m[0], 1, sizeof(threadcache)); + if(!tc) + { + RELEASE_LOCK(&p->mutex); + return 0; + } +#ifdef FULLSANITYCHECKS + tc->magic1=*(unsigned int *)"NEDMALC1"; + tc->magic2=*(unsigned int *)"NEDMALC2"; +#endif + tc->threadid=(long)(size_t)CURRENT_THREAD; + for(end=0; p->m[end]; end++); + tc->mymspace=tc->threadid % end; + RELEASE_LOCK(&p->mutex); + if(TLSSET(p->mycache, (void *)(size_t)(n+1))) abort(); + return tc; +} + +static void *threadcache_malloc(nedpool *p, threadcache *tc, size_t *size) THROWSPEC +{ + void *ret=0; + unsigned int bestsize; + unsigned int idx=size2binidx(*size); + size_t blksize=0; + threadcacheblk *blk, **binsptr; +#ifdef FULLSANITYCHECKS + tcfullsanitycheck(tc); +#endif + /* Calculate best fit bin size */ + bestsize=1<<(idx+4); +#if 0 + /* Finer grained bin fit */ + idx<<=1; + if(*size>bestsize) + { + idx++; + bestsize+=bestsize>>1; + } + if(*size>bestsize) + { + idx++; + bestsize=1<<(4+(idx>>1)); + } +#else + if(*size>bestsize) + { + idx++; + bestsize<<=1; + } +#endif + assert(bestsize>=*size); + if(*size<bestsize) *size=bestsize; + assert(*size<=THREADCACHEMAX); + assert(idx<=THREADCACHEMAXBINS); + binsptr=&tc->bins[idx*2]; + /* Try to match close, but move up a bin if necessary */ + blk=*binsptr; + if(!blk || blk->size<*size) + { /* Bump it up a bin */ + if(idx<THREADCACHEMAXBINS) + { + idx++; + binsptr+=2; + blk=*binsptr; + } + } + if(blk) + { + blksize=blk->size; /*nedblksize(blk);*/ + assert(nedblksize(blk)>=blksize); + assert(blksize>=*size); + if(blk->next) + blk->next->prev=0; + *binsptr=blk->next; + if(!*binsptr) + binsptr[1]=0; +#ifdef FULLSANITYCHECKS + blk->magic=0; +#endif + assert(binsptr[0]!=blk && binsptr[1]!=blk); + assert(nedblksize(blk)>=sizeof(threadcacheblk) && nedblksize(blk)<=THREADCACHEMAX+CHUNK_OVERHEAD); + /*printf("malloc: %p, %p, %p, %lu\n", p, tc, blk, (long) size);*/ + ret=(void *) blk; + } + ++tc->mallocs; + if(ret) + { + assert(blksize>=*size); + ++tc->successes; + tc->freeInCache-=blksize; + assert((long) tc->freeInCache>=0); + } +#if defined(DEBUG) && 0 + if(!(tc->mallocs & 0xfff)) + { + printf("*** threadcache=%u, mallocs=%u (%f), free=%u (%f), freeInCache=%u\n", (unsigned int) tc->threadid, tc->mallocs, + (float) tc->successes/tc->mallocs, tc->frees, (float) tc->successes/tc->frees, (unsigned int) tc->freeInCache); + } +#endif +#ifdef FULLSANITYCHECKS + tcfullsanitycheck(tc); +#endif + return ret; +} +static NOINLINE void ReleaseFreeInCache(nedpool *p, threadcache *tc, int mymspace) THROWSPEC +{ + unsigned int age=THREADCACHEMAXFREESPACE/8192; + /*ACQUIRE_LOCK(&p->m[mymspace]->mutex);*/ + while(age && tc->freeInCache>=THREADCACHEMAXFREESPACE) + { + RemoveCacheEntries(p, tc, age); + /*printf("*** Removing cache entries older than %u (%u)\n", age, (unsigned int) tc->freeInCache);*/ + age>>=1; + } + /*RELEASE_LOCK(&p->m[mymspace]->mutex);*/ +} +static void threadcache_free(nedpool *p, threadcache *tc, int mymspace, void *mem, size_t size) THROWSPEC +{ + unsigned int bestsize; + unsigned int idx=size2binidx(size); + threadcacheblk **binsptr, *tck=(threadcacheblk *) mem; + assert(size>=sizeof(threadcacheblk) && size<=THREADCACHEMAX+CHUNK_OVERHEAD); +#ifdef DEBUG + { /* Make sure this is a valid memory block */ + mchunkptr p = mem2chunk(mem); + mstate fm = get_mstate_for(p); + if (!ok_magic(fm)) { + USAGE_ERROR_ACTION(fm, p); + return; + } + } +#endif +#ifdef FULLSANITYCHECKS + tcfullsanitycheck(tc); +#endif + /* Calculate best fit bin size */ + bestsize=1<<(idx+4); +#if 0 + /* Finer grained bin fit */ + idx<<=1; + if(size>bestsize) + { + unsigned int biggerbestsize=bestsize+bestsize<<1; + if(size>=biggerbestsize) + { + idx++; + bestsize=biggerbestsize; + } + } +#endif + if(bestsize!=size) /* dlmalloc can round up, so we round down to preserve indexing */ + size=bestsize; + binsptr=&tc->bins[idx*2]; + assert(idx<=THREADCACHEMAXBINS); + if(tck==*binsptr) + { + fprintf(stderr, "Attempt to free already freed memory block %p - aborting!\n", tck); + abort(); + } +#ifdef FULLSANITYCHECKS + tck->magic=*(unsigned int *) "NEDN"; +#endif + tck->lastUsed=++tc->frees; + tck->size=(unsigned int) size; + tck->next=*binsptr; + tck->prev=0; + if(tck->next) + tck->next->prev=tck; + else + binsptr[1]=tck; + assert(!*binsptr || (*binsptr)->size==tck->size); + *binsptr=tck; + assert(tck==tc->bins[idx*2]); + assert(tc->bins[idx*2+1]==tck || binsptr[0]->next->prev==tck); + /*printf("free: %p, %p, %p, %lu\n", p, tc, mem, (long) size);*/ + tc->freeInCache+=size; +#ifdef FULLSANITYCHECKS + tcfullsanitycheck(tc); +#endif +#if 1 + if(tc->freeInCache>=THREADCACHEMAXFREESPACE) + ReleaseFreeInCache(p, tc, mymspace); +#endif +} + + + + +static NOINLINE int InitPool(nedpool *p, size_t capacity, int threads) THROWSPEC +{ /* threads is -1 for system pool */ + ensure_initialization(); + ACQUIRE_MALLOC_GLOBAL_LOCK(); + if(p->threads) goto done; + if(INITIAL_LOCK(&p->mutex)) goto err; + if(TLSALLOC(&p->mycache)) goto err; + if(!(p->m[0]=(mstate) create_mspace(capacity, 1))) goto err; + p->m[0]->extp=p; + p->threads=(threads<1 || threads>MAXTHREADSINPOOL) ? MAXTHREADSINPOOL : threads; +done: + RELEASE_MALLOC_GLOBAL_LOCK(); + return 1; +err: + if(threads<0) + abort(); /* If you can't allocate for system pool, we're screwed */ + DestroyCaches(p); + if(p->m[0]) + { + destroy_mspace(p->m[0]); + p->m[0]=0; + } + if(p->mycache) + { + if(TLSFREE(p->mycache)) abort(); + p->mycache=0; + } + RELEASE_MALLOC_GLOBAL_LOCK(); + return 0; +} +static NOINLINE mstate FindMSpace(nedpool *p, threadcache *tc, int *lastUsed, size_t size) THROWSPEC +{ /* Gets called when thread's last used mspace is in use. The strategy + is to run through the list of all available mspaces looking for an + unlocked one and if we fail, we create a new one so long as we don't + exceed p->threads */ + int n, end; + for(n=end=*lastUsed+1; p->m[n]; end=++n) + { + if(TRY_LOCK(&p->m[n]->mutex)) goto found; + } + for(n=0; n<*lastUsed && p->m[n]; n++) + { + if(TRY_LOCK(&p->m[n]->mutex)) goto found; + } + if(end<p->threads) + { + mstate temp; + if(!(temp=(mstate) create_mspace(size, 1))) + goto badexit; + /* Now we're ready to modify the lists, we lock */ + ACQUIRE_LOCK(&p->mutex); + while(p->m[end] && end<p->threads) + end++; + if(end>=p->threads) + { /* Drat, must destroy it now */ + RELEASE_LOCK(&p->mutex); + destroy_mspace((mspace) temp); + goto badexit; + } + /* We really want to make sure this goes into memory now but we + have to be careful of breaking aliasing rules, so write it twice */ + *((volatile struct malloc_state **) &p->m[end])=p->m[end]=temp; + ACQUIRE_LOCK(&p->m[end]->mutex); + /*printf("Created mspace idx %d\n", end);*/ + RELEASE_LOCK(&p->mutex); + n=end; + goto found; + } + /* Let it lock on the last one it used */ +badexit: + ACQUIRE_LOCK(&p->m[*lastUsed]->mutex); + return p->m[*lastUsed]; +found: + *lastUsed=n; + if(tc) + tc->mymspace=n; + else + { + if(TLSSET(p->mycache, (void *)(size_t)(-(n+1)))) abort(); + } + return p->m[n]; +} + +nedpool *nedcreatepool(size_t capacity, int threads) THROWSPEC +{ + nedpool *ret; + if(!(ret=(nedpool *) nedpcalloc(0, 1, sizeof(nedpool)))) return 0; + if(!InitPool(ret, capacity, threads)) + { + nedpfree(0, ret); + return 0; + } + return ret; +} +void neddestroypool(nedpool *p) THROWSPEC +{ + int n; + ACQUIRE_LOCK(&p->mutex); + DestroyCaches(p); + for(n=0; p->m[n]; n++) + { + destroy_mspace(p->m[n]); + p->m[n]=0; + } + RELEASE_LOCK(&p->mutex); + if(TLSFREE(p->mycache)) abort(); + nedpfree(0, p); +} + +void nedpsetvalue(nedpool *p, void *v) THROWSPEC +{ + if(!p) { p=&syspool; if(!syspool.threads) InitPool(&syspool, 0, -1); } + p->uservalue=v; +} +void *nedgetvalue(nedpool **p, void *mem) THROWSPEC +{ + nedpool *np=0; + mchunkptr mcp=mem2chunk(mem); + mstate fm; + if(!(is_aligned(chunk2mem(mcp))) && mcp->head != FENCEPOST_HEAD) return 0; + if(!cinuse(mcp)) return 0; + if(!next_pinuse(mcp)) return 0; + if(!is_mmapped(mcp) && !pinuse(mcp)) + { + if(next_chunk(prev_chunk(mcp))!=mcp) return 0; + } + fm=get_mstate_for(mcp); + if(!ok_magic(fm)) return 0; + if(!ok_address(fm, mcp)) return 0; + if(!fm->extp) return 0; + np=(nedpool *) fm->extp; + if(p) *p=np; + return np->uservalue; +} + +void neddisablethreadcache(nedpool *p) THROWSPEC +{ + int mycache; + if(!p) + { + p=&syspool; + if(!syspool.threads) InitPool(&syspool, 0, -1); + } + mycache=(int)(size_t) TLSGET(p->mycache); + if(!mycache) + { /* Set to mspace 0 */ + if(TLSSET(p->mycache, (void *)-1)) abort(); + } + else if(mycache>0) + { /* Set to last used mspace */ + threadcache *tc=p->caches[mycache-1]; +#if defined(DEBUG) + printf("Threadcache utilisation: %lf%% in cache with %lf%% lost to other threads\n", + 100.0*tc->successes/tc->mallocs, 100.0*((double) tc->mallocs-tc->frees)/tc->mallocs); +#endif + if(TLSSET(p->mycache, (void *)(size_t)(-tc->mymspace))) abort(); + tc->frees++; + RemoveCacheEntries(p, tc, 0); + assert(!tc->freeInCache); + tc->mymspace=-1; + tc->threadid=0; + mspace_free(0, p->caches[mycache-1]); + p->caches[mycache-1]=0; + } +} + +#define GETMSPACE(m,p,tc,ms,s,action) \ + do \ + { \ + mstate m = GetMSpace((p),(tc),(ms),(s)); \ + action; \ + RELEASE_LOCK(&m->mutex); \ + } while (0) + +static FORCEINLINE mstate GetMSpace(nedpool *p, threadcache *tc, int mymspace, size_t size) THROWSPEC +{ /* Returns a locked and ready for use mspace */ + mstate m=p->m[mymspace]; + assert(m); + if(!TRY_LOCK(&p->m[mymspace]->mutex)) m=FindMSpace(p, tc, &mymspace, size);\ + /*assert(IS_LOCKED(&p->m[mymspace]->mutex));*/ + return m; +} +static FORCEINLINE void GetThreadCache(nedpool **p, threadcache **tc, int *mymspace, size_t *size) THROWSPEC +{ + int mycache; + if(size && *size<sizeof(threadcacheblk)) *size=sizeof(threadcacheblk); + if(!*p) + { + *p=&syspool; + if(!syspool.threads) InitPool(&syspool, 0, -1); + } + mycache=(int)(size_t) TLSGET((*p)->mycache); + if(mycache>0) + { + *tc=(*p)->caches[mycache-1]; + *mymspace=(*tc)->mymspace; + } + else if(!mycache) + { + *tc=AllocCache(*p); + if(!*tc) + { /* Disable */ + if(TLSSET((*p)->mycache, (void *)-1)) abort(); + *mymspace=0; + } + else + *mymspace=(*tc)->mymspace; + } + else + { + *tc=0; + *mymspace=-mycache-1; + } + assert(*mymspace>=0); + assert((long)(size_t)CURRENT_THREAD==(*tc)->threadid); +#ifdef FULLSANITYCHECKS + if(*tc) + { + if(*(unsigned int *)"NEDMALC1"!=(*tc)->magic1 || *(unsigned int *)"NEDMALC2"!=(*tc)->magic2) + { + abort(); + } + } +#endif +} + +void * nedpmalloc(nedpool *p, size_t size) THROWSPEC +{ + void *ret=0; + threadcache *tc; + int mymspace; + GetThreadCache(&p, &tc, &mymspace, &size); +#if THREADCACHEMAX + if(tc && size<=THREADCACHEMAX) + { /* Use the thread cache */ + ret=threadcache_malloc(p, tc, &size); + } +#endif + if(!ret) + { /* Use this thread's mspace */ + GETMSPACE(m, p, tc, mymspace, size, + ret=mspace_malloc(m, size)); + } + return ret; +} +void * nedpcalloc(nedpool *p, size_t no, size_t size) THROWSPEC +{ + size_t rsize=size*no; + void *ret=0; + threadcache *tc; + int mymspace; + GetThreadCache(&p, &tc, &mymspace, &rsize); +#if THREADCACHEMAX + if(tc && rsize<=THREADCACHEMAX) + { /* Use the thread cache */ + if((ret=threadcache_malloc(p, tc, &rsize))) + memset(ret, 0, rsize); + } +#endif + if(!ret) + { /* Use this thread's mspace */ + GETMSPACE(m, p, tc, mymspace, rsize, + ret=mspace_calloc(m, 1, rsize)); + } + return ret; +} +void * nedprealloc(nedpool *p, void *mem, size_t size) THROWSPEC +{ + void *ret=0; + threadcache *tc; + int mymspace; + if(!mem) return nedpmalloc(p, size); + GetThreadCache(&p, &tc, &mymspace, &size); +#if THREADCACHEMAX + if(tc && size && size<=THREADCACHEMAX) + { /* Use the thread cache */ + size_t memsize=nedblksize(mem); + assert(memsize); + if((ret=threadcache_malloc(p, tc, &size))) + { + memcpy(ret, mem, memsize<size ? memsize : size); + if(memsize<=THREADCACHEMAX) + threadcache_free(p, tc, mymspace, mem, memsize); + else + mspace_free(0, mem); + } + } +#endif + if(!ret) + { /* Reallocs always happen in the mspace they happened in, so skip + locking the preferred mspace for this thread */ + ret=mspace_realloc(0, mem, size); + } + return ret; +} +void nedpfree(nedpool *p, void *mem) THROWSPEC +{ /* Frees always happen in the mspace they happened in, so skip + locking the preferred mspace for this thread */ + threadcache *tc; + int mymspace; + size_t memsize; + assert(mem); + GetThreadCache(&p, &tc, &mymspace, 0); +#if THREADCACHEMAX + memsize=nedblksize(mem); + assert(memsize); + if(mem && tc && memsize<=(THREADCACHEMAX+CHUNK_OVERHEAD)) + threadcache_free(p, tc, mymspace, mem, memsize); + else +#endif + mspace_free(0, mem); +} +void * nedpmemalign(nedpool *p, size_t alignment, size_t bytes) THROWSPEC +{ + void *ret; + threadcache *tc; + int mymspace; + GetThreadCache(&p, &tc, &mymspace, &bytes); + { /* Use this thread's mspace */ + GETMSPACE(m, p, tc, mymspace, bytes, + ret=mspace_memalign(m, alignment, bytes)); + } + return ret; +} +#if !NO_MALLINFO +struct mallinfo nedpmallinfo(nedpool *p) THROWSPEC +{ + int n; + struct mallinfo ret={0}; + if(!p) { p=&syspool; if(!syspool.threads) InitPool(&syspool, 0, -1); } + for(n=0; p->m[n]; n++) + { + struct mallinfo t=mspace_mallinfo(p->m[n]); + ret.arena+=t.arena; + ret.ordblks+=t.ordblks; + ret.hblkhd+=t.hblkhd; + ret.usmblks+=t.usmblks; + ret.uordblks+=t.uordblks; + ret.fordblks+=t.fordblks; + ret.keepcost+=t.keepcost; + } + return ret; +} +#endif +int nedpmallopt(nedpool *p, int parno, int value) THROWSPEC +{ + return mspace_mallopt(parno, value); +} +int nedpmalloc_trim(nedpool *p, size_t pad) THROWSPEC +{ + int n, ret=0; + if(!p) { p=&syspool; if(!syspool.threads) InitPool(&syspool, 0, -1); } + for(n=0; p->m[n]; n++) + { + ret+=mspace_trim(p->m[n], pad); + } + return ret; +} +void nedpmalloc_stats(nedpool *p) THROWSPEC +{ + int n; + if(!p) { p=&syspool; if(!syspool.threads) InitPool(&syspool, 0, -1); } + for(n=0; p->m[n]; n++) + { + mspace_malloc_stats(p->m[n]); + } +} +size_t nedpmalloc_footprint(nedpool *p) THROWSPEC +{ + size_t ret=0; + int n; + if(!p) { p=&syspool; if(!syspool.threads) InitPool(&syspool, 0, -1); } + for(n=0; p->m[n]; n++) + { + ret+=mspace_footprint(p->m[n]); + } + return ret; +} +void **nedpindependent_calloc(nedpool *p, size_t elemsno, size_t elemsize, void **chunks) THROWSPEC +{ + void **ret; + threadcache *tc; + int mymspace; + GetThreadCache(&p, &tc, &mymspace, &elemsize); + GETMSPACE(m, p, tc, mymspace, elemsno*elemsize, + ret=mspace_independent_calloc(m, elemsno, elemsize, chunks)); + return ret; +} +void **nedpindependent_comalloc(nedpool *p, size_t elems, size_t *sizes, void **chunks) THROWSPEC +{ + void **ret; + threadcache *tc; + int mymspace; + size_t i, *adjustedsizes=(size_t *) alloca(elems*sizeof(size_t)); + if(!adjustedsizes) return 0; + for(i=0; i<elems; i++) + adjustedsizes[i]=sizes[i]<sizeof(threadcacheblk) ? sizeof(threadcacheblk) : sizes[i]; + GetThreadCache(&p, &tc, &mymspace, 0); + GETMSPACE(m, p, tc, mymspace, 0, + ret=mspace_independent_comalloc(m, elems, adjustedsizes, chunks)); + return ret; +} + +#ifdef OVERRIDE_STRDUP +/* + * This implementation is purely there to override the libc version, to + * avoid a crash due to allocation and free on different 'heaps'. + */ +char *strdup(const char *s1) +{ + char *s2 = 0; + if (s1) { + s2 = malloc(strlen(s1) + 1); + strcpy(s2, s1); + } + return s2; +} +#endif + +#if defined(__cplusplus) +} +#endif diff --git a/compat/nedmalloc/nedmalloc.h b/compat/nedmalloc/nedmalloc.h new file mode 100644 index 0000000000..f960e66063 --- /dev/null +++ b/compat/nedmalloc/nedmalloc.h @@ -0,0 +1,180 @@ +/* nedalloc, an alternative malloc implementation for multiple threads without +lock contention based on dlmalloc v2.8.3. (C) 2005 Niall Douglas + +Boost Software License - Version 1.0 - August 17th, 2003 + +Permission is hereby granted, free of charge, to any person or organization +obtaining a copy of the software and accompanying documentation covered by +this license (the "Software") to use, reproduce, display, distribute, +execute, and transmit the Software, and to prepare derivative works of the +Software, and to permit third-parties to whom the Software is furnished to +do so, all subject to the following: + +The copyright notices in the Software and this entire statement, including +the above license grant, this restriction and the following disclaimer, +must be included in all copies of the Software, in whole or in part, and +all derivative works of the Software, unless such copies or derivative +works are solely in the form of machine-executable object code generated by +a source language processor. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. +*/ + +#ifndef NEDMALLOC_H +#define NEDMALLOC_H + + +/* See malloc.c.h for what each function does. + +REPLACE_SYSTEM_ALLOCATOR causes nedalloc's functions to be called malloc, +free etc. instead of nedmalloc, nedfree etc. You may or may not want this. + +NO_NED_NAMESPACE prevents the functions from being defined in the nedalloc +namespace when in C++ (uses the global namespace instead). + +EXTSPEC can be defined to be __declspec(dllexport) or +__attribute__ ((visibility("default"))) or whatever you like. It defaults +to extern. + +USE_LOCKS can be 2 if you want to define your own MLOCK_T, INITIAL_LOCK, +ACQUIRE_LOCK, RELEASE_LOCK, TRY_LOCK, IS_LOCKED and NULL_LOCK_INITIALIZER. + +*/ + +#include <stddef.h> /* for size_t */ + +#ifndef EXTSPEC + #define EXTSPEC extern +#endif + +#if defined(_MSC_VER) && _MSC_VER>=1400 + #define MALLOCATTR __declspec(restrict) +#endif +#ifdef __GNUC__ + #define MALLOCATTR __attribute__ ((malloc)) +#endif +#ifndef MALLOCATTR + #define MALLOCATTR +#endif + +#ifdef REPLACE_SYSTEM_ALLOCATOR + #define nedmalloc malloc + #define nedcalloc calloc + #define nedrealloc realloc + #define nedfree free + #define nedmemalign memalign + #define nedmallinfo mallinfo + #define nedmallopt mallopt + #define nedmalloc_trim malloc_trim + #define nedmalloc_stats malloc_stats + #define nedmalloc_footprint malloc_footprint + #define nedindependent_calloc independent_calloc + #define nedindependent_comalloc independent_comalloc + #ifdef _MSC_VER + #define nedblksize _msize + #endif +#endif + +#ifndef NO_MALLINFO +#define NO_MALLINFO 0 +#endif + +#if !NO_MALLINFO +struct mallinfo; +#endif + +#if defined(__cplusplus) + #if !defined(NO_NED_NAMESPACE) +namespace nedalloc { + #else +extern "C" { + #endif + #define THROWSPEC throw() +#else + #define THROWSPEC +#endif + +/* These are the global functions */ + +/* Gets the usable size of an allocated block. Note this will always be bigger than what was +asked for due to rounding etc. +*/ +EXTSPEC size_t nedblksize(void *mem) THROWSPEC; + +EXTSPEC void nedsetvalue(void *v) THROWSPEC; + +EXTSPEC MALLOCATTR void * nedmalloc(size_t size) THROWSPEC; +EXTSPEC MALLOCATTR void * nedcalloc(size_t no, size_t size) THROWSPEC; +EXTSPEC MALLOCATTR void * nedrealloc(void *mem, size_t size) THROWSPEC; +EXTSPEC void nedfree(void *mem) THROWSPEC; +EXTSPEC MALLOCATTR void * nedmemalign(size_t alignment, size_t bytes) THROWSPEC; +#if !NO_MALLINFO +EXTSPEC struct mallinfo nedmallinfo(void) THROWSPEC; +#endif +EXTSPEC int nedmallopt(int parno, int value) THROWSPEC; +EXTSPEC int nedmalloc_trim(size_t pad) THROWSPEC; +EXTSPEC void nedmalloc_stats(void) THROWSPEC; +EXTSPEC size_t nedmalloc_footprint(void) THROWSPEC; +EXTSPEC MALLOCATTR void **nedindependent_calloc(size_t elemsno, size_t elemsize, void **chunks) THROWSPEC; +EXTSPEC MALLOCATTR void **nedindependent_comalloc(size_t elems, size_t *sizes, void **chunks) THROWSPEC; + +/* These are the pool functions */ +struct nedpool_t; +typedef struct nedpool_t nedpool; + +/* Creates a memory pool for use with the nedp* functions below. +Capacity is how much to allocate immediately (if you know you'll be allocating a lot +of memory very soon) which you can leave at zero. Threads specifies how many threads +will *normally* be accessing the pool concurrently. Setting this to zero means it +extends on demand, but be careful of this as it can rapidly consume system resources +where bursts of concurrent threads use a pool at once. +*/ +EXTSPEC MALLOCATTR nedpool *nedcreatepool(size_t capacity, int threads) THROWSPEC; + +/* Destroys a memory pool previously created by nedcreatepool(). +*/ +EXTSPEC void neddestroypool(nedpool *p) THROWSPEC; + +/* Sets a value to be associated with a pool. You can retrieve this value by passing +any memory block allocated from that pool. +*/ +EXTSPEC void nedpsetvalue(nedpool *p, void *v) THROWSPEC; +/* Gets a previously set value using nedpsetvalue() or zero if memory is unknown. +Optionally can also retrieve pool. +*/ +EXTSPEC void *nedgetvalue(nedpool **p, void *mem) THROWSPEC; + +/* Disables the thread cache for the calling thread, returning any existing cache +data to the central pool. +*/ +EXTSPEC void neddisablethreadcache(nedpool *p) THROWSPEC; + +EXTSPEC MALLOCATTR void * nedpmalloc(nedpool *p, size_t size) THROWSPEC; +EXTSPEC MALLOCATTR void * nedpcalloc(nedpool *p, size_t no, size_t size) THROWSPEC; +EXTSPEC MALLOCATTR void * nedprealloc(nedpool *p, void *mem, size_t size) THROWSPEC; +EXTSPEC void nedpfree(nedpool *p, void *mem) THROWSPEC; +EXTSPEC MALLOCATTR void * nedpmemalign(nedpool *p, size_t alignment, size_t bytes) THROWSPEC; +#if !NO_MALLINFO +EXTSPEC struct mallinfo nedpmallinfo(nedpool *p) THROWSPEC; +#endif +EXTSPEC int nedpmallopt(nedpool *p, int parno, int value) THROWSPEC; +EXTSPEC int nedpmalloc_trim(nedpool *p, size_t pad) THROWSPEC; +EXTSPEC void nedpmalloc_stats(nedpool *p) THROWSPEC; +EXTSPEC size_t nedpmalloc_footprint(nedpool *p) THROWSPEC; +EXTSPEC MALLOCATTR void **nedpindependent_calloc(nedpool *p, size_t elemsno, size_t elemsize, void **chunks) THROWSPEC; +EXTSPEC MALLOCATTR void **nedpindependent_comalloc(nedpool *p, size_t elems, size_t *sizes, void **chunks) THROWSPEC; + +#if defined(__cplusplus) +} +#endif + +#undef MALLOCATTR +#undef EXTSPEC + +#endif diff --git a/compat/snprintf.c b/compat/snprintf.c index 357e733074..6c0fb056a5 100644 --- a/compat/snprintf.c +++ b/compat/snprintf.c @@ -6,8 +6,12 @@ * number of characters to write without the trailing NUL. */ #ifndef SNPRINTF_SIZE_CORR +#if defined(__MINGW32__) && defined(__GNUC__) && __GNUC__ < 4 +#define SNPRINTF_SIZE_CORR 1 +#else #define SNPRINTF_SIZE_CORR 0 #endif +#endif #undef vsnprintf int git_vsnprintf(char *str, size_t maxsize, const char *format, va_list ap) diff --git a/compat/winansi.c b/compat/winansi.c index 44dc293ad3..9217c24b43 100644 --- a/compat/winansi.c +++ b/compat/winansi.c @@ -80,6 +80,7 @@ static void set_console_attr(void) static void erase_in_line(void) { CONSOLE_SCREEN_BUFFER_INFO sbi; + DWORD dummy; /* Needed for Windows 7 (or Vista) regression */ if (!console) return; @@ -87,7 +88,7 @@ static void erase_in_line(void) GetConsoleScreenBufferInfo(console, &sbi); FillConsoleOutputCharacterA(console, ' ', sbi.dwSize.X - sbi.dwCursorPosition.X, sbi.dwCursorPosition, - NULL); + &dummy); } @@ -62,7 +62,8 @@ static char *parse_value(void) if (comment) continue; if (isspace(c) && !quote) { - space = 1; + if (len) + space++; continue; } if (!quote) { @@ -71,11 +72,8 @@ static char *parse_value(void) continue; } } - if (space) { - if (len) - value[len++] = ' '; - space = 0; - } + for (; space; space--) + value[len++] = ' '; if (c == '\\') { c = get_next_char(); switch (c) { @@ -1174,7 +1172,9 @@ write_err_out: static int section_name_match (const char *buf, const char *name) { int i = 0, j = 0, dot = 0; - for (; buf[i] && buf[i] != ']'; i++) { + if (buf[i] != '[') + return 0; + for (i = 1; buf[i] && buf[i] != ']'; i++) { if (!dot && isspace(buf[i])) { dot = 1; if (name[j++] != '.') @@ -1195,7 +1195,17 @@ static int section_name_match (const char *buf, const char *name) if (buf[i] != name[j++]) break; } - return (buf[i] == ']' && name[j] == 0); + if (buf[i] == ']' && name[j] == 0) { + /* + * We match, now just find the right length offset by + * gobbling up any whitespace after it, as well + */ + i++; + for (; buf[i] && isspace(buf[i]); i++) + ; /* do nothing */ + return i; + } + return 0; } /* if new_name == NULL, the section is removed instead */ @@ -1225,11 +1235,13 @@ int git_config_rename_section(const char *old_name, const char *new_name) while (fgets(buf, sizeof(buf), config_file)) { int i; int length; + char *output = buf; for (i = 0; buf[i] && isspace(buf[i]); i++) ; /* do nothing */ if (buf[i] == '[') { /* it's a section */ - if (section_name_match (&buf[i+1], old_name)) { + int offset = section_name_match(&buf[i], old_name); + if (offset > 0) { ret++; if (new_name == NULL) { remove = 1; @@ -1240,14 +1252,29 @@ int git_config_rename_section(const char *old_name, const char *new_name) ret = write_error(lock->filename); goto out; } - continue; + /* + * We wrote out the new section, with + * a newline, now skip the old + * section's length + */ + output += offset + i; + if (strlen(output) > 0) { + /* + * More content means there's + * a declaration to put on the + * next line; indent with a + * tab + */ + output -= 1; + output[0] = '\t'; + } } remove = 0; } if (remove) continue; - length = strlen(buf); - if (write_in_full(out_fd, buf, length) != length) { + length = strlen(output); + if (write_in_full(out_fd, output, length) != length) { ret = write_error(lock->filename); goto out; } diff --git a/config.mak.in b/config.mak.in index 7cce0c12d5..67b12f73a1 100644 --- a/config.mak.in +++ b/config.mak.in @@ -30,8 +30,11 @@ NEEDS_SSL_WITH_CRYPTO=@NEEDS_SSL_WITH_CRYPTO@ NO_OPENSSL=@NO_OPENSSL@ NO_CURL=@NO_CURL@ NO_EXPAT=@NO_EXPAT@ +NO_LIBGEN_H=@NO_LIBGEN_H@ NEEDS_LIBICONV=@NEEDS_LIBICONV@ NEEDS_SOCKET=@NEEDS_SOCKET@ +NEEDS_RESOLV=@NEEDS_RESOLV@ +NEEDS_LIBGEN=@NEEDS_LIBGEN@ NO_SYS_SELECT_H=@NO_SYS_SELECT_H@ NO_D_INO_IN_DIRENT=@NO_D_INO_IN_DIRENT@ NO_D_TYPE_IN_DIRENT=@NO_D_TYPE_IN_DIRENT@ @@ -46,6 +49,7 @@ NO_STRTOUMAX=@NO_STRTOUMAX@ NO_SETENV=@NO_SETENV@ NO_UNSETENV=@NO_UNSETENV@ NO_MKDTEMP=@NO_MKDTEMP@ +NO_MKSTEMPS=@NO_MKSTEMPS@ NO_ICONV=@NO_ICONV@ OLD_ICONV=@OLD_ICONV@ NO_DEFLATE_BOUND=@NO_DEFLATE_BOUND@ diff --git a/configure.ac b/configure.ac index 25fbe3bb6b..3f1922d0bf 100644 --- a/configure.ac +++ b/configure.ac @@ -342,9 +342,8 @@ GIT_STASH_FLAGS($OPENSSLDIR) AC_CHECK_LIB([crypto], [SHA1_Init], [NEEDS_SSL_WITH_CRYPTO=], [AC_CHECK_LIB([ssl], [SHA1_Init], - [NEEDS_SSL_WITH_CRYPTO=YesPlease - NEEDS_SSL_WITH_CRYPTO=], - [NO_OPENSSL=YesPlease])]) + [NEEDS_SSL_WITH_CRYPTO=YesPlease], + [NEEDS_SSL_WITH_CRYPTO= NO_OPENSSL=YesPlease])]) GIT_UNSTASH_FLAGS($OPENSSLDIR) @@ -475,6 +474,21 @@ AC_CHECK_LIB([c], [socket], AC_SUBST(NEEDS_SOCKET) test -n "$NEEDS_SOCKET" && LIBS="$LIBS -lsocket" +# +# Define NEEDS_RESOLV if linking with -lnsl and/or -lsocket is not enough. +# Notably on Solaris hstrerror resides in libresolv and on Solaris 7 +# inet_ntop and inet_pton additionally reside there. +AC_CHECK_LIB([c], [hstrerror], +[NEEDS_RESOLV=], +[NEEDS_RESOLV=YesPlease]) +AC_SUBST(NEEDS_RESOLV) +test -n "$NEEDS_RESOLV" && LIBS="$LIBS -lresolv" + +AC_CHECK_LIB([c], [basename], +[NEEDS_LIBGEN=], +[NEEDS_LIBGEN=YesPlease]) +AC_SUBST(NEEDS_LIBGEN) +test -n "$NEEDS_LIBGEN" && LIBS="$LIBS -lgen" ## Checks for header files. AC_MSG_NOTICE([CHECKS for header files]) @@ -635,6 +649,12 @@ AC_SUBST(SNPRINTF_RETURNS_BOGUS) ## (in default C library and libraries checked by AC_CHECK_LIB) AC_MSG_NOTICE([CHECKS for library functions]) # +# Define NO_LIBGEN_H if you don't have libgen.h. +AC_CHECK_HEADER([libgen.h], +[NO_LIBGEN_H=], +[NO_LIBGEN_H=YesPlease]) +AC_SUBST(NO_LIBGEN_H) +# # Define NO_STRCASESTR if you don't have strcasestr. GIT_CHECK_FUNC(strcasestr, [NO_STRCASESTR=], @@ -685,6 +705,13 @@ GIT_CHECK_FUNC(mkdtemp, [NO_MKDTEMP=YesPlease]) AC_SUBST(NO_MKDTEMP) # +# Define NO_MKSTEMPS if you don't have mkstemps in the C library. +GIT_CHECK_FUNC(mkstemps, +[NO_MKSTEMPS=], +[NO_MKSTEMPS=YesPlease]) +AC_SUBST(NO_MKSTEMPS) +# +# # Define NO_MMAP if you want to avoid mmap. # # Define NO_ICONV if your libc does not properly support iconv. @@ -464,7 +464,7 @@ static void git_proxy_connect(int fd[2], char *host) #define MAX_CMD_LEN 1024 -char *get_port(char *host) +static char *get_port(char *host) { char *end; char *p = strchr(host, ':'); @@ -605,14 +605,18 @@ struct child_process *git_connect(int fd[2], const char *url_orig, die("command line too long"); conn->in = conn->out = -1; - conn->argv = arg = xcalloc(6, sizeof(*arg)); + conn->argv = arg = xcalloc(7, sizeof(*arg)); if (protocol == PROTO_SSH) { const char *ssh = getenv("GIT_SSH"); + int putty = ssh && strcasestr(ssh, "plink"); if (!ssh) ssh = "ssh"; *arg++ = ssh; + if (putty && !strcasestr(ssh, "tortoiseplink")) + *arg++ = "-batch"; if (port) { - *arg++ = "-p"; + /* P is for PuTTY, p is for OpenSSH */ + *arg++ = putty ? "-P" : "-p"; *arg++ = port; } *arg++ = host; diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index f44152c433..745b5fb78b 100755 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -40,6 +40,14 @@ # with the bash.showDirtyState variable, which defaults to true # once GIT_PS1_SHOWDIRTYSTATE is enabled. # +# You can also see if currently something is stashed, by setting +# GIT_PS1_SHOWSTASHSTATE to a nonempty value. If something is stashed, +# then a '$' will be shown next to the branch name. +# +# If you would like to see if there're untracked files, then you can +# set GIT_PS1_SHOWUNTRACKEDFILES to a nonempty value. If there're +# untracked files, then a '%' will be shown next to the branch name. +# # To submit patches: # # *) Read Documentation/SubmittingPatches @@ -84,26 +92,24 @@ __git_ps1 () if [ -n "$g" ]; then local r local b - if [ -d "$g/rebase-apply" ]; then - if [ -f "$g/rebase-apply/rebasing" ]; then - r="|REBASE" - elif [ -f "$g/rebase-apply/applying" ]; then - r="|AM" - else - r="|AM/REBASE" - fi - b="$(git symbolic-ref HEAD 2>/dev/null)" - elif [ -f "$g/rebase-merge/interactive" ]; then + if [ -f "$g/rebase-merge/interactive" ]; then r="|REBASE-i" b="$(cat "$g/rebase-merge/head-name")" elif [ -d "$g/rebase-merge" ]; then r="|REBASE-m" b="$(cat "$g/rebase-merge/head-name")" else - if [ -f "$g/MERGE_HEAD" ]; then + if [ -d "$g/rebase-apply" ]; then + if [ -f "$g/rebase-apply/rebasing" ]; then + r="|REBASE" + elif [ -f "$g/rebase-apply/applying" ]; then + r="|AM" + else + r="|AM/REBASE" + fi + elif [ -f "$g/MERGE_HEAD" ]; then r="|MERGING" - fi - if [ -f "$g/BISECT_LOG" ]; then + elif [ -f "$g/BISECT_LOG" ]; then r="|BISECTING" fi @@ -129,6 +135,8 @@ __git_ps1 () local w local i + local s + local u local c if [ "true" = "$(git rev-parse --is-inside-git-dir 2>/dev/null)" ]; then @@ -150,15 +158,22 @@ __git_ps1 () fi fi fi - fi + if [ -n "${GIT_PS1_SHOWSTASHSTATE-}" ]; then + git rev-parse --verify refs/stash >/dev/null 2>&1 && s="$" + fi - if [ -n "$b" ]; then - if [ -n "${1-}" ]; then - printf "$1" "$c${b##refs/heads/}$w$i$r" - else - printf " (%s)" "$c${b##refs/heads/}$w$i$r" + if [ -n "${GIT_PS1_SHOWUNTRACKEDFILES-}" ]; then + if [ -n "$(git ls-files --others --exclude-standard)" ]; then + u="%" + fi fi fi + + if [ -n "${1-}" ]; then + printf "$1" "$c${b##refs/heads/}$w$i$s$u$r" + else + printf " (%s)" "$c${b##refs/heads/}$w$i$s$u$r" + fi fi } @@ -923,7 +938,7 @@ _git_diff () } __git_mergetools_common="diffuse ecmerge emerge kdiff3 meld opendiff - tkdiff vimdiff gvimdiff xxdiff + tkdiff vimdiff gvimdiff xxdiff araxis " _git_difftool () @@ -1110,7 +1125,7 @@ _git_ls_tree () __git_log_common_options=" --not --all --branches --tags --remotes - --first-parent --no-merges + --first-parent --merges --no-merges --max-count= --max-age= --since= --after= --min-age= --until= --before= @@ -1161,7 +1176,7 @@ _git_log () $__git_log_shortlog_options $__git_log_gitk_options --root --topo-order --date-order --reverse - --follow + --follow --full-diff --abbrev-commit --abbrev= --relative-date --date= --pretty= --format= --oneline @@ -1295,7 +1310,7 @@ _git_rebase () } __git_send_email_confirm_options="always never auto cc compose" -__git_send_email_suppresscc_options="author self cc ccbody sob cccmd body all" +__git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all" _git_send_email () { @@ -1334,6 +1349,36 @@ _git_send_email () COMPREPLY=() } +__git_config_get_set_variables () +{ + local prevword word config_file= c=$COMP_CWORD + while [ $c -gt 1 ]; do + word="${COMP_WORDS[c]}" + case "$word" in + --global|--system|--file=*) + config_file="$word" + break + ;; + -f|--file) + config_file="$word $prevword" + break + ;; + esac + prevword=$word + c=$((--c)) + done + + git --git-dir="$(__gitdir)" config $config_file --list 2>/dev/null | + while read line + do + case "$line" in + *.*=*) + echo "${line/=*/}" + ;; + esac + done +} + _git_config () { local cur="${COMP_WORDS[COMP_CWORD]}" @@ -1365,7 +1410,8 @@ _git_config () __gitcomp "$(__git_merge_strategies)" return ;; - color.branch|color.diff|color.interactive|color.status|color.ui) + color.branch|color.diff|color.interactive|\ + color.showbranch|color.status|color.ui) __gitcomp "always never auto" return ;; @@ -1400,6 +1446,10 @@ _git_config () __gitcomp "$__git_send_email_suppresscc_options" return ;; + --get|--get-all|--unset|--unset-all) + __gitcomp "$(__git_config_get_set_variables)" + return + ;; *.*) COMPREPLY=() return @@ -1419,7 +1469,7 @@ _git_config () branch.*.*) local pfx="${cur%.*}." cur="${cur##*.}" - __gitcomp "remote merge mergeoptions" "$pfx" "$cur" + __gitcomp "remote merge mergeoptions rebase" "$pfx" "$cur" return ;; branch.*) @@ -1466,7 +1516,7 @@ _git_config () cur="${cur##*.}" __gitcomp " url proxy fetch push mirror skipDefaultUpdate - receivepack uploadpack tagopt + receivepack uploadpack tagopt pushurl " "$pfx" "$cur" return ;; @@ -1484,6 +1534,7 @@ _git_config () ;; esac __gitcomp " + add.ignore-errors alias. apply.whitespace branch.autosetupmerge @@ -1510,6 +1561,7 @@ _git_config () color.interactive.help color.interactive.prompt color.pager + color.showbranch color.status color.status.added color.status.changed @@ -1821,6 +1873,7 @@ _git_show_branch () __gitcomp " --all --remotes --topo-order --current --more= --list --independent --merge-base --no-name + --color --no-color --sha1-name --sparse --topics --reflog " return @@ -1841,10 +1894,10 @@ _git_stash () save,--*) __gitcomp "--keep-index" ;; - apply,--*) + apply,--*|pop,--*) __gitcomp "--index" ;; - show,--*|drop,--*|pop,--*|branch,--*) + show,--*|drop,--*|branch,--*) COMPREPLY=() ;; show,*|apply,*|drop,*|pop,*|branch,*) diff --git a/contrib/hg-to-git/hg-to-git.py b/contrib/hg-to-git/hg-to-git.py index 7b03204ed1..2a6839d81e 100755 --- a/contrib/hg-to-git/hg-to-git.py +++ b/contrib/hg-to-git/hg-to-git.py @@ -20,7 +20,7 @@ """ import os, os.path, sys -import tempfile, popen2, pickle, getopt +import tempfile, pickle, getopt import re # Maps hg version -> git version diff --git a/contrib/hooks/post-receive-email b/contrib/hooks/post-receive-email index 60cbab65d3..2a66063e44 100644..100755 --- a/contrib/hooks/post-receive-email +++ b/contrib/hooks/post-receive-email @@ -44,6 +44,10 @@ # --pretty %s", displaying the commit id, author, date and log # message. To list full patches separated by a blank line, you # could set this to "git show -C %s; echo". +# To list a gitweb/cgit URL *and* a full patch for each change set, use this: +# "t=%s; printf 'http://.../?id=%%s' \$t; echo;echo; git show -C \$t; echo" +# Be careful if "..." contains things that will be expanded by shell "eval" +# or printf. # # Notes # ----- diff --git a/csum-file.c b/csum-file.c index 2ddb12a0b7..4d50cc5ce1 100644 --- a/csum-file.c +++ b/csum-file.c @@ -26,7 +26,7 @@ static void flush(struct sha1file *f, void * buf, unsigned int count) } if (!ret) die("sha1 file '%s' write error. Out of diskspace", f->name); - die("sha1 file '%s' write error (%s)", f->name, strerror(errno)); + die_errno("sha1 file '%s' write error", f->name); } } @@ -55,8 +55,7 @@ int sha1close(struct sha1file *f, unsigned char *result, unsigned int flags) if (flags & CSUM_FSYNC) fsync_or_die(f->fd, f->name); if (close(f->fd)) - die("%s: sha1 file error on close (%s)", - f->name, strerror(errno)); + die_errno("%s: sha1 file error on close", f->name); fd = 0; } else fd = f->fd; @@ -1,6 +1,8 @@ #include "cache.h" #include "pkt-line.h" #include "exec_cmd.h" +#include "run-command.h" +#include "strbuf.h" #include <syslog.h> @@ -343,28 +345,66 @@ static int run_service(char *dir, struct daemon_service *service) return service->fn(); } +static void copy_to_log(int fd) +{ + struct strbuf line = STRBUF_INIT; + FILE *fp; + + fp = fdopen(fd, "r"); + if (fp == NULL) { + logerror("fdopen of error channel failed"); + close(fd); + return; + } + + while (strbuf_getline(&line, fp, '\n') != EOF) { + logerror("%s", line.buf); + strbuf_setlen(&line, 0); + } + + strbuf_release(&line); + fclose(fp); +} + +static int run_service_command(const char **argv) +{ + struct child_process cld; + + memset(&cld, 0, sizeof(cld)); + cld.argv = argv; + cld.git_cmd = 1; + cld.err = -1; + if (start_command(&cld)) + return -1; + + close(0); + close(1); + + copy_to_log(cld.err); + + return finish_command(&cld); +} + static int upload_pack(void) { /* Timeout as string */ char timeout_buf[64]; + const char *argv[] = { "upload-pack", "--strict", timeout_buf, ".", NULL }; snprintf(timeout_buf, sizeof timeout_buf, "--timeout=%u", timeout); - - /* git-upload-pack only ever reads stuff, so this is safe */ - execl_git_cmd("upload-pack", "--strict", timeout_buf, ".", NULL); - return -1; + return run_service_command(argv); } static int upload_archive(void) { - execl_git_cmd("upload-archive", ".", NULL); - return -1; + static const char *argv[] = { "upload-archive", ".", NULL }; + return run_service_command(argv); } static int receive_pack(void) { - execl_git_cmd("receive-pack", ".", NULL); - return -1; + static const char *argv[] = { "receive-pack", ".", NULL }; + return run_service_command(argv); } static struct daemon_service daemon_service[] = { @@ -453,7 +493,7 @@ static void parse_host_arg(char *extra_args, int buflen) memset(&hints, 0, sizeof(hints)); hints.ai_flags = AI_CANONNAME; - gai = getaddrinfo(hostname, 0, &hints, &ai); + gai = getaddrinfo(hostname, NULL, &hints, &ai); if (!gai) { struct sockaddr_in *sin_addr = (void *)ai->ai_addr; @@ -862,7 +902,7 @@ static int service_loop(int socknum, int *socklist) case ECONNABORTED: continue; default: - die("accept returned %s", strerror(errno)); + die_errno("accept returned"); } } handle(incoming, (struct sockaddr *)&ss, sslen); @@ -878,7 +918,7 @@ static void sanitize_stdfds(void) while (fd != -1 && fd < 2) fd = dup(fd); if (fd == -1) - die("open /dev/null or dup failed: %s", strerror(errno)); + die_errno("open /dev/null or dup failed"); if (fd > 2) close(fd); } @@ -889,12 +929,12 @@ static void daemonize(void) case 0: break; case -1: - die("fork failed: %s", strerror(errno)); + die_errno("fork failed"); default: exit(0); } if (setsid() == -1) - die("setsid failed: %s", strerror(errno)); + die_errno("setsid failed"); close(0); close(1); close(2); @@ -905,9 +945,9 @@ static void store_pid(const char *path) { FILE *f = fopen(path, "w"); if (!f) - die("cannot open pid file %s: %s", path, strerror(errno)); + die_errno("cannot open pid file '%s'", path); if (fprintf(f, "%"PRIuMAX"\n", (uintmax_t) getpid()) < 0 || fclose(f) != 0) - die("failed to write pid file %s: %s", path, strerror(errno)); + die_errno("failed to write pid file '%s'", path); } static int serve(char *listen_addr, int listen_port, struct passwd *pass, gid_t gid) @@ -1107,8 +1147,7 @@ int main(int argc, char **argv) socklen_t slen = sizeof(ss); if (!freopen("/dev/null", "w", stderr)) - die("failed to redirect stderr to /dev/null: %s", - strerror(errno)); + die_errno("failed to redirect stderr to /dev/null"); if (getpeername(0, peer, &slen)) peer = NULL; @@ -135,7 +135,7 @@ const char *show_date(unsigned long time, int tz, enum date_mode mode) } /* Give years and months for 5 years or so */ if (diff < 1825) { - unsigned long years = (diff + 183) / 365; + unsigned long years = diff / 365; unsigned long months = (diff % 365 + 15) / 30; int n; n = snprintf(timebuf, sizeof(timebuf), "%lu year%s", diff --git a/decorate.c b/decorate.c index e6fd8a7441..2f8a63e388 100644 --- a/decorate.c +++ b/decorate.c @@ -18,7 +18,7 @@ static void *insert_decoration(struct decoration *n, const struct object *base, { int size = n->size; struct object_decoration *hash = n->hash; - int j = hash_obj(base, size); + unsigned int j = hash_obj(base, size); while (hash[j].base) { if (hash[j].base == base) { @@ -70,7 +70,7 @@ void *add_decoration(struct decoration *n, const struct object *obj, /* Lookup a decoration pointer */ void *lookup_decoration(struct decoration *n, const struct object *obj) { - int j; + unsigned int j; /* nothing to lookup */ if (!n->size) diff --git a/diff-lib.c b/diff-lib.c index 0aba6cda3c..ad2a4cde74 100644 --- a/diff-lib.c +++ b/diff-lib.c @@ -446,6 +446,8 @@ int run_diff_index(struct rev_info *revs, int cached) memset(&opts, 0, sizeof(opts)); opts.head_idx = 1; opts.index_only = cached; + opts.diff_index_cached = (cached && + !DIFF_OPT_TST(&revs->diffopt, FIND_COPIES_HARDER)); opts.merge = 1; opts.fn = oneway_diff; opts.unpack_data = revs; @@ -502,6 +504,7 @@ int do_diff_cache(const unsigned char *tree_sha1, struct diff_options *opt) memset(&opts, 0, sizeof(opts)); opts.head_idx = 1; opts.index_only = 1; + opts.diff_index_cached = !DIFF_OPT_TST(opt, FIND_COPIES_HARDER); opts.merge = 1; opts.fn = oneway_diff; opts.unpack_data = &revs; @@ -839,10 +839,9 @@ static int scale_linear(int it, int width, int max_change) } static void show_name(FILE *file, - const char *prefix, const char *name, int len, - const char *reset, const char *set) + const char *prefix, const char *name, int len) { - fprintf(file, " %s%s%-*s%s |", set, prefix, len, name, reset); + fprintf(file, " %s%-*s |", prefix, len, name); } static void show_graph(FILE *file, char ch, int cnt, const char *set, const char *reset) @@ -956,7 +955,7 @@ static void show_stats(struct diffstat_t *data, struct diff_options *options) } if (data->files[i]->is_binary) { - show_name(options->file, prefix, name, len, reset, set); + show_name(options->file, prefix, name, len); fprintf(options->file, " Bin "); fprintf(options->file, "%s%d%s", del_c, deleted, reset); fprintf(options->file, " -> "); @@ -966,7 +965,7 @@ static void show_stats(struct diffstat_t *data, struct diff_options *options) continue; } else if (data->files[i]->is_unmerged) { - show_name(options->file, prefix, name, len, reset, set); + show_name(options->file, prefix, name, len); fprintf(options->file, " Unmerged\n"); continue; } @@ -988,7 +987,7 @@ static void show_stats(struct diffstat_t *data, struct diff_options *options) add = scale_linear(add, width, max_change); del = scale_linear(del, width, max_change); } - show_name(options->file, prefix, name, len, reset, set); + show_name(options->file, prefix, name, len); fprintf(options->file, "%5d%s", added + deleted, added + deleted ? " " : ""); show_graph(options->file, '+', add, add_c, reset); @@ -996,8 +995,8 @@ static void show_stats(struct diffstat_t *data, struct diff_options *options) fprintf(options->file, "\n"); } fprintf(options->file, - "%s %d files changed, %d insertions(+), %d deletions(-)%s\n", - set, total_files, adds, dels, reset); + " %d files changed, %d insertions(+), %d deletions(-)\n", + total_files, adds, dels); } static void show_shortstats(struct diffstat_t* data, struct diff_options *options) @@ -1604,6 +1603,7 @@ static void builtin_diff(const char *name_a, free(mf1.ptr); if (textconv_two) free(mf2.ptr); + xdiff_clear_find_func(&xecfg); } free_ab_and_return: @@ -1965,23 +1965,33 @@ static void prep_temp_blob(const char *path, struct diff_tempfile *temp, { int fd; struct strbuf buf = STRBUF_INIT; + struct strbuf template = STRBUF_INIT; + char *path_dup = xstrdup(path); + const char *base = basename(path_dup); + + /* Generate "XXXXXX_basename.ext" */ + strbuf_addstr(&template, "XXXXXX_"); + strbuf_addstr(&template, base); - fd = git_mkstemp(temp->tmp_path, PATH_MAX, ".diff_XXXXXX"); + fd = git_mkstemps(temp->tmp_path, PATH_MAX, template.buf, + strlen(base) + 1); if (fd < 0) - die("unable to create temp-file: %s", strerror(errno)); + die_errno("unable to create temp-file"); if (convert_to_working_tree(path, (const char *)blob, (size_t)size, &buf)) { blob = buf.buf; size = buf.len; } if (write_in_full(fd, blob, size) != size) - die("unable to write temp-file"); + die_errno("unable to write temp-file"); close(fd); temp->name = temp->tmp_path; strcpy(temp->hex, sha1_to_hex(sha1)); temp->hex[40] = 0; sprintf(temp->mode, "%06o", mode); strbuf_release(&buf); + strbuf_release(&template); + free(path_dup); } static struct diff_tempfile *prepare_temp_file(const char *name, @@ -2012,21 +2022,18 @@ static struct diff_tempfile *prepare_temp_file(const char *name, if (lstat(name, &st) < 0) { if (errno == ENOENT) goto not_a_valid_file; - die("stat(%s): %s", name, strerror(errno)); + die_errno("stat(%s)", name); } if (S_ISLNK(st.st_mode)) { - int ret; - char buf[PATH_MAX + 1]; /* ought to be SYMLINK_MAX */ - ret = readlink(name, buf, sizeof(buf)); - if (ret < 0) - die("readlink(%s)", name); - if (ret == sizeof(buf)) - die("symlink too long: %s", name); - prep_temp_blob(name, temp, buf, ret, + struct strbuf sb = STRBUF_INIT; + if (strbuf_readlink(&sb, name, st.st_size) < 0) + die_errno("readlink(%s)", name); + prep_temp_blob(name, temp, sb.buf, sb.len, (one->sha1_valid ? one->sha1 : null_sha1), (one->sha1_valid ? one->mode : S_IFLNK)); + strbuf_release(&sb); } else { /* we can borrow from the file in the work tree */ @@ -2213,7 +2220,7 @@ static void diff_fill_sha1_info(struct diff_filespec *one) return; } if (lstat(one->path, &st) < 0) - die("stat %s", one->path); + die_errno("stat '%s'", one->path); if (index_path(one->sha1, one->path, &st, 0)) die("cannot hash %s", one->path); } @@ -14,12 +14,11 @@ struct path_simplify { const char *path; }; -static int read_directory_recursive(struct dir_struct *dir, - const char *path, const char *base, int baselen, +static int read_directory_recursive(struct dir_struct *dir, const char *path, int len, int check_only, const struct path_simplify *simplify); -static int get_dtype(struct dirent *de, const char *path); +static int get_dtype(struct dirent *de, const char *path, int len); -int common_prefix(const char **pathspec) +static int common_prefix(const char **pathspec) { const char *path, *slash, *next; int prefix; @@ -52,6 +51,26 @@ int common_prefix(const char **pathspec) return prefix; } +int fill_directory(struct dir_struct *dir, const char **pathspec) +{ + const char *path; + int len; + + /* + * Calculate common prefix for the pathspec, and + * use that to optimize the directory walk + */ + len = common_prefix(pathspec); + path = ""; + + if (len) + path = xmemdupz(*pathspec, len); + + /* Read the directory and prune it */ + read_directory(dir, path, len, pathspec); + return len; +} + /* * Does 'match' match the given name? * A match is found if @@ -307,7 +326,7 @@ static int excluded_1(const char *pathname, if (x->flags & EXC_FLAG_MUSTBEDIR) { if (*dtype == DT_UNKNOWN) - *dtype = get_dtype(NULL, pathname); + *dtype = get_dtype(NULL, pathname, pathlen); if (*dtype != DT_DIR) continue; } @@ -396,7 +415,7 @@ static struct dir_entry *dir_add_name(struct dir_struct *dir, const char *pathna static struct dir_entry *dir_add_ignored(struct dir_struct *dir, const char *pathname, int len) { - if (cache_name_pos(pathname, len) >= 0) + if (!cache_name_is_other(pathname, len)) return NULL; ALLOC_GROW(dir->ignored, dir->ignored_nr+1, dir->ignored_alloc); @@ -505,7 +524,7 @@ static enum directory_treatment treat_directory(struct dir_struct *dir, /* This is the "show_other_directories" case */ if (!(dir->flags & DIR_HIDE_EMPTY_DIRECTORIES)) return show_directory; - if (!read_directory_recursive(dir, dirname, dirname, len, 1, simplify)) + if (!read_directory_recursive(dir, dirname, len, 1, simplify)) return ignore_directory; return show_directory; } @@ -547,13 +566,54 @@ static int in_pathspec(const char *path, int len, const struct path_simplify *si return 0; } -static int get_dtype(struct dirent *de, const char *path) +static int get_index_dtype(const char *path, int len) +{ + int pos; + struct cache_entry *ce; + + ce = cache_name_exists(path, len, 0); + if (ce) { + if (!ce_uptodate(ce)) + return DT_UNKNOWN; + if (S_ISGITLINK(ce->ce_mode)) + return DT_DIR; + /* + * Nobody actually cares about the + * difference between DT_LNK and DT_REG + */ + return DT_REG; + } + + /* Try to look it up as a directory */ + pos = cache_name_pos(path, len); + if (pos >= 0) + return DT_UNKNOWN; + pos = -pos-1; + while (pos < active_nr) { + ce = active_cache[pos++]; + if (strncmp(ce->name, path, len)) + break; + if (ce->name[len] > '/') + break; + if (ce->name[len] < '/') + continue; + if (!ce_uptodate(ce)) + break; /* continue? */ + return DT_DIR; + } + return DT_UNKNOWN; +} + +static int get_dtype(struct dirent *de, const char *path, int len) { int dtype = de ? DTYPE(de) : DT_UNKNOWN; struct stat st; if (dtype != DT_UNKNOWN) return dtype; + dtype = get_index_dtype(path, len); + if (dtype != DT_UNKNOWN) + return dtype; if (lstat(path, &st)) return dtype; if (S_ISREG(st.st_mode)) @@ -574,15 +634,15 @@ static int get_dtype(struct dirent *de, const char *path) * Also, we ignore the name ".git" (even if it is not a directory). * That likely will not change. */ -static int read_directory_recursive(struct dir_struct *dir, const char *path, const char *base, int baselen, int check_only, const struct path_simplify *simplify) +static int read_directory_recursive(struct dir_struct *dir, const char *base, int baselen, int check_only, const struct path_simplify *simplify) { - DIR *fdir = opendir(*path ? path : "."); + DIR *fdir = opendir(*base ? base : "."); int contents = 0; if (fdir) { struct dirent *de; - char fullname[PATH_MAX + 1]; - memcpy(fullname, base, baselen); + char path[PATH_MAX + 1]; + memcpy(path, base, baselen); while ((de = readdir(fdir)) != NULL) { int len, dtype; @@ -593,17 +653,18 @@ static int read_directory_recursive(struct dir_struct *dir, const char *path, co continue; len = strlen(de->d_name); /* Ignore overly long pathnames! */ - if (len + baselen + 8 > sizeof(fullname)) + if (len + baselen + 8 > sizeof(path)) continue; - memcpy(fullname + baselen, de->d_name, len+1); - if (simplify_away(fullname, baselen + len, simplify)) + memcpy(path + baselen, de->d_name, len+1); + len = baselen + len; + if (simplify_away(path, len, simplify)) continue; dtype = DTYPE(de); - exclude = excluded(dir, fullname, &dtype); + exclude = excluded(dir, path, &dtype); if (exclude && (dir->flags & DIR_COLLECT_IGNORED) - && in_pathspec(fullname, baselen + len, simplify)) - dir_add_ignored(dir, fullname, baselen + len); + && in_pathspec(path, len, simplify)) + dir_add_ignored(dir, path,len); /* * Excluded? If we don't explicitly want to show @@ -613,7 +674,7 @@ static int read_directory_recursive(struct dir_struct *dir, const char *path, co continue; if (dtype == DT_UNKNOWN) - dtype = get_dtype(de, fullname); + dtype = get_dtype(de, path, len); /* * Do we want to see just the ignored files? @@ -630,9 +691,9 @@ static int read_directory_recursive(struct dir_struct *dir, const char *path, co default: continue; case DT_DIR: - memcpy(fullname + baselen + len, "/", 2); + memcpy(path + len, "/", 2); len++; - switch (treat_directory(dir, fullname, baselen + len, simplify)) { + switch (treat_directory(dir, path, len, simplify)) { case show_directory: if (exclude != !!(dir->flags & DIR_SHOW_IGNORED)) @@ -640,7 +701,7 @@ static int read_directory_recursive(struct dir_struct *dir, const char *path, co break; case recurse_into_directory: contents += read_directory_recursive(dir, - fullname, fullname, baselen + len, 0, simplify); + path, len, 0, simplify); continue; case ignore_directory: continue; @@ -654,7 +715,7 @@ static int read_directory_recursive(struct dir_struct *dir, const char *path, co if (check_only) goto exit_early; else - dir_add_name(dir, fullname, baselen + len); + dir_add_name(dir, path, len); } exit_early: closedir(fdir); @@ -717,15 +778,15 @@ static void free_simplify(struct path_simplify *simplify) free(simplify); } -int read_directory(struct dir_struct *dir, const char *path, const char *base, int baselen, const char **pathspec) +int read_directory(struct dir_struct *dir, const char *path, int len, const char **pathspec) { struct path_simplify *simplify; - if (has_symlink_leading_path(path, strlen(path))) + if (has_symlink_leading_path(path, len)) return dir->nr; simplify = create_simplify(pathspec); - read_directory_recursive(dir, path, base, baselen, 0, simplify); + read_directory_recursive(dir, path, len, 0, simplify); free_simplify(simplify); qsort(dir->entries, dir->nr, sizeof(struct dir_entry *), cmp_name); qsort(dir->ignored, dir->ignored_nr, sizeof(struct dir_entry *), cmp_name); @@ -759,7 +820,7 @@ char *get_relative_cwd(char *buffer, int size, const char *dir) if (!dir) return NULL; if (!getcwd(buffer, size)) - die("can't find the current directory: %s", strerror(errno)); + die_errno("can't find the current directory"); if (!is_absolute_path(dir)) dir = make_absolute_path(dir); @@ -800,12 +861,20 @@ int is_empty_dir(const char *path) return ret; } -int remove_dir_recursively(struct strbuf *path, int only_empty) +int remove_dir_recursively(struct strbuf *path, int flag) { - DIR *dir = opendir(path->buf); + DIR *dir; struct dirent *e; int ret = 0, original_len = path->len, len; + int only_empty = (flag & REMOVE_DIR_EMPTY_ONLY); + unsigned char submodule_head[20]; + + if ((flag & REMOVE_DIR_KEEP_NESTED_GIT) && + !resolve_gitlink_ref(path->buf, "HEAD", submodule_head)) + /* Do not descend and nuke a nested git work tree. */ + return 0; + dir = opendir(path->buf); if (!dir) return -1; if (path->buf[original_len - 1] != '/') @@ -61,14 +61,13 @@ struct dir_struct { char basebuf[PATH_MAX]; }; -extern int common_prefix(const char **pathspec); - #define MATCHED_RECURSIVELY 1 #define MATCHED_FNMATCH 2 #define MATCHED_EXACTLY 3 extern int match_pathspec(const char **pathspec, const char *name, int namelen, int prefix, char *seen); -extern int read_directory(struct dir_struct *, const char *path, const char *base, int baselen, const char **pathspec); +extern int fill_directory(struct dir_struct *dir, const char **pathspec); +extern int read_directory(struct dir_struct *, const char *path, int len, const char **pathspec); extern int excluded(struct dir_struct *, const char *, int *); extern void add_excludes_from_file(struct dir_struct *, const char *fname); @@ -89,7 +88,10 @@ static inline int is_dot_or_dotdot(const char *name) extern int is_empty_dir(const char *dir); extern void setup_standard_excludes(struct dir_struct *dir); -extern int remove_dir_recursively(struct strbuf *path, int only_empty); + +#define REMOVE_DIR_EMPTY_ONLY 01 +#define REMOVE_DIR_KEEP_NESTED_GIT 02 +extern int remove_dir_recursively(struct strbuf *path, int flag); /* tries to remove the path with empty directories along it, ignores ENOENT */ extern int remove_path(const char *path); @@ -37,7 +37,7 @@ static void create_directories(const char *path, int path_len, if (errno == EEXIST && state->force && !unlink_or_warn(buf) && !mkdir(buf, 0777)) continue; - die("cannot create directory at %s", buf); + die_errno("cannot create directory at '%s'", buf); } } free(buf); @@ -51,7 +51,7 @@ static void remove_subtree(const char *path) char *name; if (!dir) - die("cannot opendir %s (%s)", path, strerror(errno)); + die_errno("cannot opendir '%s'", path); strcpy(pathbuf, path); name = pathbuf + strlen(path); *name++ = '/'; @@ -61,15 +61,15 @@ static void remove_subtree(const char *path) continue; strcpy(name, de->d_name); if (lstat(pathbuf, &st)) - die("cannot lstat %s (%s)", pathbuf, strerror(errno)); + die_errno("cannot lstat '%s'", pathbuf); if (S_ISDIR(st.st_mode)) remove_subtree(pathbuf); else if (unlink(pathbuf)) - die("cannot unlink %s (%s)", pathbuf, strerror(errno)); + die_errno("cannot unlink '%s'", pathbuf); } closedir(dir); if (rmdir(path)) - die("cannot rmdir %s (%s)", path, strerror(errno)); + die_errno("cannot rmdir '%s'", path); } static int create_file(const char *path, unsigned int mode) @@ -175,6 +175,19 @@ static int write_entry(struct cache_entry *ce, char *path, const struct checkout return 0; } +/* + * This is like 'lstat()', except it refuses to follow symlinks + * in the path. + */ +int check_path(const char *path, int len, struct stat *st) +{ + if (has_symlink_leading_path(path, len)) { + errno = ENOENT; + return -1; + } + return lstat(path, st); +} + int checkout_entry(struct cache_entry *ce, const struct checkout *state, char *topath) { static char path[PATH_MAX + 1]; @@ -188,7 +201,7 @@ int checkout_entry(struct cache_entry *ce, const struct checkout *state, char *t strcpy(path + len, ce->name); len += ce_namelen(ce); - if (!lstat(path, &st)) { + if (!check_path(path, len, &st)) { unsigned changed = ce_match_stat(ce, &st, CE_MATCH_IGNORE_VALID); if (!changed) return 0; diff --git a/environment.c b/environment.c index 801a005ef1..8f5eaa7dd8 100644 --- a/environment.c +++ b/environment.c @@ -42,11 +42,12 @@ enum safe_crlf safe_crlf = SAFE_CRLF_WARN; unsigned whitespace_rule_cfg = WS_DEFAULT_RULE; enum branch_track git_branch_track = BRANCH_TRACK_REMOTE; enum rebase_setup_type autorebase = AUTOREBASE_NEVER; -enum push_default_type push_default = PUSH_DEFAULT_UNSPECIFIED; +enum push_default_type push_default = PUSH_DEFAULT_MATCHING; #ifndef OBJECT_CREATION_MODE #define OBJECT_CREATION_MODE OBJECT_CREATION_USES_HARDLINKS #endif enum object_creation_mode object_creation_mode = OBJECT_CREATION_MODE; +int grafts_replace_parents = 1; /* Parallel index stat data preload? */ int core_preload_index = 0; diff --git a/fast-import.c b/fast-import.c index a2a24588a9..7ef9865aa6 100644 --- a/fast-import.c +++ b/fast-import.c @@ -905,10 +905,10 @@ static char *keep_pack(char *curr_index_name) keep_fd = odb_pack_keep(name, sizeof(name), pack_data->sha1); if (keep_fd < 0) - die("cannot create keep file"); + die_errno("cannot create keep file"); write_or_die(keep_fd, keep_msg, strlen(keep_msg)); if (close(keep_fd)) - die("failed to write keep file"); + die_errno("failed to write keep file"); snprintf(name, sizeof(name), "%s/pack/pack-%s.pack", get_object_directory(), sha1_to_hex(pack_data->sha1)); @@ -2342,7 +2342,7 @@ static void import_marks(const char *input_file) char line[512]; FILE *f = fopen(input_file, "r"); if (!f) - die("cannot read %s: %s", input_file, strerror(errno)); + die_errno("cannot read '%s'", input_file); while (fgets(line, sizeof(line), f)) { uintmax_t mark; char *end; @@ -2448,7 +2448,7 @@ int main(int argc, const char **argv) fclose(pack_edges); pack_edges = fopen(a + 20, "a"); if (!pack_edges) - die("Cannot open %s: %s", a + 20, strerror(errno)); + die_errno("Cannot open '%s'", a + 20); } else if (!strcmp(a, "--force")) force_update = 1; else if (!strcmp(a, "--quiet")) @@ -229,7 +229,7 @@ static int fsck_commit(struct commit *commit, fsck_error error_func) struct commit_graft *graft; int parents = 0; - if (!commit->date) + if (commit->date == ULONG_MAX) return error_func(&commit->object, FSCK_ERROR, "invalid author/committer line"); if (memcmp(buffer, "tree ", 5)) diff --git a/git-add--interactive.perl b/git-add--interactive.perl index df9f231635..06f70602cc 100755 --- a/git-add--interactive.perl +++ b/git-add--interactive.perl @@ -841,6 +841,10 @@ sub coalesce_overlapping_hunks { my ($last_o_ctx, $last_was_dirty); for (grep { $_->{USE} } @in) { + if ($_->{TYPE} ne 'hunk') { + push @out, $_; + next; + } my $text = $_->{TEXT}; my ($o_ofs) = parse_hunk_header($text->[0]); if (defined $last_o_ctx && @@ -11,6 +11,7 @@ git am [options] (--resolved | --skip | --abort) i,interactive run interactively b,binary* (historical option -- no-op) 3,3way allow fall back on 3way merging if needed +q,quiet be quiet s,signoff add a Signed-off-by line to the commit message u,utf8 recode into utf8 (default) k,keep pass -k flag to git-mailinfo @@ -18,6 +19,7 @@ whitespace= pass it through git-apply directory= pass it through git-apply C= pass it through git-apply p= pass it through git-apply +patch-format= format the patch(es) are in reject pass it through git-apply resolvemsg= override error message when patch failure occurs r,resolved to be used after a patch failure @@ -44,11 +46,7 @@ else fi sq () { - for sqarg - do - printf "%s" "$sqarg" | - sed -e 's/'\''/'\''\\'\'''\''/g' -e 's/.*/ '\''&'\''/' - done + git rev-parse --sq-quote "$@" } stop_here () { @@ -103,7 +101,7 @@ fall_back_3way () { git write-tree >"$dotest/patch-merge-base+" || cannot_fallback "Repository lacks necessary blobs to fall back on 3-way merge." - echo Using index info to reconstruct a base tree... + say Using index info to reconstruct a base tree... if GIT_INDEX_FILE="$dotest/patch-merge-tmp-index" \ git apply --cached <"$dotest/patch" then @@ -119,7 +117,7 @@ It does not apply to blobs recorded in its index." orig_tree=$(cat "$dotest/patch-merge-base") && rm -fr "$dotest"/patch-merge-* || exit 1 - echo Falling back to patching base and 3-way merge... + say Falling back to patching base and 3-way merge... # This is not so wrong. Depending on which base we picked, # orig_tree may be wildly different from ours, but his_tree @@ -129,6 +127,10 @@ It does not apply to blobs recorded in its index." eval GITHEAD_$his_tree='"$FIRSTLINE"' export GITHEAD_$his_tree + if test -n "$GIT_QUIET" + then + export GIT_MERGE_VERBOSITY=0 + fi git-merge-recursive $orig_tree -- HEAD $his_tree || { git rerere echo Failed to merge in the changes. @@ -137,6 +139,144 @@ It does not apply to blobs recorded in its index." unset GITHEAD_$his_tree } +clean_abort () { + test $# = 0 || echo >&2 "$@" + rm -fr "$dotest" + exit 1 +} + +patch_format= + +check_patch_format () { + # early return if patch_format was set from the command line + if test -n "$patch_format" + then + return 0 + fi + + # we default to mbox format if input is from stdin and for + # directories + if test $# = 0 || test "x$1" = "x-" || test -d "$1" + then + patch_format=mbox + return 0 + fi + + # otherwise, check the first few lines of the first patch to try + # to detect its format + { + read l1 + read l2 + read l3 + case "$l1" in + "From "* | "From: "*) + patch_format=mbox + ;; + '# This series applies on GIT commit'*) + patch_format=stgit-series + ;; + "# HG changeset patch") + patch_format=hg + ;; + *) + # if the second line is empty and the third is + # a From, Author or Date entry, this is very + # likely an StGIT patch + case "$l2,$l3" in + ,"From: "* | ,"Author: "* | ,"Date: "*) + patch_format=stgit + ;; + *) + ;; + esac + ;; + esac + if test -z "$patch_format" && + test -n "$l1" && + test -n "$l2" && + test -n "$l3" + then + # This begins with three non-empty lines. Is this a + # piece of e-mail a-la RFC2822? Grab all the headers, + # discarding the indented remainder of folded lines, + # and see if it looks like that they all begin with the + # header field names... + sed -n -e '/^$/q' -e '/^[ ]/d' -e p "$1" | + egrep -v '^[A-Za-z]+(-[A-Za-z]+)*:' >/dev/null || + patch_format=mbox + fi + } < "$1" || clean_abort +} + +split_patches () { + case "$patch_format" in + mbox) + git mailsplit -d"$prec" -o"$dotest" -b -- "$@" > "$dotest/last" || + clean_abort + ;; + stgit-series) + if test $# -ne 1 + then + clean_abort "Only one StGIT patch series can be applied at once" + fi + series_dir=`dirname "$1"` + series_file="$1" + shift + { + set x + while read filename + do + set "$@" "$series_dir/$filename" + done + # remove the safety x + shift + # remove the arg coming from the first-line comment + shift + } < "$series_file" || clean_abort + # set the patch format appropriately + patch_format=stgit + # now handle the actual StGIT patches + split_patches "$@" + ;; + stgit) + this=0 + for stgit in "$@" + do + this=`expr "$this" + 1` + msgnum=`printf "%0${prec}d" $this` + # Perl version of StGIT parse_patch. The first nonemptyline + # not starting with Author, From or Date is the + # subject, and the body starts with the next nonempty + # line not starting with Author, From or Date + perl -ne 'BEGIN { $subject = 0 } + if ($subject > 1) { print ; } + elsif (/^\s+$/) { next ; } + elsif (/^Author:/) { print s/Author/From/ ; } + elsif (/^(From|Date)/) { print ; } + elsif ($subject) { + $subject = 2 ; + print "\n" ; + print ; + } else { + print "Subject: ", $_ ; + $subject = 1; + } + ' < "$stgit" > "$dotest/$msgnum" || clean_abort + done + echo "$this" > "$dotest/last" + this= + msgnum= + ;; + *) + if test -n "$parse_patch" ; then + clean_abort "Patch format $patch_format is not supported." + else + clean_abort "Patch format detection failed." + fi + ;; + esac +} + prec=4 dotest="$GIT_DIR/rebase-apply" sign= utf8=t keep= skip= interactive= resolved= rebasing= abort= @@ -179,12 +319,16 @@ do git_apply_opt="$git_apply_opt $(sq "$1=$2")"; shift ;; -C|-p) git_apply_opt="$git_apply_opt $(sq "$1$2")"; shift ;; + --patch-format) + shift ; patch_format="$1" ;; --reject) git_apply_opt="$git_apply_opt $1" ;; --committer-date-is-author-date) committer_date_is_author_date=t ;; --ignore-date) ignore_date=t ;; + -q|--quiet) + GIT_QUIET=t ;; --) shift; break ;; *) @@ -278,12 +422,12 @@ else done shift fi - git mailsplit -d"$prec" -o"$dotest" -b -- "$@" > "$dotest/last" || { - rm -fr "$dotest" - exit 1 - } - # -s, -u, -k, --whitespace, -3, -C and -p flags are kept + check_patch_format "$@" + + split_patches "$@" + + # -s, -u, -k, --whitespace, -3, -C, -q and -p flags are kept # for the resuming session after a patch failure. # -i can and must be given when resuming. echo " $git_apply_opt" >"$dotest/apply-opt" @@ -291,6 +435,7 @@ else echo "$sign" >"$dotest/sign" echo "$utf8" >"$dotest/utf8" echo "$keep" >"$dotest/keep" + echo "$GIT_QUIET" >"$dotest/quiet" echo 1 >"$dotest/next" if test -n "$rebasing" then @@ -331,6 +476,10 @@ if test "$(cat "$dotest/keep")" = t then keep=-k fi +if test "$(cat "$dotest/quiet")" = t +then + GIT_QUIET=t +fi if test "$(cat "$dotest/threeway")" = t then threeway=t @@ -356,7 +505,7 @@ fi if test "$this" -gt "$last" then - echo Nothing to do. + say Nothing to do. rm -fr "$dotest" exit fi @@ -502,11 +651,18 @@ do stop_here $this fi - printf 'Applying: %s\n' "$FIRSTLINE" + say "Applying: $FIRSTLINE" case "$resolved" in '') - eval 'git apply '"$git_apply_opt"' --index "$dotest/patch"' + # When we are allowed to fall back to 3-way later, don't give + # false errors during the initial attempt. + squelch= + if test "$threeway" = t + then + squelch='>/dev/null 2>&1 ' + fi + eval "git apply $squelch$git_apply_opt"' --index "$dotest/patch"' apply_status=$? ;; t) @@ -538,7 +694,7 @@ do # Applying the patch to an earlier tree and merging the # result may have produced the same tree as ours. git diff-index --quiet --cached HEAD -- && { - echo No changes -- Patch already applied. + say No changes -- Patch already applied. go_next continue } @@ -564,7 +720,7 @@ do GIT_AUTHOR_DATE= fi parent=$(git rev-parse --verify -q HEAD) || - echo >&2 "applying to an empty history" + say >&2 "applying to an empty history" if test -n "$committer_date_is_author_date" then diff --git a/git-bisect.sh b/git-bisect.sh index 24712ff304..6f6f03966f 100755 --- a/git-bisect.sh +++ b/git-bisect.sh @@ -33,16 +33,6 @@ require_work_tree _x40='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]' _x40="$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40" -sq() { - @@PERL@@ -e ' - for (@ARGV) { - s/'\''/'\'\\\\\'\''/g; - print " '\''$_'\''"; - } - print "\n"; - ' "$@" -} - bisect_autostart() { test -s "$GIT_DIR/BISECT_START" || { echo >&2 'You need to start by "git bisect start"' @@ -107,7 +97,7 @@ bisect_start() { for arg; do case "$arg" in --) has_double_dash=1; break ;; esac done - orig_args=$(sq "$@") + orig_args=$(git rev-parse --sq-quote "$@") bad_seen=0 eval='' while [ $# -gt 0 ]; do @@ -147,7 +137,7 @@ bisect_start() { # Write new start state. # echo "$start_head" >"$GIT_DIR/BISECT_START" && - sq "$@" >"$GIT_DIR/BISECT_NAMES" && + git rev-parse --sq-quote "$@" >"$GIT_DIR/BISECT_NAMES" && eval "$eval" && echo "git bisect start$orig_args" >>"$GIT_DIR/BISECT_LOG" || exit # @@ -177,10 +167,6 @@ is_expected_rev() { test "$1" = $(cat "$GIT_DIR/BISECT_EXPECTED_REV") } -mark_expected_rev() { - echo "$1" > "$GIT_DIR/BISECT_EXPECTED_REV" -} - check_expected_revs() { for _rev in "$@"; do if ! is_expected_rev "$_rev"; then @@ -199,7 +185,7 @@ bisect_skip() { *..*) revs=$(git rev-list "$arg") || die "Bad rev input: $arg" ;; *) - revs=$(sq "$arg") ;; + revs=$(git rev-parse --sq-quote "$arg") ;; esac all="$all $revs" done @@ -279,162 +265,22 @@ bisect_auto_next() { bisect_next_check && bisect_next || : } -exit_if_skipped_commits () { - _tried=$1 - _bad=$2 - if test -n "$_tried" ; then - echo "There are only 'skip'ped commit left to test." - echo "The first bad commit could be any of:" - echo "$_tried" | tr '[|]' '[\012]' - test -n "$_bad" && echo "$_bad" - echo "We cannot bisect more!" - exit 2 - fi -} - -bisect_checkout() { - _rev="$1" - _msg="$2" - echo "Bisecting: $_msg" - mark_expected_rev "$_rev" - git checkout -q "$_rev" -- || exit - git show-branch "$_rev" -} - -is_among() { - _rev="$1" - _list="$2" - case "$_list" in *$_rev*) return 0 ;; esac - return 1 -} - -handle_bad_merge_base() { - _badmb="$1" - _good="$2" - if is_expected_rev "$_badmb"; then - cat >&2 <<EOF -The merge base $_badmb is bad. -This means the bug has been fixed between $_badmb and [$_good]. -EOF - exit 3 - else - cat >&2 <<EOF -Some good revs are not ancestor of the bad rev. -git bisect cannot work properly in this case. -Maybe you mistake good and bad revs? -EOF - exit 1 - fi -} - -handle_skipped_merge_base() { - _mb="$1" - _bad="$2" - _good="$3" - cat >&2 <<EOF -Warning: the merge base between $_bad and [$_good] must be skipped. -So we cannot be sure the first bad commit is between $_mb and $_bad. -We continue anyway. -EOF -} - -# -# "check_merge_bases" checks that merge bases are not "bad". -# -# - If one is "good", that's good, we have nothing to do. -# - If one is "bad", it means the user assumed something wrong -# and we must exit. -# - If one is "skipped", we can't know but we should warn. -# - If we don't know, we should check it out and ask the user to test. -# -# In the last case we will return 1, and otherwise 0. -# -check_merge_bases() { - _bad="$1" - _good="$2" - _skip="$3" - for _mb in $(git merge-base --all $_bad $_good) - do - if is_among "$_mb" "$_good"; then - continue - elif test "$_mb" = "$_bad"; then - handle_bad_merge_base "$_bad" "$_good" - elif is_among "$_mb" "$_skip"; then - handle_skipped_merge_base "$_mb" "$_bad" "$_good" - else - bisect_checkout "$_mb" "a merge base must be tested" - return 1 - fi - done - return 0 -} - -# -# "check_good_are_ancestors_of_bad" checks that all "good" revs are -# ancestor of the "bad" rev. -# -# If that's not the case, we need to check the merge bases. -# If a merge base must be tested by the user we return 1 and -# otherwise 0. -# -check_good_are_ancestors_of_bad() { - test -f "$GIT_DIR/BISECT_ANCESTORS_OK" && - return - - _bad="$1" - _good=$(echo $2 | sed -e 's/\^//g') - _skip="$3" - - # Bisecting with no good rev is ok - test -z "$_good" && return - - _side=$(git rev-list $_good ^$_bad) - if test -n "$_side"; then - # Return if a checkout was done - check_merge_bases "$_bad" "$_good" "$_skip" || return - fi - - : > "$GIT_DIR/BISECT_ANCESTORS_OK" - - return 0 -} - bisect_next() { case "$#" in 0) ;; *) usage ;; esac bisect_autostart bisect_next_check good - # Get bad, good and skipped revs - bad=$(git rev-parse --verify refs/bisect/bad) && - good=$(git for-each-ref --format='^%(objectname)' \ - "refs/bisect/good-*" | tr '\012' ' ') && - skip=$(git for-each-ref --format='%(objectname)' \ - "refs/bisect/skip-*" | tr '\012' ' ') || exit - - # Maybe some merge bases must be tested first - check_good_are_ancestors_of_bad "$bad" "$good" "$skip" - # Return now if a checkout has already been done - test "$?" -eq "1" && return - - # Get bisection information - eval=$(eval "git bisect--helper --next-vars") && - eval "$eval" || exit - - if [ -z "$bisect_rev" ]; then - # We should exit here only if the "bad" - # commit is also a "skip" commit (see above). - exit_if_skipped_commits "$bisect_tried" - echo "$bad was both good and bad" - exit 1 - fi - if [ "$bisect_rev" = "$bad" ]; then - exit_if_skipped_commits "$bisect_tried" "$bad" - echo "$bisect_rev is first bad commit" - git diff-tree --pretty $bisect_rev - exit 0 - fi + # Perform all bisection computation, display and checkout + git bisect--helper --next-all + res=$? + + # Check if we should exit because bisection is finished + test $res -eq 10 && exit 0 - bisect_checkout "$bisect_rev" "$bisect_nr revisions left to test after this (roughly $bisect_steps steps)" + # Check for an error in the bisection process + test $res -ne 0 && exit $res + + return 0 } bisect_visualize() { @@ -559,7 +405,7 @@ bisect_run () { exit $res fi - if grep "is first bad commit" "$GIT_DIR/BISECT_RUN" > /dev/null; then + if grep "is the first bad commit" "$GIT_DIR/BISECT_RUN" > /dev/null; then echo "bisect run success" exit 0; fi diff --git a/git-compat-util.h b/git-compat-util.h index c7cf2d5d9c..9f941e42b1 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -7,7 +7,7 @@ /* * See if our compiler is known to support flexible array members. */ -#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) +#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && (!defined(__SUNPRO_C) || (__SUNPRO_C > 0x580)) # define FLEX_ARRAY /* empty */ #elif defined(__GNUC__) # if (__GNUC__ >= 3) @@ -26,6 +26,7 @@ #endif #define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0])) +#define bitsizeof(x) (CHAR_BIT * sizeof(x)) #ifdef __GNUC__ #define TYPEOF(x) (__typeof__(x)) @@ -33,20 +34,38 @@ #define TYPEOF(x) #endif -#define MSB(x, bits) ((x) & TYPEOF(x)(~0ULL << (sizeof(x) * 8 - (bits)))) +#define MSB(x, bits) ((x) & TYPEOF(x)(~0ULL << (bitsizeof(x) - (bits)))) #define HAS_MULTI_BITS(i) ((i) & ((i) - 1)) /* checks if an integer has more than 1 bit set */ +#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d)) + /* Approximation of the length of the decimal representation of this type. */ #define decimal_length(x) ((int)(sizeof(x) * 2.56 + 0.5) + 1) -#if !defined(__APPLE__) && !defined(__FreeBSD__) && !defined(__USLC__) && !defined(_M_UNIX) +#if defined(__sun__) + /* + * On Solaris, when _XOPEN_EXTENDED is set, its header file + * forces the programs to be XPG4v2, defeating any _XOPEN_SOURCE + * setting to say we are XPG5 or XPG6. Also on Solaris, + * XPG6 programs must be compiled with a c99 compiler, while + * non XPG6 programs must be compiled with a pre-c99 compiler. + */ +# if __STDC_VERSION__ - 0 >= 199901L +# define _XOPEN_SOURCE 600 +# else +# define _XOPEN_SOURCE 500 +# endif +#elif !defined(__APPLE__) && !defined(__FreeBSD__) && !defined(__USLC__) && !defined(_M_UNIX) && !defined(sgi) #define _XOPEN_SOURCE 600 /* glibc2 and AIX 5.3L need 500, OpenBSD needs 600 for S_ISLNK() */ +#ifndef __sun__ #define _XOPEN_SOURCE_EXTENDED 1 /* AIX 5.3L needs this */ #endif +#endif #define _ALL_SOURCE 1 #define _GNU_SOURCE 1 #define _BSD_SOURCE 1 #define _NETBSD_SOURCE 1 +#define _SGI_SOURCE 1 #include <unistd.h> #include <stdio.h> @@ -97,6 +116,13 @@ #include "compat/mingw.h" #endif /* __MINGW32__ */ +#ifndef NO_LIBGEN_H +#include <libgen.h> +#else +#define basename gitbasename +extern char *gitbasename(char *); +#endif + #ifndef NO_ICONV #include <iconv.h> #endif @@ -153,6 +179,7 @@ /* General helper functions */ extern void usage(const char *err) NORETURN; extern void die(const char *err, ...) NORETURN __attribute__((format (printf, 1, 2))); +extern void die_errno(const char *err, ...) NORETURN __attribute__((format (printf, 1, 2))); extern int error(const char *err, ...) __attribute__((format (printf, 1, 2))); extern void warning(const char *err, ...) __attribute__((format (printf, 1, 2))); @@ -232,6 +259,11 @@ extern int gitsetenv(const char *, const char *, int); extern char *gitmkdtemp(char *); #endif +#ifdef NO_MKSTEMPS +#define mkstemps gitmkstemps +extern int gitmkstemps(char *, int); +#endif + #ifdef NO_UNSETENV #define unsetenv gitunsetenv extern void gitunsetenv(const char *); diff --git a/git-cvsexportcommit.perl b/git-cvsexportcommit.perl index 6d9f0ef0f9..59b672213b 100755 --- a/git-cvsexportcommit.perl +++ b/git-cvsexportcommit.perl @@ -8,9 +8,9 @@ use File::Basename qw(basename dirname); use File::Spec; use Git; -our ($opt_h, $opt_P, $opt_p, $opt_v, $opt_c, $opt_f, $opt_a, $opt_m, $opt_d, $opt_u, $opt_w, $opt_W); +our ($opt_h, $opt_P, $opt_p, $opt_v, $opt_c, $opt_f, $opt_a, $opt_m, $opt_d, $opt_u, $opt_w, $opt_W, $opt_k); -getopts('uhPpvcfam:d:w:W'); +getopts('uhPpvcfkam:d:w:W'); $opt_h && usage(); @@ -225,7 +225,14 @@ if (@canstatusfiles) { foreach my $name (keys %todo) { my $basename = basename($name); - $basename = "no file " . $basename if (exists($added{$basename})); + # CVS reports files that don't exist in the current revision as + # "no file $basename" in its "status" output, so we should + # anticipate that. Totally unknown files will have a status + # "Unknown". However, if they exist in the Attic, their status + # will be "Up-to-date" (this means they were added once but have + # been removed). + $basename = "no file $basename" if $added{$basename}; + $basename =~ s/^\s+//; $basename =~ s/\s+$//; @@ -233,31 +240,46 @@ if (@canstatusfiles) { $fullname{$basename} = $name; push (@canstatusfiles2, $name); delete($todo{$name}); - } + } } my @cvsoutput; @cvsoutput = xargs_safe_pipe_capture([@cvs, 'status'], @canstatusfiles2); foreach my $l (@cvsoutput) { - chomp $l; - if ($l =~ /^File:\s+(.*\S)\s+Status: (.*)$/) { - if (!exists($fullname{$1})) { - print STDERR "Huh? Status reported for unexpected file '$1'\n"; - } else { - $cvsstat{$fullname{$1}} = $2; - } - } + chomp $l; + next unless + my ($file, $status) = $l =~ /^File:\s+(.*\S)\s+Status: (.*)$/; + + my $fullname = $fullname{$file}; + print STDERR "Huh? Status '$status' reported for unexpected file '$file'\n" + unless defined $fullname; + + # This response means the file does not exist except in + # CVS's attic, so set the status accordingly + $status = "In-attic" + if $file =~ /^no file / + && $status eq 'Up-to-date'; + + $cvsstat{$fullname{$file}} = $status + if defined $fullname{$file}; } } } -# ... validate new files, +# ... Validate that new files have the correct status foreach my $f (@afiles) { - if (defined ($cvsstat{$f}) and $cvsstat{$f} ne "Unknown") { - $dirty = 1; + next unless defined(my $stat = $cvsstat{$f}); + + # This means the file has never been seen before + next if $stat eq 'Unknown'; + + # This means the file has been seen before but was removed + next if $stat eq 'In-attic'; + + $dirty = 1; warn "File $f is already known in your CVS checkout -- perhaps it has been added by another user. Or this may indicate that it exists on a different branch. If this is the case, use -f to force the merge.\n"; warn "Status was: $cvsstat{$f}\n"; - } } + # ... validate known files. foreach my $f (@files) { next if grep { $_ eq $f } @afiles; @@ -266,7 +288,26 @@ foreach my $f (@files) { $dirty = 1; warn "File $f not up to date but has status '$cvsstat{$f}' in your CVS checkout!\n"; } + + # Depending on how your GIT tree got imported from CVS you may + # have a conflict between expanded keywords in your CVS tree and + # unexpanded keywords in the patch about to be applied. + if ($opt_k) { + my $orig_file ="$f.orig"; + rename $f, $orig_file; + open(FILTER_IN, "<$orig_file") or die "Cannot open $orig_file\n"; + open(FILTER_OUT, ">$f") or die "Cannot open $f\n"; + while (<FILTER_IN>) + { + my $line = $_; + $line =~ s/\$([A-Z][a-z]+):[^\$]+\$/\$$1\$/g; + print FILTER_OUT $line; + } + close FILTER_IN; + close FILTER_OUT; + } } + if ($dirty) { if ($opt_f) { warn "The tree is not clean -- forced merge\n"; $dirty = 0; @@ -370,7 +411,7 @@ sleep(1); sub usage { print STDERR <<END; -Usage: GIT_DIR=/path/to/.git git cvsexportcommit [-h] [-p] [-v] [-c] [-f] [-u] [-w cvsworkdir] [-m msgprefix] [ parent ] commit +Usage: GIT_DIR=/path/to/.git git cvsexportcommit [-h] [-p] [-v] [-c] [-f] [-u] [-k] [-w cvsworkdir] [-m msgprefix] [ parent ] commit END exit(1); } diff --git a/git-cvsserver.perl b/git-cvsserver.perl index ab6cea3e53..6dc45f5d45 100755 --- a/git-cvsserver.perl +++ b/git-cvsserver.perl @@ -285,7 +285,7 @@ sub req_Root return 0; } - my @gitvars = `git-config -l`; + my @gitvars = `git config -l`; if ($?) { print "E problems executing git-config on the server -- this is not a git repository or the PATH is not set correctly.\n"; print "E \n"; @@ -702,7 +702,7 @@ sub req_Modified # Save the file data in $state $state->{entries}{$state->{directory}.$data}{modified_filename} = $filename; $state->{entries}{$state->{directory}.$data}{modified_mode} = $mode; - $state->{entries}{$state->{directory}.$data}{modified_hash} = `git-hash-object $filename`; + $state->{entries}{$state->{directory}.$data}{modified_hash} = `git hash-object $filename`; $state->{entries}{$state->{directory}.$data}{modified_hash} =~ s/\s.*$//s; #$log->debug("req_Modified : file=$data mode=$mode size=$size"); @@ -1289,7 +1289,7 @@ sub req_ci # do a checkout of the file if it is part of this tree if ($wrev) { - system('git-checkout-index', '-f', '-u', $filename); + system('git', 'checkout-index', '-f', '-u', $filename); unless ($? == 0) { die "Error running git-checkout-index -f -u $filename : $!"; } @@ -1331,15 +1331,15 @@ sub req_ci { $log->info("Removing file '$filename'"); unlink($filename); - system("git-update-index", "--remove", $filename); + system("git", "update-index", "--remove", $filename); } elsif ( $addflag ) { $log->info("Adding file '$filename'"); - system("git-update-index", "--add", $filename); + system("git", "update-index", "--add", $filename); } else { $log->info("Updating file '$filename'"); - system("git-update-index", $filename); + system("git", "update-index", $filename); } } @@ -1351,7 +1351,7 @@ sub req_ci return; } - my $treehash = `git-write-tree`; + my $treehash = `git write-tree`; chomp $treehash; $log->debug("Treehash : $treehash, Parenthash : $parenthash"); @@ -1368,7 +1368,7 @@ sub req_ci } close $msg_fh; - my $commithash = `git-commit-tree $treehash -p $parenthash < $msg_filename`; + my $commithash = `git commit-tree $treehash -p $parenthash < $msg_filename`; chomp($commithash); $log->info("Commit hash : $commithash"); @@ -1821,7 +1821,7 @@ sub req_annotate # TODO: if we got a revision from the client, use that instead # to look up the commithash in sqlite (still good to default to # the current head as we do now) - system("git-read-tree", $lastseenin); + system("git", "read-tree", $lastseenin); unless ($? == 0) { print "E error running git-read-tree $lastseenin $ENV{GIT_INDEX_FILE} $!\n"; @@ -1830,7 +1830,7 @@ sub req_annotate $log->info("Created index '$ENV{GIT_INDEX_FILE}' with commit $lastseenin - exit status $?"); # do a checkout of the file - system('git-checkout-index', '-f', '-u', $filename); + system('git', 'checkout-index', '-f', '-u', $filename); unless ($? == 0) { print "E error running git-checkout-index -f -u $filename : $!\n"; return; @@ -1861,7 +1861,7 @@ sub req_annotate close ANNOTATEHINTS or (print "E failed to write $a_hints: $!\n"), return; - my @cmd = (qw(git-annotate -l -S), $a_hints, $filename); + my @cmd = (qw(git annotate -l -S), $a_hints, $filename); if (!open(ANNOTATE, "-|", @cmd)) { print "E error invoking ". join(' ',@cmd) .": $!\n"; return; @@ -2078,17 +2078,17 @@ sub transmitfile die "Need filehash" unless ( defined ( $filehash ) and $filehash =~ /^[a-zA-Z0-9]{40}$/ ); - my $type = `git-cat-file -t $filehash`; + my $type = `git cat-file -t $filehash`; chomp $type; die ( "Invalid type '$type' (expected 'blob')" ) unless ( defined ( $type ) and $type eq "blob" ); - my $size = `git-cat-file -s $filehash`; + my $size = `git cat-file -s $filehash`; chomp $size; $log->debug("transmitfile($filehash) size=$size, type=$type"); - if ( open my $fh, '-|', "git-cat-file", "blob", $filehash ) + if ( open my $fh, '-|', "git", "cat-file", "blob", $filehash ) { if ( defined ( $options->{targetfile} ) ) { @@ -2935,7 +2935,7 @@ sub update push @git_log_params, $self->{module}; } # git-rev-list is the backend / plumbing version of git-log - open(GITLOG, '-|', 'git-rev-list', @git_log_params) or die "Cannot call git-rev-list: $!"; + open(GITLOG, '-|', 'git', 'rev-list', @git_log_params) or die "Cannot call git-rev-list: $!"; my @commits; @@ -3021,7 +3021,7 @@ sub update next; } my $base = eval { - safe_pipe_capture('git-merge-base', + safe_pipe_capture('git', 'merge-base', $lastpicked, $parent); }; # The two branches may not be related at all, @@ -3033,7 +3033,7 @@ sub update if ($base) { my @merged; # print "want to log between $base $parent \n"; - open(GITLOG, '-|', 'git-log', '--pretty=medium', "$base..$parent") + open(GITLOG, '-|', 'git', 'log', '--pretty=medium', "$base..$parent") or die "Cannot call git-log: $!"; my $mergedhash; while (<GITLOG>) { @@ -3075,7 +3075,7 @@ sub update if ( defined ( $lastpicked ) ) { - my $filepipe = open(FILELIST, '-|', 'git-diff-tree', '-z', '-r', $lastpicked, $commit->{hash}) or die("Cannot call git-diff-tree : $!"); + my $filepipe = open(FILELIST, '-|', 'git', 'diff-tree', '-z', '-r', $lastpicked, $commit->{hash}) or die("Cannot call git-diff-tree : $!"); local ($/) = "\0"; while ( <FILELIST> ) { @@ -3149,7 +3149,7 @@ sub update # this is used to detect files removed from the repo my $seen_files = {}; - my $filepipe = open(FILELIST, '-|', 'git-ls-tree', '-z', '-r', $commit->{hash}) or die("Cannot call git-ls-tree : $!"); + my $filepipe = open(FILELIST, '-|', 'git', 'ls-tree', '-z', '-r', $commit->{hash}) or die("Cannot call git-ls-tree : $!"); local $/ = "\0"; while ( <FILELIST> ) { @@ -3451,7 +3451,7 @@ sub commitmessage return $message; } - my @lines = safe_pipe_capture("git-cat-file", "commit", $commithash); + my @lines = safe_pipe_capture("git", "cat-file", "commit", $commithash); shift @lines while ( $lines[0] =~ /\S/ ); $message = join("",@lines); $message .= " " if ( $message =~ /\n$/ ); diff --git a/git-filter-branch.sh b/git-filter-branch.sh index 37e044db40..a480d6fc70 100755 --- a/git-filter-branch.sh +++ b/git-filter-branch.sh @@ -97,12 +97,12 @@ set_ident () { echo "case \"\$GIT_${uid}_NAME\" in \"\") GIT_${uid}_NAME=\"\${GIT_${uid}_EMAIL%%@*}\" && export GIT_${uid}_NAME;; esac" } -USAGE="[--env-filter <command>] [--tree-filter <command>] \ -[--index-filter <command>] [--parent-filter <command>] \ -[--msg-filter <command>] [--commit-filter <command>] \ -[--tag-name-filter <command>] [--subdirectory-filter <directory>] \ -[--original <namespace>] [-d <directory>] [-f | --force] \ -[<rev-list options>...]" +USAGE="[--env-filter <command>] [--tree-filter <command>] + [--index-filter <command>] [--parent-filter <command>] + [--msg-filter <command>] [--commit-filter <command>] + [--tag-name-filter <command>] [--subdirectory-filter <directory>] + [--original <namespace>] [-d <directory>] [-f | --force] + [<rev-list options>...]" OPTIONS_SPEC= . git-sh-setup diff --git a/git-instaweb.sh b/git-instaweb.sh index 5f4419b69b..5f5cac75ea 100755 --- a/git-instaweb.sh +++ b/git-instaweb.sh @@ -256,7 +256,7 @@ apache2_conf () { mkdir -p "$GIT_DIR/gitweb/logs" bind= test x"$local" = xtrue && bind='127.0.0.1:' - echo 'text/css css' > $fqgitdir/mime.types + echo 'text/css css' > "$fqgitdir/mime.types" cat > "$conf" <<EOF ServerName "git-instaweb" ServerRoot "$fqgitdir/gitweb" @@ -272,13 +272,13 @@ EOF fi done cat >> "$conf" <<EOF -TypesConfig $fqgitdir/mime.types +TypesConfig "$fqgitdir/mime.types" DirectoryIndex gitweb.cgi EOF # check to see if Dennis Stosberg's mod_perl compatibility patch # (<20060621130708.Gcbc6e5c@leonov.stosberg.net>) has been applied - if test -f "$module_path/mod_perl.so" && grep '^our $gitbin' \ + if test -f "$module_path/mod_perl.so" && grep 'MOD_PERL' \ "$GIT_DIR/gitweb/gitweb.cgi" >/dev/null then # favor mod_perl if available diff --git a/git-mergetool--lib.sh b/git-mergetool--lib.sh index a16a2795d7..bfb01f7842 100644 --- a/git-mergetool--lib.sh +++ b/git-mergetool--lib.sh @@ -18,6 +18,9 @@ translate_merge_tool_path () { emerge) echo emacs ;; + araxis) + echo compare + ;; *) echo "$1" ;; @@ -43,7 +46,7 @@ check_unchanged () { valid_tool () { case "$1" in kdiff3 | tkdiff | xxdiff | meld | opendiff | \ - emerge | vimdiff | gvimdiff | ecmerge | diffuse) + emerge | vimdiff | gvimdiff | ecmerge | diffuse | araxis) ;; # happy tortoisemerge) if ! merge_mode; then @@ -228,8 +231,8 @@ run_merge_tool () { fi check_unchanged else - "$merge_tool_path" "$LOCAL" "$REMOTE" \ - --default --mode=merge2 --to="$MERGED" + "$merge_tool_path" --default --mode=diff2 \ + "$LOCAL" "$REMOTE" fi ;; emerge) @@ -248,7 +251,7 @@ run_merge_tool () { status=$? else "$merge_tool_path" -f emerge-files-command \ - "$LOCAL" "$REMOTE" "$(basename "$MERGED")" + "$LOCAL" "$REMOTE" fi ;; tortoisemerge) @@ -263,6 +266,24 @@ run_merge_tool () { status=1 fi ;; + araxis) + if merge_mode; then + touch "$BACKUP" + if $base_present; then + "$merge_tool_path" -wait -merge -3 -a1 \ + "$BASE" "$LOCAL" "$REMOTE" "$MERGED" \ + >/dev/null 2>&1 + else + "$merge_tool_path" -wait -2 \ + "$LOCAL" "$REMOTE" "$MERGED" \ + >/dev/null 2>&1 + fi + check_unchanged + else + "$merge_tool_path" -wait -2 "$LOCAL" "$REMOTE" \ + >/dev/null 2>&1 + fi + ;; *) merge_tool_cmd="$(get_merge_tool_cmd "$1")" if test -z "$merge_tool_cmd"; then @@ -302,7 +323,7 @@ guess_merge_tool () { else tools="opendiff kdiff3 tkdiff xxdiff meld $tools" fi - tools="$tools gvimdiff diffuse ecmerge" + tools="$tools gvimdiff diffuse ecmerge araxis" fi if echo "${VISUAL:-$EDITOR}" | grep emacs > /dev/null 2>&1; then # $EDITOR is emacs so add emerge as a candidate diff --git a/git-parse-remote.sh b/git-parse-remote.sh index a296719861..5f47b18141 100755 --- a/git-parse-remote.sh +++ b/git-parse-remote.sh @@ -60,205 +60,36 @@ get_default_remote () { echo ${origin:-origin} } -get_remote_default_refs_for_push () { - data_source=$(get_data_source "$1") - case "$data_source" in - '' | branches | self) - ;; # no default push mapping, just send matching refs. - config) - git config --get-all "remote.$1.push" ;; - remotes) - sed -ne '/^Push: */{ - s///p - }' "$GIT_DIR/remotes/$1" ;; - *) - die "internal error: get-remote-default-ref-for-push $1" ;; - esac -} - -# Called from canon_refs_list_for_fetch -d "$remote", which -# is called from get_remote_default_refs_for_fetch to grok -# refspecs that are retrieved from the configuration, but not -# from get_remote_refs_for_fetch when it deals with refspecs -# supplied on the command line. $ls_remote_result has the list -# of refs available at remote. -# -# The first token returned is either "explicit" or "glob"; this -# is to help prevent randomly "globbed" ref from being chosen as -# a merge candidate -expand_refs_wildcard () { - echo "$ls_remote_result" | - git fetch--tool expand-refs-wildcard "-" "$@" -} - -# Subroutine to canonicalize remote:local notation. -canon_refs_list_for_fetch () { - # If called from get_remote_default_refs_for_fetch - # leave the branches in branch.${curr_branch}.merge alone, - # or the first one otherwise; add prefix . to the rest - # to prevent the secondary branches to be merged by default. - merge_branches= - curr_branch= - if test "$1" = "-d" - then - shift ; remote="$1" ; shift - set $(expand_refs_wildcard "$remote" "$@") - is_explicit="$1" - shift - if test "$remote" = "$(get_default_remote)" - then - curr_branch=$(git symbolic-ref -q HEAD | \ - sed -e 's|^refs/heads/||') - merge_branches=$(git config \ - --get-all "branch.${curr_branch}.merge") - fi - if test -z "$merge_branches" && test $is_explicit != explicit - then - merge_branches=..this.will.never.match.any.ref.. - fi - fi - for ref - do - force= - case "$ref" in - +*) - ref=$(expr "z$ref" : 'z+\(.*\)') - force=+ - ;; - esac - expr "z$ref" : 'z.*:' >/dev/null || ref="${ref}:" - remote=$(expr "z$ref" : 'z\([^:]*\):') - local=$(expr "z$ref" : 'z[^:]*:\(.*\)') - dot_prefix=. - if test -z "$merge_branches" - then - merge_branches=$remote - dot_prefix= - else - for merge_branch in $merge_branches - do - [ "$remote" = "$merge_branch" ] && - dot_prefix= && break - done - fi - case "$remote" in - '' | HEAD ) remote=HEAD ;; - refs/*) ;; - heads/* | tags/* | remotes/* ) remote="refs/$remote" ;; - *) remote="refs/heads/$remote" ;; - esac - case "$local" in - '') local= ;; - refs/*) ;; - heads/* | tags/* | remotes/* ) local="refs/$local" ;; - *) local="refs/heads/$local" ;; - esac - - if local_ref_name=$(expr "z$local" : 'zrefs/\(.*\)') - then - git check-ref-format "$local_ref_name" || - die "* refusing to create funny ref '$local_ref_name' locally" - fi - echo "${dot_prefix}${force}${remote}:${local}" - done -} - -# Returns list of src: (no store), or src:dst (store) -get_remote_default_refs_for_fetch () { - data_source=$(get_data_source "$1") - case "$data_source" in - '') - echo "HEAD:" ;; - self) - canon_refs_list_for_fetch -d "$1" \ - $(git for-each-ref --format='%(refname):') - ;; - config) - canon_refs_list_for_fetch -d "$1" \ - $(git config --get-all "remote.$1.fetch") ;; - branches) - remote_branch=$(sed -ne '/#/s/.*#//p' "$GIT_DIR/branches/$1") - case "$remote_branch" in '') remote_branch=master ;; esac - echo "refs/heads/${remote_branch}:refs/heads/$1" - ;; - remotes) - canon_refs_list_for_fetch -d "$1" $(sed -ne '/^Pull: */{ - s///p - }' "$GIT_DIR/remotes/$1") - ;; - *) - die "internal error: get-remote-default-ref-for-fetch $1" ;; - esac -} - -get_remote_refs_for_push () { +get_remote_merge_branch () { case "$#" in - 0) die "internal error: get-remote-refs-for-push." ;; - 1) get_remote_default_refs_for_push "$@" ;; - *) shift; echo "$@" ;; - esac -} - -get_remote_refs_for_fetch () { - case "$#" in - 0) - die "internal error: get-remote-refs-for-fetch." ;; - 1) - get_remote_default_refs_for_fetch "$@" ;; - *) - shift - tag_just_seen= - for ref - do - if test "$tag_just_seen" - then - echo "refs/tags/${ref}:refs/tags/${ref}" - tag_just_seen= - continue - else - case "$ref" in - tag) - tag_just_seen=yes - continue - ;; - esac - fi - canon_refs_list_for_fetch "$ref" - done + 0|1) + origin="$1" + default=$(get_default_remote) + test -z "$origin" && origin=$default + curr_branch=$(git symbolic-ref -q HEAD) + [ "$origin" = "$default" ] && + echo $(git for-each-ref --format='%(upstream)' $curr_branch) ;; - esac -} - -resolve_alternates () { - # original URL (xxx.git) - top_=`expr "z$1" : 'z\([^:]*:/*[^/]*\)/'` - while read path - do - case "$path" in - \#* | '') - continue ;; - /*) - echo "$top_$path/" ;; - ../*) - # relative -- ugly but seems to work. - echo "$1/objects/$path/" ;; - *) - # exit code may not be caught by the reader. - echo "bad alternate: $path" - exit 1 ;; - esac - done -} - -get_uploadpack () { - data_source=$(get_data_source "$1") - case "$data_source" in - config) - uplp=$(git config --get "remote.$1.uploadpack") - echo ${uplp:-git-upload-pack} - ;; *) - echo "git-upload-pack" + repo=$1 + shift + ref=$1 + # FIXME: It should return the tracking branch + # Currently only works with the default mapping + case "$ref" in + +*) + ref=$(expr "z$ref" : 'z+\(.*\)') ;; + esac + expr "z$ref" : 'z.*:' >/dev/null || ref="${ref}:" + remote=$(expr "z$ref" : 'z\([^:]*\):') + case "$remote" in + '' | HEAD ) remote=HEAD ;; + heads/*) remote=${remote#heads/} ;; + refs/heads/*) remote=${remote#refs/heads/} ;; + refs/* | tags/* | remotes/* ) remote= + esac + + [ -n "$remote" ] && echo "refs/remotes/$repo/$remote" esac } diff --git a/git-pull.sh b/git-pull.sh index cab367ada0..0f24182974 100755 --- a/git-pull.sh +++ b/git-pull.sh @@ -124,13 +124,18 @@ test true = "$rebase" && { git diff-index --ignore-submodules --cached --quiet HEAD -- || die "refusing to pull with rebase: your working tree is not up-to-date" + oldremoteref= && . git-parse-remote && - origin="$1" - test -z "$origin" && origin=$(get_default_remote) - reflist="$(get_remote_refs_for_fetch "$@" 2>/dev/null | - sed "s|refs/heads/\(.*\):|\1|")" && - oldremoteref="$(git rev-parse -q --verify \ - "refs/remotes/$origin/$reflist")" + remoteref="$(get_remote_merge_branch "$@" 2>/dev/null)" && + oldremoteref="$(git rev-parse -q --verify "$remoteref")" && + for reflog in $(git rev-list -g $remoteref 2>/dev/null) + do + if test "$reflog" = "$(git merge-base $reflog $curr_branch)" + then + oldremoteref="$reflog" + break + fi + done } orig_head=$(git rev-parse -q --verify HEAD) git fetch $verbosity --update-head-ok "$@" || exit 1 diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh index f96d887d23..23ded48322 100755 --- a/git-rebase--interactive.sh +++ b/git-rebase--interactive.sh @@ -703,7 +703,7 @@ first and then run 'git rebase --continue' again." preserve=t for p in $(git rev-list --parents -1 $sha1 | cut -d' ' -s -f2-) do - if test -f "$REWRITTEN"/$p -a \( $p != $UPSTREAM -o $sha1 = $first_after_upstream \) + if test -f "$REWRITTEN"/$p -a \( $p != $ONTO -o $sha1 = $first_after_upstream \) then preserve=f fi diff --git a/git-rebase.sh b/git-rebase.sh index 334629fc97..18bc6946cf 100755 --- a/git-rebase.sh +++ b/git-rebase.sh @@ -3,7 +3,7 @@ # Copyright (c) 2005 Junio C Hamano. # -USAGE='[--interactive | -i] [-v] [--force-rebase | -f] [--onto <newbase>] [<upstream>|--root] [<branch>]' +USAGE='[--interactive | -i] [-v] [--force-rebase | -f] [--onto <newbase>] [<upstream>|--root] [<branch>] [--quiet | -q]' LONG_USAGE='git-rebase replaces <branch> with a new branch of the same name. When the --onto option is provided the new branch starts out with a HEAD equal to <newbase>, otherwise it is equal to <upstream> @@ -72,11 +72,20 @@ continue_merge () { echo "directly, but instead do one of the following: " die "$RESOLVEMSG" fi - printf "Committed: %0${prec}d " $msgnum + if test -z "$GIT_QUIET" + then + printf "Committed: %0${prec}d " $msgnum + fi else - printf "Already applied: %0${prec}d " $msgnum + if test -z "$GIT_QUIET" + then + printf "Already applied: %0${prec}d " $msgnum + fi + fi + if test -z "$GIT_QUIET" + then + git rev-list --pretty=oneline -1 "$cmt" | sed -e 's/^[^ ]* //' fi - git rev-list --pretty=oneline -1 "$cmt" | sed -e 's/^[^ ]* //' prev_head=`git rev-parse HEAD^0` # save the resulting commit so we can read-tree on it later @@ -97,6 +106,10 @@ call_merge () { eval GITHEAD_$cmt='"${cmt_name##refs/heads/}~$(($end - $msgnum))"' eval GITHEAD_$hd='$(cat "$dotest/onto_name")' export GITHEAD_$cmt GITHEAD_$hd + if test -n "$GIT_QUIET" + then + export GIT_MERGE_VERBOSITY=1 + fi git-merge-$strategy "$cmt^" -- "$hd" "$cmt" rv=$? case "$rv" in @@ -138,7 +151,7 @@ move_to_original_branch () { finish_rb_merge () { move_to_original_branch rm -r "$dotest" - echo "All done." + say All done. } is_interactive () { @@ -207,6 +220,7 @@ do end=$(cat "$dotest/end") msgnum=$(cat "$dotest/msgnum") onto=$(cat "$dotest/onto") + GIT_QUIET=$(cat "$dotest/quiet") continue_merge while test "$msgnum" -le "$end" do @@ -219,6 +233,7 @@ do head_name=$(cat "$GIT_DIR"/rebase-apply/head-name) && onto=$(cat "$GIT_DIR"/rebase-apply/onto) && orig_head=$(cat "$GIT_DIR"/rebase-apply/orig-head) && + GIT_QUIET=$(cat "$GIT_DIR"/rebase-apply/quiet) git am --resolved --3way --resolvemsg="$RESOLVEMSG" && move_to_original_branch exit @@ -236,6 +251,7 @@ do msgnum=$(cat "$dotest/msgnum") msgnum=$(($msgnum + 1)) onto=$(cat "$dotest/onto") + GIT_QUIET=$(cat "$dotest/quiet") while test "$msgnum" -le "$end" do call_merge "$msgnum" @@ -247,6 +263,7 @@ do head_name=$(cat "$GIT_DIR"/rebase-apply/head-name) && onto=$(cat "$GIT_DIR"/rebase-apply/onto) && orig_head=$(cat "$GIT_DIR"/rebase-apply/orig-head) && + GIT_QUIET=$(cat "$GIT_DIR"/rebase-apply/quiet) git am -3 --skip --resolvemsg="$RESOLVEMSG" && move_to_original_branch exit @@ -258,9 +275,11 @@ do git rerere clear if test -d "$dotest" then + GIT_QUIET=$(cat "$dotest/quiet") move_to_original_branch else dotest="$GIT_DIR"/rebase-apply + GIT_QUIET=$(cat "$dotest/quiet") move_to_original_branch fi git reset --hard $(cat "$dotest/orig-head") @@ -298,6 +317,13 @@ do -v|--verbose) verbose=t diffstat=t + GIT_QUIET= + ;; + -q|--quiet) + GIT_QUIET=t + git_am_opt="$git_am_opt -q" + verbose= + diffstat= ;; --whitespace=*) git_am_opt="$git_am_opt $1" @@ -442,15 +468,15 @@ then then # Lazily switch to the target branch if needed... test -z "$switch_to" || git checkout "$switch_to" - echo >&2 "Current branch $branch_name is up to date." + say "Current branch $branch_name is up to date." exit 0 else - echo "Current branch $branch_name is up to date, rebase forced." + say "Current branch $branch_name is up to date, rebase forced." fi fi # Detach HEAD and reset the tree -echo "First, rewinding head to replay your work on top of it..." +say "First, rewinding head to replay your work on top of it..." git checkout -q "$onto^0" || die "could not detach HEAD" git update-ref ORIG_HEAD $branch @@ -468,7 +494,7 @@ fi # we just fast forwarded. if test "$mb" = "$branch" then - echo >&2 "Fast-forwarded $branch_name to $onto_name." + say "Fast-forwarded $branch_name to $onto_name." move_to_original_branch exit 0 fi @@ -490,7 +516,8 @@ then test 0 != $ret -a -d "$GIT_DIR"/rebase-apply && echo $head_name > "$GIT_DIR"/rebase-apply/head-name && echo $onto > "$GIT_DIR"/rebase-apply/onto && - echo $orig_head > "$GIT_DIR"/rebase-apply/orig-head + echo $orig_head > "$GIT_DIR"/rebase-apply/orig-head && + echo "$GIT_QUIET" > "$GIT_DIR"/rebase-apply/quiet exit $ret fi @@ -504,6 +531,7 @@ prev_head=$orig_head echo "$prev_head" > "$dotest/prev_head" echo "$orig_head" > "$dotest/orig-head" echo "$head_name" > "$dotest/head-name" +echo "$GIT_QUIET" > "$dotest/quiet" msgnum=0 for cmt in `git rev-list --reverse --no-merges "$revisions"` diff --git a/git-repack.sh b/git-repack.sh index 0868734723..1eb3bca352 100755 --- a/git-repack.sh +++ b/git-repack.sh @@ -24,7 +24,7 @@ SUBDIRECTORY_OK='Yes' . git-sh-setup no_update_info= all_into_one= remove_redundant= unpack_unreachable= -local= quiet= no_reuse= extra= +local= no_reuse= extra= while test $# != 0 do case "$1" in @@ -33,7 +33,7 @@ do -A) all_into_one=t unpack_unreachable=--unpack-unreachable ;; -d) remove_redundant=t ;; - -q) quiet=-q ;; + -q) GIT_QUIET=t ;; -f) no_reuse=--no-reuse-object ;; -l) local=--local ;; --max-pack-size|--window|--window-memory|--depth) @@ -80,13 +80,11 @@ case ",$all_into_one," in ;; esac -args="$args $local $quiet $no_reuse$extra" -names=$(git pack-objects --honor-pack-keep --non-empty --all --reflog $args </dev/null "$PACKTMP") || +args="$args $local ${GIT_QUIET:+-q} $no_reuse$extra" +names=$(git pack-objects --keep-true-parents --honor-pack-keep --non-empty --all --reflog $args </dev/null "$PACKTMP") || exit 1 if [ -z "$names" ]; then - if test -z "$quiet"; then - echo Nothing new to pack. - fi + say Nothing new to pack. fi # Ok we have prepared all new packfiles. @@ -176,7 +174,7 @@ then done ) fi - git prune-packed $quiet + git prune-packed ${GIT_QUIET:+-q} fi case "$no_update_info" in diff --git a/git-send-email.perl b/git-send-email.perl index cccbf4517a..0700d80afc 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -210,6 +210,7 @@ my %config_settings = ( "envelopesender" => \$envelope_sender, "multiedit" => \$multiedit, "confirm" => \$confirm, + "from" => \$sender, ); # Handle Uncouth Termination @@ -333,7 +334,7 @@ if (@suppress_cc) { } if ($suppress_cc{'all'}) { - foreach my $entry (qw (ccmd cc author self sob body bodycc)) { + foreach my $entry (qw (cccmd cc author self sob body bodycc)) { $suppress_cc{$entry} = 1; } delete $suppress_cc{'all'}; @@ -409,7 +410,7 @@ my %parse_alias = ( mailrc => sub { my $fh = shift; while (<$fh>) { if (/^alias\s+(\S+)\s+(.*)$/) { # spaces delimit multiple addresses - $aliases{$1} = [ split(/\s+/, $2) ]; + $aliases{$1} = [ quotewords('\s+', 0, $2) ]; }}}, pine => sub { my $fh = shift; my $f='\t[^\t]*'; for (my $x = ''; defined($x); $x = $_) { @@ -449,7 +450,6 @@ sub check_file_rev_conflict($) { try { $repo->command('rev-parse', '--verify', '--quiet', $f); if (defined($format_patch)) { - print "foo\n"; return $format_patch; } die(<<EOF); @@ -537,7 +537,7 @@ if ($compose) { print C <<EOT; From $tpl_sender # This line is ignored. -GIT: Lines beginning in "GIT: " will be removed. +GIT: Lines beginning in "GIT:" will be removed. GIT: Consider including an overall diffstat or table of contents GIT: for the patch you are writing. GIT: @@ -552,8 +552,6 @@ EOT } close(C); - my $editor = $ENV{GIT_EDITOR} || Git::config(@repo, "core.editor") || $ENV{VISUAL} || $ENV{EDITOR} || "vi"; - if ($annotate) { do_edit($compose_filename, @files); } else { @@ -570,7 +568,7 @@ EOT my $in_body = 0; my $summary_empty = 1; while(<C>) { - next if m/^GIT: /; + next if m/^GIT:/; if ($in_body) { $summary_empty = 0 unless (/^\n$/); } elsif (/^\n$/) { @@ -578,7 +576,7 @@ EOT if ($need_8bit_cte) { print C2 "MIME-Version: 1.0\n", "Content-Type: text/plain; ", - "charset=utf-8\n", + "charset=UTF-8\n", "Content-Transfer-Encoding: 8bit\n"; } } elsif (/^MIME-Version:/i) { @@ -655,13 +653,17 @@ if (!@to) { } sub expand_aliases { - my @cur = @_; - my @last; - do { - @last = @cur; - @cur = map { $aliases{$_} ? @{$aliases{$_}} : $_ } @last; - } while (join(',',@cur) ne join(',',@last)); - return @cur; + return map { expand_one_alias($_) } @_; +} + +my %EXPANDED_ALIASES; +sub expand_one_alias { + my $alias = shift; + if ($EXPANDED_ALIASES{$alias}) { + die "fatal: alias '$alias' expands to itself\n"; + } + local $EXPANDED_ALIASES{$alias} = 1; + return $aliases{$alias} ? expand_aliases(@{$aliases{$alias}}) : $alias; } @to = expand_aliases(@to); @@ -767,12 +769,20 @@ sub unquote_rfc2047 { sub quote_rfc2047 { local $_ = shift; - my $encoding = shift || 'utf-8'; + my $encoding = shift || 'UTF-8'; s/([^-a-zA-Z0-9!*+\/])/sprintf("=%02X", ord($1))/eg; s/(.*)/=\?$encoding\?q\?$1\?=/; return $_; } +sub is_rfc2047_quoted { + my $s = shift; + my $token = '[^][()<>@,;:"\/?.= \000-\037\177-\377]+'; + my $encoded_text = '[!->@-~]+'; + length($s) <= 75 && + $s =~ m/^(?:"[[:ascii:]]*"|=\?$token\?$token\?$encoded_text\?=)$/o; +} + # use the simplest quoting being able to handle the recipient sub sanitize_address { @@ -784,7 +794,7 @@ sub sanitize_address } # if recipient_name is already quoted, do nothing - if ($recipient_name =~ /^("[[:ascii:]]*"|=\?utf-8\?q\?.*\?=)$/) { + if (is_rfc2047_quoted($recipient_name)) { return $recipient; } @@ -804,6 +814,10 @@ sub sanitize_address } +# Returns 1 if the message was sent, and 0 otherwise. +# In actuality, the whole program dies when there +# is an error sending a message. + sub send_message { my @recipients = unique_email_list(@to); @@ -872,7 +886,7 @@ X-Mailer: git-send-email $gitversion default => $ask_default); die "Send this email reply required" unless defined $_; if (/^n/i) { - return; + return 0; } elsif (/^q/i) { cleanup_compose_files(); exit(0); @@ -953,7 +967,7 @@ X-Mailer: git-send-email $gitversion $smtp->data or die $smtp->message; $smtp->datasend("$header\n$message") or die $smtp->message; $smtp->dataend() or die $smtp->message; - $smtp->ok or die "Failed to send $subject\n".$smtp->message; + $smtp->code =~ /250|200/ or die "Failed to send $subject\n".$smtp->message; } if ($quiet) { printf (($dry_run ? "Dry-" : "")."Sent %s\n", $subject); @@ -974,6 +988,8 @@ X-Mailer: git-send-email $gitversion print "Result: OK\n"; } } + + return 1; } $reply_to = $initial_reply_to; @@ -1091,7 +1107,7 @@ foreach my $t (@files) { close F; if (defined $cc_cmd && !$suppress_cc{'cccmd'}) { - open(F, "$cc_cmd $t |") + open(F, "$cc_cmd \Q$t\E |") or die "(cc-cmd) Could not execute '$cc_cmd'"; while(<F>) { my $c = $_; @@ -1134,10 +1150,11 @@ foreach my $t (@files) { @cc = (@initial_cc, @cc); - send_message(); + my $message_was_sent = send_message(); # set up for the next message - if ($chain_reply_to || !defined $reply_to || length($reply_to) == 0) { + if ($thread && $message_was_sent && + ($chain_reply_to || !defined $reply_to || length($reply_to) == 0)) { $reply_to = $message_id; if (length $references > 0) { $references .= "\n $message_id"; diff --git a/git-sh-setup.sh b/git-sh-setup.sh index 838233926f..c41c2f7439 100755 --- a/git-sh-setup.sh +++ b/git-sh-setup.sh @@ -11,11 +11,48 @@ # exporting it. unset CDPATH +git_broken_path_fix () { + case ":$PATH:" in + *:$1:*) : ok ;; + *) + PATH=$( + SANE_TOOL_PATH="$1" + IFS=: path= sep= + set x $PATH + shift + for elem + do + case "$SANE_TOOL_PATH:$elem" in + (?*:/bin | ?*:/usr/bin) + path="$path$sep$SANE_TOOL_PATH" + sep=: + SANE_TOOL_PATH= + esac + path="$path$sep$elem" + sep=: + done + echo "$path" + ) + ;; + esac +} + +# @@BROKEN_PATH_FIX@@ + die() { echo >&2 "$@" exit 1 } +GIT_QUIET= + +say () { + if test -z "$GIT_QUIET" + then + printf '%s\n' "$*" + fi +} + if test -n "$OPTIONS_SPEC"; then usage() { "$0" -h diff --git a/git-stash.sh b/git-stash.sh index b9ace99704..03e589f764 100755 --- a/git-stash.sh +++ b/git-stash.sh @@ -3,10 +3,11 @@ dashless=$(basename "$0" | sed -e 's/-/ /') USAGE="list [<options>] - or: $dashless (show | drop | pop ) [<stash>] - or: $dashless apply [--index] [<stash>] + or: $dashless show [<stash>] + or: $dashless drop [-q|--quiet] [<stash>] + or: $dashless ( pop | apply ) [--index] [-q|--quiet] [<stash>] or: $dashless branch <branchname> [<stash>] - or: $dashless [save [--keep-index] [<message>]] + or: $dashless [save [--keep-index] [-q|--quiet] [<message>]] or: $dashless clear" SUBDIRECTORY_OK=Yes @@ -94,18 +95,28 @@ create_stash () { save_stash () { keep_index= - case "$1" in - --keep-index) - keep_index=t + while test $# != 0 + do + case "$1" in + --keep-index) + keep_index=t + ;; + -q|--quiet) + GIT_QUIET=t + ;; + *) + break + ;; + esac shift - esac + done stash_msg="$*" git update-index -q --refresh if no_changes then - echo 'No local changes to save' + say 'No local changes to save' exit 0 fi test -f "$GIT_DIR/logs/$ref_stash" || @@ -118,9 +129,9 @@ save_stash () { git update-ref -m "$stash_msg" $ref_stash $w_commit || die "Cannot save the current status" - printf 'Saved working directory and index state "%s"\n' "$stash_msg" + say Saved working directory and index state "$stash_msg" - git reset --hard + git reset --hard ${GIT_QUIET:+-q} if test -n "$keep_index" && test -n $i_tree then @@ -156,11 +167,22 @@ apply_stash () { die 'Cannot apply to a dirty working tree, please stage your changes' unstash_index= - case "$1" in - --index) - unstash_index=t + + while test $# != 0 + do + case "$1" in + --index) + unstash_index=t + ;; + -q|--quiet) + GIT_QUIET=t + ;; + *) + break + ;; + esac shift - esac + done # current index state c_tree=$(git write-tree) || @@ -181,7 +203,7 @@ apply_stash () { git diff-tree --binary $s^2^..$s^2 | git apply --cached test $? -ne 0 && die 'Conflicts in index. Try without --index.' - unstashed_index_tree=$(git-write-tree) || + unstashed_index_tree=$(git write-tree) || die 'Could not save index tree' git reset fi @@ -193,7 +215,11 @@ apply_stash () { export GITHEAD_$w_tree GITHEAD_$c_tree GITHEAD_$b_tree " - if git-merge-recursive $b_tree -- $c_tree $w_tree + if test -n "$GIT_QUIET" + then + export GIT_MERGE_VERBOSITY=0 + fi + if git merge-recursive $b_tree -- $c_tree $w_tree then # No conflict if test -n "$unstashed_index_tree" @@ -207,7 +233,12 @@ apply_stash () { die "Cannot unstage modified files" rm -f "$a" fi - git status || : + squelch= + if test -n "$GIT_QUIET" + then + squelch='>/dev/null 2>&1' + fi + eval "git status $squelch" || : else # Merge conflict; keep the exit status from merge-recursive status=$? @@ -222,6 +253,19 @@ apply_stash () { drop_stash () { have_stash || die 'No stash entries to drop' + while test $# != 0 + do + case "$1" in + -q|--quiet) + GIT_QUIET=t + ;; + *) + break + ;; + esac + shift + done + if test $# = 0 then set x "$ref_stash@{0}" @@ -235,7 +279,7 @@ drop_stash () { die "$*: not a valid stashed state" git reflog delete --updateref --rewrite "$@" && - echo "Dropped $* ($s)" || die "$*: Could not drop stash entry" + say "Dropped $* ($s)" || die "$*: Could not drop stash entry" # clear_stash if we just dropped the last stash entry git rev-parse --verify "$ref_stash@{0}" > /dev/null 2>&1 || clear_stash @@ -253,7 +297,7 @@ apply_to_branch () { fi stash=$2 - git-checkout -b $branch $stash^ && + git checkout -b $branch $stash^ && apply_stash --index $stash && drop_stash $stash } @@ -312,7 +356,7 @@ branch) if test $# -eq 0 then save_stash && - echo '(To restore them type "git stash apply")' + say '(To restore them type "git stash apply")' else usage fi diff --git a/git-submodule.sh b/git-submodule.sh index 8e234a4028..ebed711da4 100755 --- a/git-submodule.sh +++ b/git-submodule.sh @@ -5,7 +5,7 @@ # Copyright (c) 2007 Lars Hjemli USAGE="[--quiet] [--cached] \ -[add [-b branch] <repo> <path>]|[status|init|update [-i|--init] [-N|--no-fetch]|summary [-n|--summary-limit <n>] [<commit>]] \ +[add [-b branch] <repo> <path>]|[status|init|update [-i|--init] [-N|--no-fetch] [--rebase|--merge]|summary [-n|--summary-limit <n>] [<commit>]] \ [--] [<path>...]|[foreach <command>]|[sync [--] [<path>...]]" OPTIONS_SPEC= . git-sh-setup @@ -14,20 +14,10 @@ require_work_tree command= branch= -quiet= +reference= cached= nofetch= - -# -# print stuff on stdout unless -q was specified -# -say() -{ - if test -z "$quiet" - then - echo "$@" - fi -} +update= # Resolve relative url by appending to parent's url resolve_relative_url () @@ -91,6 +81,7 @@ module_clone() { path=$1 url=$2 + reference="$3" # If there already is a directory at the submodule path, # expect it to be empty (since that is the default checkout @@ -106,7 +97,12 @@ module_clone() test -e "$path" && die "A file already exist at path '$path'" - git-clone -n "$url" "$path" || + if test -n "$reference" + then + git-clone "$reference" -n "$url" "$path" + else + git-clone -n "$url" "$path" + fi || die "Clone of '$url' into submodule path '$path' failed" } @@ -129,7 +125,16 @@ cmd_add() shift ;; -q|--quiet) - quiet=1 + GIT_QUIET=1 + ;; + --reference) + case "$2" in '') usage ;; esac + reference="--reference=$2" + shift + ;; + --reference=*) + reference="$1" + shift ;; --) shift @@ -203,7 +208,7 @@ cmd_add() git config submodule."$path".url "$url" else - module_clone "$path" "$realrepo" || exit + module_clone "$path" "$realrepo" "$reference" || exit ( unset GIT_DIR cd "$path" && @@ -256,7 +261,7 @@ cmd_init() do case "$1" in -q|--quiet) - quiet=1 + GIT_QUIET=1 ;; --) shift @@ -294,6 +299,11 @@ cmd_init() git config submodule."$name".url "$url" || die "Failed to register url for submodule path '$path'" + upd="$(git config -f .gitmodules submodule."$name".update)" + test -z "$upd" || + git config submodule."$name".update "$upd" || + die "Failed to register update mode for submodule path '$path'" + say "Submodule '$name' ($url) registered for path '$path'" done } @@ -311,16 +321,33 @@ cmd_update() case "$1" in -q|--quiet) shift - quiet=1 + GIT_QUIET=1 ;; -i|--init) + init=1 shift - cmd_init "$@" || return ;; -N|--no-fetch) shift nofetch=1 ;; + -r|--rebase) + shift + update="rebase" + ;; + --reference) + case "$2" in '') usage ;; esac + reference="--reference=$2" + shift 2 + ;; + --reference=*) + reference="$1" + shift + ;; + -m|--merge) + shift + update="merge" + ;; --) shift break @@ -334,11 +361,17 @@ cmd_update() esac done + if test -n "$init" + then + cmd_init "--" "$@" || return + fi + module_list "$@" | while read mode sha1 stage path do name=$(module_name "$path") || exit url=$(git config submodule."$name".url) + update_module=$(git config submodule."$name".update) if test -z "$url" then # Only mention uninitialized submodules when its @@ -351,7 +384,7 @@ cmd_update() if ! test -d "$path"/.git -o -f "$path"/.git then - module_clone "$path" "$url" || exit + module_clone "$path" "$url" "$reference"|| exit subsha1= else subsha1=$(unset GIT_DIR; cd "$path" && @@ -359,6 +392,11 @@ cmd_update() die "Unable to find current revision in submodule path '$path'" fi + if ! test -z "$update" + then + update_module=$update + fi + if test "$subsha1" != "$sha1" then force= @@ -374,11 +412,27 @@ cmd_update() die "Unable to fetch in submodule path '$path'" fi - (unset GIT_DIR; cd "$path" && - git-checkout $force -q "$sha1") || - die "Unable to checkout '$sha1' in submodule path '$path'" + case "$update_module" in + rebase) + command="git rebase" + action="rebase" + msg="rebased onto" + ;; + merge) + command="git merge" + action="merge" + msg="merged in" + ;; + *) + command="git checkout $force -q" + action="checkout" + msg="checked out" + ;; + esac - say "Submodule path '$path': checked out '$sha1'" + (unset GIT_DIR; cd "$path" && $command "$sha1") || + die "Unable to $action '$sha1' in submodule path '$path'" + say "Submodule path '$path': $msg '$sha1'" fi done } @@ -593,7 +647,7 @@ cmd_status() do case "$1" in -q|--quiet) - quiet=1 + GIT_QUIET=1 ;; --cached) cached=1 @@ -647,7 +701,7 @@ cmd_sync() do case "$1" in -q|--quiet) - quiet=1 + GIT_QUIET=1 shift ;; --) @@ -702,7 +756,7 @@ do command=$1 ;; -q|--quiet) - quiet=1 + GIT_QUIET=1 ;; -b|--branch) case "$2" in diff --git a/git-svn.perl b/git-svn.perl index ef1d30db38..d075810724 100755 --- a/git-svn.perl +++ b/git-svn.perl @@ -5,7 +5,7 @@ use warnings; use strict; use vars qw/ $AUTHOR $VERSION $sha1 $sha1_short $_revision $_repository - $_q $_authors %users/; + $_q $_authors $_authors_prog %users/; $AUTHOR = 'Eric Wong <normalperson@yhbt.net>'; $VERSION = '@@GIT_VERSION@@'; @@ -19,6 +19,7 @@ $ENV{GIT_DIR} ||= '.git'; $Git::SVN::default_repo_id = 'svn'; $Git::SVN::default_ref_id = $ENV{GIT_SVN_ID} || 'git-svn'; $Git::SVN::Ra::_log_window_size = 100; +$Git::SVN::_minimize_url = 'unset'; $Git::SVN::Log::TZ = $ENV{TZ}; $ENV{TZ} = 'UTC'; @@ -31,6 +32,7 @@ require SVN::Delta; if ($SVN::Core::VERSION lt '1.1.0') { fatal "Need SVN::Core 1.1.0 or better (got $SVN::Core::VERSION)"; } +my $can_compress = eval { require Compress::Zlib; 1}; push @Git::SVN::Ra::ISA, 'SVN::Ra'; push @SVN::Git::Editor::ISA, 'SVN::Delta::Editor'; push @SVN::Git::Fetcher::ISA, 'SVN::Delta::Editor'; @@ -39,6 +41,8 @@ use Digest::MD5; use IO::File qw//; use File::Basename qw/dirname basename/; use File::Path qw/mkpath/; +use File::Spec; +use File::Find; use Getopt::Long qw/:config gnu_getopt no_ignore_case auto_abbrev/; use IPC::Open3; use Git; @@ -62,7 +66,7 @@ my ($SVN); $sha1 = qr/[a-f\d]{40}/; $sha1_short = qr/[a-f\d]{4,40}/; my ($_stdin, $_help, $_edit, - $_message, $_file, + $_message, $_file, $_branch_dest, $_template, $_shared, $_version, $_fetch_all, $_no_rebase, $_fetch_parent, $_merge, $_strategy, $_dry_run, $_local, @@ -76,6 +80,7 @@ my %remote_opts = ( 'username=s' => \$Git::SVN::Prompt::_username, 'ignore-paths=s' => \$SVN::Git::Fetcher::_ignore_regex ); my %fc_opts = ( 'follow-parent|follow!' => \$Git::SVN::_follow_parent, 'authors-file|A=s' => \$_authors, + 'authors-prog=s' => \$_authors_prog, 'repack:i' => \$Git::SVN::_repack, 'noMetadata' => \$Git::SVN::_no_metadata, 'useSvmProps' => \$Git::SVN::_use_svm_props, @@ -90,13 +95,13 @@ my %fc_opts = ( 'follow-parent|follow!' => \$Git::SVN::_follow_parent, 'localtime' => \$Git::SVN::_localtime, %remote_opts ); -my ($_trunk, $_tags, $_branches, $_stdlayout); +my ($_trunk, @_tags, @_branches, $_stdlayout); my %icv; my %init_opts = ( 'template=s' => \$_template, 'shared:s' => \$_shared, - 'trunk|T=s' => \$_trunk, 'tags|t=s' => \$_tags, - 'branches|b=s' => \$_branches, 'prefix=s' => \$_prefix, + 'trunk|T=s' => \$_trunk, 'tags|t=s@' => \@_tags, + 'branches|b=s@' => \@_branches, 'prefix=s' => \$_prefix, 'stdlayout|s' => \$_stdlayout, - 'minimize-url|m' => \$Git::SVN::_minimize_url, + 'minimize-url|m!' => \$Git::SVN::_minimize_url, 'no-metadata' => sub { $icv{noMetadata} = 1 }, 'use-svm-props' => sub { $icv{useSvmProps} = 1 }, 'use-svnsync-props' => sub { $icv{useSvnsyncProps} = 1 }, @@ -139,11 +144,13 @@ my %cmd = ( branch => [ \&cmd_branch, 'Create a branch in the SVN repository', { 'message|m=s' => \$_message, + 'destination|d=s' => \$_branch_dest, 'dry-run|n' => \$_dry_run, 'tag|t' => \$_tag } ], tag => [ sub { $_tag = 1; cmd_branch(@_) }, 'Create a tag in the SVN repository', { 'message|m=s' => \$_message, + 'destination|d=s' => \$_branch_dest, 'dry-run|n' => \$_dry_run } ], 'set-tree' => [ \&cmd_set_tree, "Set an SVN repository to a git tree-ish", @@ -209,6 +216,14 @@ my %cmd = ( 'blame' => [ \&Git::SVN::Log::cmd_blame, "Show what revision and author last modified each line of a file", { 'git-format' => \$_git_format } ], + 'reset' => [ \&cmd_reset, + "Undo fetches back to the specified SVN revision", + { 'revision|r=s' => \$_revision, + 'parent|p' => \$_fetch_parent } ], + 'gc' => [ \&cmd_gc, + "Compress unhandled.log files in .git/svn and remove " . + "index files in .git/svn", + {} ], ); my $cmd; @@ -217,6 +232,9 @@ for (my $i = 0; $i < @ARGV; $i++) { $cmd = $ARGV[$i]; splice @ARGV, $i, 1; last; + } elsif ($ARGV[$i] eq 'help') { + $cmd = $ARGV[$i+1]; + usage(0); } }; @@ -263,6 +281,9 @@ usage(0) if $_help; version() if $_version; usage(1) unless defined $cmd; load_authors() if $_authors; +if (defined $_authors_prog) { + $_authors_prog = "'" . File::Spec->rel2abs($_authors_prog) . "'"; +} unless ($cmd =~ /^(?:clone|init|multi-init|commit-diff)$/) { Git::SVN::Migration::migration_check(); @@ -353,7 +374,7 @@ sub init_subdir { sub cmd_clone { my ($url, $path) = @_; if (!defined $path && - (defined $_trunk || defined $_branches || defined $_tags || + (defined $_trunk || @_branches || @_tags || defined $_stdlayout) && $url !~ m#^[a-z\+]+://#) { $path = $url; @@ -361,22 +382,28 @@ sub cmd_clone { $path = basename($url) if !defined $path || !length $path; cmd_init($url, $path); Git::SVN::fetch_all($Git::SVN::default_repo_id); + command_oneline('config', 'svn.authorsfile', $_authors) if $_authors; } sub cmd_init { if (defined $_stdlayout) { $_trunk = 'trunk' if (!defined $_trunk); - $_tags = 'tags' if (!defined $_tags); - $_branches = 'branches' if (!defined $_branches); + @_tags = 'tags' if (! @_tags); + @_branches = 'branches' if (! @_branches); } - if (defined $_trunk || defined $_branches || defined $_tags) { + if (defined $_trunk || @_branches || @_tags) { return cmd_multi_init(@_); } my $url = shift or die "SVN repository location required ", "as a command-line argument\n"; + $url = canonicalize_url($url); init_subdir(@_); do_git_init_db(); + if ($Git::SVN::_minimize_url eq 'unset') { + $Git::SVN::_minimize_url = 0; + } + Git::SVN->init($url); } @@ -448,8 +475,22 @@ sub cmd_dcommit { 'Cannot dcommit with a dirty index. Commit your changes first, ' . "or stash them with `git stash'.\n"; $head ||= 'HEAD'; + + my $old_head; + if ($head ne 'HEAD') { + $old_head = eval { + command_oneline([qw/symbolic-ref -q HEAD/]) + }; + if ($old_head) { + $old_head =~ s{^refs/heads/}{}; + } else { + $old_head = eval { command_oneline(qw/rev-parse HEAD/) }; + } + command(['checkout', $head], STDERR => 0); + } + my @refs; - my ($url, $rev, $uuid, $gs) = working_head_info($head, \@refs); + my ($url, $rev, $uuid, $gs) = working_head_info('HEAD', \@refs); unless ($gs) { die "Unable to determine upstream SVN information from ", "$head history.\nPerhaps the repository is empty."; @@ -535,7 +576,7 @@ sub cmd_dcommit { if (@diff) { @refs = (); my ($url_, $rev_, $uuid_, $gs_) = - working_head_info($head, \@refs); + working_head_info('HEAD', \@refs); my ($linear_refs_, $parents_) = linearize_history($gs_, \@refs); if (scalar(@$linear_refs) != @@ -573,6 +614,22 @@ sub cmd_dcommit { } } } + + if ($old_head) { + my $new_head = command_oneline(qw/rev-parse HEAD/); + my $new_is_symbolic = eval { + command_oneline(qw/symbolic-ref -q HEAD/); + }; + if ($new_is_symbolic) { + print "dcommitted the branch ", $head, "\n"; + } else { + print "dcommitted on a detached HEAD because you gave ", + "a revision argument.\n", + "The rewritten commit is: ", $new_head, "\n"; + } + command(['checkout', $old_head], STDERR => 0); + } + unlink $gs->{index}; } @@ -587,7 +644,46 @@ sub cmd_branch { my ($src, $rev, undef, $gs) = working_head_info($head); my $remote = Git::SVN::read_all_remotes()->{$gs->{repo_id}}; - my $glob = $remote->{ $_tag ? 'tags' : 'branches' }; + my $allglobs = $remote->{ $_tag ? 'tags' : 'branches' }; + my $glob; + if ($#{$allglobs} == 0) { + $glob = $allglobs->[0]; + } else { + unless(defined $_branch_dest) { + die "Multiple ", + $_tag ? "tag" : "branch", + " paths defined for Subversion repository.\n", + "You must specify where you want to create the ", + $_tag ? "tag" : "branch", + " with the --destination argument.\n"; + } + foreach my $g (@{$allglobs}) { + # SVN::Git::Editor could probably be moved to Git.pm.. + my $re = SVN::Git::Editor::glob2pat($g->{path}->{left}); + if ($_branch_dest =~ /$re/) { + $glob = $g; + last; + } + } + unless (defined $glob) { + my $dest_re = qr/\b\Q$_branch_dest\E\b/; + foreach my $g (@{$allglobs}) { + $g->{path}->{left} =~ /$dest_re/ or next; + if (defined $glob) { + die "Ambiguous destination: ", + $_branch_dest, "\nmatches both '", + $glob->{path}->{left}, "' and '", + $g->{path}->{left}, "'\n"; + } + $glob = $g; + } + unless (defined $glob) { + die "Unknown ", + $_tag ? "tag" : "branch", + " destination $_branch_dest\n"; + } + } + } my ($lft, $rgt) = @{ $glob->{path} }{qw/left right/}; my $dst = join '/', $remote->{url}, $lft, $branch_name, ($rgt || ()); @@ -735,6 +831,12 @@ sub canonicalize_path { return $path; } +sub canonicalize_url { + my ($url) = @_; + $url =~ s#^([^:]+://[^/]*/)(.*)$#$1 . canonicalize_path($2)#e; + return $url; +} + # get_svnprops(PATH) # ------------------ # Helper for cmd_propget and cmd_proplist below. @@ -794,17 +896,13 @@ sub cmd_proplist { sub cmd_multi_init { my $url = shift; - unless (defined $_trunk || defined $_branches || defined $_tags) { + unless (defined $_trunk || @_branches || @_tags) { usage(1); } - # there are currently some bugs that prevent multi-init/multi-fetch - # setups from working well without this. - $Git::SVN::_minimize_url = 1; - $_prefix = '' unless defined $_prefix; if (defined $url) { - $url =~ s#/+$##; + $url = canonicalize_url($url); init_subdir(@_); } do_git_init_db(); @@ -819,10 +917,14 @@ sub cmd_multi_init { undef, $trunk_ref); } } - return unless defined $_branches || defined $_tags; + return unless @_branches || @_tags; my $ra = $url ? Git::SVN::Ra->new($url) : undef; - complete_url_ls_init($ra, $_branches, '--branches/-b', $_prefix); - complete_url_ls_init($ra, $_tags, '--tags/-t', $_prefix . 'tags/'); + foreach my $path (@_branches) { + complete_url_ls_init($ra, $path, '--branches/-b', $_prefix); + } + foreach my $path (@_tags) { + complete_url_ls_init($ra, $path, '--tags/-t', $_prefix.'tags/'); + } } sub cmd_multi_fetch { @@ -1015,6 +1117,28 @@ sub cmd_info { print $result, "\n"; } +sub cmd_reset { + my $target = shift || $_revision or die "SVN revision required\n"; + $target = $1 if $target =~ /^r(\d+)$/; + $target =~ /^\d+$/ or die "Numeric SVN revision expected\n"; + my ($url, $rev, $uuid, $gs) = working_head_info('HEAD'); + unless ($gs) { + die "Unable to determine upstream SVN information from ". + "history\n"; + } + my ($r, $c) = $gs->find_rev_before($target, not $_fetch_parent); + $gs->rev_map_set($r, $c, 'reset', $uuid); + print "r$r = $c ($gs->{ref_id})\n"; +} + +sub cmd_gc { + if (!$can_compress) { + warn "Compress::Zlib could not be found; unhandled.log " . + "files will not be compressed.\n"; + } + find({ wanted => \&gc_directory, no_chdir => 1}, "$ENV{GIT_DIR}/svn"); +} + ########################### utility functions ######################### sub rebase_cmd { @@ -1084,7 +1208,7 @@ sub complete_url_ls_init { "wanted to set to: $gs->{url}\n"; } command_oneline('config', $k, $gs->{url}) unless $orig_url; - my $remote_path = "$ra->{svn_path}/$repo_path"; + my $remote_path = "$gs->{path}/$repo_path"; $remote_path =~ s#/+#/#g; $remote_path =~ s#^/##g; $remote_path .= "/*" if $remote_path !~ /\*/; @@ -1093,6 +1217,7 @@ sub complete_url_ls_init { die "--prefix='$pfx' must have a trailing slash '/'\n"; } command_noisy('config', + '--add', "svn-remote.$gs->{repo_id}.$n", "$remote_path:refs/remotes/$pfx*" . ('/*' x (($remote_path =~ tr/*/*/) - 1)) ); @@ -1172,16 +1297,27 @@ sub get_commit_entry { } rename $commit_editmsg, $commit_msg or croak $!; { + require Encode; # SVN requires messages to be UTF-8 when entering the repo local $/; open $log_fh, '<', $commit_msg or croak $!; binmode $log_fh; chomp($log_entry{log} = <$log_fh>); - if (my $enc = Git::config('i18n.commitencoding')) { - require Encode; - Encode::from_to($log_entry{log}, $enc, 'UTF-8'); + my $enc = Git::config('i18n.commitencoding') || 'UTF-8'; + my $msg = $log_entry{log}; + + eval { $msg = Encode::decode($enc, $msg, 1) }; + if ($@) { + die "Could not decode as $enc:\n", $msg, + "\nPerhaps you need to set i18n.commitencoding\n"; } + + eval { $msg = Encode::encode('UTF-8', $msg, 1) }; + die "Could not encode as UTF-8:\n$msg\n" if $@; + + $log_entry{log} = $msg; + close $log_fh or croak $!; } unlink $commit_msg; @@ -1255,11 +1391,11 @@ sub read_repo_config { sub extract_metadata { my $id = shift or return (undef, undef, undef); my ($url, $rev, $uuid) = ($id =~ /^\s*git-svn-id:\s+(.*)\@(\d+) - \s([a-f\d\-]+)$/x); + \s([a-f\d\-]+)$/ix); if (!defined $rev || !$uuid || !$url) { # some of the original repositories I made had # identifiers like this: - ($rev, $uuid) = ($id =~/^\s*git-svn-id:\s(\d+)\@([a-f\d\-]+)/); + ($rev, $uuid) = ($id =~/^\s*git-svn-id:\s(\d+)\@([a-f\d\-]+)/i); } return ($url, $rev, $uuid); } @@ -1423,6 +1559,25 @@ sub md5sum { return $md5->hexdigest(); } +sub gc_directory { + if ($can_compress && -f $_ && basename($_) eq "unhandled.log") { + my $out_filename = $_ . ".gz"; + open my $in_fh, "<", $_ or die "Unable to open $_: $!\n"; + binmode $in_fh; + my $gz = Compress::Zlib::gzopen($out_filename, "ab") or + die "Unable to open $out_filename: $!\n"; + + my $res; + while ($res = sysread($in_fh, my $str, 1024)) { + $gz->gzwrite($str) or + die "Unable to write: ".$gz->gzerror()."!\n"; + } + unlink $_ or die "unlink $File::Find::name: $!\n"; + } elsif (-f $_ && basename($_) eq "index") { + unlink $_ or die "unlink $_: $!\n"; + } +} + package Git::SVN; use strict; use warnings; @@ -1543,12 +1698,14 @@ sub fetch_all { my $ra = Git::SVN::Ra->new($url); my $uuid = $ra->get_uuid; my $head = $ra->get_latest_revnum; + $ra->get_log("", $head, 0, 1, 0, 1, sub { $head = $_[1] }); my $base = defined $fetch ? $head : 0; # read the max revs for wildcard expansion (branches/*, tags/*) foreach my $t (qw/branches tags/) { defined $remote->{$t} or next; - push @globs, $remote->{$t}; + push @globs, @{$remote->{$t}}; + my $max_rev = eval { tmp_config(qw/--int --get/, "svn-remote.$repo_id.${t}-maxRev") }; if (defined $max_rev && ($max_rev < $base)) { @@ -1595,15 +1752,16 @@ sub read_all_remotes { } elsif (m!^(.+)\.(branches|tags)= (.*):refs/remotes/(.+)\s*$/!x) { my ($p, $g) = ($3, $4); - my $rs = $r->{$1}->{$2} = { - t => $2, - remote => $1, - path => Git::SVN::GlobSpec->new($p), - ref => Git::SVN::GlobSpec->new($g) }; + my $rs = { + t => $2, + remote => $1, + path => Git::SVN::GlobSpec->new($p), + ref => Git::SVN::GlobSpec->new($g) }; if (length($rs->{ref}->{right}) != 0) { die "The '*' glob character must be the last ", "character of '$g'\n"; } + push @{ $r->{$1}->{$2} }, $rs; } } @@ -1743,9 +1901,10 @@ sub find_by_url { # repos_root and, path are optional next if defined $repos_root && $repos_root ne $u; my $fetch = $remotes->{$repo_id}->{fetch} || {}; - foreach (qw/branches tags/) { - resolve_local_globs($u, $fetch, - $remotes->{$repo_id}->{$_}); + foreach my $t (qw/branches tags/) { + foreach my $globspec (@{$remotes->{$repo_id}->{$t}}) { + resolve_local_globs($u, $fetch, $globspec); + } } my $p = $path; my $rwr = rewrite_root({repo_id => $repo_id}); @@ -1903,7 +2062,7 @@ sub _set_svm_vars { chomp($src, $uuid); - $uuid =~ m{^[0-9a-f\-]{30,}$} + $uuid =~ m{^[0-9a-f\-]{30,}$}i or die "doesn't look right - svm:uuid is '$uuid'\n"; # the '!' is used to mark the repos_root!/relative/path @@ -1989,7 +2148,7 @@ sub svnsync { die "doesn't look right - svn:sync-from-url is '$url'\n"; my $uuid = tmp_config('--get', "$section.svnsync-uuid"); - ($uuid) = ($uuid =~ m{^([0-9a-f\-]{30,})$}) or + ($uuid) = ($uuid =~ m{^([0-9a-f\-]{30,})$}i) or die "doesn't look right - svn:sync-from-uuid is '$uuid'\n"; $svnsync = { url => $url, uuid => $uuid } @@ -2007,7 +2166,7 @@ sub svnsync { die "doesn't look right - svn:sync-from-url is '$url'\n"; my $uuid = $rp->{'svn:sync-from-uuid'} or die $err . "uuid\n"; - ($uuid) = ($uuid =~ m{^([0-9a-f\-]{30,})$}) or + ($uuid) = ($uuid =~ m{^([0-9a-f\-]{30,})$}i) or die "doesn't look right - svn:sync-from-uuid is '$uuid'\n"; my $section = "svn-remote.$self->{repo_id}"; @@ -2023,7 +2182,7 @@ sub ra_uuid { unless ($self->{ra_uuid}) { my $key = "svn-remote.$self->{repo_id}.uuid"; my $uuid = eval { tmp_config('--get', $key) }; - if (!$@ && $uuid && $uuid =~ /^([a-f\d\-]{30,})$/) { + if (!$@ && $uuid && $uuid =~ /^([a-f\d\-]{30,})$/i) { $self->{ra_uuid} = $uuid; } else { die "ra_uuid called without URL\n" unless $self->{url}; @@ -2066,16 +2225,6 @@ sub ra { $ra; } -sub rel_path { - my ($self) = @_; - my $repos_root = $self->ra->{repos_root}; - return $self->{path} if ($self->{url} eq $repos_root); - my $url = $self->{url} . - (length $self->{path} ? "/$self->{path}" : $self->{path}); - $url =~ s!^\Q$repos_root\E(?:/+|$)!!g; - $url; -} - # prop_walk(PATH, REV, SUB) # ------------------------- # Recursively traverse PATH at revision REV and invoke SUB for each @@ -2401,10 +2550,7 @@ sub match_paths { if (my $path = $paths->{"/$self->{path}"}) { return ($path->{action} eq 'D') ? 0 : 1; } - my $repos_root = $self->ra->{repos_root}; - my $extended_path = $self->{url} . '/' . $self->{path}; - $extended_path =~ s#^\Q$repos_root\E(/|$)##; - $self->{path_regex} ||= qr/^\/\Q$extended_path\E\//; + $self->{path_regex} ||= qr/^\/\Q$self->{path}\E\//; if (grep /$self->{path_regex}/, keys %$paths) { return 1; } @@ -2427,15 +2573,14 @@ sub find_parent_branch { unless (defined $paths) { my $err_handler = $SVN::Error::handler; $SVN::Error::handler = \&Git::SVN::Ra::skip_unknown_revs; - $self->ra->get_log([$self->{path}], $rev, $rev, 0, 1, 1, sub { - $paths = - Git::SVN::Ra::dup_changed_paths($_[0]) }); + $self->ra->get_log([$self->{path}], $rev, $rev, 0, 1, 1, + sub { $paths = $_[0] }); $SVN::Error::handler = $err_handler; } return undef unless defined $paths; # look for a parent from another branch: - my @b_path_components = split m#/#, $self->rel_path; + my @b_path_components = split m#/#, $self->{path}; my @a_path_components; my $i; while (@b_path_components) { @@ -2453,11 +2598,11 @@ sub find_parent_branch { my $r = $i->{copyfrom_rev}; my $repos_root = $self->ra->{repos_root}; my $url = $self->ra->{url}; - my $new_url = $repos_root . $branch_from; + my $new_url = $url . $branch_from; print STDERR "Found possible branch point: ", "$new_url => ", $self->full_url, ", $r\n"; $branch_from =~ s#^/##; - my $gs = $self->other_gs($new_url, $url, $repos_root, + my $gs = $self->other_gs($new_url, $url, $branch_from, $r, $self->{ref_id}); my ($r0, $parent) = $gs->find_rev_before($r, 1); { @@ -2642,9 +2787,9 @@ sub parse_svn_date { } sub other_gs { - my ($self, $new_url, $url, $repos_root, + my ($self, $new_url, $url, $branch_from, $r, $old_ref_id) = @_; - my $gs = Git::SVN->find_by_url($new_url, $repos_root, $branch_from); + my $gs = Git::SVN->find_by_url($new_url, $url, $branch_from); unless ($gs) { my $ref_id = $old_ref_id; $ref_id =~ s/\@\d+$//; @@ -2663,12 +2808,33 @@ sub other_gs { $gs } +sub call_authors_prog { + my ($orig_author) = @_; + my $author = `$::_authors_prog $orig_author`; + if ($? != 0) { + die "$::_authors_prog failed with exit code $?\n" + } + if ($author =~ /^\s*(.+?)\s*<(.*)>\s*$/) { + my ($name, $email) = ($1, $2); + $email = undef if length $2 == 0; + return [$name, $email]; + } else { + die "Author: $orig_author: $::_authors_prog returned " + . "invalid author format: $author\n"; + } +} + sub check_author { my ($author) = @_; if (!defined $author || length $author == 0) { $author = '(no author)'; - } elsif (defined $::_authors && ! defined $::users{$author}) { - die "Author: $author not defined in $::_authors file\n"; + } + if (!defined $::users{$author}) { + if (defined $::_authors_prog) { + $::users{$author} = call_authors_prog($author); + } elsif (defined $::_authors) { + die "Author: $author not defined in $::_authors file\n"; + } } $author; } @@ -2734,7 +2900,7 @@ sub make_log_entry { die "Can't have both 'useSvmProps' and 'rewriteRoot' ", "options set!\n"; } - my ($uuid, $r) = $headrev =~ m{^([a-f\d\-]{30,}):(\d+)$}; + my ($uuid, $r) = $headrev =~ m{^([a-f\d\-]{30,}):(\d+)$}i; # we don't want "SVM: initializing mirror for junk" ... return undef if $r == 0; my $svm = $self->svm; @@ -2952,6 +3118,14 @@ sub _rev_map_set { croak "write: $!"; } +sub _rev_map_reset { + my ($fh, $rev, $commit) = @_; + my $c = _rev_map_get($fh, $rev); + $c eq $commit or die "_rev_map_reset(@_) commit $c does not match!\n"; + my $offset = sysseek($fh, 0, SEEK_CUR) or croak "seek: $!"; + truncate $fh, $offset or croak "truncate: $!"; +} + sub mkfile { my ($path) = @_; unless (-e $path) { @@ -2968,6 +3142,7 @@ sub rev_map_set { my $db = $self->map_path($uuid); my $db_lock = "$db.lock"; my $sig; + $update_ref ||= 0; if ($update_ref) { $SIG{INT} = $SIG{HUP} = $SIG{TERM} = $SIG{ALRM} = $SIG{PIPE} = $SIG{USR1} = $SIG{USR2} = sub { $sig = $_[0] }; @@ -2991,7 +3166,8 @@ sub rev_map_set { sysopen(my $fh, $db_lock, O_RDWR | O_CREAT) or croak "Couldn't open $db_lock: $!\n"; - _rev_map_set($fh, $rev, $commit); + $update_ref eq 'reset' ? _rev_map_reset($fh, $rev, $commit) : + _rev_map_set($fh, $rev, $commit); if ($sync) { $fh->flush or die "Couldn't flush $db_lock: $!\n"; $fh->sync or die "Couldn't sync $db_lock: $!\n"; @@ -2999,7 +3175,9 @@ sub rev_map_set { close $fh or croak $!; if ($update_ref) { $_head = $self; - command_noisy('update-ref', '-m', "r$rev", + my $note = ""; + $note = " ($update_ref)" if ($update_ref !~ /^\d*$/); + command_noisy('update-ref', '-m', "r$rev$note", $self->refname, $commit); } rename $db_lock, $db or die "rev_map_set(@_): ", "Failed to rename: ", @@ -3061,12 +3239,19 @@ sub rev_map_get { return undef unless -e $map_path; sysopen(my $fh, $map_path, O_RDONLY) or croak "open: $!"; + my $c = _rev_map_get($fh, $rev); + close($fh) or croak "close: $!"; + $c +} + +sub _rev_map_get { + my ($fh, $rev) = @_; + binmode $fh or croak "binmode: $!"; my $size = (stat($fh))[7]; ($size % 24) == 0 or croak "inconsistent size: $size"; if ($size == 0) { - close $fh or croak "close: $fh"; return undef; } @@ -3084,11 +3269,9 @@ sub rev_map_get { } elsif ($r > $rev) { $u = $i - 24; } else { # $r == $rev - close($fh) or croak "close: $!"; return $c eq ('0' x 40) ? undef : $c; } } - close($fh) or croak "close: $!"; undef; } @@ -3100,6 +3283,8 @@ sub find_rev_before { my ($self, $rev, $eq_ok, $min_rev) = @_; --$rev unless $eq_ok; $min_rev ||= 1; + my $max_rev = $self->rev_map_max; + $rev = $max_rev if ($rev > $max_rev); while ($rev >= $min_rev) { if (my $c = $self->rev_map_get($rev)) { return ($rev, $c); @@ -3820,7 +4005,7 @@ sub repo_path { sub url_path { my ($self, $path) = @_; if ($self->{url} =~ m#^https?://#) { - $path =~ s/([^~a-zA-Z0-9_.-])/uc sprintf("%%%02x",ord($1))/eg; + $path =~ s!([^~a-zA-Z0-9_./-])!uc sprintf("%%%02x",ord($1))!eg; } $self->{url} . '/' . $self->repo_path($path); } @@ -4280,6 +4465,34 @@ sub get_log { my ($self, @args) = @_; my $pool = SVN::Pool->new; + # svn_log_changed_path_t objects passed to get_log are likely to be + # overwritten even if only the refs are copied to an external variable, + # so we should dup the structures in their entirety. Using an + # externally passed pool (instead of our temporary and quickly cleared + # pool in Git::SVN::Ra) does not help matters at all... + my $receiver = pop @args; + my $prefix = "/".$self->{svn_path}; + $prefix =~ s#/+($)##; + my $prefix_regex = qr#^\Q$prefix\E#; + push(@args, sub { + my ($paths) = $_[0]; + return &$receiver(@_) unless $paths; + $_[0] = (); + foreach my $p (keys %$paths) { + my $i = $paths->{$p}; + # Make path relative to our url, not repos_root + $p =~ s/$prefix_regex//; + my %s = map { $_ => $i->$_; } + qw/copyfrom_path copyfrom_rev action/; + if ($s{'copyfrom_path'}) { + $s{'copyfrom_path'} =~ s/$prefix_regex//; + } + $_[0]{$p} = \%s; + } + &$receiver(@_); + }); + + # the limit parameter was not supported in SVN 1.1.x, so we # drop it. Therefore, the receiver callback passed to it # is made aware of this limitation by being wrapped if @@ -4364,10 +4577,12 @@ sub gs_do_switch { my $full_url = $self->{url}; my $old_url = $full_url; - $full_url .= '/' . escape_uri_only($path) if length $path; + $full_url .= '/' . $path if length $path; my ($ra, $reparented); - if ($old_url =~ m#^svn(\+ssh)?://#) { + if ($old_url =~ m#^svn(\+ssh)?://# || + ($full_url =~ m#^https?://# && + escape_url($full_url) ne $full_url)) { $_[0] = undef; $self = undef; $RA = undef; @@ -4438,6 +4653,7 @@ sub gs_fetch_loop_common { my ($min, $max) = ($base, $head < $base + $inc ? $head : $base + $inc); my $longest_path = longest_common_path($gsv, $globs); my $ra_url = $self->{url}; + my $find_trailing_edge; while (1) { my %revs; my $err; @@ -4448,15 +4664,17 @@ sub gs_fetch_loop_common { }; sub _cb { my ($paths, $r, $author, $date, $log) = @_; - [ dup_changed_paths($paths), + [ $paths, { author => $author, date => $date, log => $log } ]; } $self->get_log([$longest_path], $min, $max, 0, 1, 1, sub { $revs{$_[1]} = _cb(@_) }); if ($err) { print "Checked through r$max\r"; + } else { + $find_trailing_edge = 1; } - if ($err && $max >= $head) { + if ($err and $find_trailing_edge) { print STDERR "Path '$longest_path' ", "was probably deleted:\n", $err->expanded_message, @@ -4468,13 +4686,14 @@ sub gs_fetch_loop_common { my $ok; $self->get_log([$longest_path], $min, $hi, 0, 1, 1, sub { - $ok ||= $_[1]; + $ok = $_[1]; $revs{$_[1]} = _cb(@_) }); if ($ok) { print STDERR "r$min .. r$ok OK\n"; last; } } + $find_trailing_edge = 0; } $SVN::Error::handler = $err_handler; @@ -4612,7 +4831,11 @@ sub minimize_url { my $c = ''; do { $url .= "/$c" if length $c; - eval { (ref $self)->new($url)->get_latest_revnum }; + eval { + my $ra = (ref $self)->new($url); + my $latest = $ra->get_latest_revnum; + $ra->get_log("", $latest, 0, 1, 0, 1, sub {}); + }; } while ($@ && ($c = shift @components)); $url; } @@ -4668,24 +4891,6 @@ sub skip_unknown_revs { die "Error from SVN, ($errno): ", $err->expanded_message,"\n"; } -# svn_log_changed_path_t objects passed to get_log are likely to be -# overwritten even if only the refs are copied to an external variable, -# so we should dup the structures in their entirety. Using an externally -# passed pool (instead of our temporary and quickly cleared pool in -# Git::SVN::Ra) does not help matters at all... -sub dup_changed_paths { - my ($paths) = @_; - return undef unless $paths; - my %ret; - foreach my $p (keys %$paths) { - my $i = $paths->{$p}; - my %s = map { $_ => $i->$_ } - qw/copyfrom_path copyfrom_rev action/; - $ret{$p} = \%s; - } - \%ret; -} - package Git::SVN::Log; use strict; use warnings; diff --git a/git-web--browse.sh b/git-web--browse.sh index 7ed0faddcd..4f5c740df5 100755 --- a/git-web--browse.sh +++ b/git-web--browse.sh @@ -161,9 +161,12 @@ case "$browser" in ;; esac ;; - w3m|links|lynx|open|start) + w3m|links|lynx|open) eval "$browser_path" "$@" ;; + start) + exec "$browser_path" '"web-browse"' "$@" + ;; dillo) "$browser_path" "$@" & ;; @@ -188,10 +188,9 @@ static int handle_alias(int *argcp, const char ***argv) alias_command); new_argv = xrealloc(new_argv, sizeof(char *) * - (count + *argcp + 1)); + (count + *argcp)); /* insert after command name */ memcpy(new_argv + count, *argv + 1, sizeof(char *) * *argcp); - new_argv[count+*argcp] = NULL; *argv = new_argv; *argcp += count - 1; @@ -200,7 +199,7 @@ static int handle_alias(int *argcp, const char ***argv) } if (subdir && chdir(subdir)) - die("Cannot change to %s: %s", subdir, strerror(errno)); + die_errno("Cannot change to '%s'", subdir); errno = saved_errno; @@ -246,7 +245,7 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv) status = p->fn(argc, argv, prefix); if (status) - return status & 0xff; + return status; /* Somebody closed stdout? */ if (fstat(fileno(stdout), &st)) @@ -257,11 +256,11 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv) /* Check for ENOSPC and EIO errors.. */ if (fflush(stdout)) - die("write failure on standard output: %s", strerror(errno)); + die_errno("write failure on standard output"); if (ferror(stdout)) die("unknown write failure on standard output"); if (fclose(stdout)) - die("close failed on standard output: %s", strerror(errno)); + die_errno("close failed on standard output"); return 0; } @@ -327,6 +326,7 @@ static void handle_internal_command(int argc, const char **argv) { "merge-ours", cmd_merge_ours, RUN_SETUP }, { "merge-recursive", cmd_merge_recursive, RUN_SETUP | NEED_WORK_TREE }, { "merge-subtree", cmd_merge_recursive, RUN_SETUP | NEED_WORK_TREE }, + { "mktree", cmd_mktree, RUN_SETUP }, { "mv", cmd_mv, RUN_SETUP | NEED_WORK_TREE }, { "name-rev", cmd_name_rev, RUN_SETUP }, { "pack-objects", cmd_pack_objects, RUN_SETUP }, diff --git a/gitk-git/gitk b/gitk-git/gitk index 1a7887b252..4604c831fe 100644 --- a/gitk-git/gitk +++ b/gitk-git/gitk @@ -187,7 +187,8 @@ proc parseviewargs {n arglist} { "--until=*" - "--before=*" - "--max-age=*" - "--min-age=*" - "--author=*" - "--committer=*" - "--grep=*" - "-[iE]" - "--remove-empty" - "--first-parent" - "--cherry-pick" - - "-S*" - "--pickaxe-all" - "--pickaxe-regex" { + "-S*" - "--pickaxe-all" - "--pickaxe-regex" - + "--simplify-by-decoration" { # These mean that we get a subset of the commits set filtered 1 lappend glflags $arg @@ -2145,7 +2146,7 @@ proc makewindow {} { label .bleft.mid.labeldiffcontext -text " [mc "Lines of context"]: " pack .bleft.mid.diff .bleft.mid.old .bleft.mid.new -side left spinbox .bleft.mid.diffcontext -width 5 -font textfont \ - -from 1 -increment 1 -to 10000000 \ + -from 0 -increment 1 -to 10000000 \ -validate all -validatecommand "diffcontextvalidate %P" \ -textvariable diffcontextstring .bleft.mid.diffcontext set $diffcontext @@ -3671,17 +3672,36 @@ proc newview {ishighlight} { } set known_view_options { - {perm b . {} {mc "Remember this view"}} - {args t50= + {} {mc "Commits to include (arguments to git log):"}} - {all b * "--all" {mc "Use all refs"}} - {dorder b . {"--date-order" "-d"} {mc "Strictly sort by date"}} - {lright b . "--left-right" {mc "Mark branch sides"}} - {since t15 + {"--since=*" "--after=*"} {mc "Since date:"}} - {until t15 . {"--until=*" "--before=*"} {mc "Until date:"}} - {limit t10 + "--max-count=*" {mc "Max count:"}} - {skip t10 . "--skip=*" {mc "Skip:"}} - {first b . "--first-parent" {mc "Limit to first parent"}} - {cmd t50= + {} {mc "Command to generate more commits to include:"}} + {perm b . {} {mc "Remember this view"}} + {reflabel l + {} {mc "References (space separated list):"}} + {refs t15 .. {} {mc "Branches & tags:"}} + {allrefs b *. "--all" {mc "All refs"}} + {branches b . "--branches" {mc "All (local) branches"}} + {tags b . "--tags" {mc "All tags"}} + {remotes b . "--remotes" {mc "All remote-tracking branches"}} + {commitlbl l + {} {mc "Commit Info (regular expressions):"}} + {author t15 .. "--author=*" {mc "Author:"}} + {committer t15 . "--committer=*" {mc "Committer:"}} + {loginfo t15 .. "--grep=*" {mc "Commit Message:"}} + {allmatch b .. "--all-match" {mc "Matches all Commit Info criteria"}} + {changes_l l + {} {mc "Changes to Files:"}} + {pickaxe_s r0 . {} {mc "Fixed String"}} + {pickaxe_t r1 . "--pickaxe-regex" {mc "Regular Expression"}} + {pickaxe t15 .. "-S*" {mc "Search string:"}} + {datelabel l + {} {mc "Commit Dates (\"2 weeks ago\", \"2009-03-17 15:27:38\", \"March 17, 2009 15:27:38\"):"}} + {since t15 .. {"--since=*" "--after=*"} {mc "Since:"}} + {until t15 . {"--until=*" "--before=*"} {mc "Until:"}} + {limit_lbl l + {} {mc "Limit and/or skip a number of revisions (positive integer):"}} + {limit t10 *. "--max-count=*" {mc "Number to show:"}} + {skip t10 . "--skip=*" {mc "Number to skip:"}} + {misc_lbl l + {} {mc "Miscellaneous options:"}} + {dorder b *. {"--date-order" "-d"} {mc "Strictly sort by date"}} + {lright b . "--left-right" {mc "Mark branch sides"}} + {first b . "--first-parent" {mc "Limit to first parent"}} + {smplhst b . "--simplify-by-decoration" {mc "Simple history"}} + {args t50 *. {} {mc "Additional arguments to git log:"}} + {allpaths path + {} {mc "Enter files and directories to include, one per line:"}} + {cmd t50= + {} {mc "Command to generate more commits to include:"}} } proc encode_view_opts {n} { @@ -3693,13 +3713,19 @@ proc encode_view_opts {n} { if {$patterns eq {}} continue set pattern [lindex $patterns 0] - set val $newviewopts($n,[lindex $opt 0]) - if {[lindex $opt 1] eq "b"} { + set val $newviewopts($n,[lindex $opt 0]) if {$val} { lappend rargs $pattern } + } elseif {[regexp {^r(\d+)$} [lindex $opt 1] type value]} { + regexp {^(.*_)} [lindex $opt 0] uselessvar button_id + set val $newviewopts($n,$button_id) + if {$val eq $value} { + lappend rargs $pattern + } } else { + set val $newviewopts($n,[lindex $opt 0]) set val [string trim $val] if {$val ne {}} { set pfix [string range $pattern 0 end-1] @@ -3707,6 +3733,7 @@ proc encode_view_opts {n} { } } } + set rargs [concat $rargs [shellsplit $newviewopts($n,refs)]] return [concat $rargs [shellsplit $newviewopts($n,args)]] } @@ -3714,14 +3741,22 @@ proc decode_view_opts {n view_args} { global known_view_options newviewopts foreach opt $known_view_options { + set id [lindex $opt 0] if {[lindex $opt 1] eq "b"} { + # Checkboxes + set val 0 + } elseif {[regexp {^r(\d+)$} [lindex $opt 1]]} { + # Radiobuttons + regexp {^(.*_)} $id uselessvar id set val 0 } else { + # Text fields set val {} } - set newviewopts($n,[lindex $opt 0]) $val + set newviewopts($n,$id) $val } set oargs [list] + set refargs [list] foreach arg $view_args { if {[regexp -- {^-([0-9]+)$} $arg arg cnt] && ![info exists found(limit)]} { @@ -3735,11 +3770,17 @@ proc decode_view_opts {n view_args} { if {[info exists found($id)]} continue foreach pattern [lindex $opt 3] { if {![string match $pattern $arg]} continue - if {[lindex $opt 1] ne "b"} { + if {[lindex $opt 1] eq "b"} { + # Check buttons + set val 1 + } elseif {[regexp {^r(\d+)$} [lindex $opt 1] match num]} { + # Radio buttons + regexp {^(.*_)} $id uselessvar id + set val $num + } else { + # Text input fields set size [string length $pattern] set val [string range $arg [expr {$size-1}] end] - } else { - set val 1 } set newviewopts($n,$id) $val set found($id) 1 @@ -3748,8 +3789,13 @@ proc decode_view_opts {n view_args} { if {[info exists val]} break } if {[info exists val]} continue - lappend oargs $arg + if {[regexp {^-} $arg]} { + lappend oargs $arg + } else { + lappend refargs $arg + } } + set newviewopts($n,refs) [shellarglist $refargs] set newviewopts($n,args) [shellarglist $oargs] } @@ -3785,16 +3831,16 @@ proc vieweditor {top n title} { global known_view_options toplevel $top - wm title $top $title + wm title $top [concat $title [mc "-- criteria for selecting revisions"]] make_transient $top . # View name frame $top.nfr - label $top.nl -text [mc "Name"] + label $top.nl -text [mc "View Name:"] entry $top.name -width 20 -textvariable newviewname($n) pack $top.nfr -in $top -fill x -pady 5 -padx 3 - pack $top.nl -in $top.nfr -side left -padx {0 30} - pack $top.name -in $top.nfr -side left + pack $top.nl -in $top.nfr -side left -padx {0 5} + pack $top.name -in $top.nfr -side left -padx {0 25} # View options set cframe $top.nfr @@ -3813,14 +3859,28 @@ proc vieweditor {top n title} { frame $cframe pack $cframe -in $top -fill x -pady 3 -padx 3 set cexpand [expr {$flags eq "*"}] + } elseif {$flags eq ".." || $flags eq "*."} { + set cframe $top.fr$cnt + incr cnt + frame $cframe + pack $cframe -in $top -fill x -pady 3 -padx [list 15 3] + set cexpand [expr {$flags eq "*."}] } else { set lxpad 5 } - if {$type eq "b"} { + if {$type eq "l"} { + label $cframe.l_$id -text $title + pack $cframe.l_$id -in $cframe -side left -pady [list 3 0] -anchor w + } elseif {$type eq "b"} { checkbutton $cframe.c_$id -text $title -variable newviewopts($n,$id) pack $cframe.c_$id -in $cframe -side left \ -padx [list $lxpad 0] -expand $cexpand -anchor w + } elseif {[regexp {^r(\d+)$} $type type sz]} { + regexp {^(.*_)} $id uselessvar button_id + radiobutton $cframe.c_$id -text $title -variable newviewopts($n,$button_id) -value $sz + pack $cframe.c_$id -in $cframe -side left \ + -padx [list $lxpad 0] -expand $cexpand -anchor w } elseif {[regexp {^t(\d+)$} $type type sz]} { message $cframe.l_$id -aspect 1500 -text $title entry $cframe.e_$id -width $sz -background $bgcolor \ @@ -3833,23 +3893,22 @@ proc vieweditor {top n title} { -textvariable newviewopts($n,$id) pack $cframe.l_$id -in $cframe -side top -pady [list 3 0] -anchor w pack $cframe.e_$id -in $cframe -side top -fill x + } elseif {$type eq "path"} { + message $top.l -aspect 1500 -text $title + pack $top.l -in $top -side top -pady [list 3 0] -anchor w -padx 3 + text $top.t -width 40 -height 5 -background $bgcolor -font uifont + if {[info exists viewfiles($n)]} { + foreach f $viewfiles($n) { + $top.t insert end $f + $top.t insert end "\n" + } + $top.t delete {end - 1c} end + $top.t mark set insert 0.0 + } + pack $top.t -in $top -side top -pady [list 0 5] -fill both -expand 1 -padx 3 } } - # Path list - message $top.l -aspect 1500 \ - -text [mc "Enter files and directories to include, one per line:"] - pack $top.l -in $top -side top -pady [list 7 0] -anchor w -padx 3 - text $top.t -width 40 -height 5 -background $bgcolor -font uifont - if {[info exists viewfiles($n)]} { - foreach f $viewfiles($n) { - $top.t insert end $f - $top.t insert end "\n" - } - $top.t delete {end - 1c} end - $top.t mark set insert 0.0 - } - pack $top.t -in $top -side top -pady [list 0 5] -fill both -expand 1 -padx 3 frame $top.buts button $top.buts.ok -text [mc "OK"] -command [list newviewok $top $n] button $top.buts.apply -text [mc "Apply (F5)"] -command [list newviewok $top $n 1] @@ -7249,7 +7308,7 @@ proc diffcontextchange {n1 n2 op} { global diffcontextstring diffcontext if {[string is integer -strict $diffcontextstring]} { - if {$diffcontextstring > 0} { + if {$diffcontextstring >= 0} { set diffcontext $diffcontextstring reselectline } @@ -7267,8 +7326,13 @@ proc getblobdiffs {ids} { global ignorespace global limitdiffs vfilelimit curview global diffencoding targetline diffnparents + global git_version - set cmd [diffcmd $ids "-p -C --cc --no-commit-id -U$diffcontext"] + set textconv {} + if {[package vcompare $git_version "1.6.1"] >= 0} { + set textconv "--textconv" + } + set cmd [diffcmd $ids "-p $textconv -C --cc --no-commit-id -U$diffcontext"] if {$ignorespace} { append cmd " -w" } @@ -11090,6 +11154,7 @@ set nullid2 "0000000000000000000000000000000000000001" set nullfile "/dev/null" set have_tk85 [expr {[package vcompare $tk_version "8.5"] >= 0}] +set git_version [join [lrange [split [lindex [exec git version] end] .] 0 2] .] set runq {} set history {} diff --git a/gitk-git/po/de.po b/gitk-git/po/de.po index 825dc98f74..53ef0d6359 100644 --- a/gitk-git/po/de.po +++ b/gitk-git/po/de.po @@ -1,14 +1,15 @@ # Translation of gitk to German. # Copyright (C) 2007 Paul Mackerras. # This file is distributed under the same license as the gitk package. -# Christian Stimming <stimming@tuhh.de>, 2007 # +# Christian Stimming <stimming@tuhh.de>, 2007. +# Frederik Schwarzer <schwarzerf@gmail.com>, 2008. msgid "" msgstr "" "Project-Id-Version: git-gui\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2008-12-06 20:40+0100\n" -"PO-Revision-Date: 2008-12-06 20:45+0100\n" +"POT-Creation-Date: 2009-05-12 21:55+0200\n" +"PO-Revision-Date: 2009-05-12 22:18+0200\n" "Last-Translator: Christian Stimming <stimming@tuhh.de>\n" "Language-Team: German\n" "MIME-Version: 1.0\n" @@ -17,297 +18,314 @@ msgstr "" #: gitk:113 msgid "Couldn't get list of unmerged files:" -msgstr "Liste der nicht-zusammengeführten Dateien nicht gefunden:" +msgstr "Liste der nicht zusammengeführten Dateien nicht gefunden:" -#: gitk:272 +#: gitk:268 msgid "Error parsing revisions:" msgstr "Fehler beim Laden der Versionen:" -#: gitk:327 +#: gitk:323 msgid "Error executing --argscmd command:" -msgstr "Fehler beim --argscmd Kommando:" +msgstr "Fehler beim Ausführen des --argscmd-Kommandos:" -#: gitk:340 +#: gitk:336 msgid "No files selected: --merge specified but no files are unmerged." msgstr "" -"Keine Dateien ausgewählt: --merge angegeben, es existieren aber keine nicht-" -"zusammengeführten Dateien." +"Keine Dateien ausgewählt: Es wurde --merge angegeben, aber es existieren " +"keine nicht zusammengeführten Dateien." -#: gitk:343 +#: gitk:339 msgid "" "No files selected: --merge specified but no unmerged files are within file " "limit." msgstr "" -"Keine Dateien ausgewähle: --merge angegeben, aber keine nicht-" -"zusammengeführten Dateien sind in der Dateiauswahl." +"Keine Dateien ausgewählt: Es wurde --merge angegeben, aber es sind keine " +"nicht zusammengeführten Dateien in der Dateiauswahl." -#: gitk:365 gitk:503 +#: gitk:361 gitk:508 msgid "Error executing git log:" -msgstr "Fehler beim Ausführen von git-log:" +msgstr "Fehler beim Ausführen von »git log«:" -#: gitk:378 +#: gitk:379 gitk:524 msgid "Reading" msgstr "Lesen" -#: gitk:438 gitk:3462 +#: gitk:439 gitk:4061 msgid "Reading commits..." -msgstr "Versionen lesen..." +msgstr "Versionen werden gelesen ..." -#: gitk:441 gitk:1528 gitk:3465 +#: gitk:442 gitk:1560 gitk:4064 msgid "No commits selected" -msgstr "Keine Versionen ausgewählt." +msgstr "Keine Versionen ausgewählt" -#: gitk:1399 +#: gitk:1436 msgid "Can't parse git log output:" -msgstr "Ausgabe von git-log kann nicht erkannt werden:" +msgstr "Ausgabe von »git log« kann nicht erkannt werden:" -#: gitk:1605 +#: gitk:1656 msgid "No commit information available" msgstr "Keine Versionsinformation verfügbar" -#: gitk:1709 gitk:1731 gitk:3259 gitk:7764 gitk:9293 gitk:9466 +#: gitk:1791 gitk:1815 gitk:3854 gitk:8714 gitk:10250 gitk:10422 msgid "OK" msgstr "Ok" -#: gitk:1733 gitk:3260 gitk:7439 gitk:7510 gitk:7613 gitk:7660 gitk:7766 -#: gitk:9294 gitk:9467 +#: gitk:1817 gitk:3856 gitk:8311 gitk:8385 gitk:8495 gitk:8544 gitk:8716 +#: gitk:10251 gitk:10423 msgid "Cancel" msgstr "Abbrechen" -#: gitk:1811 +#: gitk:1917 msgid "Update" msgstr "Aktualisieren" -#: gitk:1812 +#: gitk:1918 msgid "Reload" msgstr "Neu laden" -#: gitk:1813 +#: gitk:1919 msgid "Reread references" msgstr "Zweige neu laden" -#: gitk:1814 +#: gitk:1920 msgid "List references" msgstr "Zweige/Markierungen auflisten" -#: gitk:1915 +#: gitk:1922 msgid "Start git gui" msgstr "»git gui« starten" -#: gitk:1917 +#: gitk:1924 msgid "Quit" msgstr "Beenden" -#: gitk:1810 +#: gitk:1916 msgid "File" msgstr "Datei" -#: gitk:1818 +#: gitk:1928 msgid "Preferences" msgstr "Einstellungen" -#: gitk:1817 +#: gitk:1927 msgid "Edit" msgstr "Bearbeiten" -#: gitk:1821 +#: gitk:1932 msgid "New view..." -msgstr "Neue Ansicht..." +msgstr "Neue Ansicht ..." -#: gitk:1822 +#: gitk:1933 msgid "Edit view..." -msgstr "Ansicht bearbeiten..." +msgstr "Ansicht bearbeiten ..." -#: gitk:1823 +#: gitk:1934 msgid "Delete view" -msgstr "Ansicht löschen" +msgstr "Ansicht entfernen" -#: gitk:1825 +#: gitk:1936 msgid "All files" msgstr "Alle Dateien" -#: gitk:1820 gitk:3196 +#: gitk:1931 gitk:3666 msgid "View" msgstr "Ansicht" -#: gitk:1828 gitk:2487 +#: gitk:1941 gitk:1951 gitk:2650 msgid "About gitk" msgstr "Ãœber gitk" -#: gitk:1829 +#: gitk:1942 gitk:1956 msgid "Key bindings" msgstr "Tastenkürzel" -#: gitk:1827 +#: gitk:1940 gitk:1955 msgid "Help" msgstr "Hilfe" -#: gitk:1887 +#: gitk:2016 msgid "SHA1 ID: " msgstr "SHA1:" -#: gitk:1918 +#: gitk:2047 msgid "Row" msgstr "Zeile" -#: gitk:1949 +#: gitk:2078 msgid "Find" msgstr "Suche" -#: gitk:1950 +#: gitk:2079 msgid "next" msgstr "nächste" -#: gitk:1951 +#: gitk:2080 msgid "prev" msgstr "vorige" -#: gitk:1952 +#: gitk:2081 msgid "commit" msgstr "Version nach" -#: gitk:1955 gitk:1957 gitk:3617 gitk:3640 gitk:3664 gitk:5550 gitk:5621 +#: gitk:2084 gitk:2086 gitk:4222 gitk:4245 gitk:4269 gitk:6210 gitk:6282 +#: gitk:6366 msgid "containing:" msgstr "Beschreibung:" -#: gitk:1958 gitk:2954 gitk:2959 gitk:3692 +#: gitk:2087 gitk:3158 gitk:3163 gitk:4297 msgid "touching paths:" msgstr "Dateien:" -#: gitk:1959 gitk:3697 +#: gitk:2088 gitk:4302 msgid "adding/removing string:" msgstr "Änderungen:" -#: gitk:1968 gitk:1970 +#: gitk:2097 gitk:2099 msgid "Exact" msgstr "Exakt" -#: gitk:1970 gitk:3773 gitk:5518 +#: gitk:2099 gitk:4377 gitk:6178 msgid "IgnCase" msgstr "Kein Groß/Klein" -#: gitk:1970 gitk:3666 gitk:3771 gitk:5514 +#: gitk:2099 gitk:4271 gitk:4375 gitk:6174 msgid "Regexp" msgstr "Regexp" -#: gitk:1972 gitk:1973 gitk:3792 gitk:3822 gitk:3829 gitk:5641 gitk:5708 +#: gitk:2101 gitk:2102 gitk:4396 gitk:4426 gitk:4433 gitk:6302 gitk:6370 msgid "All fields" msgstr "Alle Felder" -#: gitk:1973 gitk:3790 gitk:3822 gitk:5580 +#: gitk:2102 gitk:4394 gitk:4426 gitk:6241 msgid "Headline" msgstr "Ãœberschrift" -#: gitk:1974 gitk:3790 gitk:5580 gitk:5708 gitk:6109 +#: gitk:2103 gitk:4394 gitk:6241 gitk:6370 gitk:6804 msgid "Comments" msgstr "Beschreibung" -#: gitk:1974 gitk:3790 gitk:3794 gitk:3829 gitk:5580 gitk:6045 gitk:7285 -#: gitk:7300 +#: gitk:2103 gitk:4394 gitk:4398 gitk:4433 gitk:6241 gitk:6739 gitk:7991 +#: gitk:8006 msgid "Author" msgstr "Autor" -#: gitk:1974 gitk:3790 gitk:5580 gitk:6047 +#: gitk:2103 gitk:4394 gitk:6241 gitk:6741 msgid "Committer" msgstr "Eintragender" -#: gitk:2003 +#: gitk:2132 msgid "Search" -msgstr "Suche" +msgstr "Suchen" -#: gitk:2010 +#: gitk:2139 msgid "Diff" msgstr "Vergleich" -#: gitk:2012 +#: gitk:2141 msgid "Old version" msgstr "Alte Version" -#: gitk:2014 +#: gitk:2143 msgid "New version" msgstr "Neue Version" -#: gitk:2016 +#: gitk:2145 msgid "Lines of context" msgstr "Kontextzeilen" -#: gitk:2026 +#: gitk:2155 msgid "Ignore space change" msgstr "Leerzeichenänderungen ignorieren" -#: gitk:2084 +#: gitk:2213 msgid "Patch" msgstr "Patch" -#: gitk:2086 +#: gitk:2215 msgid "Tree" msgstr "Baum" -#: gitk:2213 gitk:2226 +#: gitk:2359 gitk:2376 msgid "Diff this -> selected" -msgstr "Vergleich diese -> gewählte" +msgstr "Vergleich: diese -> gewählte" -#: gitk:2214 gitk:2227 +#: gitk:2360 gitk:2377 msgid "Diff selected -> this" -msgstr "Vergleich gewählte -> diese" +msgstr "Vergleich: gewählte -> diese" -#: gitk:2215 gitk:2228 +#: gitk:2361 gitk:2378 msgid "Make patch" msgstr "Patch erstellen" -#: gitk:2216 gitk:7494 +#: gitk:2362 gitk:8369 msgid "Create tag" msgstr "Markierung erstellen" -#: gitk:2217 gitk:7593 +#: gitk:2363 gitk:8475 msgid "Write commit to file" msgstr "Version in Datei schreiben" -#: gitk:2218 gitk:7647 +#: gitk:2364 gitk:8532 msgid "Create new branch" msgstr "Neuen Zweig erstellen" -#: gitk:2219 +#: gitk:2365 msgid "Cherry-pick this commit" msgstr "Diese Version pflücken" -#: gitk:2220 +#: gitk:2366 msgid "Reset HEAD branch to here" msgstr "HEAD-Zweig auf diese Version zurücksetzen" -#: gitk:2234 +#: gitk:2367 +msgid "Mark this commit" +msgstr "Lesezeichen setzen" + +#: gitk:2368 +msgid "Return to mark" +msgstr "Zum Lesezeichen" + +#: gitk:2369 +msgid "Find descendant of this and mark" +msgstr "Abkömmling von Lesezeichen und dieser Version finden" + +#: gitk:2370 +msgid "Compare with marked commit" +msgstr "Mit Lesezeichen vergleichen" + +#: gitk:2384 msgid "Check out this branch" msgstr "Auf diesen Zweig umstellen" -#: gitk:2235 +#: gitk:2385 msgid "Remove this branch" msgstr "Zweig löschen" -#: gitk:2242 +#: gitk:2392 msgid "Highlight this too" msgstr "Diesen auch hervorheben" -#: gitk:2243 +#: gitk:2393 msgid "Highlight this only" msgstr "Nur diesen hervorheben" -#: gitk:2244 +#: gitk:2394 msgid "External diff" -msgstr "Externer Vergleich" +msgstr "Externes Diff-Programm" -#: gitk:2255 +#: gitk:2395 msgid "Blame parent commit" msgstr "Annotieren der Elternversion" -#: gitk:2360 +#: gitk:2402 msgid "Show origin of this line" msgstr "Herkunft dieser Zeile anzeigen" -#: gitk:2361 +#: gitk:2403 msgid "Run git gui blame on this line" -msgstr "Annotieren (»git gui blame«) von dieser Zeile" +msgstr "Diese Zeile annotieren (»git gui blame«)" -#: gitk:2606 +#: gitk:2652 msgid "" "\n" "Gitk - a commit viewer for git\n" @@ -317,504 +335,552 @@ msgid "" "Use and redistribute under the terms of the GNU General Public License" msgstr "" "\n" -"Gitk - eine Visualisierung der Git Historie\n" +"Gitk - eine Visualisierung der Git-Historie\n" "\n" "Copyright © 2005-2008 Paul Mackerras\n" "\n" "Benutzung und Weiterverbreitung gemäß den Bedingungen der GNU General Public " "License" -#: gitk:2496 gitk:2557 gitk:7943 +#: gitk:2660 gitk:2722 gitk:8897 msgid "Close" msgstr "Schließen" -#: gitk:2515 +#: gitk:2679 msgid "Gitk key bindings" -msgstr "Gitk Tastaturbelegung" +msgstr "Gitk-Tastaturbelegung" -#: gitk:2517 +#: gitk:2682 msgid "Gitk key bindings:" -msgstr "Gitk Tastaturbelegung:" +msgstr "Gitk-Tastaturbelegung:" -#: gitk:2519 +#: gitk:2684 #, tcl-format msgid "<%s-Q>\t\tQuit" msgstr "<%s-Q>\t\tBeenden" -#: gitk:2520 +#: gitk:2685 msgid "<Home>\t\tMove to first commit" msgstr "<Pos1>\t\tZur neuesten Version springen" -#: gitk:2521 +#: gitk:2686 msgid "<End>\t\tMove to last commit" msgstr "<Ende>\t\tZur ältesten Version springen" -#: gitk:2522 +#: gitk:2687 msgid "<Up>, p, i\tMove up one commit" msgstr "<Hoch>, p, i\tNächste neuere Version" -#: gitk:2523 +#: gitk:2688 msgid "<Down>, n, k\tMove down one commit" msgstr "<Runter>, n, k\tNächste ältere Version" -#: gitk:2524 +#: gitk:2689 msgid "<Left>, z, j\tGo back in history list" msgstr "<Links>, z, j\tEine Version zurückgehen" -#: gitk:2525 +#: gitk:2690 msgid "<Right>, x, l\tGo forward in history list" msgstr "<Rechts>, x, l\tEine Version weitergehen" -#: gitk:2526 +#: gitk:2691 msgid "<PageUp>\tMove up one page in commit list" msgstr "<BildHoch>\tEine Seite nach oben blättern" -#: gitk:2527 +#: gitk:2692 msgid "<PageDown>\tMove down one page in commit list" msgstr "<BildRunter>\tEine Seite nach unten blättern" -#: gitk:2528 +#: gitk:2693 #, tcl-format msgid "<%s-Home>\tScroll to top of commit list" msgstr "<%s-Pos1>\tZum oberen Ende der Versionsliste blättern" -#: gitk:2529 +#: gitk:2694 #, tcl-format msgid "<%s-End>\tScroll to bottom of commit list" msgstr "<%s-Ende>\tZum unteren Ende der Versionsliste blättern" -#: gitk:2530 +#: gitk:2695 #, tcl-format msgid "<%s-Up>\tScroll commit list up one line" msgstr "<%s-Hoch>\tVersionsliste eine Zeile nach oben blättern" -#: gitk:2531 +#: gitk:2696 #, tcl-format msgid "<%s-Down>\tScroll commit list down one line" msgstr "<%s-Runter>\tVersionsliste eine Zeile nach unten blättern" -#: gitk:2532 +#: gitk:2697 #, tcl-format msgid "<%s-PageUp>\tScroll commit list up one page" -msgstr "<%s-BildHoch>\tVersionsliste eine Seite hoch blättern" +msgstr "<%s-BildHoch>\tVersionsliste eine Seite nach oben blättern" -#: gitk:2533 +#: gitk:2698 #, tcl-format msgid "<%s-PageDown>\tScroll commit list down one page" msgstr "<%s-BildRunter>\tVersionsliste eine Seite nach unten blättern" -#: gitk:2534 +#: gitk:2699 msgid "<Shift-Up>\tFind backwards (upwards, later commits)" msgstr "<Umschalt-Hoch>\tRückwärts suchen (nach oben; neuere Versionen)" -#: gitk:2535 +#: gitk:2700 msgid "<Shift-Down>\tFind forwards (downwards, earlier commits)" msgstr "<Umschalt-Runter> Suchen (nach unten; ältere Versionen)" -#: gitk:2536 +#: gitk:2701 msgid "<Delete>, b\tScroll diff view up one page" msgstr "<Entf>, b\t\tVergleich eine Seite nach oben blättern" -#: gitk:2537 +#: gitk:2702 msgid "<Backspace>\tScroll diff view up one page" msgstr "<Löschtaste>\tVergleich eine Seite nach oben blättern" -#: gitk:2538 +#: gitk:2703 msgid "<Space>\t\tScroll diff view down one page" msgstr "<Leertaste>\tVergleich eine Seite nach unten blättern" -#: gitk:2539 +#: gitk:2704 msgid "u\t\tScroll diff view up 18 lines" -msgstr "u\t\tVergleich um 18 Zeilen nach oben (»up«) blättern" +msgstr "u\t\tVergleich um 18 Zeilen nach oben blättern" -#: gitk:2540 +#: gitk:2705 msgid "d\t\tScroll diff view down 18 lines" -msgstr "d\t\tVergleich um 18 Zeilen nach unten (»down«) blättern" +msgstr "d\t\tVergleich um 18 Zeilen nach unten blättern" -#: gitk:2541 +#: gitk:2706 #, tcl-format msgid "<%s-F>\t\tFind" msgstr "<%s-F>\t\tSuchen" -#: gitk:2542 +#: gitk:2707 #, tcl-format msgid "<%s-G>\t\tMove to next find hit" msgstr "<%s-G>\t\tWeitersuchen" -#: gitk:2543 +#: gitk:2708 msgid "<Return>\tMove to next find hit" msgstr "<Eingabetaste>\tWeitersuchen" -#: gitk:2544 -msgid "/\t\tMove to next find hit, or redo find" -msgstr "/\t\tWeitersuchen oder neue Suche beginnen" +#: gitk:2709 +msgid "/\t\tFocus the search box" +msgstr "/\t\tTastaturfokus ins Suchfeld" -#: gitk:2545 +#: gitk:2710 msgid "?\t\tMove to previous find hit" msgstr "?\t\tRückwärts weitersuchen" -#: gitk:2546 +#: gitk:2711 msgid "f\t\tScroll diff view to next file" -msgstr "f\t\tVergleich zur nächsten Datei (»file«) blättern" +msgstr "f\t\tVergleich zur nächsten Datei blättern" -#: gitk:2547 +#: gitk:2712 #, tcl-format msgid "<%s-S>\t\tSearch for next hit in diff view" msgstr "<%s-S>\t\tWeitersuchen im Vergleich" -#: gitk:2548 +#: gitk:2713 #, tcl-format msgid "<%s-R>\t\tSearch for previous hit in diff view" msgstr "<%s-R>\t\tRückwärts weitersuchen im Vergleich" -#: gitk:2549 +#: gitk:2714 #, tcl-format msgid "<%s-KP+>\tIncrease font size" -msgstr "<%s-Nummerblock-Plus>\tSchriftgröße vergrößern" +msgstr "<%s-Nummerblock-Plus>\tSchrift vergrößern" -#: gitk:2550 +#: gitk:2715 #, tcl-format msgid "<%s-plus>\tIncrease font size" -msgstr "<%s-Plus>\tSchriftgröße vergrößern" +msgstr "<%s-Plus>\tSchrift vergrößern" -#: gitk:2551 +#: gitk:2716 #, tcl-format msgid "<%s-KP->\tDecrease font size" -msgstr "<%s-Nummernblock-> Schriftgröße verkleinern" +msgstr "<%s-Nummernblock-Minus> Schrift verkleinern" -#: gitk:2552 +#: gitk:2717 #, tcl-format msgid "<%s-minus>\tDecrease font size" -msgstr "<%s-Minus>\tSchriftgröße verkleinern" +msgstr "<%s-Minus>\tSchrift verkleinern" -#: gitk:2553 +#: gitk:2718 msgid "<F5>\t\tUpdate" msgstr "<F5>\t\tAktualisieren" -#: gitk:2979 +#: gitk:3173 #, tcl-format msgid "Error getting \"%s\" from %s:" msgstr "Fehler beim Holen von »%s« von »%s«:" -#: gitk:3036 gitk:3045 +#: gitk:3230 gitk:3239 #, tcl-format msgid "Error creating temporary directory %s:" -msgstr "Fehler beim Erzeugen eines temporären Verzeichnisses »%s«:" +msgstr "Fehler beim Erzeugen des temporären Verzeichnisses »%s«:" -#: gitk:3058 +#: gitk:3251 msgid "command failed:" msgstr "Kommando fehlgeschlagen:" -#: gitk:3078 +#: gitk:3397 msgid "No such commit" msgstr "Version nicht gefunden" -#: gitk:3083 +#: gitk:3411 msgid "git gui blame: command failed:" msgstr "git gui blame: Kommando fehlgeschlagen:" -#: gitk:3398 +#: gitk:3442 #, tcl-format msgid "Couldn't read merge head: %s" msgstr "Zusammenführungs-Spitze konnte nicht gelesen werden: %s" -#: gitk:3406 +#: gitk:3450 #, tcl-format msgid "Error reading index: %s" msgstr "Fehler beim Lesen der Bereitstellung (»index«): %s" -#: gitk:3431 +#: gitk:3475 #, tcl-format msgid "Couldn't start git blame: %s" msgstr "»git blame« konnte nicht gestartet werden: %s" -#: gitk:3434 gitk:6160 +#: gitk:3478 gitk:6209 msgid "Searching" msgstr "Suchen" -#: gitk:3466 +#: gitk:3510 #, tcl-format msgid "Error running git blame: %s" msgstr "Fehler beim Ausführen von »git blame«: %s" -#: gitk:3494 +#: gitk:3538 #, tcl-format msgid "That line comes from commit %s, which is not in this view" msgstr "" -"Diese Zeile stammt aus Version %s, welche nicht in dieser Ansicht gezeigt " -"wird." +"Diese Zeile stammt aus Version %s, die nicht in dieser Ansicht gezeigt wird" -#: gitk:3508 +#: gitk:3552 msgid "External diff viewer failed:" -msgstr "Externes Vergleich-(Diff-)Programm fehlgeschlagen:" +msgstr "Externes Diff-Programm fehlgeschlagen:" -#: gitk:3210 +#: gitk:3670 msgid "Gitk view definition" -msgstr "Gitk Ansichten" +msgstr "Gitk-Ansichten" -#: gitk:3630 +#: gitk:3674 msgid "Remember this view" msgstr "Diese Ansicht speichern" -#: gitk:3232 +#: gitk:3675 msgid "Commits to include (arguments to git log):" -msgstr "Versionen anzeigen (Argumente von git-log):" +msgstr "Versionen anzeigen (Argumente von git log):" -#: gitk:3632 +#: gitk:3676 msgid "Use all refs" msgstr "Alle Zweige verwenden" -#: gitk:3633 +#: gitk:3677 msgid "Strictly sort by date" msgstr "Streng nach Datum sortieren" -#: gitk:3634 +#: gitk:3678 msgid "Mark branch sides" msgstr "Zweig-Seiten markieren" -#: gitk:3635 +#: gitk:3679 msgid "Since date:" msgstr "Von Datum:" -#: gitk:3636 +#: gitk:3680 msgid "Until date:" msgstr "Bis Datum:" -#: gitk:3637 +#: gitk:3681 msgid "Max count:" msgstr "Max. Anzahl:" -#: gitk:3638 +#: gitk:3682 msgid "Skip:" msgstr "Ãœberspringen:" -#: gitk:3639 +#: gitk:3683 msgid "Limit to first parent" msgstr "Auf erste Elternversion beschränken" -#: gitk:3640 +#: gitk:3684 msgid "Command to generate more commits to include:" msgstr "Versionsliste durch folgendes Kommando erzeugen lassen:" -#: gitk:3749 +#: gitk:3780 +msgid "Gitk: edit view" +msgstr "Gitk: Ansicht bearbeiten" + +#: gitk:3793 msgid "Name" msgstr "Name" -#: gitk:3797 +#: gitk:3841 msgid "Enter files and directories to include, one per line:" msgstr "Folgende Dateien und Verzeichnisse anzeigen (eine pro Zeile):" -#: gitk:3811 +#: gitk:3855 msgid "Apply (F5)" msgstr "Anwenden (F5)" -#: gitk:3849 +#: gitk:3893 msgid "Error in commit selection arguments:" msgstr "Fehler in den ausgewählten Versionen:" -#: gitk:3347 gitk:3399 gitk:3842 gitk:3856 gitk:5060 gitk:10141 gitk:10142 +#: gitk:3946 gitk:3998 gitk:4446 gitk:4460 gitk:5721 gitk:11114 gitk:11115 msgid "None" msgstr "Keine" -#: gitk:3790 gitk:5580 gitk:7287 gitk:7302 +#: gitk:4394 gitk:6241 gitk:7993 gitk:8008 msgid "Date" msgstr "Datum" -#: gitk:3790 gitk:5580 +#: gitk:4394 gitk:6241 msgid "CDate" msgstr "Eintragedatum" -#: gitk:3939 gitk:3944 +#: gitk:4543 gitk:4548 msgid "Descendant" msgstr "Abkömmling" -#: gitk:3940 +#: gitk:4544 msgid "Not descendant" -msgstr "Nicht Abkömmling" +msgstr "Kein Abkömmling" -#: gitk:3947 gitk:3952 +#: gitk:4551 gitk:4556 msgid "Ancestor" msgstr "Vorgänger" -#: gitk:3948 +#: gitk:4552 msgid "Not ancestor" -msgstr "Nicht Vorgänger" +msgstr "Kein Vorgänger" -#: gitk:4187 +#: gitk:4842 msgid "Local changes checked in to index but not committed" msgstr "Lokale Änderungen bereitgestellt, aber nicht eingetragen" -#: gitk:4220 +#: gitk:4878 msgid "Local uncommitted changes, not checked in to index" msgstr "Lokale Änderungen, nicht bereitgestellt" -#: gitk:6673 +#: gitk:6559 +msgid "many" +msgstr "viele" + +#: gitk:6743 msgid "Tags:" msgstr "Markierungen:" -#: gitk:6066 gitk:6072 gitk:7280 +#: gitk:6760 gitk:6766 gitk:7986 msgid "Parent" msgstr "Eltern" -#: gitk:6077 +#: gitk:6771 msgid "Child" msgstr "Kind" -#: gitk:6086 +#: gitk:6780 msgid "Branch" msgstr "Zweig" -#: gitk:6089 +#: gitk:6783 msgid "Follows" msgstr "Folgt auf" -#: gitk:6092 +#: gitk:6786 msgid "Precedes" msgstr "Vorgänger von" -#: gitk:7209 +#: gitk:7279 #, tcl-format msgid "Error getting diffs: %s" msgstr "Fehler beim Laden des Vergleichs: %s" -#: gitk:7748 +#: gitk:7819 msgid "Goto:" msgstr "Gehe zu:" -#: gitk:7115 +#: gitk:7821 msgid "SHA1 ID:" msgstr "SHA1-Hashwert:" -#: gitk:7134 +#: gitk:7840 #, tcl-format msgid "Short SHA1 id %s is ambiguous" msgstr "Kurzer SHA1-Hashwert »%s« ist mehrdeutig" -#: gitk:7146 +#: gitk:7852 #, tcl-format msgid "SHA1 id %s is not known" -msgstr "SHA1-Hashwert »%s« unbekannt" +msgstr "SHA1-Hashwert »%s« ist unbekannt" -#: gitk:7148 +#: gitk:7854 #, tcl-format msgid "Tag/Head %s is not known" msgstr "Markierung/Zweig »%s« ist unbekannt" -#: gitk:7290 +#: gitk:7996 msgid "Children" msgstr "Kinder" -#: gitk:7347 +#: gitk:8053 #, tcl-format msgid "Reset %s branch to here" msgstr "Zweig »%s« hierher zurücksetzen" -#: gitk:7349 +#: gitk:8055 msgid "Detached head: can't reset" msgstr "Zweigspitze ist abgetrennt: Zurücksetzen nicht möglich" -#: gitk:7381 +#: gitk:8164 gitk:8170 +msgid "Skipping merge commit " +msgstr "Ãœberspringe Zusammenführungs-Version " + +#: gitk:8179 gitk:8184 +msgid "Error getting patch ID for " +msgstr "Fehler beim Holen der Patch-ID für " + +#: gitk:8180 gitk:8185 +msgid " - stopping\n" +msgstr " - Abbruch.\n" + +#: gitk:8190 gitk:8193 gitk:8201 gitk:8211 gitk:8220 +msgid "Commit " +msgstr "Version " + +#: gitk:8194 +msgid "" +" is the same patch as\n" +" " +msgstr "" +" ist das gleiche Patch wie\n" +" " + +#: gitk:8202 +msgid "" +" differs from\n" +" " +msgstr "" +" ist unterschiedlich von\n" +" " + +#: gitk:8204 +msgid "- stopping\n" +msgstr "- Abbruch.\n" + +#: gitk:8212 gitk:8221 +#, tcl-format +msgid " has %s children - stopping\n" +msgstr " hat %s Kinder. Abbruch\n" + +#: gitk:8252 msgid "Top" msgstr "Oben" -#: gitk:7382 +#: gitk:8253 msgid "From" msgstr "Von" -#: gitk:7387 +#: gitk:8258 msgid "To" msgstr "bis" -#: gitk:7410 +#: gitk:8282 msgid "Generate patch" msgstr "Patch erstellen" -#: gitk:7412 +#: gitk:8284 msgid "From:" msgstr "Von:" -#: gitk:7421 +#: gitk:8293 msgid "To:" msgstr "bis:" -#: gitk:7430 +#: gitk:8302 msgid "Reverse" msgstr "Umgekehrt" -#: gitk:7432 gitk:7607 +#: gitk:8304 gitk:8489 msgid "Output file:" msgstr "Ausgabedatei:" -#: gitk:7438 +#: gitk:8310 msgid "Generate" msgstr "Erzeugen" -#: gitk:7474 +#: gitk:8348 msgid "Error creating patch:" -msgstr "Fehler beim Patch erzeugen:" +msgstr "Fehler beim Erzeugen des Patches:" -#: gitk:7496 gitk:7595 gitk:7649 +#: gitk:8371 gitk:8477 gitk:8534 msgid "ID:" msgstr "ID:" -#: gitk:7505 +#: gitk:8380 msgid "Tag name:" msgstr "Markierungsname:" -#: gitk:7509 gitk:7659 +#: gitk:8384 gitk:8543 msgid "Create" msgstr "Erstellen" -#: gitk:7524 +#: gitk:8401 msgid "No tag name specified" msgstr "Kein Markierungsname angegeben" -#: gitk:7528 +#: gitk:8405 #, tcl-format msgid "Tag \"%s\" already exists" msgstr "Markierung »%s« existiert bereits." -#: gitk:7534 +#: gitk:8411 msgid "Error creating tag:" -msgstr "Fehler bei Markierung erstellen:" +msgstr "Fehler beim Erstellen der Markierung:" -#: gitk:7604 +#: gitk:8486 msgid "Command:" msgstr "Kommando:" -#: gitk:7612 +#: gitk:8494 msgid "Write" msgstr "Schreiben" -#: gitk:7628 +#: gitk:8512 msgid "Error writing commit:" msgstr "Fehler beim Schreiben der Version:" -#: gitk:7654 +#: gitk:8539 msgid "Name:" msgstr "Name:" -#: gitk:7674 +#: gitk:8562 msgid "Please specify a name for the new branch" msgstr "Bitte geben Sie einen Namen für den neuen Zweig an." -#: gitk:8328 +#: gitk:8567 #, tcl-format msgid "Branch '%s' already exists. Overwrite?" msgstr "Zweig »%s« existiert bereits. Soll er überschrieben werden?" -#: gitk:8394 +#: gitk:8633 #, tcl-format msgid "Commit %s is already included in branch %s -- really re-apply it?" msgstr "" "Version »%s« ist bereits im Zweig »%s« enthalten -- trotzdem erneut " "eintragen?" -#: gitk:7718 +#: gitk:8638 msgid "Cherry-picking" msgstr "Version pflücken" -#: gitk:8408 +#: gitk:8647 #, tcl-format msgid "" "Cherry-pick failed because of local changes to file '%s'.\n" @@ -822,45 +888,45 @@ msgid "" msgstr "" "Pflücken fehlgeschlagen, da noch lokale Änderungen in Datei »%s«\n" "vorliegen. Bitte diese Änderungen eintragen, zurücksetzen oder\n" -"zwischenspeichern (»git stash») und dann erneut versuchen." +"zwischenspeichern (»git stash«) und dann erneut versuchen." -#: gitk:8414 +#: gitk:8653 msgid "" "Cherry-pick failed because of merge conflict.\n" "Do you wish to run git citool to resolve it?" msgstr "" "Pflücken fehlgeschlagen, da ein Zusammenführungs-Konflikt aufgetreten\n" -"ist. Soll das »git citool« (Zusammenführungs-Werkzeug) aufgerufen\n" +"ist. Soll das Zusammenführungs-Werkzeug (»git citool«) aufgerufen\n" "werden, um diesen Konflikt aufzulösen?" -#: gitk:8430 +#: gitk:8669 msgid "No changes committed" msgstr "Keine Änderungen eingetragen" -#: gitk:7745 +#: gitk:8695 msgid "Confirm reset" msgstr "Zurücksetzen bestätigen" -#: gitk:7747 +#: gitk:8697 #, tcl-format msgid "Reset branch %s to %s?" msgstr "Zweig »%s« auf »%s« zurücksetzen?" -#: gitk:7751 +#: gitk:8701 msgid "Reset type:" msgstr "Art des Zurücksetzens:" -#: gitk:7755 +#: gitk:8705 msgid "Soft: Leave working tree and index untouched" msgstr "Harmlos: Arbeitskopie und Bereitstellung unverändert" -#: gitk:7758 +#: gitk:8708 msgid "Mixed: Leave working tree untouched, reset index" msgstr "" "Gemischt: Arbeitskopie unverändert,\n" "Bereitstellung zurückgesetzt" -#: gitk:7761 +#: gitk:8711 msgid "" "Hard: Reset working tree and index\n" "(discard ALL local changes)" @@ -868,21 +934,21 @@ msgstr "" "Hart: Arbeitskopie und Bereitstellung\n" "(Alle lokalen Änderungen werden gelöscht)" -#: gitk:7777 +#: gitk:8728 msgid "Resetting" msgstr "Zurücksetzen" -#: gitk:7834 +#: gitk:8785 msgid "Checking out" msgstr "Umstellen" -#: gitk:7885 +#: gitk:8838 msgid "Cannot delete the currently checked-out branch" msgstr "" "Der Zweig, auf den die Arbeitskopie momentan umgestellt ist, kann nicht " "gelöscht werden." -#: gitk:7891 +#: gitk:8844 #, tcl-format msgid "" "The commits on branch %s aren't on any other branch.\n" @@ -891,174 +957,174 @@ msgstr "" "Die Versionen auf Zweig »%s« existieren auf keinem anderen Zweig.\n" "Zweig »%s« trotzdem löschen?" -#: gitk:7922 +#: gitk:8875 #, tcl-format msgid "Tags and heads: %s" msgstr "Markierungen und Zweige: %s" -#: gitk:7936 +#: gitk:8890 msgid "Filter" msgstr "Filtern" -#: gitk:8230 +#: gitk:9185 msgid "" "Error reading commit topology information; branch and preceding/following " "tag information will be incomplete." msgstr "" -"Fehler beim Lesen der Strukturinformationen; Zweige und Vorgänger/Nachfolger " -"Informationen werden unvollständig sein." +"Fehler beim Lesen der Strukturinformationen; Zweige und Informationen zu " +"Vorgänger/Nachfolger werden unvollständig sein." -#: gitk:9216 +#: gitk:10171 msgid "Tag" msgstr "Markierung" -#: gitk:9216 +#: gitk:10171 msgid "Id" msgstr "Id" -#: gitk:9262 +#: gitk:10219 msgid "Gitk font chooser" -msgstr "Gitk Schriften wählen" +msgstr "Gitk-Schriften wählen" -#: gitk:9279 +#: gitk:10236 msgid "B" msgstr "F" -#: gitk:9282 +#: gitk:10239 msgid "I" msgstr "K" -#: gitk:9375 +#: gitk:10334 msgid "Gitk preferences" -msgstr "Gitk Einstellungen" +msgstr "Gitk-Einstellungen" -#: gitk:9376 +#: gitk:10336 msgid "Commit list display options" -msgstr "Anzeige Versionsliste" +msgstr "Anzeige der Versionsliste" -#: gitk:9379 +#: gitk:10339 msgid "Maximum graph width (lines)" msgstr "Maximale Graphenbreite (Zeilen)" -#: gitk:9383 +#: gitk:10343 #, tcl-format msgid "Maximum graph width (% of pane)" msgstr "Maximale Graphenbreite (% des Fensters)" -#: gitk:9388 +#: gitk:10347 msgid "Show local changes" msgstr "Lokale Änderungen anzeigen" -#: gitk:9393 +#: gitk:10350 msgid "Auto-select SHA1" -msgstr "SHA1-Hashwert automatisch markieren" +msgstr "SHA1-Hashwert automatisch auswählen" -#: gitk:9398 +#: gitk:10354 msgid "Diff display options" -msgstr "Anzeige Vergleich" +msgstr "Anzeige des Vergleichs" -#: gitk:9400 +#: gitk:10356 msgid "Tab spacing" msgstr "Tabulatorbreite" -#: gitk:9404 +#: gitk:10359 msgid "Display nearby tags" -msgstr "Naheliegende Ãœberschriften anzeigen" +msgstr "Naheliegende Markierungen anzeigen" -#: gitk:9409 +#: gitk:10362 msgid "Limit diffs to listed paths" msgstr "Vergleich nur für angezeigte Pfade" -#: gitk:9414 +#: gitk:10365 msgid "Support per-file encodings" msgstr "Zeichenkodierung pro Datei ermitteln" -#: gitk:9421 +#: gitk:10371 gitk:10436 msgid "External diff tool" -msgstr "Externes Vergleich-(Diff-)Programm" +msgstr "Externes Diff-Programm" -#: gitk:9423 +#: gitk:10373 msgid "Choose..." -msgstr "Wählen..." +msgstr "Wählen ..." -#: gitk:9428 +#: gitk:10378 msgid "Colors: press to choose" msgstr "Farben: Klicken zum Wählen" -#: gitk:9431 +#: gitk:10381 msgid "Background" msgstr "Hintergrund" -#: gitk:10153 gitk:10183 +#: gitk:10382 gitk:10412 msgid "background" msgstr "Hintergrund" -#: gitk:10156 +#: gitk:10385 msgid "Foreground" msgstr "Vordergrund" -#: gitk:10157 +#: gitk:10386 msgid "foreground" msgstr "Vordergrund" -#: gitk:10160 +#: gitk:10389 msgid "Diff: old lines" msgstr "Vergleich: Alte Zeilen" -#: gitk:10161 +#: gitk:10390 msgid "diff old lines" msgstr "Vergleich - Alte Zeilen" -#: gitk:10165 +#: gitk:10394 msgid "Diff: new lines" msgstr "Vergleich: Neue Zeilen" -#: gitk:10166 +#: gitk:10395 msgid "diff new lines" msgstr "Vergleich - Neue Zeilen" -#: gitk:10170 +#: gitk:10399 msgid "Diff: hunk header" msgstr "Vergleich: Änderungstitel" -#: gitk:10172 +#: gitk:10401 msgid "diff hunk header" msgstr "Vergleich - Änderungstitel" -#: gitk:10176 +#: gitk:10405 msgid "Marked line bg" -msgstr "Markierte Zeile Hintergrund" +msgstr "Hintergrund für markierte Zeile" -#: gitk:10178 +#: gitk:10407 msgid "marked line background" -msgstr "markierte Zeile Hintergrund" +msgstr "Hintergrund für markierte Zeile" -#: gitk:10182 +#: gitk:10411 msgid "Select bg" -msgstr "Hintergrundfarbe Auswählen" +msgstr "Hintergrundfarbe auswählen" -#: gitk:9459 +#: gitk:10415 msgid "Fonts: press to choose" msgstr "Schriftart: Klicken zum Wählen" -#: gitk:9461 +#: gitk:10417 msgid "Main font" msgstr "Programmschriftart" -#: gitk:9462 +#: gitk:10418 msgid "Diff display font" -msgstr "Vergleich" +msgstr "Schriftart für Vergleich" -#: gitk:9463 +#: gitk:10419 msgid "User interface font" msgstr "Beschriftungen" -#: gitk:9488 +#: gitk:10446 #, tcl-format msgid "Gitk: choose color for %s" msgstr "Gitk: Farbe wählen für %s" -#: gitk:9934 +#: gitk:10893 msgid "" "Sorry, gitk cannot run with this version of Tcl/Tk.\n" " Gitk requires at least Tcl/Tk 8.4." @@ -1066,24 +1132,24 @@ msgstr "" "Gitk läuft nicht mit dieser Version von Tcl/Tk.\n" "Gitk benötigt mindestens Tcl/Tk 8.4." -#: gitk:10047 +#: gitk:11020 msgid "Cannot find a git repository here." msgstr "Kein Git-Projektarchiv gefunden." -#: gitk:10051 +#: gitk:11024 #, tcl-format msgid "Cannot find the git directory \"%s\"." msgstr "Git-Verzeichnis »%s« wurde nicht gefunden." -#: gitk:10098 +#: gitk:11071 #, tcl-format msgid "Ambiguous argument '%s': both revision and filename" msgstr "Mehrdeutige Angabe »%s«: Sowohl Version als auch Dateiname existiert." -#: gitk:10110 +#: gitk:11083 msgid "Bad arguments to gitk:" msgstr "Falsche Kommandozeilen-Parameter für gitk:" -#: gitk:10170 +#: gitk:11167 msgid "Command line" msgstr "Kommandozeile" diff --git a/gitweb/README b/gitweb/README index 9056d1e090..66c6a9391d 100644 --- a/gitweb/README +++ b/gitweb/README @@ -165,6 +165,12 @@ not include variables usually directly set during build): Full URL and absolute URL of gitweb script; in earlier versions of gitweb you might have need to set those variables, now there should be no need to do it. + * $base_url + Base URL for relative URLs in pages generated by gitweb, + (e.g. $logo, $favicon, @stylesheets if they are relative URLs), + needed and used only for URLs with nonempty PATH_INFO via + <base href="$base_url>. Usually gitweb sets its value correctly, + and there is no need to set this variable, e.g. to $my_uri or "/". * $home_link Target of the home link on top of all pages (the first part of view "breadcrumbs"). By default set to absolute URI of a page ($my_uri). diff --git a/gitweb/gitweb.css b/gitweb/gitweb.css index a01eac814e..d05bc37646 100644 --- a/gitweb/gitweb.css +++ b/gitweb/gitweb.css @@ -28,6 +28,10 @@ img.logo { border-width: 0px; } +img.avatar { + vertical-align: middle; +} + div.page_header { height: 25px; padding: 8px; @@ -132,11 +136,14 @@ div.list_head { font-style: italic; } +.author_date, .author { + font-style: italic; +} + div.author_date { padding: 8px; border: solid #d9d8d1; border-width: 0px 0px 1px 0px; - font-style: italic; } a.list { diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index 3f99361ed0..2cb832753a 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -94,7 +94,7 @@ our $favicon = "++GITWEB_FAVICON++"; # URI and label (title) of GIT logo link #our $logo_url = "http://www.kernel.org/pub/software/scm/git/docs/"; #our $logo_label = "git documentation"; -our $logo_url = "http://git.or.cz/"; +our $logo_url = "http://git-scm.com/"; our $logo_label = "git homepage"; # source of projects list @@ -195,6 +195,14 @@ our %known_snapshot_format_aliases = ( 'x-zip' => undef, '' => undef, ); +# Pixel sizes for icons and avatars. If the default font sizes or lineheights +# are changed, it may be appropriate to change these values too via +# $GITWEB_CONFIG. +our %avatar_size = ( + 'default' => 16, + 'double' => 32 +); + # You define site-wide feature defaults here; override them with # $GITWEB_CONFIG as necessary. our %feature = ( @@ -365,6 +373,27 @@ our %feature = ( 'sub' => \&feature_patches, 'override' => 0, 'default' => [16]}, + + # Avatar support. When this feature is enabled, views such as + # shortlog or commit will display an avatar associated with + # the email of the committer(s) and/or author(s). + + # Currently available providers are gravatar and picon. + # If an unknown provider is specified, the feature is disabled. + + # Gravatar depends on Digest::MD5. + # Picon currently relies on the indiana.edu database. + + # To enable system wide have in $GITWEB_CONFIG + # $feature{'avatar'}{'default'} = ['<provider>']; + # where <provider> is either gravatar or picon. + # To have project specific config enable override in $GITWEB_CONFIG + # $feature{'avatar'}{'override'} = 1; + # and in project config gitweb.avatar = <provider>; + 'avatar' => { + 'sub' => \&feature_avatar, + 'override' => 0, + 'default' => ['']}, ); sub gitweb_get_feature { @@ -376,7 +405,7 @@ sub gitweb_get_feature { @{$feature{$name}{'default'}}); if (!$override) { return @defaults; } if (!defined $sub) { - warn "feature $name is not overrideable"; + warn "feature $name is not overridable"; return @defaults; } return $sub->(@defaults); @@ -433,6 +462,12 @@ sub feature_patches { return ($_[0]); } +sub feature_avatar { + my @val = (git_get_project_config('avatar')); + + return @val ? @val : @_; +} + # checking HEAD file with -e is fragile if the repository was # initialized long time ago (i.e. symlink HEAD) and was pack-ref'ed # and then pruned. @@ -458,8 +493,8 @@ sub filter_snapshot_fmts { @fmts = map { exists $known_snapshot_format_aliases{$_} ? $known_snapshot_format_aliases{$_} : $_} @fmts; - @fmts = grep(exists $known_snapshot_formats{$_}, @fmts); - + @fmts = grep { + exists $known_snapshot_formats{$_} } @fmts; } our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++"; @@ -690,9 +725,10 @@ sub evaluate_path_info { # format key itself, with a prepended dot while (my ($fmt, $opt) = each %known_snapshot_formats) { my $hash = $refname; - my $sfx; - $hash =~ s/(\Q$opt->{'suffix'}\E|\Q.$fmt\E)$//; - next unless $sfx = $1; + unless ($hash =~ s/(\Q$opt->{'suffix'}\E|\Q.$fmt\E)$//) { + next; + } + my $sfx = $1; # a valid suffix was found, so set the snapshot format # and reset the hash parameter $input_params{'snapshot_format'} = $fmt; @@ -813,6 +849,19 @@ $git_dir = "$projectroot/$project" if $project; our @snapshot_fmts = gitweb_get_feature('snapshot'); @snapshot_fmts = filter_snapshot_fmts(@snapshot_fmts); +# check that the avatar feature is set to a known provider name, +# and for each provider check if the dependencies are satisfied. +# if the provider name is invalid or the dependencies are not met, +# reset $git_avatar to the empty string. +our ($git_avatar) = gitweb_get_feature('avatar'); +if ($git_avatar eq 'gravatar') { + $git_avatar = '' unless (eval { require Digest::MD5; 1; }); +} elsif ($git_avatar eq 'picon') { + # no dependencies +} else { + $git_avatar = ''; +} + # dispatch if (!defined $action) { if (defined $hash) { @@ -828,7 +877,7 @@ if (!defined $action) { if (!defined($actions{$action})) { die_error(400, "Unknown action"); } -if ($action !~ m/^(opml|project_list|project_index)$/ && +if ($action !~ m/^(?:opml|project_list|project_index)$/ && !$project) { die_error(400, "Project needed"); } @@ -838,7 +887,7 @@ exit; ## ====================================================================== ## action links -sub href (%) { +sub href { my %params = @_; # default is to use -absolute url() i.e. $my_uri my $href = $params{-full} ? $my_url : $my_uri; @@ -1036,7 +1085,7 @@ sub esc_url { } # replace invalid utf8 character with SUBSTITUTION sequence -sub esc_html ($;%) { +sub esc_html { my $str = shift; my %opts = @_; @@ -1235,7 +1284,7 @@ sub chop_and_escape_str { if ($chopped eq $str) { return esc_html($chopped); } else { - $str =~ s/([[:cntrl:]])/?/g; + $str =~ s/[[:cntrl:]]/?/g; return $cgi->span({-title=>$str}, esc_html($chopped)); } } @@ -1296,7 +1345,7 @@ use constant { }; # submodule/subproject, a commit object reference -sub S_ISGITLINK($) { +sub S_ISGITLINK { my $mode = shift; return (($mode & S_IFMT) == S_IFGITLINK) @@ -1458,6 +1507,7 @@ sub format_subject_html { $extra = '' unless defined($extra); if (length($short) < length($long)) { + $long =~ s/[[:cntrl:]]/?/g; return $cgi->a({-href => $href, -class => "list subject", -title => to_utf8($long)}, esc_html($short) . $extra); @@ -1467,6 +1517,82 @@ sub format_subject_html { } } +# Rather than recomputing the url for an email multiple times, we cache it +# after the first hit. This gives a visible benefit in views where the avatar +# for the same email is used repeatedly (e.g. shortlog). +# The cache is shared by all avatar engines (currently gravatar only), which +# are free to use it as preferred. Since only one avatar engine is used for any +# given page, there's no risk for cache conflicts. +our %avatar_cache = (); + +# Compute the picon url for a given email, by using the picon search service over at +# http://www.cs.indiana.edu/picons/search.html +sub picon_url { + my $email = lc shift; + if (!$avatar_cache{$email}) { + my ($user, $domain) = split('@', $email); + $avatar_cache{$email} = + "http://www.cs.indiana.edu/cgi-pub/kinzler/piconsearch.cgi/" . + "$domain/$user/" . + "users+domains+unknown/up/single"; + } + return $avatar_cache{$email}; +} + +# Compute the gravatar url for a given email, if it's not in the cache already. +# Gravatar stores only the part of the URL before the size, since that's the +# one computationally more expensive. This also allows reuse of the cache for +# different sizes (for this particular engine). +sub gravatar_url { + my $email = lc shift; + my $size = shift; + $avatar_cache{$email} ||= + "http://www.gravatar.com/avatar/" . + Digest::MD5::md5_hex($email) . "?s="; + return $avatar_cache{$email} . $size; +} + +# Insert an avatar for the given $email at the given $size if the feature +# is enabled. +sub git_get_avatar { + my ($email, %opts) = @_; + my $pre_white = ($opts{-pad_before} ? " " : ""); + my $post_white = ($opts{-pad_after} ? " " : ""); + $opts{-size} ||= 'default'; + my $size = $avatar_size{$opts{-size}} || $avatar_size{'default'}; + my $url = ""; + if ($git_avatar eq 'gravatar') { + $url = gravatar_url($email, $size); + } elsif ($git_avatar eq 'picon') { + $url = picon_url($email); + } + # Other providers can be added by extending the if chain, defining $url + # as needed. If no variant puts something in $url, we assume avatars + # are completely disabled/unavailable. + if ($url) { + return $pre_white . + "<img width=\"$size\" " . + "class=\"avatar\" " . + "src=\"$url\" " . + "alt=\"\" " . + "/>" . $post_white; + } else { + return ""; + } +} + +# format the author name of the given commit with the given tag +# the author name is chopped and escaped according to the other +# optional parameters (see chop_str). +sub format_author_html { + my $tag = shift; + my $co = shift; + my $author = chop_and_escape_str($co->{'author_name'}, @_); + return "<$tag class=\"author\">" . + git_get_avatar($co->{'author_email'}, -pad_after => 1) . + $author . "</$tag>"; +} + # format git diff header line, i.e. "diff --(git|combined|cc) ..." sub format_git_diff_header_line { my $line = shift; @@ -1838,7 +1964,7 @@ sub git_cmd { # Try to avoid using this function wherever possible. sub quote_command { return join(' ', - map( { my $a = $_; $a =~ s/(['!])/'\\$1'/g; "'$a'" } @_ )); + map { my $a = $_; $a =~ s/(['!])/'\\$1'/g; "'$a'" } @_ ); } # get HEAD ref of given project as hash @@ -2050,7 +2176,7 @@ sub git_get_project_description { my $path = shift; $git_dir = "$projectroot/$path"; - open my $fd, "$git_dir/description" + open my $fd, '<', "$git_dir/description" or return git_get_project_config('description'); my $descr = <$fd>; close $fd; @@ -2065,18 +2191,17 @@ sub git_get_project_ctags { my $ctags = {}; $git_dir = "$projectroot/$path"; - unless (opendir D, "$git_dir/ctags") { - return $ctags; - } - foreach (grep { -f $_ } map { "$git_dir/ctags/$_" } readdir(D)) { - open CT, $_ or next; - my $val = <CT>; + opendir my $dh, "$git_dir/ctags" + or return $ctags; + foreach (grep { -f $_ } map { "$git_dir/ctags/$_" } readdir($dh)) { + open my $ct, '<', $_ or next; + my $val = <$ct>; chomp $val; - close CT; + close $ct; my $ctag = $_; $ctag =~ s#.*/##; $ctags->{$ctag} = $val; } - closedir D; + closedir $dh; $ctags; } @@ -2129,7 +2254,7 @@ sub git_get_project_url_list { my $path = shift; $git_dir = "$projectroot/$path"; - open my $fd, "$git_dir/cloneurl" + open my $fd, '<', "$git_dir/cloneurl" or return wantarray ? @{ config_to_multi(git_get_project_config('url')) } : config_to_multi(git_get_project_config('url')); @@ -2187,7 +2312,7 @@ sub git_get_projects_list { # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin' # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman' my %paths; - open my ($fd), $projects_list or return; + open my $fd, '<', $projects_list or return; PROJECT: while (my $line = <$fd>) { chomp $line; @@ -2250,7 +2375,7 @@ sub git_get_project_list_from_file { # 'libs%2Fklibc%2Fklibc.git H.+Peter+Anvin' # 'linux%2Fhotplug%2Fudev.git Greg+Kroah-Hartman' if (-f $projects_list) { - open (my $fd , $projects_list); + open(my $fd, '<', $projects_list); while (my $line = <$fd>) { chomp $line; my ($pr, $ow) = split ' ', $line; @@ -2398,8 +2523,14 @@ sub parse_tag { $tag{'name'} = $1; } elsif ($line =~ m/^tagger (.*) ([0-9]+) (.*)$/) { $tag{'author'} = $1; - $tag{'epoch'} = $2; - $tag{'tz'} = $3; + $tag{'author_epoch'} = $2; + $tag{'author_tz'} = $3; + if ($tag{'author'} =~ m/^([^<]+) <([^>]*)>/) { + $tag{'author_name'} = $1; + $tag{'author_email'} = $2; + } else { + $tag{'author_name'} = $tag{'author'}; + } } elsif ($line =~ m/--BEGIN/) { push @comment, $line; last; @@ -2439,7 +2570,7 @@ sub parse_commit_text { } elsif ((!defined $withparents) && ($line =~ m/^parent ([0-9a-fA-F]{40})$/)) { push @parents, $1; } elsif ($line =~ m/^author (.*) ([0-9]+) (.*)$/) { - $co{'author'} = $1; + $co{'author'} = to_utf8($1); $co{'author_epoch'} = $2; $co{'author_tz'} = $3; if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) { @@ -2449,10 +2580,9 @@ sub parse_commit_text { $co{'author_name'} = $co{'author'}; } } elsif ($line =~ m/^committer (.*) ([0-9]+) (.*)$/) { - $co{'committer'} = $1; + $co{'committer'} = to_utf8($1); $co{'committer_epoch'} = $2; $co{'committer_tz'} = $3; - $co{'committer_name'} = $co{'committer'}; if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) { $co{'committer_name'} = $1; $co{'committer_email'} = $2; @@ -2615,7 +2745,7 @@ sub parsed_difftree_line { } # parse line of git-ls-tree output -sub parse_ls_tree_line ($;%) { +sub parse_ls_tree_line { my $line = shift; my %opts = @_; my %res; @@ -2804,18 +2934,18 @@ sub mimetype_guess_file { -r $mimemap or return undef; my %mimemap; - open(MIME, $mimemap) or return undef; - while (<MIME>) { + open(my $mh, '<', $mimemap) or return undef; + while (<$mh>) { next if m/^#/; # skip comments - my ($mime, $exts) = split(/\t+/); + my ($mimetype, $exts) = split(/\t+/); if (defined $exts) { my @exts = split(/\s+/, $exts); foreach my $ext (@exts) { - $mimemap{$ext} = $mime; + $mimemap{$ext} = $mimetype; } } } - close(MIME); + close($mh); $filename =~ /\.([^.]*)$/; return $mimemap{$1}; @@ -3213,22 +3343,54 @@ sub git_print_header_div { "\n</div>\n"; } -#sub git_print_authorship (\%) { +sub print_local_time { + my %date = @_; + if ($date{'hour_local'} < 6) { + printf(" (<span class=\"atnight\">%02d:%02d</span> %s)", + $date{'hour_local'}, $date{'minute_local'}, $date{'tz_local'}); + } else { + printf(" (%02d:%02d %s)", + $date{'hour_local'}, $date{'minute_local'}, $date{'tz_local'}); + } +} + +# Outputs the author name and date in long form sub git_print_authorship { my $co = shift; + my %opts = @_; + my $tag = $opts{-tag} || 'div'; my %ad = parse_date($co->{'author_epoch'}, $co->{'author_tz'}); - print "<div class=\"author_date\">" . + print "<$tag class=\"author_date\">" . esc_html($co->{'author_name'}) . " [$ad{'rfc2822'}"; - if ($ad{'hour_local'} < 6) { - printf(" (<span class=\"atnight\">%02d:%02d</span> %s)", - $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}); - } else { - printf(" (%02d:%02d %s)", - $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}); + print_local_time(%ad) if ($opts{-localtime}); + print "]" . git_get_avatar($co->{'author_email'}, -pad_before => 1) + . "</$tag>\n"; +} + +# Outputs table rows containing the full author or committer information, +# in the format expected for 'commit' view (& similia). +# Parameters are a commit hash reference, followed by the list of people +# to output information for. If the list is empty it defalts to both +# author and committer. +sub git_print_authorship_rows { + my $co = shift; + # too bad we can't use @people = @_ || ('author', 'committer') + my @people = @_; + @people = ('author', 'committer') unless @people; + foreach my $who (@people) { + my %wd = parse_date($co->{"${who}_epoch"}, $co->{"${who}_tz"}); + print "<tr><td>$who</td><td>" . esc_html($co->{$who}) . "</td>" . + "<td rowspan=\"2\">" . + git_get_avatar($co->{"${who}_email"}, -size => 'double') . + "</td></tr>\n" . + "<tr>" . + "<td></td><td> $wd{'rfc2822'}"; + print_local_time(%wd); + print "</td>" . + "</tr>\n"; } - print "]</div>\n"; } sub git_print_page_path { @@ -3269,8 +3431,7 @@ sub git_print_page_path { print "<br/></div>\n"; } -# sub git_print_log (\@;%) { -sub git_print_log ($;%) { +sub git_print_log { my $log = shift; my %opts = @_; @@ -3328,7 +3489,7 @@ sub git_get_link_target { open my $fd, "-|", git_cmd(), "cat-file", "blob", $hash or return; { - local $/; + local $/ = undef; $link_target = <$fd>; } close $fd @@ -3341,10 +3502,7 @@ sub git_get_link_target { # return target of link relative to top directory (top tree); # return undef if it is not possible (including absolute links). sub normalize_link_target { - my ($link_target, $basedir, $hash_base) = @_; - - # we can normalize symlink target only if $hash_base is provided - return unless $hash_base; + my ($link_target, $basedir) = @_; # absolute symlinks (beginning with '/') cannot be normalized return if (substr($link_target, 0, 1) eq '/'); @@ -3400,7 +3558,7 @@ sub git_print_tree_entry { if (S_ISLNK(oct $t->{'mode'})) { my $link_target = git_get_link_target($t->{'hash'}); if ($link_target) { - my $norm_target = normalize_link_target($link_target, $basedir, $hash_base); + my $norm_target = normalize_link_target($link_target, $basedir); if (defined $norm_target) { print " -> " . $cgi->a({-href => href(action=>"object", hash_base=>$hash_base, @@ -3993,7 +4151,7 @@ sub fill_project_list_info { ($pname !~ /\/$/) && (-d "$projectroot/$pname")) { $pr->{'forks'} = "-d $projectroot/$pname"; - } else { + } else { $pr->{'forks'} = 0; } } @@ -4146,11 +4304,9 @@ sub git_shortlog_body { print "<tr class=\"light\">\n"; } $alternate ^= 1; - my $author = chop_and_escape_str($co{'author_name'}, 10); # git_summary() used print "<td><i>$co{'age_string'}</i></td>\n" . print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" . - "<td><i>" . $author . "</i></td>\n" . - "<td>"; + format_author_html('td', \%co, 10) . "<td>"; print format_subject_html($co{'title'}, $co{'title_short'}, href(action=>"commit", hash=>$commit), $ref); print "</td>\n" . @@ -4197,11 +4353,9 @@ sub git_history_body { print "<tr class=\"light\">\n"; } $alternate ^= 1; - # shortlog uses chop_str($co{'author_name'}, 10) - my $author = chop_and_escape_str($co{'author_name'}, 15, 3); print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" . - "<td><i>" . $author . "</i></td>\n" . - "<td>"; + # shortlog: format_author_html('td', \%co, 10) + format_author_html('td', \%co, 15, 3) . "<td>"; # originally git_history used chop_str($co{'title'}, 50) print format_subject_html($co{'title'}, $co{'title_short'}, href(action=>"commit", hash=>$commit), $ref); @@ -4354,9 +4508,8 @@ sub git_search_grep_body { print "<tr class=\"light\">\n"; } $alternate ^= 1; - my $author = chop_and_escape_str($co{'author_name'}, 15, 5); print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" . - "<td><i>" . $author . "</i></td>\n" . + format_author_html('td', \%co, 15, 5) . "<td>" . $cgi->a({-href => href(action=>"commit", hash=>$co{'id'}), -class => "list subject"}, @@ -4590,11 +4743,7 @@ sub git_tag { $tag{'type'}) . "</td>\n" . "</tr>\n"; if (defined($tag{'author'})) { - my %ad = parse_date($tag{'epoch'}, $tag{'tz'}); - print "<tr><td>author</td><td>" . esc_html($tag{'author'}) . "</td></tr>\n"; - print "<tr><td></td><td>" . $ad{'rfc2822'} . - sprintf(" (%02d:%02d %s)", $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}) . - "</td></tr>\n"; + git_print_authorship_rows(\%tag, 'author'); } print "</table>\n\n" . "</div>\n"; @@ -4803,11 +4952,10 @@ sub git_blob_plain { -content_disposition => ($sandbox ? 'attachment' : 'inline') . '; filename="' . $save_as . '"'); - undef $/; + local $/ = undef; binmode STDOUT, ':raw'; print <$fd>; binmode STDOUT, ':utf8'; # as set at the beginning of gitweb.cgi - $/ = "\n"; close $fd; } @@ -4909,12 +5057,16 @@ sub git_tree { } } die_error(404, "No such tree") unless defined($hash); - $/ = "\0"; - open my $fd, "-|", git_cmd(), "ls-tree", '-z', $hash - or die_error(500, "Open git-ls-tree failed"); - my @entries = map { chomp; $_ } <$fd>; - close $fd or die_error(404, "Reading tree failed"); - $/ = "\n"; + + my @entries = (); + { + local $/ = "\0"; + open my $fd, "-|", git_cmd(), "ls-tree", '-z', $hash + or die_error(500, "Open git-ls-tree failed"); + @entries = map { chomp; $_ } <$fd>; + close $fd + or die_error(404, "Reading tree failed"); + } my $refs = git_get_references(); my $ref = format_ref_marker($refs, $hash_base); @@ -5095,9 +5247,9 @@ sub git_log { " | " . $cgi->a({-href => href(action=>"tree", hash=>$commit, hash_base=>$commit)}, "tree") . "<br/>\n" . - "</div>\n" . - "<i>" . esc_html($co{'author_name'}) . " [$ad{'rfc2822'}]</i><br/>\n" . "</div>\n"; + git_print_authorship(\%co, -tag => 'span'); + print "<br/>\n</div>\n"; print "<div class=\"log_body\">\n"; git_print_log($co{'comment'}, -final_empty_line=> 1); @@ -5116,8 +5268,6 @@ sub git_commit { $hash ||= $hash_base || "HEAD"; my %co = parse_commit($hash) or die_error(404, "Unknown commit object"); - my %ad = parse_date($co{'author_epoch'}, $co{'author_tz'}); - my %cd = parse_date($co{'committer_epoch'}, $co{'committer_tz'}); my $parent = $co{'parent'}; my $parents = $co{'parents'}; # listref @@ -5184,22 +5334,7 @@ sub git_commit { } print "<div class=\"title_text\">\n" . "<table class=\"object_header\">\n"; - print "<tr><td>author</td><td>" . esc_html($co{'author'}) . "</td></tr>\n". - "<tr>" . - "<td></td><td> $ad{'rfc2822'}"; - if ($ad{'hour_local'} < 6) { - printf(" (<span class=\"atnight\">%02d:%02d</span> %s)", - $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}); - } else { - printf(" (%02d:%02d %s)", - $ad{'hour_local'}, $ad{'minute_local'}, $ad{'tz_local'}); - } - print "</td>" . - "</tr>\n"; - print "<tr><td>committer</td><td>" . esc_html($co{'committer'}) . "</td></tr>\n"; - print "<tr><td></td><td> $cd{'rfc2822'}" . - sprintf(" (%02d:%02d %s)", $cd{'hour_local'}, $cd{'minute_local'}, $cd{'tz_local'}) . - "</td></tr>\n"; + git_print_authorship_rows(\%co); print "<tr><td>commit</td><td class=\"sha1\">$co{'id'}</td></tr>\n"; print "<tr>" . "<td>tree</td>" . @@ -5580,7 +5715,11 @@ sub git_commitdiff { git_header_html(undef, $expires); git_print_page_nav('commitdiff','', $hash,$co{'tree'},$hash, $formats_nav); git_print_header_div('commit', esc_html($co{'title'}) . $ref, $hash); - git_print_authorship(\%co); + print "<div class=\"title_text\">\n" . + "<table class=\"object_header\">\n"; + git_print_authorship_rows(\%co); + print "</table>". + "</div>\n"; print "<div class=\"page_body\">\n"; if (@{$co{'comment'}} > 1) { print "<div class=\"log\">\n"; @@ -5809,7 +5948,7 @@ sub git_search { print "<table class=\"pickaxe search\">\n"; my $alternate = 1; - $/ = "\n"; + local $/ = "\n"; open my $fd, '-|', git_cmd(), '--no-pager', 'log', @diff_opts, '--pretty=format:%H', '--no-abbrev', '--raw', "-S$searchtext", ($search_use_regexp ? '--pickaxe-regex' : ()); @@ -5879,7 +6018,7 @@ sub git_search { print "<table class=\"grep_search\">\n"; my $alternate = 1; my $matches = 0; - $/ = "\n"; + local $/ = "\n"; open my $fd, "-|", git_cmd(), 'grep', '-n', $search_use_regexp ? ('-E', '-i') : '-F', $searchtext, $co{'tree'}; @@ -6282,7 +6421,7 @@ XML # end of feed if ($format eq 'rss') { print "</channel>\n</rss>\n"; - } elsif ($format eq 'atom') { + } elsif ($format eq 'atom') { print "</feed>\n"; } } @@ -47,20 +47,6 @@ static void graph_show_strbuf(struct git_graph *graph, struct strbuf const *sb); * - Limit the number of columns, similar to the way gitk does. * If we reach more than a specified number of columns, omit * sections of some columns. - * - * - The output during the GRAPH_PRE_COMMIT and GRAPH_COLLAPSING states - * could be made more compact by printing horizontal lines, instead of - * long diagonal lines. For example, during collapsing, something like - * this: instead of this: - * | | | | | | | | | | - * | |_|_|/ | | | |/ - * |/| | | | | |/| - * | | | | | |/| | - * |/| | | - * | | | | - * - * If there are several parallel diagonal lines, they will need to be - * replaced with horizontal lines on subsequent rows. */ struct column { @@ -907,7 +893,7 @@ static struct column *find_new_column_by_commit(struct git_graph *graph, if (graph->new_columns[i].commit == commit) return &graph->new_columns[i]; } - return 0; + return NULL; } static void graph_output_post_merge_line(struct git_graph *graph, struct strbuf *sb) @@ -982,6 +968,9 @@ static void graph_output_collapsing_line(struct git_graph *graph, struct strbuf { int i; int *tmp_mapping; + short used_horizontal = 0; + int horizontal_edge = -1; + int horizontal_edge_target = -1; /* * Clear out the new_mapping array @@ -1019,6 +1008,23 @@ static void graph_output_collapsing_line(struct git_graph *graph, struct strbuf * Move to the left by one */ graph->new_mapping[i - 1] = target; + /* + * If there isn't already an edge moving horizontally + * select this one. + */ + if (horizontal_edge == -1) { + int j; + horizontal_edge = i; + horizontal_edge_target = target; + /* + * The variable target is the index of the graph + * column, and therefore target*2+3 is the + * actual screen column of the first horizontal + * line. + */ + for (j = (target * 2)+3; j < (i - 2); j += 2) + graph->new_mapping[j] = target; + } } else if (graph->new_mapping[i - 1] == target) { /* * There is a branch line to our left @@ -1039,10 +1045,21 @@ static void graph_output_collapsing_line(struct git_graph *graph, struct strbuf * * The space just to the left of this * branch should always be empty. + * + * The branch to the left of that space + * should be our eventual target. */ assert(graph->new_mapping[i - 1] > target); assert(graph->new_mapping[i - 2] < 0); + assert(graph->new_mapping[i - 3] == target); graph->new_mapping[i - 2] = target; + /* + * Mark this branch as the horizontal edge to + * prevent any other edges from moving + * horizontally. + */ + if (horizontal_edge == -1) + horizontal_edge = i; } } @@ -1061,8 +1078,23 @@ static void graph_output_collapsing_line(struct git_graph *graph, struct strbuf strbuf_addch(sb, ' '); else if (target * 2 == i) strbuf_write_column(sb, &graph->new_columns[target], '|'); - else + else if (target == horizontal_edge_target && + i != horizontal_edge - 1) { + /* + * Set the mappings for all but the + * first segment to -1 so that they + * won't continue into the next line. + */ + if (i != (target * 2)+3) + graph->new_mapping[i] = -1; + used_horizontal = 1; + strbuf_write_column(sb, &graph->new_columns[target], '_'); + } else { + if (used_horizontal && i < horizontal_edge) + graph->new_mapping[i] = -1; strbuf_write_column(sb, &graph->new_columns[target], '/'); + + } } graph_pad_horizontally(graph, sb, graph->mapping_size); @@ -1,5 +1,6 @@ #include "cache.h" #include "grep.h" +#include "userdiff.h" #include "xdiff-interface.h" void append_header_grep_pattern(struct grep_opt *opt, enum grep_header_field field, const char *pat) @@ -490,6 +491,17 @@ static void show_line(struct grep_opt *opt, char *bol, char *eol, { int rest = eol - bol; + if (opt->pre_context || opt->post_context) { + if (opt->last_shown == 0) { + if (opt->show_hunk_mark) + fputs("--\n", stdout); + else + opt->show_hunk_mark = 1; + } else if (lno > opt->last_shown + 1) + fputs("--\n", stdout); + } + opt->last_shown = lno; + if (opt->null_following_name) sign = '\0'; if (opt->pathname) @@ -520,22 +532,95 @@ static void show_line(struct grep_opt *opt, char *bol, char *eol, printf("%.*s\n", rest, bol); } +static int match_funcname(struct grep_opt *opt, char *bol, char *eol) +{ + xdemitconf_t *xecfg = opt->priv; + if (xecfg && xecfg->find_func) { + char buf[1]; + return xecfg->find_func(bol, eol - bol, buf, 1, + xecfg->find_func_priv) >= 0; + } + + if (bol == eol) + return 0; + if (isalpha(*bol) || *bol == '_' || *bol == '$') + return 1; + return 0; +} + +static void show_funcname_line(struct grep_opt *opt, const char *name, + char *buf, char *bol, unsigned lno) +{ + while (bol > buf) { + char *eol = --bol; + + while (bol > buf && bol[-1] != '\n') + bol--; + lno--; + + if (lno <= opt->last_shown) + break; + + if (match_funcname(opt, bol, eol)) { + show_line(opt, bol, eol, name, lno, '='); + break; + } + } +} + +static void show_pre_context(struct grep_opt *opt, const char *name, char *buf, + char *bol, unsigned lno) +{ + unsigned cur = lno, from = 1, funcname_lno = 0; + int funcname_needed = opt->funcname; + + if (opt->pre_context < lno) + from = lno - opt->pre_context; + if (from <= opt->last_shown) + from = opt->last_shown + 1; + + /* Rewind. */ + while (bol > buf && cur > from) { + char *eol = --bol; + + while (bol > buf && bol[-1] != '\n') + bol--; + cur--; + if (funcname_needed && match_funcname(opt, bol, eol)) { + funcname_lno = cur; + funcname_needed = 0; + } + } + + /* We need to look even further back to find a function signature. */ + if (opt->funcname && funcname_needed) + show_funcname_line(opt, name, buf, bol, cur); + + /* Back forward. */ + while (cur < lno) { + char *eol = bol, sign = (cur == funcname_lno) ? '=' : '-'; + + while (*eol != '\n') + eol++; + show_line(opt, bol, eol, name, cur, sign); + bol = eol + 1; + cur++; + } +} + static int grep_buffer_1(struct grep_opt *opt, const char *name, char *buf, unsigned long size, int collect_hits) { char *bol = buf; unsigned long left = size; unsigned lno = 1; - struct pre_context_line { - char *bol; - char *eol; - } *prev = NULL, *pcl; unsigned last_hit = 0; - unsigned last_shown = 0; int binary_match_only = 0; - const char *hunk_mark = ""; unsigned count = 0; enum grep_context ctx = GREP_CONTEXT_HEAD; + xdemitconf_t xecfg; + + opt->last_shown = 0; if (buffer_is_binary(buf, size)) { switch (opt->binary) { @@ -550,10 +635,16 @@ static int grep_buffer_1(struct grep_opt *opt, const char *name, } } - if (opt->pre_context) - prev = xcalloc(opt->pre_context, sizeof(*prev)); - if (opt->pre_context || opt->post_context) - hunk_mark = "--\n"; + memset(&xecfg, 0, sizeof(xecfg)); + if (opt->funcname && !opt->unmatch_name_only && !opt->status_only && + !opt->name_only && !binary_match_only && !collect_hits) { + struct userdiff_driver *drv = userdiff_find_by_path(name); + if (drv && drv->funcname.pattern) { + const struct userdiff_funcname *pe = &drv->funcname; + xdiff_set_find_func(&xecfg, pe->pattern, pe->cflags); + opt->priv = &xecfg; + } + } while (left) { char *eol, ch; @@ -601,45 +692,20 @@ static int grep_buffer_1(struct grep_opt *opt, const char *name, * the context which is nonsense, but the user * deserves to get that ;-). */ - if (opt->pre_context) { - unsigned from; - if (opt->pre_context < lno) - from = lno - opt->pre_context; - else - from = 1; - if (from <= last_shown) - from = last_shown + 1; - if (last_shown && from != last_shown + 1) - fputs(hunk_mark, stdout); - while (from < lno) { - pcl = &prev[lno-from-1]; - show_line(opt, pcl->bol, pcl->eol, - name, from, '-'); - from++; - } - last_shown = lno-1; - } - if (last_shown && lno != last_shown + 1) - fputs(hunk_mark, stdout); + if (opt->pre_context) + show_pre_context(opt, name, buf, bol, lno); + else if (opt->funcname) + show_funcname_line(opt, name, buf, bol, lno); if (!opt->count) show_line(opt, bol, eol, name, lno, ':'); - last_shown = last_hit = lno; + last_hit = lno; } else if (last_hit && lno <= last_hit + opt->post_context) { /* If the last hit is within the post context, * we need to show this line. */ - if (last_shown && lno != last_shown + 1) - fputs(hunk_mark, stdout); show_line(opt, bol, eol, name, lno, '-'); - last_shown = lno; - } - if (opt->pre_context) { - memmove(prev+1, prev, - (opt->pre_context-1) * sizeof(*prev)); - prev->bol = bol; - prev->eol = eol; } next_line: @@ -650,7 +716,6 @@ static int grep_buffer_1(struct grep_opt *opt, const char *name, lno++; } - free(prev); if (collect_hits) return 0; @@ -662,6 +727,9 @@ static int grep_buffer_1(struct grep_opt *opt, const char *name, return 1; } + xdiff_clear_find_func(&xecfg); + opt->priv = NULL; + /* NEEDSWORK: * The real "grep -c foo *.c" gives many "bar.c:0" lines, * which feels mostly useless but sometimes useful. Maybe @@ -62,29 +62,33 @@ struct grep_opt { const char *prefix; int prefix_length; regex_t regexp; - unsigned linenum:1; - unsigned invert:1; - unsigned status_only:1; - unsigned name_only:1; - unsigned unmatch_name_only:1; - unsigned count:1; - unsigned word_regexp:1; - unsigned fixed:1; - unsigned all_match:1; + int linenum; + int invert; + int status_only; + int name_only; + int unmatch_name_only; + int count; + int word_regexp; + int fixed; + int all_match; #define GREP_BINARY_DEFAULT 0 #define GREP_BINARY_NOMATCH 1 #define GREP_BINARY_TEXT 2 - unsigned binary:2; - unsigned extended:1; - unsigned relative:1; - unsigned pathname:1; - unsigned null_following_name:1; + int binary; + int extended; + int relative; + int pathname; + int null_following_name; int color; + int funcname; char color_match[COLOR_MAXLEN]; const char *color_external; int regflags; unsigned pre_context; unsigned post_context; + unsigned last_shown; + int show_hunk_mark; + void *priv; }; extern void append_grep_pattern(struct grep_opt *opt, const char *pat, const char *origin, int no, enum grep_pat_token t); diff --git a/hash-object.c b/hash-object.c index ebb3bedb07..9455dd0709 100644 --- a/hash-object.c +++ b/hash-object.c @@ -29,7 +29,7 @@ static void hash_object(const char *path, const char *type, int write_object, int fd; fd = open(path, O_RDONLY); if (fd < 0) - die("Cannot open %s", path); + die_errno("Cannot open '%s'", path); hash_fd(fd, type, write_object, vpath); } @@ -84,7 +84,8 @@ int main(int argc, const char **argv) git_extract_argv0_path(argv[0]); - argc = parse_options(argc, argv, hash_object_options, hash_object_usage, 0); + argc = parse_options(argc, argv, NULL, hash_object_options, + hash_object_usage, 0); if (write_object) { prefix = setup_git_directory(); @@ -100,7 +100,7 @@ static void pretty_print_string_list(struct cmdnames *cmds, int longest) if (space < max_cols) cols = max_cols / space; - rows = (cmds->cnt + cols - 1) / cols; + rows = DIV_ROUND_UP(cmds->cnt, cols); for (i = 0; i < rows; i++) { printf(" "); @@ -302,7 +302,7 @@ const char *help_unknown_cmd(const char *cmd) struct cmdnames main_cmds, other_cmds; memset(&main_cmds, 0, sizeof(main_cmds)); - memset(&other_cmds, 0, sizeof(main_cmds)); + memset(&other_cmds, 0, sizeof(other_cmds)); memset(&aliases, 0, sizeof(aliases)); git_config(git_unknown_cmd_config, NULL); @@ -334,7 +334,7 @@ const char *help_unknown_cmd(const char *cmd) const char *assumed = main_cmds.names[0]->name; main_cmds.names[0] = NULL; clean_cmdnames(&main_cmds); - fprintf(stderr, "WARNING: You called a Git program named '%s', " + fprintf(stderr, "WARNING: You called a Git command named '%s', " "which does not exist.\n" "Continuing under the assumption that you meant '%s'\n", cmd, assumed); diff --git a/http-push.c b/http-push.c index 0b12ffe18f..00e83dcec1 100644 --- a/http-push.c +++ b/http-push.c @@ -1,6 +1,5 @@ #include "cache.h" #include "commit.h" -#include "pack.h" #include "tag.h" #include "blob.h" #include "http.h" @@ -27,7 +26,6 @@ enum XML_Status { #endif #define PREV_BUF_SIZE 4096 -#define RANGE_HEADER_SIZE 30 /* DAV methods */ #define DAV_LOCK "LOCK" @@ -76,8 +74,6 @@ static int pushing; static int aborted; static signed char remote_dir_exists[256]; -static struct curl_slist *no_pragma_header; - static int push_verbosely; static int push_all = MATCH_REFS_NONE; static int force_all; @@ -119,19 +115,10 @@ struct transfer_request struct remote_lock *lock; struct curl_slist *headers; struct buffer buffer; - char filename[PATH_MAX]; - char tmpfile[PATH_MAX]; - int local_fileno; - FILE *local_stream; enum transfer_state state; CURLcode curl_result; char errorstr[CURL_ERROR_SIZE]; long http_code; - unsigned char real_sha1[20]; - git_SHA_CTX c; - z_stream stream; - int zret; - int rename; void *userData; struct active_request_slot *slot; struct transfer_request *next; @@ -206,6 +193,8 @@ static char *xml_entities(char *s) case '&': strbuf_addstr(&buf, "&"); break; + case 0: + return strbuf_detach(&buf, NULL); } s++; } @@ -237,15 +226,6 @@ static struct curl_slist *get_dav_token_headers(struct remote_lock *lock, enum d return dav_headers; } -static void append_remote_object_url(struct strbuf *buf, const char *url, - const char *hex, - int only_two_digit_prefix) -{ - strbuf_addf(buf, "%sobjects/%.*s/", url, 2, hex); - if (!only_two_digit_prefix) - strbuf_addf(buf, "%s", hex+2); -} - static void finish_request(struct transfer_request *request); static void release_request(struct transfer_request *request); @@ -259,163 +239,29 @@ static void process_response(void *callback_data) #ifdef USE_CURL_MULTI -static char *get_remote_object_url(const char *url, const char *hex, - int only_two_digit_prefix) -{ - struct strbuf buf = STRBUF_INIT; - append_remote_object_url(&buf, url, hex, only_two_digit_prefix); - return strbuf_detach(&buf, NULL); -} - -static size_t fwrite_sha1_file(void *ptr, size_t eltsize, size_t nmemb, - void *data) -{ - unsigned char expn[4096]; - size_t size = eltsize * nmemb; - int posn = 0; - struct transfer_request *request = (struct transfer_request *)data; - do { - ssize_t retval = xwrite(request->local_fileno, - (char *) ptr + posn, size - posn); - if (retval < 0) - return posn; - posn += retval; - } while (posn < size); - - request->stream.avail_in = size; - request->stream.next_in = ptr; - do { - request->stream.next_out = expn; - request->stream.avail_out = sizeof(expn); - request->zret = git_inflate(&request->stream, Z_SYNC_FLUSH); - git_SHA1_Update(&request->c, expn, - sizeof(expn) - request->stream.avail_out); - } while (request->stream.avail_in && request->zret == Z_OK); - data_received++; - return size; -} - static void start_fetch_loose(struct transfer_request *request) { - char *hex = sha1_to_hex(request->obj->sha1); - char *filename; - char prevfile[PATH_MAX]; - char *url; - int prevlocal; - unsigned char prev_buf[PREV_BUF_SIZE]; - ssize_t prev_read = 0; - long prev_posn = 0; - char range[RANGE_HEADER_SIZE]; - struct curl_slist *range_header = NULL; struct active_request_slot *slot; + struct http_object_request *obj_req; - filename = sha1_file_name(request->obj->sha1); - snprintf(request->filename, sizeof(request->filename), "%s", filename); - snprintf(request->tmpfile, sizeof(request->tmpfile), - "%s.temp", filename); - - snprintf(prevfile, sizeof(prevfile), "%s.prev", request->filename); - unlink_or_warn(prevfile); - rename(request->tmpfile, prevfile); - unlink_or_warn(request->tmpfile); - - if (request->local_fileno != -1) - error("fd leakage in start: %d", request->local_fileno); - request->local_fileno = open(request->tmpfile, - O_WRONLY | O_CREAT | O_EXCL, 0666); - /* This could have failed due to the "lazy directory creation"; - * try to mkdir the last path component. - */ - if (request->local_fileno < 0 && errno == ENOENT) { - char *dir = strrchr(request->tmpfile, '/'); - if (dir) { - *dir = 0; - mkdir(request->tmpfile, 0777); - *dir = '/'; - } - request->local_fileno = open(request->tmpfile, - O_WRONLY | O_CREAT | O_EXCL, 0666); - } - - if (request->local_fileno < 0) { + obj_req = new_http_object_request(repo->url, request->obj->sha1); + if (obj_req == NULL) { request->state = ABORTED; - error("Couldn't create temporary file %s for %s: %s", - request->tmpfile, request->filename, strerror(errno)); return; } - memset(&request->stream, 0, sizeof(request->stream)); - - git_inflate_init(&request->stream); - - git_SHA1_Init(&request->c); - - url = get_remote_object_url(repo->url, hex, 0); - request->url = xstrdup(url); - - /* If a previous temp file is present, process what was already - fetched. */ - prevlocal = open(prevfile, O_RDONLY); - if (prevlocal != -1) { - do { - prev_read = xread(prevlocal, prev_buf, PREV_BUF_SIZE); - if (prev_read>0) { - if (fwrite_sha1_file(prev_buf, - 1, - prev_read, - request) == prev_read) { - prev_posn += prev_read; - } else { - prev_read = -1; - } - } - } while (prev_read > 0); - close(prevlocal); - } - unlink_or_warn(prevfile); - - /* Reset inflate/SHA1 if there was an error reading the previous temp - file; also rewind to the beginning of the local file. */ - if (prev_read == -1) { - memset(&request->stream, 0, sizeof(request->stream)); - git_inflate_init(&request->stream); - git_SHA1_Init(&request->c); - if (prev_posn>0) { - prev_posn = 0; - lseek(request->local_fileno, 0, SEEK_SET); - ftruncate(request->local_fileno, 0); - } - } - - slot = get_active_slot(); + slot = obj_req->slot; slot->callback_func = process_response; slot->callback_data = request; request->slot = slot; - - curl_easy_setopt(slot->curl, CURLOPT_FILE, request); - curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_sha1_file); - curl_easy_setopt(slot->curl, CURLOPT_ERRORBUFFER, request->errorstr); - curl_easy_setopt(slot->curl, CURLOPT_URL, url); - curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, no_pragma_header); - - /* If we have successfully processed data from a previous fetch - attempt, only fetch the data we don't already have. */ - if (prev_posn>0) { - if (push_verbosely) - fprintf(stderr, - "Resuming fetch of object %s at byte %ld\n", - hex, prev_posn); - sprintf(range, "Range: bytes=%ld-", prev_posn); - range_header = curl_slist_append(range_header, range); - curl_easy_setopt(slot->curl, - CURLOPT_HTTPHEADER, range_header); - } + request->userData = obj_req; /* Try to get the request started, abort the request on error */ request->state = RUN_FETCH_LOOSE; if (!start_active_slot(slot)) { fprintf(stderr, "Unable to start GET request\n"); repo->can_update_info_refs = 0; + release_http_object_request(obj_req); release_request(request); } } @@ -449,16 +295,10 @@ static void start_mkcol(struct transfer_request *request) static void start_fetch_packed(struct transfer_request *request) { - char *url; struct packed_git *target; - FILE *packfile; - char *filename; - long prev_posn = 0; - char range[RANGE_HEADER_SIZE]; - struct curl_slist *range_header = NULL; struct transfer_request *check_request = request_queue_head; - struct active_request_slot *slot; + struct http_pack_request *preq; target = find_sha1_pack(request->obj->sha1, repo->packs); if (!target) { @@ -471,66 +311,35 @@ static void start_fetch_packed(struct transfer_request *request) fprintf(stderr, "Fetching pack %s\n", sha1_to_hex(target->sha1)); fprintf(stderr, " which contains %s\n", sha1_to_hex(request->obj->sha1)); - filename = sha1_pack_name(target->sha1); - snprintf(request->filename, sizeof(request->filename), "%s", filename); - snprintf(request->tmpfile, sizeof(request->tmpfile), - "%s.temp", filename); - - url = xmalloc(strlen(repo->url) + 64); - sprintf(url, "%sobjects/pack/pack-%s.pack", - repo->url, sha1_to_hex(target->sha1)); + preq = new_http_pack_request(target, repo->url); + if (preq == NULL) { + release_http_pack_request(preq); + repo->can_update_info_refs = 0; + return; + } + preq->lst = &repo->packs; /* Make sure there isn't another open request for this pack */ while (check_request) { if (check_request->state == RUN_FETCH_PACKED && - !strcmp(check_request->url, url)) { - free(url); + !strcmp(check_request->url, preq->url)) { + release_http_pack_request(preq); release_request(request); return; } check_request = check_request->next; } - packfile = fopen(request->tmpfile, "a"); - if (!packfile) { - fprintf(stderr, "Unable to open local file %s for pack", - request->tmpfile); - repo->can_update_info_refs = 0; - free(url); - return; - } - - slot = get_active_slot(); - slot->callback_func = process_response; - slot->callback_data = request; - request->slot = slot; - request->local_stream = packfile; - request->userData = target; - - request->url = url; - curl_easy_setopt(slot->curl, CURLOPT_FILE, packfile); - curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite); - curl_easy_setopt(slot->curl, CURLOPT_URL, url); - curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, no_pragma_header); - slot->local = packfile; - - /* If there is data present from a previous transfer attempt, - resume where it left off */ - prev_posn = ftell(packfile); - if (prev_posn>0) { - if (push_verbosely) - fprintf(stderr, - "Resuming fetch of pack %s at byte %ld\n", - sha1_to_hex(target->sha1), prev_posn); - sprintf(range, "Range: bytes=%ld-", prev_posn); - range_header = curl_slist_append(range_header, range); - curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, range_header); - } + preq->slot->callback_func = process_response; + preq->slot->callback_data = request; + request->slot = preq->slot; + request->userData = preq; /* Try to get the request started, abort the request on error */ request->state = RUN_FETCH_PACKED; - if (!start_active_slot(slot)) { + if (!start_active_slot(preq->slot)) { fprintf(stderr, "Unable to start GET request\n"); + release_http_pack_request(preq); repo->can_update_info_refs = 0; release_request(request); } @@ -711,24 +520,17 @@ static void release_request(struct transfer_request *request) entry->next = entry->next->next; } - if (request->local_fileno != -1) - close(request->local_fileno); - if (request->local_stream) - fclose(request->local_stream); free(request->url); free(request); } static void finish_request(struct transfer_request *request) { - struct stat st; - struct packed_git *target; - struct packed_git **lst; - struct active_request_slot *slot; + struct http_pack_request *preq; + struct http_object_request *obj_req; request->curl_result = request->slot->curl_result; request->http_code = request->slot->http_code; - slot = request->slot; request->slot = NULL; /* Keep locks active */ @@ -780,77 +582,46 @@ static void finish_request(struct transfer_request *request) aborted = 1; } } else if (request->state == RUN_FETCH_LOOSE) { - close(request->local_fileno); request->local_fileno = -1; + obj_req = (struct http_object_request *)request->userData; - if (request->curl_result != CURLE_OK && - request->http_code != 416) { - if (stat(request->tmpfile, &st) == 0) { - if (st.st_size == 0) - unlink_or_warn(request->tmpfile); - } - } else { - if (request->http_code == 416) - warning("requested range invalid; we may already have all the data."); - - git_inflate_end(&request->stream); - git_SHA1_Final(request->real_sha1, &request->c); - if (request->zret != Z_STREAM_END) { - unlink_or_warn(request->tmpfile); - } else if (hashcmp(request->obj->sha1, request->real_sha1)) { - unlink_or_warn(request->tmpfile); - } else { - request->rename = - move_temp_to_file( - request->tmpfile, - request->filename); - if (request->rename == 0) { - request->obj->flags |= (LOCAL | REMOTE); - } - } - } + if (finish_http_object_request(obj_req) == 0) + if (obj_req->rename == 0) + request->obj->flags |= (LOCAL | REMOTE); /* Try fetching packed if necessary */ - if (request->obj->flags & LOCAL) + if (request->obj->flags & LOCAL) { + release_http_object_request(obj_req); release_request(request); - else + } else start_fetch_packed(request); } else if (request->state == RUN_FETCH_PACKED) { + int fail = 1; if (request->curl_result != CURLE_OK) { fprintf(stderr, "Unable to get pack file %s\n%s", request->url, curl_errorstr); - repo->can_update_info_refs = 0; } else { - off_t pack_size = ftell(request->local_stream); - - fclose(request->local_stream); - request->local_stream = NULL; - slot->local = NULL; - if (!move_temp_to_file(request->tmpfile, - request->filename)) { - target = (struct packed_git *)request->userData; - target->pack_size = pack_size; - lst = &repo->packs; - while (*lst != target) - lst = &((*lst)->next); - *lst = (*lst)->next; - - if (!verify_pack(target)) - install_packed_git(target); - else - repo->can_update_info_refs = 0; + preq = (struct http_pack_request *)request->userData; + + if (preq) { + if (finish_http_pack_request(preq) > 0) + fail = 0; + release_http_pack_request(preq); } } + if (fail) + repo->can_update_info_refs = 0; release_request(request); } } #ifdef USE_CURL_MULTI +static int is_running_queue; static int fill_active_slot(void *unused) { struct transfer_request *request; - if (aborted) + if (aborted || !is_running_queue) return 0; for (request = request_queue_head; request; request = request->next) { @@ -893,8 +664,6 @@ static void add_fetch_request(struct object *obj) request->url = NULL; request->lock = NULL; request->headers = NULL; - request->local_fileno = -1; - request->local_stream = NULL; request->state = NEED_FETCH; request->next = request_queue_head; request_queue_head = request; @@ -933,8 +702,6 @@ static int add_send_request(struct object *obj, struct remote_lock *lock) request->url = NULL; request->lock = lock; request->headers = NULL; - request->local_fileno = -1; - request->local_stream = NULL; request->state = NEED_PUSH; request->next = request_queue_head; request_queue_head = request; @@ -947,179 +714,23 @@ static int add_send_request(struct object *obj, struct remote_lock *lock) return 1; } -static int fetch_index(unsigned char *sha1) -{ - char *hex = sha1_to_hex(sha1); - char *filename; - char *url; - char tmpfile[PATH_MAX]; - long prev_posn = 0; - char range[RANGE_HEADER_SIZE]; - struct curl_slist *range_header = NULL; - - FILE *indexfile; - struct active_request_slot *slot; - struct slot_results results; - - /* Don't use the index if the pack isn't there */ - url = xmalloc(strlen(repo->url) + 64); - sprintf(url, "%sobjects/pack/pack-%s.pack", repo->url, hex); - slot = get_active_slot(); - slot->results = &results; - curl_easy_setopt(slot->curl, CURLOPT_URL, url); - curl_easy_setopt(slot->curl, CURLOPT_NOBODY, 1); - if (start_active_slot(slot)) { - run_active_slot(slot); - if (results.curl_result != CURLE_OK) { - free(url); - return error("Unable to verify pack %s is available", - hex); - } - } else { - free(url); - return error("Unable to start request"); - } - - if (has_pack_index(sha1)) { - free(url); - return 0; - } - - if (push_verbosely) - fprintf(stderr, "Getting index for pack %s\n", hex); - - sprintf(url, "%sobjects/pack/pack-%s.idx", repo->url, hex); - - filename = sha1_pack_index_name(sha1); - snprintf(tmpfile, sizeof(tmpfile), "%s.temp", filename); - indexfile = fopen(tmpfile, "a"); - if (!indexfile) { - free(url); - return error("Unable to open local file %s for pack index", - tmpfile); - } - - slot = get_active_slot(); - slot->results = &results; - curl_easy_setopt(slot->curl, CURLOPT_NOBODY, 0); - curl_easy_setopt(slot->curl, CURLOPT_HTTPGET, 1); - curl_easy_setopt(slot->curl, CURLOPT_FILE, indexfile); - curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite); - curl_easy_setopt(slot->curl, CURLOPT_URL, url); - curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, no_pragma_header); - slot->local = indexfile; - - /* If there is data present from a previous transfer attempt, - resume where it left off */ - prev_posn = ftell(indexfile); - if (prev_posn>0) { - if (push_verbosely) - fprintf(stderr, - "Resuming fetch of index for pack %s at byte %ld\n", - hex, prev_posn); - sprintf(range, "Range: bytes=%ld-", prev_posn); - range_header = curl_slist_append(range_header, range); - curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, range_header); - } - - if (start_active_slot(slot)) { - run_active_slot(slot); - if (results.curl_result != CURLE_OK) { - free(url); - fclose(indexfile); - slot->local = NULL; - return error("Unable to get pack index %s\n%s", url, - curl_errorstr); - } - } else { - free(url); - fclose(indexfile); - slot->local = NULL; - return error("Unable to start request"); - } - - free(url); - fclose(indexfile); - slot->local = NULL; - - return move_temp_to_file(tmpfile, filename); -} - -static int setup_index(unsigned char *sha1) -{ - struct packed_git *new_pack; - - if (fetch_index(sha1)) - return -1; - - new_pack = parse_pack_index(sha1); - new_pack->next = repo->packs; - repo->packs = new_pack; - return 0; -} - static int fetch_indices(void) { - unsigned char sha1[20]; - char *url; - struct strbuf buffer = STRBUF_INIT; - char *data; - int i = 0; - - struct active_request_slot *slot; - struct slot_results results; + int ret; if (push_verbosely) fprintf(stderr, "Getting pack list\n"); - url = xmalloc(strlen(repo->url) + 20); - sprintf(url, "%sobjects/info/packs", repo->url); - - slot = get_active_slot(); - slot->results = &results; - curl_easy_setopt(slot->curl, CURLOPT_FILE, &buffer); - curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_buffer); - curl_easy_setopt(slot->curl, CURLOPT_URL, url); - curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, NULL); - if (start_active_slot(slot)) { - run_active_slot(slot); - if (results.curl_result != CURLE_OK) { - strbuf_release(&buffer); - free(url); - if (results.http_code == 404) - return 0; - else - return error("%s", curl_errorstr); - } - } else { - strbuf_release(&buffer); - free(url); - return error("Unable to start request"); - } - free(url); - - data = buffer.buf; - while (i < buffer.len) { - switch (data[i]) { - case 'P': - i++; - if (i + 52 < buffer.len && - !prefixcmp(data + i, " pack-") && - !prefixcmp(data + i + 46, ".pack\n")) { - get_sha1_hex(data + i + 6, sha1); - setup_index(sha1); - i += 51; - break; - } - default: - while (data[i] != '\n') - i++; - } - i++; + switch (http_get_info_packs(repo->url, &repo->packs)) { + case HTTP_OK: + case HTTP_MISSING_TARGET: + ret = 0; + break; + default: + ret = -1; } - strbuf_release(&buffer); - return 0; + return ret; } static void one_remote_object(const char *hex) @@ -1850,7 +1461,7 @@ static int update_remote(unsigned char *sha1, struct remote_lock *lock) return 1; } -static struct ref *remote_refs, **remote_tail; +static struct ref *remote_refs; static void one_remote_ref(char *refname) { @@ -1880,27 +1491,15 @@ static void one_remote_ref(char *refname) } } - *remote_tail = ref; - remote_tail = &ref->next; + ref->next = remote_refs; + remote_refs = ref; } static void get_dav_remote_heads(void) { - remote_tail = &remote_refs; remote_ls("refs/", (PROCESS_FILES | PROCESS_DIRS | RECURSIVE), process_ls_ref, NULL); } -static int is_zero_sha1(const unsigned char *sha1) -{ - int i; - - for (i = 0; i < 20; i++) { - if (*sha1++) - return 0; - } - return 1; -} - static void add_remote_info_ref(struct remote_ls_ctx *ls) { struct strbuf *buf = (struct strbuf *)ls->userData; @@ -1994,29 +1593,22 @@ static void update_remote_info_refs(struct remote_lock *lock) static int remote_exists(const char *path) { char *url = xmalloc(strlen(repo->url) + strlen(path) + 1); - struct active_request_slot *slot; - struct slot_results results; - int ret = -1; + int ret; sprintf(url, "%s%s", repo->url, path); - slot = get_active_slot(); - slot->results = &results; - curl_easy_setopt(slot->curl, CURLOPT_URL, url); - curl_easy_setopt(slot->curl, CURLOPT_NOBODY, 1); - - if (start_active_slot(slot)) { - run_active_slot(slot); - if (results.http_code == 404) - ret = 0; - else if (results.curl_result == CURLE_OK) - ret = 1; - else - fprintf(stderr, "HEAD HTTP error %ld\n", results.http_code); - } else { - fprintf(stderr, "Unable to start HEAD request\n"); + switch (http_get_strbuf(url, NULL, 0)) { + case HTTP_OK: + ret = 1; + break; + case HTTP_MISSING_TARGET: + ret = 0; + break; + case HTTP_ERROR: + http_error(url, HTTP_ERROR); + default: + ret = -1; } - free(url); return ret; } @@ -2025,27 +1617,13 @@ static void fetch_symref(const char *path, char **symref, unsigned char *sha1) { char *url; struct strbuf buffer = STRBUF_INIT; - struct active_request_slot *slot; - struct slot_results results; url = xmalloc(strlen(repo->url) + strlen(path) + 1); sprintf(url, "%s%s", repo->url, path); - slot = get_active_slot(); - slot->results = &results; - curl_easy_setopt(slot->curl, CURLOPT_FILE, &buffer); - curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_buffer); - curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, NULL); - curl_easy_setopt(slot->curl, CURLOPT_URL, url); - if (start_active_slot(slot)) { - run_active_slot(slot); - if (results.curl_result != CURLE_OK) { - die("Couldn't get %s for remote symref\n%s", - url, curl_errorstr); - } - } else { - die("Unable to start remote symref request"); - } + if (http_get_strbuf(url, &buffer, 0) != HTTP_OK) + die("Couldn't get %s for remote symref\n%s", url, + curl_errorstr); free(url); free(*symref); @@ -2126,13 +1704,13 @@ static int delete_remote_branch(char *pattern, int force) /* Remote HEAD must resolve to a known object */ if (symref) return error("Remote HEAD symrefs too deep"); - if (is_zero_sha1(head_sha1)) + if (is_null_sha1(head_sha1)) return error("Unable to resolve remote HEAD"); if (!has_sha1_file(head_sha1)) return error("Remote HEAD resolves to object %s\nwhich does not exist locally, perhaps you need to fetch?", sha1_to_hex(head_sha1)); /* Remote branch must resolve to a known object */ - if (is_zero_sha1(remote_ref->old_sha1)) + if (is_null_sha1(remote_ref->old_sha1)) return error("Unable to resolve remote branch %s", remote_ref->name); if (!has_sha1_file(remote_ref->old_sha1)) @@ -2174,6 +1752,25 @@ static int delete_remote_branch(char *pattern, int force) return 0; } +static void run_request_queue(void) +{ +#ifdef USE_CURL_MULTI + is_running_queue = 1; + fill_active_slots(); + add_fill_function(NULL, fill_active_slot); +#endif + do { + finish_all_active_slots(); +#ifdef USE_CURL_MULTI + fill_active_slots(); +#endif + } while (request_queue_head && !aborted); + +#ifdef USE_CURL_MULTI + is_running_queue = 0; +#endif +} + int main(int argc, char **argv) { struct transfer_request *request; @@ -2218,6 +1815,7 @@ int main(int argc, char **argv) } if (!strcmp(arg, "--verbose")) { push_verbosely = 1; + http_is_verbose = 1; continue; } if (!strcmp(arg, "-d")) { @@ -2267,8 +1865,6 @@ int main(int argc, char **argv) remote->url[remote->url_nr++] = repo->url; http_init(remote); - no_pragma_header = curl_slist_append(no_pragma_header, "Pragma:"); - if (repo->url && repo->url[strlen(repo->url)-1] != '/') { rewritten_url = xmalloc(strlen(repo->url)+2); strcpy(rewritten_url, repo->url); @@ -2278,6 +1874,10 @@ int main(int argc, char **argv) repo->url = rewritten_url; } +#ifdef USE_CURL_MULTI + is_running_queue = 0; +#endif + /* Verify DAV compliance/lock support */ if (!locking_available()) { rc = 1; @@ -2307,6 +1907,7 @@ int main(int argc, char **argv) local_refs = get_local_heads(); fprintf(stderr, "Fetching remote heads...\n"); get_dav_remote_heads(); + run_request_queue(); /* Remove a remote branch if -d or -D was specified */ if (delete_branch) { @@ -2317,9 +1918,7 @@ int main(int argc, char **argv) } /* match them up */ - if (!remote_tail) - remote_tail = &remote_refs; - if (match_refs(local_refs, remote_refs, &remote_tail, + if (match_refs(local_refs, &remote_refs, nr_refspec, (const char **) refspec, push_all)) { rc = -1; goto cleanup; @@ -2333,14 +1932,14 @@ int main(int argc, char **argv) new_refs = 0; for (ref = remote_refs; ref; ref = ref->next) { char old_hex[60], *new_hex; - const char *commit_argv[4]; + const char *commit_argv[5]; int commit_argc; char *new_sha1_hex, *old_sha1_hex; if (!ref->peer_ref) continue; - if (is_zero_sha1(ref->peer_ref->new_sha1)) { + if (is_null_sha1(ref->peer_ref->new_sha1)) { if (delete_remote_branch(ref->name, 1) == -1) { error("Could not remove %s", ref->name); rc = -4; @@ -2356,7 +1955,7 @@ int main(int argc, char **argv) } if (!force_all && - !is_zero_sha1(ref->old_sha1) && + !is_null_sha1(ref->old_sha1) && !ref->force) { if (!has_sha1_file(ref->old_sha1) || !ref_newer(ref->peer_ref->new_sha1, @@ -2406,13 +2005,14 @@ int main(int argc, char **argv) old_sha1_hex = NULL; commit_argv[1] = "--objects"; commit_argv[2] = new_sha1_hex; - if (!push_all && !is_zero_sha1(ref->old_sha1)) { + if (!push_all && !is_null_sha1(ref->old_sha1)) { old_sha1_hex = xmalloc(42); sprintf(old_sha1_hex, "^%s", sha1_to_hex(ref->old_sha1)); commit_argv[3] = old_sha1_hex; commit_argc++; } + commit_argv[commit_argc] = NULL; init_revisions(&revs, setup_git_directory()); setup_revisions(commit_argc, commit_argv, &revs, NULL); revs.edge_hint = 0; /* just in case */ @@ -2436,16 +2036,8 @@ int main(int argc, char **argv) if (objects_to_send) fprintf(stderr, " sending %d objects\n", objects_to_send); -#ifdef USE_CURL_MULTI - fill_active_slots(); - add_fill_function(NULL, fill_active_slot); -#endif - do { - finish_all_active_slots(); -#ifdef USE_CURL_MULTI - fill_active_slots(); -#endif - } while (request_queue_head && !aborted); + + run_request_queue(); /* Update the remote branch if all went well */ if (aborted || !update_remote(ref->new_sha1, ref_lock)) @@ -2474,8 +2066,6 @@ int main(int argc, char **argv) unlock_remote(info_ref_lock); free(repo); - curl_slist_free_all(no_pragma_header); - http_cleanup(); request = request_queue_head; diff --git a/http-walker.c b/http-walker.c index 9377851925..700bc13112 100644 --- a/http-walker.c +++ b/http-walker.c @@ -1,12 +1,8 @@ #include "cache.h" #include "commit.h" -#include "pack.h" #include "walker.h" #include "http.h" -#define PREV_BUF_SIZE 4096 -#define RANGE_HEADER_SIZE 30 - struct alt_base { char *base; @@ -27,20 +23,8 @@ struct object_request struct walker *walker; unsigned char sha1[20]; struct alt_base *repo; - char *url; - char filename[PATH_MAX]; - char tmpfile[PATH_MAX]; - int local; enum object_request_state state; - CURLcode curl_result; - char errorstr[CURL_ERROR_SIZE]; - long http_code; - unsigned char real_sha1[20]; - git_SHA_CTX c; - z_stream stream; - int zret; - int rename; - struct active_request_slot *slot; + struct http_object_request *req; struct object_request *next; }; @@ -57,39 +41,10 @@ struct walker_data { const char *url; int got_alternates; struct alt_base *alt; - struct curl_slist *no_pragma_header; }; static struct object_request *object_queue_head; -static size_t fwrite_sha1_file(void *ptr, size_t eltsize, size_t nmemb, - void *data) -{ - unsigned char expn[4096]; - size_t size = eltsize * nmemb; - int posn = 0; - struct object_request *obj_req = (struct object_request *)data; - do { - ssize_t retval = xwrite(obj_req->local, - (char *) ptr + posn, size - posn); - if (retval < 0) - return posn; - posn += retval; - } while (posn < size); - - obj_req->stream.avail_in = size; - obj_req->stream.next_in = ptr; - do { - obj_req->stream.next_out = expn; - obj_req->stream.avail_out = sizeof(expn); - obj_req->zret = git_inflate(&obj_req->stream, Z_SYNC_FLUSH); - git_SHA1_Update(&obj_req->c, expn, - sizeof(expn) - obj_req->stream.avail_out); - } while (obj_req->stream.avail_in && obj_req->zret == Z_OK); - data_received++; - return size; -} - static void fetch_alternates(struct walker *walker, const char *base); static void process_object_response(void *callback_data); @@ -97,165 +52,35 @@ static void process_object_response(void *callback_data); static void start_object_request(struct walker *walker, struct object_request *obj_req) { - char *hex = sha1_to_hex(obj_req->sha1); - char prevfile[PATH_MAX]; - char *url; - char *posn; - int prevlocal; - unsigned char prev_buf[PREV_BUF_SIZE]; - ssize_t prev_read = 0; - long prev_posn = 0; - char range[RANGE_HEADER_SIZE]; - struct curl_slist *range_header = NULL; struct active_request_slot *slot; - struct walker_data *data = walker->data; + struct http_object_request *req; - snprintf(prevfile, sizeof(prevfile), "%s.prev", obj_req->filename); - unlink_or_warn(prevfile); - rename(obj_req->tmpfile, prevfile); - unlink_or_warn(obj_req->tmpfile); - - if (obj_req->local != -1) - error("fd leakage in start: %d", obj_req->local); - obj_req->local = open(obj_req->tmpfile, - O_WRONLY | O_CREAT | O_EXCL, 0666); - /* This could have failed due to the "lazy directory creation"; - * try to mkdir the last path component. - */ - if (obj_req->local < 0 && errno == ENOENT) { - char *dir = strrchr(obj_req->tmpfile, '/'); - if (dir) { - *dir = 0; - mkdir(obj_req->tmpfile, 0777); - *dir = '/'; - } - obj_req->local = open(obj_req->tmpfile, - O_WRONLY | O_CREAT | O_EXCL, 0666); - } - - if (obj_req->local < 0) { + req = new_http_object_request(obj_req->repo->base, obj_req->sha1); + if (req == NULL) { obj_req->state = ABORTED; - error("Couldn't create temporary file %s for %s: %s", - obj_req->tmpfile, obj_req->filename, strerror(errno)); return; } + obj_req->req = req; - memset(&obj_req->stream, 0, sizeof(obj_req->stream)); - - git_inflate_init(&obj_req->stream); - - git_SHA1_Init(&obj_req->c); - - url = xmalloc(strlen(obj_req->repo->base) + 51); - obj_req->url = xmalloc(strlen(obj_req->repo->base) + 51); - strcpy(url, obj_req->repo->base); - posn = url + strlen(obj_req->repo->base); - strcpy(posn, "/objects/"); - posn += 9; - memcpy(posn, hex, 2); - posn += 2; - *(posn++) = '/'; - strcpy(posn, hex + 2); - strcpy(obj_req->url, url); - - /* If a previous temp file is present, process what was already - fetched. */ - prevlocal = open(prevfile, O_RDONLY); - if (prevlocal != -1) { - do { - prev_read = xread(prevlocal, prev_buf, PREV_BUF_SIZE); - if (prev_read>0) { - if (fwrite_sha1_file(prev_buf, - 1, - prev_read, - obj_req) == prev_read) { - prev_posn += prev_read; - } else { - prev_read = -1; - } - } - } while (prev_read > 0); - close(prevlocal); - } - unlink_or_warn(prevfile); - - /* Reset inflate/SHA1 if there was an error reading the previous temp - file; also rewind to the beginning of the local file. */ - if (prev_read == -1) { - memset(&obj_req->stream, 0, sizeof(obj_req->stream)); - git_inflate_init(&obj_req->stream); - git_SHA1_Init(&obj_req->c); - if (prev_posn>0) { - prev_posn = 0; - lseek(obj_req->local, 0, SEEK_SET); - ftruncate(obj_req->local, 0); - } - } - - slot = get_active_slot(); + slot = req->slot; slot->callback_func = process_object_response; slot->callback_data = obj_req; - obj_req->slot = slot; - - curl_easy_setopt(slot->curl, CURLOPT_FILE, obj_req); - curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_sha1_file); - curl_easy_setopt(slot->curl, CURLOPT_ERRORBUFFER, obj_req->errorstr); - curl_easy_setopt(slot->curl, CURLOPT_URL, url); - curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, data->no_pragma_header); - - /* If we have successfully processed data from a previous fetch - attempt, only fetch the data we don't already have. */ - if (prev_posn>0) { - if (walker->get_verbosely) - fprintf(stderr, - "Resuming fetch of object %s at byte %ld\n", - hex, prev_posn); - sprintf(range, "Range: bytes=%ld-", prev_posn); - range_header = curl_slist_append(range_header, range); - curl_easy_setopt(slot->curl, - CURLOPT_HTTPHEADER, range_header); - } /* Try to get the request started, abort the request on error */ obj_req->state = ACTIVE; if (!start_active_slot(slot)) { obj_req->state = ABORTED; - obj_req->slot = NULL; - close(obj_req->local); obj_req->local = -1; - free(obj_req->url); + release_http_object_request(req); return; } } static void finish_object_request(struct object_request *obj_req) { - struct stat st; - - close(obj_req->local); obj_req->local = -1; - - if (obj_req->http_code == 416) { - fprintf(stderr, "Warning: requested range invalid; we may already have all the data.\n"); - } else if (obj_req->curl_result != CURLE_OK) { - if (stat(obj_req->tmpfile, &st) == 0) - if (st.st_size == 0) - unlink_or_warn(obj_req->tmpfile); - return; - } - - git_inflate_end(&obj_req->stream); - git_SHA1_Final(obj_req->real_sha1, &obj_req->c); - if (obj_req->zret != Z_STREAM_END) { - unlink_or_warn(obj_req->tmpfile); + if (finish_http_object_request(obj_req->req)) return; - } - if (hashcmp(obj_req->sha1, obj_req->real_sha1)) { - unlink_or_warn(obj_req->tmpfile); - return; - } - obj_req->rename = - move_temp_to_file(obj_req->tmpfile, obj_req->filename); - if (obj_req->rename == 0) + if (obj_req->req->rename == 0) walker_say(obj_req->walker, "got %s\n", sha1_to_hex(obj_req->sha1)); } @@ -267,19 +92,16 @@ static void process_object_response(void *callback_data) struct walker_data *data = walker->data; struct alt_base *alt = data->alt; - obj_req->curl_result = obj_req->slot->curl_result; - obj_req->http_code = obj_req->slot->http_code; - obj_req->slot = NULL; + process_http_object_request(obj_req->req); obj_req->state = COMPLETE; /* Use alternates if necessary */ - if (missing_target(obj_req)) { + if (missing_target(obj_req->req)) { fetch_alternates(walker, alt->base); if (obj_req->repo->next != NULL) { obj_req->repo = obj_req->repo->next; - close(obj_req->local); - obj_req->local = -1; + release_http_object_request(obj_req->req); start_object_request(walker, obj_req); return; } @@ -292,8 +114,8 @@ static void release_object_request(struct object_request *obj_req) { struct object_request *entry = object_queue_head; - if (obj_req->local != -1) - error("fd leakage in release: %d", obj_req->local); + if (obj_req->req !=NULL && obj_req->req->localfile != -1) + error("fd leakage in release: %d", obj_req->req->localfile); if (obj_req == object_queue_head) { object_queue_head = obj_req->next; } else { @@ -303,7 +125,6 @@ static void release_object_request(struct object_request *obj_req) entry->next = entry->next->next; } - free(obj_req->url); free(obj_req); } @@ -331,28 +152,23 @@ static void prefetch(struct walker *walker, unsigned char *sha1) struct object_request *newreq; struct object_request *tail; struct walker_data *data = walker->data; - char *filename = sha1_file_name(sha1); newreq = xmalloc(sizeof(*newreq)); newreq->walker = walker; hashcpy(newreq->sha1, sha1); newreq->repo = data->alt; - newreq->url = NULL; - newreq->local = -1; newreq->state = WAITING; - snprintf(newreq->filename, sizeof(newreq->filename), "%s", filename); - snprintf(newreq->tmpfile, sizeof(newreq->tmpfile), - "%s.temp", filename); - newreq->slot = NULL; + newreq->req = NULL; newreq->next = NULL; + http_is_verbose = walker->get_verbosely; + if (object_queue_head == NULL) { object_queue_head = newreq; } else { tail = object_queue_head; - while (tail->next != NULL) { + while (tail->next != NULL) tail = tail->next; - } tail->next = newreq; } @@ -362,95 +178,6 @@ static void prefetch(struct walker *walker, unsigned char *sha1) #endif } -static int fetch_index(struct walker *walker, struct alt_base *repo, unsigned char *sha1) -{ - char *hex = sha1_to_hex(sha1); - char *filename; - char *url; - char tmpfile[PATH_MAX]; - long prev_posn = 0; - char range[RANGE_HEADER_SIZE]; - struct curl_slist *range_header = NULL; - struct walker_data *data = walker->data; - - FILE *indexfile; - struct active_request_slot *slot; - struct slot_results results; - - if (has_pack_index(sha1)) - return 0; - - if (walker->get_verbosely) - fprintf(stderr, "Getting index for pack %s\n", hex); - - url = xmalloc(strlen(repo->base) + 64); - sprintf(url, "%s/objects/pack/pack-%s.idx", repo->base, hex); - - filename = sha1_pack_index_name(sha1); - snprintf(tmpfile, sizeof(tmpfile), "%s.temp", filename); - indexfile = fopen(tmpfile, "a"); - if (!indexfile) - return error("Unable to open local file %s for pack index", - tmpfile); - - slot = get_active_slot(); - slot->results = &results; - curl_easy_setopt(slot->curl, CURLOPT_FILE, indexfile); - curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite); - curl_easy_setopt(slot->curl, CURLOPT_URL, url); - curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, data->no_pragma_header); - slot->local = indexfile; - - /* If there is data present from a previous transfer attempt, - resume where it left off */ - prev_posn = ftell(indexfile); - if (prev_posn>0) { - if (walker->get_verbosely) - fprintf(stderr, - "Resuming fetch of index for pack %s at byte %ld\n", - hex, prev_posn); - sprintf(range, "Range: bytes=%ld-", prev_posn); - range_header = curl_slist_append(range_header, range); - curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, range_header); - } - - if (start_active_slot(slot)) { - run_active_slot(slot); - if (results.curl_result != CURLE_OK) { - fclose(indexfile); - slot->local = NULL; - return error("Unable to get pack index %s\n%s", url, - curl_errorstr); - } - } else { - fclose(indexfile); - slot->local = NULL; - return error("Unable to start request"); - } - - fclose(indexfile); - slot->local = NULL; - - return move_temp_to_file(tmpfile, filename); -} - -static int setup_index(struct walker *walker, struct alt_base *repo, unsigned char *sha1) -{ - struct packed_git *new_pack; - if (has_pack_file(sha1)) - return 0; /* don't list this as something we can get */ - - if (fetch_index(walker, repo, sha1)) - return -1; - - new_pack = parse_pack_index(sha1); - if (!new_pack) - return -1; /* parse_pack_index() already issued error message */ - new_pack->next = repo->packs; - repo->packs = new_pack; - return 0; -} - static void process_alternates_response(void *callback_data) { struct alternates_request *alt_req = @@ -507,7 +234,8 @@ static void process_alternates_response(void *callback_data) struct alt_base *newalt; char *target = NULL; if (data[i] == '/') { - /* This counts + /* + * This counts * http://git.host/pub/scm/linux.git/ * -----------here^ * so memcpy(dst, base, serverlen) will @@ -520,7 +248,8 @@ static void process_alternates_response(void *callback_data) okay = 1; } } else if (!memcmp(data + i, "../", 3)) { - /* Relative URL; chop the corresponding + /* + * Relative URL; chop the corresponding * number of subpath from base (and ../ * from data), and concatenate the result. * @@ -549,7 +278,7 @@ static void process_alternates_response(void *callback_data) } /* If the server got removed, give up. */ okay = strchr(base, ':') - base + 3 < - serverlen; + serverlen; } else if (alt_req->http_specific) { char *colon = strchr(data + i, ':'); char *slash = strchr(data + i, '/'); @@ -593,9 +322,11 @@ static void fetch_alternates(struct walker *walker, const char *base) struct alternates_request alt_req; struct walker_data *cdata = walker->data; - /* If another request has already started fetching alternates, - wait for them to arrive and return to processing this request's - curl message */ + /* + * If another request has already started fetching alternates, + * wait for them to arrive and return to processing this request's + * curl message + */ #ifdef USE_CURL_MULTI while (cdata->got_alternates == 0) { step_active_slots(); @@ -615,8 +346,10 @@ static void fetch_alternates(struct walker *walker, const char *base) url = xmalloc(strlen(base) + 31); sprintf(url, "%s/objects/info/http-alternates", base); - /* Use a callback to process the result, since another request - may fail and need to have alternates loaded before continuing */ + /* + * Use a callback to process the result, since another request + * may fail and need to have alternates loaded before continuing + */ slot = get_active_slot(); slot->callback_func = process_alternates_response; alt_req.walker = walker; @@ -643,15 +376,7 @@ static void fetch_alternates(struct walker *walker, const char *base) static int fetch_indices(struct walker *walker, struct alt_base *repo) { - unsigned char sha1[20]; - char *url; - struct strbuf buffer = STRBUF_INIT; - char *data; - int i = 0; - int ret = 0; - - struct active_request_slot *slot; - struct slot_results results; + int ret; if (repo->got_indices) return 0; @@ -659,76 +384,26 @@ static int fetch_indices(struct walker *walker, struct alt_base *repo) if (walker->get_verbosely) fprintf(stderr, "Getting pack list for %s\n", repo->base); - url = xmalloc(strlen(repo->base) + 21); - sprintf(url, "%s/objects/info/packs", repo->base); - - slot = get_active_slot(); - slot->results = &results; - curl_easy_setopt(slot->curl, CURLOPT_FILE, &buffer); - curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_buffer); - curl_easy_setopt(slot->curl, CURLOPT_URL, url); - curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, NULL); - if (start_active_slot(slot)) { - run_active_slot(slot); - if (results.curl_result != CURLE_OK) { - if (missing_target(&results)) { - repo->got_indices = 1; - goto cleanup; - } else { - repo->got_indices = 0; - ret = error("%s", curl_errorstr); - goto cleanup; - } - } - } else { + switch (http_get_info_packs(repo->base, &repo->packs)) { + case HTTP_OK: + case HTTP_MISSING_TARGET: + repo->got_indices = 1; + ret = 0; + break; + default: repo->got_indices = 0; - ret = error("Unable to start request"); - goto cleanup; + ret = -1; } - data = buffer.buf; - while (i < buffer.len) { - switch (data[i]) { - case 'P': - i++; - if (i + 52 <= buffer.len && - !prefixcmp(data + i, " pack-") && - !prefixcmp(data + i + 46, ".pack\n")) { - get_sha1_hex(data + i + 6, sha1); - setup_index(walker, repo, sha1); - i += 51; - break; - } - default: - while (i < buffer.len && data[i] != '\n') - i++; - } - i++; - } - - repo->got_indices = 1; -cleanup: - strbuf_release(&buffer); - free(url); return ret; } static int fetch_pack(struct walker *walker, struct alt_base *repo, unsigned char *sha1) { - char *url; struct packed_git *target; - struct packed_git **lst; - FILE *packfile; - char *filename; - char tmpfile[PATH_MAX]; int ret; - long prev_posn = 0; - char range[RANGE_HEADER_SIZE]; - struct curl_slist *range_header = NULL; - struct walker_data *data = walker->data; - - struct active_request_slot *slot; struct slot_results results; + struct http_pack_request *preq; if (fetch_indices(walker, repo)) return -1; @@ -743,83 +418,37 @@ static int fetch_pack(struct walker *walker, struct alt_base *repo, unsigned cha sha1_to_hex(sha1)); } - url = xmalloc(strlen(repo->base) + 65); - sprintf(url, "%s/objects/pack/pack-%s.pack", - repo->base, sha1_to_hex(target->sha1)); + preq = new_http_pack_request(target, repo->base); + if (preq == NULL) + goto abort; + preq->lst = &repo->packs; + preq->slot->results = &results; - filename = sha1_pack_name(target->sha1); - snprintf(tmpfile, sizeof(tmpfile), "%s.temp", filename); - packfile = fopen(tmpfile, "a"); - if (!packfile) - return error("Unable to open local file %s for pack", - tmpfile); - - slot = get_active_slot(); - slot->results = &results; - curl_easy_setopt(slot->curl, CURLOPT_FILE, packfile); - curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite); - curl_easy_setopt(slot->curl, CURLOPT_URL, url); - curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, data->no_pragma_header); - slot->local = packfile; - - /* If there is data present from a previous transfer attempt, - resume where it left off */ - prev_posn = ftell(packfile); - if (prev_posn>0) { - if (walker->get_verbosely) - fprintf(stderr, - "Resuming fetch of pack %s at byte %ld\n", - sha1_to_hex(target->sha1), prev_posn); - sprintf(range, "Range: bytes=%ld-", prev_posn); - range_header = curl_slist_append(range_header, range); - curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, range_header); - } - - if (start_active_slot(slot)) { - run_active_slot(slot); + if (start_active_slot(preq->slot)) { + run_active_slot(preq->slot); if (results.curl_result != CURLE_OK) { - fclose(packfile); - slot->local = NULL; - return error("Unable to get pack file %s\n%s", url, - curl_errorstr); + error("Unable to get pack file %s\n%s", preq->url, + curl_errorstr); + goto abort; } } else { - fclose(packfile); - slot->local = NULL; - return error("Unable to start request"); + error("Unable to start request"); + goto abort; } - target->pack_size = ftell(packfile); - fclose(packfile); - slot->local = NULL; - - ret = move_temp_to_file(tmpfile, filename); + ret = finish_http_pack_request(preq); + release_http_pack_request(preq); if (ret) return ret; - lst = &repo->packs; - while (*lst != target) - lst = &((*lst)->next); - *lst = (*lst)->next; - - if (verify_pack(target)) - return -1; - install_packed_git(target); - return 0; + +abort: + return -1; } static void abort_object_request(struct object_request *obj_req) { - if (obj_req->local >= 0) { - close(obj_req->local); - obj_req->local = -1; - } - unlink_or_warn(obj_req->tmpfile); - if (obj_req->slot) { - release_active_slot(obj_req->slot); - obj_req->slot = NULL; - } release_object_request(obj_req); } @@ -828,6 +457,7 @@ static int fetch_object(struct walker *walker, struct alt_base *repo, unsigned c char *hex = sha1_to_hex(sha1); int ret = 0; struct object_request *obj_req = object_queue_head; + struct http_object_request *req; while (obj_req != NULL && hashcmp(obj_req->sha1, sha1)) obj_req = obj_req->next; @@ -835,45 +465,55 @@ static int fetch_object(struct walker *walker, struct alt_base *repo, unsigned c return error("Couldn't find request for %s in the queue", hex); if (has_sha1_file(obj_req->sha1)) { + if (obj_req->req != NULL) + abort_http_object_request(obj_req->req); abort_object_request(obj_req); return 0; } #ifdef USE_CURL_MULTI - while (obj_req->state == WAITING) { + while (obj_req->state == WAITING) step_active_slots(); - } #else start_object_request(walker, obj_req); #endif - while (obj_req->state == ACTIVE) { - run_active_slot(obj_req->slot); - } - if (obj_req->local != -1) { - close(obj_req->local); obj_req->local = -1; + /* + * obj_req->req might change when fetching alternates in the callback + * process_object_response; therefore, the "shortcut" variable, req, + * is used only after we're done with slots. + */ + while (obj_req->state == ACTIVE) + run_active_slot(obj_req->req->slot); + + req = obj_req->req; + + if (req->localfile != -1) { + close(req->localfile); + req->localfile = -1; } if (obj_req->state == ABORTED) { ret = error("Request for %s aborted", hex); - } else if (obj_req->curl_result != CURLE_OK && - obj_req->http_code != 416) { - if (missing_target(obj_req)) + } else if (req->curl_result != CURLE_OK && + req->http_code != 416) { + if (missing_target(req)) ret = -1; /* Be silent, it is probably in a pack. */ else ret = error("%s (curl_result = %d, http_code = %ld, sha1 = %s)", - obj_req->errorstr, obj_req->curl_result, - obj_req->http_code, hex); - } else if (obj_req->zret != Z_STREAM_END) { + req->errorstr, req->curl_result, + req->http_code, hex); + } else if (req->zret != Z_STREAM_END) { walker->corrupt_object_found++; - ret = error("File %s (%s) corrupt", hex, obj_req->url); - } else if (hashcmp(obj_req->sha1, obj_req->real_sha1)) { + ret = error("File %s (%s) corrupt", hex, req->url); + } else if (hashcmp(obj_req->sha1, req->real_sha1)) { ret = error("File %s has bad hash", hex); - } else if (obj_req->rename < 0) { + } else if (req->rename < 0) { ret = error("unable to write sha1 filename %s", - obj_req->filename); + req->filename); } + release_http_object_request(req); release_object_request(obj_req); return ret; } @@ -903,10 +543,7 @@ static int fetch_ref(struct walker *walker, struct ref *ref) static void cleanup(struct walker *walker) { - struct walker_data *data = walker->data; http_cleanup(); - - curl_slist_free_all(data->no_pragma_header); } struct walker *get_http_walker(const char *url, struct remote *remote) @@ -917,8 +554,6 @@ struct walker *get_http_walker(const char *url, struct remote *remote) http_init(remote); - data->no_pragma_header = curl_slist_append(NULL, "Pragma:"); - data->alt = xmalloc(sizeof(*data->alt)); data->alt->base = xmalloc(strlen(url) + 1); strcpy(data->alt->base, url); @@ -1,7 +1,9 @@ #include "http.h" +#include "pack.h" int data_received; int active_requests; +int http_is_verbose; #ifdef USE_CURL_MULTI static int max_requests = -1; @@ -10,6 +12,10 @@ static CURLM *curlm; #ifndef NO_CURL_EASY_DUPHANDLE static CURL *curl_default; #endif + +#define PREV_BUF_SIZE 4096 +#define RANGE_HEADER_SIZE 30 + char curl_errorstr[CURL_ERROR_SIZE]; static int curl_ssl_verify = -1; @@ -27,7 +33,19 @@ static int curl_ftp_no_epsv; static const char *curl_http_proxy; static char *user_name, *user_pass; +#if LIBCURL_VERSION_NUM >= 0x071700 +/* Use CURLOPT_KEYPASSWD as is */ +#elif LIBCURL_VERSION_NUM >= 0x070903 +#define CURLOPT_KEYPASSWD CURLOPT_SSLKEYPASSWD +#else +#define CURLOPT_KEYPASSWD CURLOPT_SSLCERTPASSWD +#endif + +static char *ssl_cert_password; +static int ssl_cert_password_required; + static struct curl_slist *pragma_header; +static struct curl_slist *no_pragma_header; static struct active_request_slot *active_queue_head; @@ -129,6 +147,11 @@ static int http_options(const char *var, const char *value, void *cb) #endif if (!strcmp("http.sslcainfo", var)) return git_config_string(&ssl_cainfo, var, value); + if (!strcmp("http.sslcertpasswordprotected", var)) { + if (git_config_bool(var, value)) + ssl_cert_password_required = 1; + return 0; + } #ifdef USE_CURL_MULTI if (!strcmp("http.maxrequests", var)) { max_requests = git_config_int(var, value); @@ -167,6 +190,22 @@ static void init_curl_http_auth(CURL *result) } } +static int has_cert_password(void) +{ + if (ssl_cert_password != NULL) + return 1; + if (ssl_cert == NULL || ssl_cert_password_required != 1) + return 0; + /* Only prompt the user once. */ + ssl_cert_password_required = -1; + ssl_cert_password = getpass("Certificate Password: "); + if (ssl_cert_password != NULL) { + ssl_cert_password = xstrdup(ssl_cert_password); + return 1; + } else + return 0; +} + static CURL *get_curl_handle(void) { CURL *result = curl_easy_init(); @@ -189,6 +228,8 @@ static CURL *get_curl_handle(void) if (ssl_cert != NULL) curl_easy_setopt(result, CURLOPT_SSLCERT, ssl_cert); + if (has_cert_password()) + curl_easy_setopt(result, CURLOPT_KEYPASSWD, ssl_cert_password); #if LIBCURL_VERSION_NUM >= 0x070903 if (ssl_key != NULL) curl_easy_setopt(result, CURLOPT_SSLKEY, ssl_key); @@ -276,6 +317,8 @@ void http_init(struct remote *remote) char *low_speed_limit; char *low_speed_time; + http_is_verbose = 0; + git_config(http_options, NULL); curl_global_init(CURL_GLOBAL_ALL); @@ -284,6 +327,7 @@ void http_init(struct remote *remote) curl_http_proxy = xstrdup(remote->http_proxy); pragma_header = curl_slist_append(pragma_header, "Pragma: no-cache"); + no_pragma_header = curl_slist_append(no_pragma_header, "Pragma:"); #ifdef USE_CURL_MULTI { @@ -329,8 +373,13 @@ void http_init(struct remote *remote) if (getenv("GIT_CURL_FTP_NO_EPSV")) curl_ftp_no_epsv = 1; - if (remote && remote->url && remote->url[0]) + if (remote && remote->url && remote->url[0]) { http_auth_init(remote->url[0]); + if (!ssl_cert_password_required && + getenv("GIT_SSL_CERT_PASSWORD_PROTECTED") && + !prefixcmp(remote->url[0], "https://")) + ssl_cert_password_required = 1; + } #ifndef NO_CURL_EASY_DUPHANDLE curl_default = get_curl_handle(); @@ -366,10 +415,20 @@ void http_cleanup(void) curl_slist_free_all(pragma_header); pragma_header = NULL; + curl_slist_free_all(no_pragma_header); + no_pragma_header = NULL; + if (curl_http_proxy) { free((void *)curl_http_proxy); curl_http_proxy = NULL; } + + if (ssl_cert_password != NULL) { + memset(ssl_cert_password, 0, strlen(ssl_cert_password)); + free(ssl_cert_password); + ssl_cert_password = NULL; + } + ssl_cert_password_required = 0; } struct active_request_slot *get_active_slot(void) @@ -611,6 +670,7 @@ void finish_all_active_slots(void) } } +/* Helpers for modifying and creating URLs */ static inline int needs_quote(int ch) { if (((ch >= 'A') && (ch <= 'Z')) @@ -631,15 +691,20 @@ static inline int hex(int v) return 'A' + v - 10; } +static void end_url_with_slash(struct strbuf *buf, const char *url) +{ + strbuf_addstr(buf, url); + if (buf->len && buf->buf[buf->len - 1] != '/') + strbuf_addstr(buf, "/"); +} + static char *quote_ref_url(const char *base, const char *ref) { struct strbuf buf = STRBUF_INIT; const char *cp; int ch; - strbuf_addstr(&buf, base); - if (buf.len && buf.buf[buf.len - 1] != '/' && *ref != '/') - strbuf_addstr(&buf, "/"); + end_url_with_slash(&buf, base); for (cp = ref; (ch = *cp) != 0; cp++) if (needs_quote(ch)) @@ -650,41 +715,571 @@ static char *quote_ref_url(const char *base, const char *ref) return strbuf_detach(&buf, NULL); } -int http_fetch_ref(const char *base, struct ref *ref) +void append_remote_object_url(struct strbuf *buf, const char *url, + const char *hex, + int only_two_digit_prefix) +{ + end_url_with_slash(buf, url); + + strbuf_addf(buf, "objects/%.*s/", 2, hex); + if (!only_two_digit_prefix) + strbuf_addf(buf, "%s", hex+2); +} + +char *get_remote_object_url(const char *url, const char *hex, + int only_two_digit_prefix) +{ + struct strbuf buf = STRBUF_INIT; + append_remote_object_url(&buf, url, hex, only_two_digit_prefix); + return strbuf_detach(&buf, NULL); +} + +/* http_request() targets */ +#define HTTP_REQUEST_STRBUF 0 +#define HTTP_REQUEST_FILE 1 + +static int http_request(const char *url, void *result, int target, int options) { - char *url; - struct strbuf buffer = STRBUF_INIT; struct active_request_slot *slot; struct slot_results results; + struct curl_slist *headers = NULL; + struct strbuf buf = STRBUF_INIT; int ret; - url = quote_ref_url(base, ref->name); slot = get_active_slot(); slot->results = &results; - curl_easy_setopt(slot->curl, CURLOPT_FILE, &buffer); - curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_buffer); - curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, NULL); + curl_easy_setopt(slot->curl, CURLOPT_HTTPGET, 1); + + if (result == NULL) { + curl_easy_setopt(slot->curl, CURLOPT_NOBODY, 1); + } else { + curl_easy_setopt(slot->curl, CURLOPT_NOBODY, 0); + curl_easy_setopt(slot->curl, CURLOPT_FILE, result); + + if (target == HTTP_REQUEST_FILE) { + long posn = ftell(result); + curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, + fwrite); + if (posn > 0) { + strbuf_addf(&buf, "Range: bytes=%ld-", posn); + headers = curl_slist_append(headers, buf.buf); + strbuf_reset(&buf); + } + slot->local = result; + } else + curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, + fwrite_buffer); + } + + strbuf_addstr(&buf, "Pragma:"); + if (options & HTTP_NO_CACHE) + strbuf_addstr(&buf, " no-cache"); + + headers = curl_slist_append(headers, buf.buf); + curl_easy_setopt(slot->curl, CURLOPT_URL, url); + curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, headers); + if (start_active_slot(slot)) { run_active_slot(slot); - if (results.curl_result == CURLE_OK) { - strbuf_rtrim(&buffer); - if (buffer.len == 40) - ret = get_sha1_hex(buffer.buf, ref->old_sha1); - else if (!prefixcmp(buffer.buf, "ref: ")) { - ref->symref = xstrdup(buffer.buf + 5); - ret = 0; - } else - ret = 1; - } else { - ret = error("Couldn't get %s for %s\n%s", - url, ref->name, curl_errorstr); - } + if (results.curl_result == CURLE_OK) + ret = HTTP_OK; + else if (missing_target(&results)) + ret = HTTP_MISSING_TARGET; + else + ret = HTTP_ERROR; } else { - ret = error("Unable to start request"); + error("Unable to start HTTP request for %s", url); + ret = HTTP_START_FAILED; + } + + slot->local = NULL; + curl_slist_free_all(headers); + strbuf_release(&buf); + + return ret; +} + +int http_get_strbuf(const char *url, struct strbuf *result, int options) +{ + return http_request(url, result, HTTP_REQUEST_STRBUF, options); +} + +int http_get_file(const char *url, const char *filename, int options) +{ + int ret; + struct strbuf tmpfile = STRBUF_INIT; + FILE *result; + + strbuf_addf(&tmpfile, "%s.temp", filename); + result = fopen(tmpfile.buf, "a"); + if (! result) { + error("Unable to open local file %s", tmpfile.buf); + ret = HTTP_ERROR; + goto cleanup; + } + + ret = http_request(url, result, HTTP_REQUEST_FILE, options); + fclose(result); + + if ((ret == HTTP_OK) && move_temp_to_file(tmpfile.buf, filename)) + ret = HTTP_ERROR; +cleanup: + strbuf_release(&tmpfile); + return ret; +} + +int http_error(const char *url, int ret) +{ + /* http_request has already handled HTTP_START_FAILED. */ + if (ret != HTTP_START_FAILED) + error("%s while accessing %s\n", curl_errorstr, url); + + return ret; +} + +int http_fetch_ref(const char *base, struct ref *ref) +{ + char *url; + struct strbuf buffer = STRBUF_INIT; + int ret = -1; + + url = quote_ref_url(base, ref->name); + if (http_get_strbuf(url, &buffer, HTTP_NO_CACHE) == HTTP_OK) { + strbuf_rtrim(&buffer); + if (buffer.len == 40) + ret = get_sha1_hex(buffer.buf, ref->old_sha1); + else if (!prefixcmp(buffer.buf, "ref: ")) { + ref->symref = xstrdup(buffer.buf + 5); + ret = 0; + } } strbuf_release(&buffer); free(url); return ret; } + +/* Helpers for fetching packs */ +static int fetch_pack_index(unsigned char *sha1, const char *base_url) +{ + int ret = 0; + char *hex = xstrdup(sha1_to_hex(sha1)); + char *filename; + char *url; + struct strbuf buf = STRBUF_INIT; + + if (has_pack_index(sha1)) { + ret = 0; + goto cleanup; + } + + if (http_is_verbose) + fprintf(stderr, "Getting index for pack %s\n", hex); + + end_url_with_slash(&buf, base_url); + strbuf_addf(&buf, "objects/pack/pack-%s.idx", hex); + url = strbuf_detach(&buf, NULL); + + filename = sha1_pack_index_name(sha1); + if (http_get_file(url, filename, 0) != HTTP_OK) + ret = error("Unable to get pack index %s\n", url); + +cleanup: + free(hex); + free(url); + return ret; +} + +static int fetch_and_setup_pack_index(struct packed_git **packs_head, + unsigned char *sha1, const char *base_url) +{ + struct packed_git *new_pack; + + if (fetch_pack_index(sha1, base_url)) + return -1; + + new_pack = parse_pack_index(sha1); + if (!new_pack) + return -1; /* parse_pack_index() already issued error message */ + new_pack->next = *packs_head; + *packs_head = new_pack; + return 0; +} + +int http_get_info_packs(const char *base_url, struct packed_git **packs_head) +{ + int ret = 0, i = 0; + char *url, *data; + struct strbuf buf = STRBUF_INIT; + unsigned char sha1[20]; + + end_url_with_slash(&buf, base_url); + strbuf_addstr(&buf, "objects/info/packs"); + url = strbuf_detach(&buf, NULL); + + ret = http_get_strbuf(url, &buf, HTTP_NO_CACHE); + if (ret != HTTP_OK) + goto cleanup; + + data = buf.buf; + while (i < buf.len) { + switch (data[i]) { + case 'P': + i++; + if (i + 52 <= buf.len && + !prefixcmp(data + i, " pack-") && + !prefixcmp(data + i + 46, ".pack\n")) { + get_sha1_hex(data + i + 6, sha1); + fetch_and_setup_pack_index(packs_head, sha1, + base_url); + i += 51; + break; + } + default: + while (i < buf.len && data[i] != '\n') + i++; + } + i++; + } + +cleanup: + free(url); + return ret; +} + +void release_http_pack_request(struct http_pack_request *preq) +{ + if (preq->packfile != NULL) { + fclose(preq->packfile); + preq->packfile = NULL; + preq->slot->local = NULL; + } + if (preq->range_header != NULL) { + curl_slist_free_all(preq->range_header); + preq->range_header = NULL; + } + preq->slot = NULL; + free(preq->url); +} + +int finish_http_pack_request(struct http_pack_request *preq) +{ + int ret; + struct packed_git **lst; + + preq->target->pack_size = ftell(preq->packfile); + + if (preq->packfile != NULL) { + fclose(preq->packfile); + preq->packfile = NULL; + preq->slot->local = NULL; + } + + ret = move_temp_to_file(preq->tmpfile, preq->filename); + if (ret) + return ret; + + lst = preq->lst; + while (*lst != preq->target) + lst = &((*lst)->next); + *lst = (*lst)->next; + + if (verify_pack(preq->target)) + return -1; + install_packed_git(preq->target); + + return 0; +} + +struct http_pack_request *new_http_pack_request( + struct packed_git *target, const char *base_url) +{ + char *url; + char *filename; + long prev_posn = 0; + char range[RANGE_HEADER_SIZE]; + struct strbuf buf = STRBUF_INIT; + struct http_pack_request *preq; + + preq = xmalloc(sizeof(*preq)); + preq->target = target; + preq->range_header = NULL; + + end_url_with_slash(&buf, base_url); + strbuf_addf(&buf, "objects/pack/pack-%s.pack", + sha1_to_hex(target->sha1)); + url = strbuf_detach(&buf, NULL); + preq->url = xstrdup(url); + + filename = sha1_pack_name(target->sha1); + snprintf(preq->filename, sizeof(preq->filename), "%s", filename); + snprintf(preq->tmpfile, sizeof(preq->tmpfile), "%s.temp", filename); + preq->packfile = fopen(preq->tmpfile, "a"); + if (!preq->packfile) { + error("Unable to open local file %s for pack", + preq->tmpfile); + goto abort; + } + + preq->slot = get_active_slot(); + preq->slot->local = preq->packfile; + curl_easy_setopt(preq->slot->curl, CURLOPT_FILE, preq->packfile); + curl_easy_setopt(preq->slot->curl, CURLOPT_WRITEFUNCTION, fwrite); + curl_easy_setopt(preq->slot->curl, CURLOPT_URL, url); + curl_easy_setopt(preq->slot->curl, CURLOPT_HTTPHEADER, + no_pragma_header); + + /* + * If there is data present from a previous transfer attempt, + * resume where it left off + */ + prev_posn = ftell(preq->packfile); + if (prev_posn>0) { + if (http_is_verbose) + fprintf(stderr, + "Resuming fetch of pack %s at byte %ld\n", + sha1_to_hex(target->sha1), prev_posn); + sprintf(range, "Range: bytes=%ld-", prev_posn); + preq->range_header = curl_slist_append(NULL, range); + curl_easy_setopt(preq->slot->curl, CURLOPT_HTTPHEADER, + preq->range_header); + } + + return preq; + +abort: + free(filename); + return NULL; +} + +/* Helpers for fetching objects (loose) */ +static size_t fwrite_sha1_file(void *ptr, size_t eltsize, size_t nmemb, + void *data) +{ + unsigned char expn[4096]; + size_t size = eltsize * nmemb; + int posn = 0; + struct http_object_request *freq = + (struct http_object_request *)data; + do { + ssize_t retval = xwrite(freq->localfile, + (char *) ptr + posn, size - posn); + if (retval < 0) + return posn; + posn += retval; + } while (posn < size); + + freq->stream.avail_in = size; + freq->stream.next_in = ptr; + do { + freq->stream.next_out = expn; + freq->stream.avail_out = sizeof(expn); + freq->zret = git_inflate(&freq->stream, Z_SYNC_FLUSH); + git_SHA1_Update(&freq->c, expn, + sizeof(expn) - freq->stream.avail_out); + } while (freq->stream.avail_in && freq->zret == Z_OK); + data_received++; + return size; +} + +struct http_object_request *new_http_object_request(const char *base_url, + unsigned char *sha1) +{ + char *hex = sha1_to_hex(sha1); + char *filename; + char prevfile[PATH_MAX]; + char *url; + int prevlocal; + unsigned char prev_buf[PREV_BUF_SIZE]; + ssize_t prev_read = 0; + long prev_posn = 0; + char range[RANGE_HEADER_SIZE]; + struct curl_slist *range_header = NULL; + struct http_object_request *freq; + + freq = xmalloc(sizeof(*freq)); + hashcpy(freq->sha1, sha1); + freq->localfile = -1; + + filename = sha1_file_name(sha1); + snprintf(freq->filename, sizeof(freq->filename), "%s", filename); + snprintf(freq->tmpfile, sizeof(freq->tmpfile), + "%s.temp", filename); + + snprintf(prevfile, sizeof(prevfile), "%s.prev", filename); + unlink_or_warn(prevfile); + rename(freq->tmpfile, prevfile); + unlink_or_warn(freq->tmpfile); + + if (freq->localfile != -1) + error("fd leakage in start: %d", freq->localfile); + freq->localfile = open(freq->tmpfile, + O_WRONLY | O_CREAT | O_EXCL, 0666); + /* + * This could have failed due to the "lazy directory creation"; + * try to mkdir the last path component. + */ + if (freq->localfile < 0 && errno == ENOENT) { + char *dir = strrchr(freq->tmpfile, '/'); + if (dir) { + *dir = 0; + mkdir(freq->tmpfile, 0777); + *dir = '/'; + } + freq->localfile = open(freq->tmpfile, + O_WRONLY | O_CREAT | O_EXCL, 0666); + } + + if (freq->localfile < 0) { + error("Couldn't create temporary file %s for %s: %s", + freq->tmpfile, freq->filename, strerror(errno)); + goto abort; + } + + memset(&freq->stream, 0, sizeof(freq->stream)); + + git_inflate_init(&freq->stream); + + git_SHA1_Init(&freq->c); + + url = get_remote_object_url(base_url, hex, 0); + freq->url = xstrdup(url); + + /* + * If a previous temp file is present, process what was already + * fetched. + */ + prevlocal = open(prevfile, O_RDONLY); + if (prevlocal != -1) { + do { + prev_read = xread(prevlocal, prev_buf, PREV_BUF_SIZE); + if (prev_read>0) { + if (fwrite_sha1_file(prev_buf, + 1, + prev_read, + freq) == prev_read) { + prev_posn += prev_read; + } else { + prev_read = -1; + } + } + } while (prev_read > 0); + close(prevlocal); + } + unlink_or_warn(prevfile); + + /* + * Reset inflate/SHA1 if there was an error reading the previous temp + * file; also rewind to the beginning of the local file. + */ + if (prev_read == -1) { + memset(&freq->stream, 0, sizeof(freq->stream)); + git_inflate_init(&freq->stream); + git_SHA1_Init(&freq->c); + if (prev_posn>0) { + prev_posn = 0; + lseek(freq->localfile, 0, SEEK_SET); + ftruncate(freq->localfile, 0); + } + } + + freq->slot = get_active_slot(); + + curl_easy_setopt(freq->slot->curl, CURLOPT_FILE, freq); + curl_easy_setopt(freq->slot->curl, CURLOPT_WRITEFUNCTION, fwrite_sha1_file); + curl_easy_setopt(freq->slot->curl, CURLOPT_ERRORBUFFER, freq->errorstr); + curl_easy_setopt(freq->slot->curl, CURLOPT_URL, url); + curl_easy_setopt(freq->slot->curl, CURLOPT_HTTPHEADER, no_pragma_header); + + /* + * If we have successfully processed data from a previous fetch + * attempt, only fetch the data we don't already have. + */ + if (prev_posn>0) { + if (http_is_verbose) + fprintf(stderr, + "Resuming fetch of object %s at byte %ld\n", + hex, prev_posn); + sprintf(range, "Range: bytes=%ld-", prev_posn); + range_header = curl_slist_append(range_header, range); + curl_easy_setopt(freq->slot->curl, + CURLOPT_HTTPHEADER, range_header); + } + + return freq; + + free(url); +abort: + free(filename); + free(freq); + return NULL; +} + +void process_http_object_request(struct http_object_request *freq) +{ + if (freq->slot == NULL) + return; + freq->curl_result = freq->slot->curl_result; + freq->http_code = freq->slot->http_code; + freq->slot = NULL; +} + +int finish_http_object_request(struct http_object_request *freq) +{ + struct stat st; + + close(freq->localfile); + freq->localfile = -1; + + process_http_object_request(freq); + + if (freq->http_code == 416) { + fprintf(stderr, "Warning: requested range invalid; we may already have all the data.\n"); + } else if (freq->curl_result != CURLE_OK) { + if (stat(freq->tmpfile, &st) == 0) + if (st.st_size == 0) + unlink_or_warn(freq->tmpfile); + return -1; + } + + git_inflate_end(&freq->stream); + git_SHA1_Final(freq->real_sha1, &freq->c); + if (freq->zret != Z_STREAM_END) { + unlink_or_warn(freq->tmpfile); + return -1; + } + if (hashcmp(freq->sha1, freq->real_sha1)) { + unlink_or_warn(freq->tmpfile); + return -1; + } + freq->rename = + move_temp_to_file(freq->tmpfile, freq->filename); + + return freq->rename; +} + +void abort_http_object_request(struct http_object_request *freq) +{ + unlink_or_warn(freq->tmpfile); + + release_http_object_request(freq); +} + +void release_http_object_request(struct http_object_request *freq) +{ + if (freq->localfile != -1) { + close(freq->localfile); + freq->localfile = -1; + } + if (freq->url != NULL) { + free(freq->url); + freq->url = NULL; + } + if (freq->slot != NULL) { + freq->slot->callback_func = NULL; + freq->slot->callback_data = NULL; + release_active_slot(freq->slot); + freq->slot = NULL; + } +} @@ -93,6 +93,7 @@ extern void http_cleanup(void); extern int data_received; extern int active_requests; +extern int http_is_verbose; extern char curl_errorstr[CURL_ERROR_SIZE]; @@ -109,6 +110,90 @@ static inline int missing__target(int code, int result) #define missing_target(a) missing__target((a)->http_code, (a)->curl_result) +/* Helpers for modifying and creating URLs */ +extern void append_remote_object_url(struct strbuf *buf, const char *url, + const char *hex, + int only_two_digit_prefix); +extern char *get_remote_object_url(const char *url, const char *hex, + int only_two_digit_prefix); + +/* Options for http_request_*() */ +#define HTTP_NO_CACHE 1 + +/* Return values for http_request_*() */ +#define HTTP_OK 0 +#define HTTP_MISSING_TARGET 1 +#define HTTP_ERROR 2 +#define HTTP_START_FAILED 3 + +/* + * Requests an url and stores the result in a strbuf. + * + * If the result pointer is NULL, a HTTP HEAD request is made instead of GET. + */ +int http_get_strbuf(const char *url, struct strbuf *result, int options); + +/* + * Downloads an url and stores the result in the given file. + * + * If a previous interrupted download is detected (i.e. a previous temporary + * file is still around) the download is resumed. + */ +int http_get_file(const char *url, const char *filename, int options); + +/* + * Prints an error message using error() containing url and curl_errorstr, + * and returns ret. + */ +int http_error(const char *url, int ret); + extern int http_fetch_ref(const char *base, struct ref *ref); +/* Helpers for fetching packs */ +extern int http_get_info_packs(const char *base_url, + struct packed_git **packs_head); + +struct http_pack_request +{ + char *url; + struct packed_git *target; + struct packed_git **lst; + FILE *packfile; + char filename[PATH_MAX]; + char tmpfile[PATH_MAX]; + struct curl_slist *range_header; + struct active_request_slot *slot; +}; + +extern struct http_pack_request *new_http_pack_request( + struct packed_git *target, const char *base_url); +extern int finish_http_pack_request(struct http_pack_request *preq); +extern void release_http_pack_request(struct http_pack_request *preq); + +/* Helpers for fetching object */ +struct http_object_request +{ + char *url; + char filename[PATH_MAX]; + char tmpfile[PATH_MAX]; + int localfile; + CURLcode curl_result; + char errorstr[CURL_ERROR_SIZE]; + long http_code; + unsigned char sha1[20]; + unsigned char real_sha1[20]; + git_SHA_CTX c; + z_stream stream; + int zret; + int rename; + struct active_request_slot *slot; +}; + +extern struct http_object_request *new_http_object_request( + const char *base_url, unsigned char *sha1); +extern void process_http_object_request(struct http_object_request *freq); +extern int finish_http_object_request(struct http_object_request *freq); +extern void abort_http_object_request(struct http_object_request *freq); +extern void release_http_object_request(struct http_object_request *freq); + #endif /* HTTP_H */ diff --git a/imap-send.c b/imap-send.c index 8154cb2116..3847fd151d 100644 --- a/imap-send.c +++ b/imap-send.c @@ -238,7 +238,7 @@ static const char *Flags[] = { #ifndef NO_OPENSSL static void ssl_socket_perror(const char *func) { - fprintf(stderr, "%s: %s\n", func, ERR_error_string(ERR_get_error(), 0)); + fprintf(stderr, "%s: %s\n", func, ERR_error_string(ERR_get_error(), NULL)); } #endif @@ -982,9 +982,7 @@ static struct store *imap_open_store(struct imap_server_conf *srvc) struct imap_store *ctx; struct imap *imap; char *arg, *rsp; - struct hostent *he; - struct sockaddr_in addr; - int s, a[2], preauth; + int s = -1, a[2], preauth; pid_t pid; ctx = xcalloc(sizeof(*ctx), 1); @@ -1021,6 +1019,51 @@ static struct store *imap_open_store(struct imap_server_conf *srvc) imap_info("ok\n"); } else { +#ifndef NO_IPV6 + struct addrinfo hints, *ai0, *ai; + int gai; + char portstr[6]; + + snprintf(portstr, sizeof(portstr), "%hu", srvc->port); + + memset(&hints, 0, sizeof(hints)); + hints.ai_socktype = SOCK_STREAM; + hints.ai_protocol = IPPROTO_TCP; + + imap_info("Resolving %s... ", srvc->host); + gai = getaddrinfo(srvc->host, portstr, &hints, &ai); + if (gai) { + fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(gai)); + goto bail; + } + imap_info("ok\n"); + + for (ai0 = ai; ai; ai = ai->ai_next) { + char addr[NI_MAXHOST]; + + s = socket(ai->ai_family, ai->ai_socktype, + ai->ai_protocol); + if (s < 0) + continue; + + getnameinfo(ai->ai_addr, ai->ai_addrlen, addr, + sizeof(addr), NULL, 0, NI_NUMERICHOST); + imap_info("Connecting to [%s]:%s... ", addr, portstr); + + if (connect(s, ai->ai_addr, ai->ai_addrlen) < 0) { + close(s); + s = -1; + perror("connect"); + continue; + } + + break; + } + freeaddrinfo(ai0); +#else /* NO_IPV6 */ + struct hostent *he; + struct sockaddr_in addr; + memset(&addr, 0, sizeof(addr)); addr.sin_port = htons(srvc->port); addr.sin_family = AF_INET; @@ -1040,7 +1083,12 @@ static struct store *imap_open_store(struct imap_server_conf *srvc) imap_info("Connecting to %s:%hu... ", inet_ntoa(addr.sin_addr), ntohs(addr.sin_port)); if (connect(s, (struct sockaddr *)&addr, sizeof(addr))) { close(s); + s = -1; perror("connect"); + } +#endif + if (s < 0) { + fputs("Error: unable to connect to server.\n", stderr); goto bail; } diff --git a/index-pack.c b/index-pack.c index 0c92bafcbb..340074fc79 100644 --- a/index-pack.c +++ b/index-pack.c @@ -143,7 +143,7 @@ static void *fill(int min) if (ret <= 0) { if (!ret) die("early EOF"); - die("read error on input: %s", strerror(errno)); + die_errno("read error on input"); } input_len += ret; if (from_stdin) @@ -178,13 +178,12 @@ static char *open_pack_file(char *pack_name) } else output_fd = open(pack_name, O_CREAT|O_EXCL|O_RDWR, 0600); if (output_fd < 0) - die("unable to create %s: %s", pack_name, strerror(errno)); + die_errno("unable to create '%s'", pack_name); pack_fd = output_fd; } else { input_fd = open(pack_name, O_RDONLY); if (input_fd < 0) - die("cannot open packfile '%s': %s", - pack_name, strerror(errno)); + die_errno("cannot open packfile '%s'", pack_name); output_fd = -1; pack_fd = input_fd; } @@ -370,7 +369,7 @@ static void *get_data_from_pack(struct object_entry *obj) do { ssize_t n = pread(pack_fd, data + rdy, len - rdy, from + rdy); if (n < 0) - die("cannot pread pack file: %s", strerror(errno)); + die_errno("cannot pread pack file"); if (!n) die("premature end of pack file, %lu bytes missing", len - rdy); @@ -469,7 +468,7 @@ static void sha1_object(const void *data, unsigned long size, die("invalid %s", typename(type)); if (fsck_object(obj, 1, fsck_error_function)) die("Error in object"); - if (fsck_walk(obj, mark_link, 0)) + if (fsck_walk(obj, mark_link, NULL)) die("Not all child objects of %s are reachable", sha1_to_hex(obj->sha1)); if (obj->type == OBJ_TREE) { @@ -631,7 +630,7 @@ static void parse_pack_objects(unsigned char *sha1) /* If input_fd is a file, we should have reached its end now. */ if (fstat(input_fd, &st)) - die("cannot fstat packfile: %s", strerror(errno)); + die_errno("cannot fstat packfile"); if (S_ISREG(st.st_mode) && lseek(input_fd, 0, SEEK_CUR) - input_len != st.st_size) die("pack has junk at the end"); @@ -788,7 +787,7 @@ static void final(const char *final_pack_name, const char *curr_pack_name, fsync_or_die(output_fd, curr_pack_name); err = close(output_fd); if (err) - die("error while closing pack file: %s", strerror(errno)); + die_errno("error while closing pack file"); } if (keep_msg) { @@ -801,16 +800,16 @@ static void final(const char *final_pack_name, const char *curr_pack_name, if (keep_fd < 0) { if (errno != EEXIST) - die("cannot write keep file '%s' (%s)", - keep_name, strerror(errno)); + die_errno("cannot write keep file '%s'", + keep_name); } else { if (keep_msg_len > 0) { write_or_die(keep_fd, keep_msg, keep_msg_len); write_or_die(keep_fd, "\n", 1); } if (close(keep_fd) != 0) - die("cannot close written keep file '%s' (%s)", - keep_name, strerror(errno)); + die_errno("cannot close written keep file '%s'", + keep_name); report = "keep"; } } diff --git a/ll-merge.c b/ll-merge.c index f7c2bc9278..0571564ddf 100644 --- a/ll-merge.c +++ b/ll-merge.c @@ -55,7 +55,7 @@ static int ll_binary_merge(const struct ll_merge_driver *drv_unused, static int ll_xdl_merge(const struct ll_merge_driver *drv_unused, mmbuffer_t *result, - const char *path_unused, + const char *path, mmfile_t *orig, mmfile_t *src1, const char *name1, mmfile_t *src2, const char *name2, @@ -67,10 +67,10 @@ static int ll_xdl_merge(const struct ll_merge_driver *drv_unused, if (buffer_is_binary(orig->ptr, orig->size) || buffer_is_binary(src1->ptr, src1->size) || buffer_is_binary(src2->ptr, src2->size)) { - warning("Cannot merge binary files: %s vs. %s\n", - name1, name2); + warning("Cannot merge binary files: %s (%s vs. %s)\n", + path, name1, name2); return ll_binary_merge(drv_unused, result, - path_unused, + path, orig, src1, name1, src2, name2, virtual_ancestor); @@ -152,7 +152,7 @@ static void create_temp(mmfile_t *src, char *path) strcpy(path, ".merge_file_XXXXXX"); fd = xmkstemp(path); if (write_in_full(fd, src->ptr, src->size) != src->size) - die("unable to write temp-file"); + die_errno("unable to write temp-file"); close(fd); } @@ -175,8 +175,7 @@ static int ll_ext_merge(const struct ll_merge_driver *fn, { "B", temp[2] }, { NULL } }; - struct child_process child; - const char *args[20]; + const char *args[] = { "sh", "-c", NULL, NULL }; int status, fd, i; struct stat st; @@ -191,14 +190,8 @@ static int ll_ext_merge(const struct ll_merge_driver *fn, strbuf_expand(&cmd, fn->cmdline, strbuf_expand_dict_cb, &dict); - memset(&child, 0, sizeof(child)); - child.argv = args; - args[0] = "sh"; - args[1] = "-c"; args[2] = cmd.buf; - args[3] = NULL; - - status = run_command(&child); + status = run_command_v_opt(args, 0); if (status < -ERR_RUN_COMMAND_FORK) ; /* failure in run-command */ else diff --git a/log-tree.c b/log-tree.c index 5bd29e6994..1c9eefee33 100644 --- a/log-tree.c +++ b/log-tree.c @@ -25,6 +25,8 @@ static int add_ref_decoration(const char *refname, const unsigned char *sha1, in struct object *obj = parse_object(sha1); if (!obj) return 0; + if (!cb_data || *(int *)cb_data == DECORATE_SHORT_REFS) + refname = prettify_refname(refname); add_name_decoration("", refname, obj); while (obj->type == OBJ_TAG) { obj = ((struct tag *)obj)->tagged; @@ -35,12 +37,12 @@ static int add_ref_decoration(const char *refname, const unsigned char *sha1, in return 0; } -void load_ref_decorations(void) +void load_ref_decorations(int flags) { static int loaded; if (!loaded) { loaded = 1; - for_each_ref(add_ref_decoration, NULL); + for_each_ref(add_ref_decoration, &flags); } } @@ -167,18 +169,6 @@ static unsigned int digits_in_number(unsigned int number) return result; } -static int has_non_ascii(const char *s) -{ - int ch; - if (!s) - return 0; - while ((ch = *s++) != '\0') { - if (non_ascii(ch)) - return 1; - } - return 0; -} - void get_patch_filename(struct commit *commit, int nr, const char *suffix, struct strbuf *buf) { @@ -320,7 +310,8 @@ void show_log(struct rev_info *opt) } /* - * If use_terminator is set, add a newline at the end of the entry. + * If use_terminator is set, we already handled any record termination + * at the end of the last record. * Otherwise, add a diffopt.line_termination character before all * entries but the first. (IOW, as a separator between entries) */ diff --git a/log-tree.h b/log-tree.h index 20b5caf1aa..3f7b40027b 100644 --- a/log-tree.h +++ b/log-tree.h @@ -17,7 +17,7 @@ void log_write_email_headers(struct rev_info *opt, struct commit *commit, const char **subject_p, const char **extra_headers_p, int *need_8bit_cte_p); -void load_ref_decorations(void); +void load_ref_decorations(int flags); #define FORMAT_PATCH_NAME_MAX 64 void get_patch_filename(struct commit *commit, int nr, const char *suffix, @@ -103,7 +103,7 @@ static char *parse_name_and_email(char *buffer, char **name, char **email, int allow_empty_email) { char *left, *right, *nstart, *nend; - *name = *email = 0; + *name = *email = NULL; if ((left = strchr(buffer, '<')) == NULL) return NULL; @@ -136,7 +136,7 @@ static int read_single_mailmap(struct string_list *map, const char *filename, ch if (f == NULL) return 1; while (fgets(buffer, sizeof(buffer), f) != NULL) { - char *name1 = 0, *email1 = 0, *name2 = 0, *email2 = 0; + char *name1 = NULL, *email1 = NULL, *name2 = NULL, *email2 = NULL; if (buffer[0] == '#') { static const char abbrev[] = "# repo-abbrev:"; int abblen = sizeof(abbrev) - 1; @@ -200,7 +200,7 @@ int map_user(struct string_list *map, if (!p) { /* email passed in might not be wrapped in <>, but end with a \0 */ p = memchr(email, '\0', maxlen_email); - if (p == 0) + if (!p) return 0; } if (p - email + 1 < sizeof(buf)) diff --git a/merge-index.c b/merge-index.c index aa9cf23a39..19ddd03e0b 100644 --- a/merge-index.c +++ b/merge-index.c @@ -3,45 +3,20 @@ #include "exec_cmd.h" static const char *pgm; -static const char *arguments[9]; static int one_shot, quiet; static int err; -static void run_program(void) -{ - struct child_process child; - memset(&child, 0, sizeof(child)); - child.argv = arguments; - if (run_command(&child)) { - if (one_shot) { - err++; - } else { - if (!quiet) - die("merge program failed"); - exit(1); - } - } -} - static int merge_entry(int pos, const char *path) { int found; + const char *arguments[] = { pgm, "", "", "", path, "", "", "", NULL }; + char hexbuf[4][60]; + char ownbuf[4][60]; if (pos >= active_nr) die("git merge-index: %s not in the cache", path); - arguments[0] = pgm; - arguments[1] = ""; - arguments[2] = ""; - arguments[3] = ""; - arguments[4] = path; - arguments[5] = ""; - arguments[6] = ""; - arguments[7] = ""; - arguments[8] = NULL; found = 0; do { - static char hexbuf[4][60]; - static char ownbuf[4][60]; struct cache_entry *ce = active_cache[pos]; int stage = ce_stage(ce); @@ -55,7 +30,16 @@ static int merge_entry(int pos, const char *path) } while (++pos < active_nr); if (!found) die("git merge-index: %s not in the cache", path); - run_program(); + + if (run_command_v_opt(arguments, 0)) { + if (one_shot) + err++; + else { + if (!quiet) + die("merge program failed"); + exit(1); + } + } return found; } diff --git a/merge-recursive.c b/merge-recursive.c index f5df9b961b..10d7913b06 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -38,7 +38,7 @@ static struct tree *shift_tree_object(struct tree *one, struct tree *two) * A virtual commit has (const char *)commit->util set to the name. */ -struct commit *make_virtual_commit(struct tree *tree, const char *comment) +static struct commit *make_virtual_commit(struct tree *tree, const char *comment) { struct commit *commit = xcalloc(1, sizeof(struct commit)); commit->tree = tree; @@ -438,7 +438,7 @@ static void flush_buffer(int fd, const char *buf, unsigned long size) /* Ignore epipe */ if (errno == EPIPE) break; - die("merge-recursive: %s", strerror(errno)); + die_errno("merge-recursive"); } else if (!ret) { die("merge-recursive: disk full?"); } @@ -554,7 +554,7 @@ static void update_file_flags(struct merge_options *o, mode = 0666; fd = open(path, O_WRONLY | O_TRUNC | O_CREAT, mode); if (fd < 0) - die("failed to open %s: %s", path, strerror(errno)); + die_errno("failed to open '%s'", path); flush_buffer(fd, buf, size); close(fd); } else if (S_ISLNK(mode)) { @@ -562,7 +562,7 @@ static void update_file_flags(struct merge_options *o, safe_create_leading_directories_const(path); unlink(path); if (symlink(lnk, path)) - die("failed to symlink %s: %s", path, strerror(errno)); + die_errno("failed to symlink '%s'", path); free(lnk); } else die("do not know what to do with %06o %s '%s'", @@ -622,8 +622,13 @@ static int merge_3way(struct merge_options *o, char *name1, *name2; int merge_status; - name1 = xstrdup(mkpath("%s:%s", branch1, a->path)); - name2 = xstrdup(mkpath("%s:%s", branch2, b->path)); + if (strcmp(a->path, b->path)) { + name1 = xstrdup(mkpath("%s:%s", branch1, a->path)); + name2 = xstrdup(mkpath("%s:%s", branch2, b->path)); + } else { + name1 = xstrdup(mkpath("%s", branch1)); + name2 = xstrdup(mkpath("%s", branch2)); + } fill_mm(one->sha1, &orig); fill_mm(a->sha1, &src1); @@ -947,9 +952,31 @@ static int process_renames(struct merge_options *o, "%s added in %s", ren1_src, ren1_dst, branch1, ren1_dst, branch2); - new_path = unique_path(o, ren1_dst, branch2); - output(o, 1, "Adding as %s instead", new_path); - update_file(o, 0, dst_other.sha1, dst_other.mode, new_path); + if (o->call_depth) { + struct merge_file_info mfi; + struct diff_filespec one, a, b; + + one.path = a.path = b.path = + (char *)ren1_dst; + hashcpy(one.sha1, null_sha1); + one.mode = 0; + hashcpy(a.sha1, ren1->pair->two->sha1); + a.mode = ren1->pair->two->mode; + hashcpy(b.sha1, dst_other.sha1); + b.mode = dst_other.mode; + mfi = merge_file(o, &one, &a, &b, + branch1, + branch2); + output(o, 1, "Adding merged %s", ren1_dst); + update_file(o, 0, + mfi.sha, + mfi.mode, + ren1_dst); + } else { + new_path = unique_path(o, ren1_dst, branch2); + output(o, 1, "Adding as %s instead", new_path); + update_file(o, 0, dst_other.sha1, dst_other.mode, new_path); + } } else if ((item = string_list_lookup(ren1_dst, renames2Dst))) { ren2 = item->util; clean_merge = 0; @@ -165,7 +165,7 @@ int main(int argc, char **argv) setup_git_directory(); if (strbuf_read(&buf, 0, 4096) < 0) { - die("could not read from stdin"); + die_errno("could not read from stdin"); } /* Verify it for some basic sanity: it needs to start with diff --git a/mktree.c b/mktree.c deleted file mode 100644 index 137a0950f6..0000000000 --- a/mktree.c +++ /dev/null @@ -1,131 +0,0 @@ -/* - * GIT - the stupid content tracker - * - * Copyright (c) Junio C Hamano, 2006 - */ -#include "cache.h" -#include "quote.h" -#include "tree.h" -#include "exec_cmd.h" - -static struct treeent { - unsigned mode; - unsigned char sha1[20]; - int len; - char name[FLEX_ARRAY]; -} **entries; -static int alloc, used; - -static void append_to_tree(unsigned mode, unsigned char *sha1, char *path) -{ - struct treeent *ent; - int len = strlen(path); - if (strchr(path, '/')) - die("path %s contains slash", path); - - if (alloc <= used) { - alloc = alloc_nr(used); - entries = xrealloc(entries, sizeof(*entries) * alloc); - } - ent = entries[used++] = xmalloc(sizeof(**entries) + len + 1); - ent->mode = mode; - ent->len = len; - hashcpy(ent->sha1, sha1); - memcpy(ent->name, path, len+1); -} - -static int ent_compare(const void *a_, const void *b_) -{ - struct treeent *a = *(struct treeent **)a_; - struct treeent *b = *(struct treeent **)b_; - return base_name_compare(a->name, a->len, a->mode, - b->name, b->len, b->mode); -} - -static void write_tree(unsigned char *sha1) -{ - struct strbuf buf; - size_t size; - int i; - - qsort(entries, used, sizeof(*entries), ent_compare); - for (size = i = 0; i < used; i++) - size += 32 + entries[i]->len; - - strbuf_init(&buf, size); - for (i = 0; i < used; i++) { - struct treeent *ent = entries[i]; - strbuf_addf(&buf, "%o %s%c", ent->mode, ent->name, '\0'); - strbuf_add(&buf, ent->sha1, 20); - } - - write_sha1_file(buf.buf, buf.len, tree_type, sha1); -} - -static const char mktree_usage[] = "git mktree [-z]"; - -int main(int ac, char **av) -{ - struct strbuf sb = STRBUF_INIT; - struct strbuf p_uq = STRBUF_INIT; - unsigned char sha1[20]; - int line_termination = '\n'; - - git_extract_argv0_path(av[0]); - - setup_git_directory(); - - while ((1 < ac) && av[1][0] == '-') { - char *arg = av[1]; - if (!strcmp("-z", arg)) - line_termination = 0; - else - usage(mktree_usage); - ac--; - av++; - } - - while (strbuf_getline(&sb, stdin, line_termination) != EOF) { - char *ptr, *ntr; - unsigned mode; - enum object_type type; - char *path; - - ptr = sb.buf; - /* Input is non-recursive ls-tree output format - * mode SP type SP sha1 TAB name - */ - mode = strtoul(ptr, &ntr, 8); - if (ptr == ntr || !ntr || *ntr != ' ') - die("input format error: %s", sb.buf); - ptr = ntr + 1; /* type */ - ntr = strchr(ptr, ' '); - if (!ntr || sb.buf + sb.len <= ntr + 40 || - ntr[41] != '\t' || - get_sha1_hex(ntr + 1, sha1)) - die("input format error: %s", sb.buf); - type = sha1_object_info(sha1, NULL); - if (type < 0) - die("object %s unavailable", sha1_to_hex(sha1)); - *ntr++ = 0; /* now at the beginning of SHA1 */ - if (type != type_from_string(ptr)) - die("object type %s mismatch (%s)", ptr, typename(type)); - - path = ntr + 41; /* at the beginning of name */ - if (line_termination && path[0] == '"') { - strbuf_reset(&p_uq); - if (unquote_c_style(&p_uq, path, NULL)) { - die("invalid quoting"); - } - path = p_uq.buf; - } - - append_to_tree(mode, sha1, path); - } - strbuf_release(&p_uq); - strbuf_release(&sb); - - write_tree(sha1); - puts(sha1_to_hex(sha1)); - exit(0); -} @@ -52,7 +52,7 @@ static unsigned int hash_obj(struct object *obj, unsigned int n) static void insert_obj_hash(struct object *obj, struct object **hash, unsigned int size) { - int j = hash_obj(obj, size); + unsigned int j = hash_obj(obj, size); while (hash[j]) { j++; @@ -62,16 +62,16 @@ static void insert_obj_hash(struct object *obj, struct object **hash, unsigned i hash[j] = obj; } -static int hashtable_index(const unsigned char *sha1) +static unsigned int hashtable_index(const unsigned char *sha1) { unsigned int i; memcpy(&i, sha1, sizeof(unsigned int)); - return (int)(i % obj_hash_size); + return i % obj_hash_size; } struct object *lookup_object(const unsigned char *sha1) { - int i; + unsigned int i; struct object *obj; if (!obj_hash) diff --git a/pack-check.c b/pack-check.c index 90c33b1b84..166ca703c1 100644 --- a/pack-check.c +++ b/pack-check.c @@ -49,7 +49,7 @@ static int verify_packfile(struct packed_git *p, const unsigned char *index_base = p->index_data; git_SHA_CTX ctx; unsigned char sha1[20], *pack_sig; - off_t offset = 0, pack_sig_ofs = p->pack_size - 20; + off_t offset = 0, pack_sig_ofs = 0; uint32_t nr_objects, i; int err = 0; struct idx_entry *entries; @@ -61,14 +61,16 @@ static int verify_packfile(struct packed_git *p, */ git_SHA1_Init(&ctx); - while (offset < pack_sig_ofs) { + do { unsigned int remaining; unsigned char *in = use_pack(p, w_curs, offset, &remaining); offset += remaining; + if (!pack_sig_ofs) + pack_sig_ofs = p->pack_size - 20; if (offset > pack_sig_ofs) remaining -= (unsigned int)(offset - pack_sig_ofs); git_SHA1_Update(&ctx, in, remaining); - } + } while (offset < pack_sig_ofs); git_SHA1_Final(sha1, &ctx); pack_sig = use_pack(p, w_curs, pack_sig_ofs, NULL); if (hashcmp(sha1, pack_sig)) diff --git a/pack-refs.c b/pack-refs.c index 301fc60eae..7f43f8ac33 100644 --- a/pack-refs.c +++ b/pack-refs.c @@ -93,8 +93,7 @@ int pack_refs(unsigned int flags) LOCK_DIE_ON_ERROR); cbdata.refs_file = fdopen(fd, "w"); if (!cbdata.refs_file) - die("unable to create ref-pack file structure (%s)", - strerror(errno)); + die_errno("unable to create ref-pack file structure"); /* perhaps other traits later as well */ fprintf(cbdata.refs_file, "# pack-refs with: peeled \n"); @@ -103,7 +102,7 @@ int pack_refs(unsigned int flags) if (ferror(cbdata.refs_file)) die("failed to write ref-pack file"); if (fflush(cbdata.refs_file) || fsync(fd) || fclose(cbdata.refs_file)) - die("failed to write ref-pack file (%s)", strerror(errno)); + die_errno("failed to write ref-pack file"); /* * Since the lock file was fdopen()'ed and then fclose()'ed above, * assign -1 to the lock file descriptor so that commit_lock_file() @@ -111,7 +110,7 @@ int pack_refs(unsigned int flags) */ packed.fd = -1; if (commit_lock_file(&packed) < 0) - die("unable to overwrite old ref-pack file (%s)", strerror(errno)); + die_errno("unable to overwrite old ref-pack file"); if (cbdata.flags & PACK_REFS_PRUNE) prune_refs(cbdata.ref_to_prune); return 0; diff --git a/pack-revindex.c b/pack-revindex.c index 1de53c8934..77a0465be6 100644 --- a/pack-revindex.c +++ b/pack-revindex.c @@ -149,8 +149,7 @@ void discard_revindex(void) if (pack_revindex_hashsz) { int i; for (i = 0; i < pack_revindex_hashsz; i++) - if (pack_revindex[i].revindex) - free(pack_revindex[i].revindex); + free(pack_revindex[i].revindex); free(pack_revindex); pack_revindex_hashsz = 0; } diff --git a/pack-write.c b/pack-write.c index 7053538f4c..741efcd93b 100644 --- a/pack-write.c +++ b/pack-write.c @@ -51,7 +51,7 @@ char *write_idx_file(char *index_name, struct pack_idx_entry **objects, fd = open(index_name, O_CREAT|O_EXCL|O_WRONLY, 0600); } if (fd < 0) - die("unable to create %s: %s", index_name, strerror(errno)); + die_errno("unable to create '%s'", index_name); f = sha1fd(fd, index_name); /* if last object's offset is >= 2^31 we should use index V2 */ @@ -174,11 +174,11 @@ void fixup_pack_header_footer(int pack_fd, git_SHA1_Init(&new_sha1_ctx); if (lseek(pack_fd, 0, SEEK_SET) != 0) - die("Failed seeking to start of %s: %s", pack_name, strerror(errno)); + die_errno("Failed seeking to start of '%s'", pack_name); if (read_in_full(pack_fd, &hdr, sizeof(hdr)) != sizeof(hdr)) - die("Unable to reread header of %s: %s", pack_name, strerror(errno)); + die_errno("Unable to reread header of '%s'", pack_name); if (lseek(pack_fd, 0, SEEK_SET) != 0) - die("Failed seeking to start of %s: %s", pack_name, strerror(errno)); + die_errno("Failed seeking to start of '%s'", pack_name); git_SHA1_Update(&old_sha1_ctx, &hdr, sizeof(hdr)); hdr.hdr_entries = htonl(object_count); git_SHA1_Update(&new_sha1_ctx, &hdr, sizeof(hdr)); @@ -195,7 +195,7 @@ void fixup_pack_header_footer(int pack_fd, if (!n) break; if (n < 0) - die("Failed to checksum %s: %s", pack_name, strerror(errno)); + die_errno("Failed to checksum '%s'", pack_name); git_SHA1_Update(&new_sha1_ctx, buf, n); aligned_sz -= n; diff --git a/parse-options.c b/parse-options.c index cf71bcffd2..f7ce523a61 100644 --- a/parse-options.c +++ b/parse-options.c @@ -31,11 +31,20 @@ static int get_arg(struct parse_opt_ctx_t *p, const struct option *opt, return 0; } +static void fix_filename(const char *prefix, const char **file) +{ + if (!file || !*file || !prefix || is_absolute_path(*file) + || !strcmp("-", *file)) + return; + *file = xstrdup(prefix_filename(prefix, strlen(prefix), *file)); +} + static int get_value(struct parse_opt_ctx_t *p, const struct option *opt, int flags) { const char *s, *arg; const int unset = flags & OPT_UNSET; + int err; if (unset && p->opt) return opterror(opt, "takes no value", flags); @@ -50,6 +59,7 @@ static int get_value(struct parse_opt_ctx_t *p, /* FALLTHROUGH */ case OPTION_BOOLEAN: case OPTION_BIT: + case OPTION_NEGBIT: case OPTION_SET_INT: case OPTION_SET_PTR: return opterror(opt, "takes no value", flags); @@ -66,6 +76,13 @@ static int get_value(struct parse_opt_ctx_t *p, *(int *)opt->value |= opt->defval; return 0; + case OPTION_NEGBIT: + if (unset) + *(int *)opt->value |= opt->defval; + else + *(int *)opt->value &= ~opt->defval; + return 0; + case OPTION_BOOLEAN: *(int *)opt->value = unset ? 0 : *(int *)opt->value + 1; return 0; @@ -87,6 +104,19 @@ static int get_value(struct parse_opt_ctx_t *p, return get_arg(p, opt, flags, (const char **)opt->value); return 0; + case OPTION_FILENAME: + err = 0; + if (unset) + *(const char **)opt->value = NULL; + else if (opt->flags & PARSE_OPT_OPTARG && !p->opt) + *(const char **)opt->value = (const char *)opt->defval; + else + err = get_arg(p, opt, flags, (const char **)opt->value); + + if (!err) + fix_filename(p->prefix, (const char **)opt->value); + return err; + case OPTION_CALLBACK: if (unset) return (*opt->callback)(opt, NULL, 1) ? (-1) : 0; @@ -121,11 +151,33 @@ static int get_value(struct parse_opt_ctx_t *p, static int parse_short_opt(struct parse_opt_ctx_t *p, const struct option *options) { + const struct option *numopt = NULL; + for (; options->type != OPTION_END; options++) { if (options->short_name == *p->opt) { p->opt = p->opt[1] ? p->opt + 1 : NULL; return get_value(p, options, OPT_SHORT); } + + /* + * Handle the numerical option later, explicit one-digit + * options take precedence over it. + */ + if (options->type == OPTION_NUMBER) + numopt = options; + } + if (numopt && isdigit(*p->opt)) { + size_t len = 1; + char *arg; + int rc; + + while (isdigit(p->opt[len])) + len++; + arg = xmemdupz(p->opt, len); + p->opt = p->opt[len] ? p->opt + len : NULL; + rc = (*numopt->callback)(numopt, arg, 0) ? (-1) : 0; + free(arg); + return rc; } return -2; } @@ -215,6 +267,25 @@ is_abbreviated: return -2; } +static int parse_nodash_opt(struct parse_opt_ctx_t *p, const char *arg, + const struct option *options) +{ + for (; options->type != OPTION_END; options++) { + if (!(options->flags & PARSE_OPT_NODASH)) + continue; + if ((options->flags & PARSE_OPT_OPTARG) || + !(options->flags & PARSE_OPT_NOARG)) + die("BUG: dashless options don't support arguments"); + if (!(options->flags & PARSE_OPT_NONEG)) + die("BUG: dashless options don't support negation"); + if (options->long_name) + die("BUG: dashless options can't be long"); + if (options->short_name == arg[0] && arg[1] == '\0') + return get_value(p, options, OPT_SHORT); + } + return -2; +} + static void check_typos(const char *arg, const struct option *options) { if (strlen(arg) < 3) @@ -235,13 +306,37 @@ static void check_typos(const char *arg, const struct option *options) } } +static void parse_options_check(const struct option *opts) +{ + int err = 0; + + for (; opts->type != OPTION_END; opts++) { + if ((opts->flags & PARSE_OPT_LASTARG_DEFAULT) && + (opts->flags & PARSE_OPT_OPTARG)) { + if (opts->long_name) { + error("`--%s` uses incompatible flags " + "LASTARG_DEFAULT and OPTARG", opts->long_name); + } else { + error("`-%c` uses incompatible flags " + "LASTARG_DEFAULT and OPTARG", opts->short_name); + } + err |= 1; + } + } + + if (err) + exit(129); +} + void parse_options_start(struct parse_opt_ctx_t *ctx, - int argc, const char **argv, int flags) + int argc, const char **argv, const char *prefix, + int flags) { memset(ctx, 0, sizeof(*ctx)); ctx->argc = argc - 1; ctx->argv = argv + 1; ctx->out = argv; + ctx->prefix = prefix; ctx->cpidx = ((flags & PARSE_OPT_KEEP_ARGV0) != 0); ctx->flags = flags; if ((flags & PARSE_OPT_KEEP_UNKNOWN) && @@ -258,6 +353,8 @@ int parse_options_step(struct parse_opt_ctx_t *ctx, { int internal_help = !(ctx->flags & PARSE_OPT_NO_INTERNAL_HELP); + parse_options_check(options); + /* we must reset ->opt, unknown short option leave it dangling */ ctx->opt = NULL; @@ -265,6 +362,8 @@ int parse_options_step(struct parse_opt_ctx_t *ctx, const char *arg = ctx->argv[0]; if (*arg != '-' || !arg[1]) { + if (parse_nodash_opt(ctx, arg, options) == 0) + continue; if (ctx->flags & PARSE_OPT_STOP_AT_NON_OPTION) break; ctx->out[ctx->cpidx++] = ctx->argv[0]; @@ -338,12 +437,13 @@ int parse_options_end(struct parse_opt_ctx_t *ctx) return ctx->cpidx + ctx->argc; } -int parse_options(int argc, const char **argv, const struct option *options, - const char * const usagestr[], int flags) +int parse_options(int argc, const char **argv, const char *prefix, + const struct option *options, const char * const usagestr[], + int flags) { struct parse_opt_ctx_t ctx; - parse_options_start(&ctx, argc, argv, flags); + parse_options_start(&ctx, argc, argv, prefix, flags); switch (parse_options_step(&ctx, options, usagestr)) { case PARSE_OPT_HELP: exit(129); @@ -361,10 +461,24 @@ int parse_options(int argc, const char **argv, const struct option *options, return parse_options_end(&ctx); } +static int usage_argh(const struct option *opts) +{ + const char *s; + int literal = (opts->flags & PARSE_OPT_LITERAL_ARGHELP) || !opts->argh; + if (opts->flags & PARSE_OPT_OPTARG) + if (opts->long_name) + s = literal ? "[=%s]" : "[=<%s>]"; + else + s = literal ? "[%s]" : "[<%s>]"; + else + s = literal ? " %s" : " <%s>"; + return fprintf(stderr, s, opts->argh ? opts->argh : "..."); +} + #define USAGE_OPTS_WIDTH 24 #define USAGE_GAP 2 -int usage_with_options_internal(const char * const *usagestr, +static int usage_with_options_internal(const char * const *usagestr, const struct option *opts, int full) { if (!usagestr) @@ -397,51 +511,21 @@ int usage_with_options_internal(const char * const *usagestr, continue; pos = fprintf(stderr, " "); - if (opts->short_name) - pos += fprintf(stderr, "-%c", opts->short_name); + if (opts->short_name) { + if (opts->flags & PARSE_OPT_NODASH) + pos += fprintf(stderr, "%c", opts->short_name); + else + pos += fprintf(stderr, "-%c", opts->short_name); + } if (opts->long_name && opts->short_name) pos += fprintf(stderr, ", "); if (opts->long_name) pos += fprintf(stderr, "--%s", opts->long_name); + if (opts->type == OPTION_NUMBER) + pos += fprintf(stderr, "-NUM"); - switch (opts->type) { - case OPTION_ARGUMENT: - break; - case OPTION_INTEGER: - if (opts->flags & PARSE_OPT_OPTARG) - if (opts->long_name) - pos += fprintf(stderr, "[=<n>]"); - else - pos += fprintf(stderr, "[<n>]"); - else - pos += fprintf(stderr, " <n>"); - break; - case OPTION_CALLBACK: - if (opts->flags & PARSE_OPT_NOARG) - break; - /* FALLTHROUGH */ - case OPTION_STRING: - if (opts->argh) { - if (opts->flags & PARSE_OPT_OPTARG) - if (opts->long_name) - pos += fprintf(stderr, "[=<%s>]", opts->argh); - else - pos += fprintf(stderr, "[<%s>]", opts->argh); - else - pos += fprintf(stderr, " <%s>", opts->argh); - } else { - if (opts->flags & PARSE_OPT_OPTARG) - if (opts->long_name) - pos += fprintf(stderr, "[=...]"); - else - pos += fprintf(stderr, "[...]"); - else - pos += fprintf(stderr, " ..."); - } - break; - default: /* OPTION_{BIT,BOOLEAN,SET_INT,SET_PTR} */ - break; - } + if (!(opts->flags & PARSE_OPT_NOARG)) + pos += usage_argh(opts); if (pos <= USAGE_OPTS_WIDTH) pad = USAGE_OPTS_WIDTH - pos; @@ -536,15 +620,3 @@ int parse_opt_with_commit(const struct option *opt, const char *arg, int unset) commit_list_insert(commit, opt->value); return 0; } - -/* - * This should really be OPTION_FILENAME type as a part of - * parse_options that take prefix to do this while parsing. - */ -extern const char *parse_options_fix_filename(const char *prefix, const char *file) -{ - if (!file || !prefix || is_absolute_path(file) || !strcmp("-", file)) - return file; - return prefix_filename(prefix, strlen(prefix), file); -} - diff --git a/parse-options.h b/parse-options.h index b54eec128b..aba30671dc 100644 --- a/parse-options.h +++ b/parse-options.h @@ -6,8 +6,10 @@ enum parse_opt_type { OPTION_END, OPTION_ARGUMENT, OPTION_GROUP, + OPTION_NUMBER, /* options with no arguments */ OPTION_BIT, + OPTION_NEGBIT, OPTION_BOOLEAN, /* _INCR would have been a better name */ OPTION_SET_INT, OPTION_SET_PTR, @@ -15,6 +17,7 @@ enum parse_opt_type { OPTION_STRING, OPTION_INTEGER, OPTION_CALLBACK, + OPTION_FILENAME }; enum parse_opt_flags { @@ -31,6 +34,8 @@ enum parse_opt_option_flags { PARSE_OPT_NONEG = 4, PARSE_OPT_HIDDEN = 8, PARSE_OPT_LASTARG_DEFAULT = 16, + PARSE_OPT_NODASH = 32, + PARSE_OPT_LITERAL_ARGHELP = 64, }; struct option; @@ -62,10 +67,19 @@ typedef int parse_opt_cb(const struct option *, const char *arg, int unset); * `flags`:: * mask of parse_opt_option_flags. * PARSE_OPT_OPTARG: says that the argument is optional (not for BOOLEANs) - * PARSE_OPT_NOARG: says that this option takes no argument, for CALLBACKs + * PARSE_OPT_NOARG: says that this option takes no argument * PARSE_OPT_NONEG: says that this option cannot be negated - * PARSE_OPT_HIDDEN this option is skipped in the default usage, showed in - * the long one. + * PARSE_OPT_HIDDEN: this option is skipped in the default usage, and + * shown only in the full usage. + * PARSE_OPT_LASTARG_DEFAULT: says that this option will take the default + * value if no argument is given when the option + * is last on the command line. If the option is + * not last it will require an argument. + * Should not be used with PARSE_OPT_OPTARG. + * PARSE_OPT_NODASH: this option doesn't start with a dash. + * PARSE_OPT_LITERAL_ARGHELP: says that argh shouldn't be enclosed in brackets + * (i.e. '<argh>') in the help message. + * Useful for options with multiple parameters. * * `callback`:: * pointer to the callback to use for OPTION_CALLBACK. @@ -90,25 +104,37 @@ struct option { }; #define OPT_END() { OPTION_END } -#define OPT_ARGUMENT(l, h) { OPTION_ARGUMENT, 0, (l), NULL, NULL, (h) } +#define OPT_ARGUMENT(l, h) { OPTION_ARGUMENT, 0, (l), NULL, NULL, \ + (h), PARSE_OPT_NOARG} #define OPT_GROUP(h) { OPTION_GROUP, 0, NULL, NULL, NULL, (h) } -#define OPT_BIT(s, l, v, h, b) { OPTION_BIT, (s), (l), (v), NULL, (h), 0, NULL, (b) } -#define OPT_BOOLEAN(s, l, v, h) { OPTION_BOOLEAN, (s), (l), (v), NULL, (h) } -#define OPT_SET_INT(s, l, v, h, i) { OPTION_SET_INT, (s), (l), (v), NULL, (h), 0, NULL, (i) } -#define OPT_SET_PTR(s, l, v, h, p) { OPTION_SET_PTR, (s), (l), (v), NULL, (h), 0, NULL, (p) } -#define OPT_INTEGER(s, l, v, h) { OPTION_INTEGER, (s), (l), (v), NULL, (h) } +#define OPT_BIT(s, l, v, h, b) { OPTION_BIT, (s), (l), (v), NULL, (h), \ + PARSE_OPT_NOARG, NULL, (b) } +#define OPT_NEGBIT(s, l, v, h, b) { OPTION_NEGBIT, (s), (l), (v), NULL, \ + (h), PARSE_OPT_NOARG, NULL, (b) } +#define OPT_BOOLEAN(s, l, v, h) { OPTION_BOOLEAN, (s), (l), (v), NULL, \ + (h), PARSE_OPT_NOARG } +#define OPT_SET_INT(s, l, v, h, i) { OPTION_SET_INT, (s), (l), (v), NULL, \ + (h), PARSE_OPT_NOARG, NULL, (i) } +#define OPT_SET_PTR(s, l, v, h, p) { OPTION_SET_PTR, (s), (l), (v), NULL, \ + (h), PARSE_OPT_NOARG, NULL, (p) } +#define OPT_INTEGER(s, l, v, h) { OPTION_INTEGER, (s), (l), (v), "n", (h) } #define OPT_STRING(s, l, v, a, h) { OPTION_STRING, (s), (l), (v), (a), (h) } #define OPT_DATE(s, l, v, h) \ { OPTION_CALLBACK, (s), (l), (v), "time",(h), 0, \ parse_opt_approxidate_cb } #define OPT_CALLBACK(s, l, v, a, h, f) \ { OPTION_CALLBACK, (s), (l), (v), (a), (h), 0, (f) } +#define OPT_NUMBER_CALLBACK(v, h, f) \ + { OPTION_NUMBER, 0, NULL, (v), NULL, (h), \ + PARSE_OPT_NOARG | PARSE_OPT_NONEG, (f) } +#define OPT_FILENAME(s, l, v, h) { OPTION_FILENAME, (s), (l), (v), \ + "FILE", (h) } /* parse_options() will filter out the processed options and leave the * non-option arguments in argv[]. * Returns the number of arguments left in argv[]. */ -extern int parse_options(int argc, const char **argv, +extern int parse_options(int argc, const char **argv, const char *prefix, const struct option *options, const char * const usagestr[], int flags); @@ -134,13 +160,15 @@ struct parse_opt_ctx_t { int argc, cpidx; const char *opt; int flags; + const char *prefix; }; extern int parse_options_usage(const char * const *usagestr, const struct option *opts); extern void parse_options_start(struct parse_opt_ctx_t *ctx, - int argc, const char **argv, int flags); + int argc, const char **argv, const char *prefix, + int flags); extern int parse_options_step(struct parse_opt_ctx_t *ctx, const struct option *options, @@ -168,6 +196,4 @@ extern int parse_opt_with_commit(const struct option *, const char *, int); "use <n> digits to display SHA-1s", \ PARSE_OPT_OPTARG, &parse_opt_abbrev_cb, 0 } -extern const char *parse_options_fix_filename(const char *prefix, const char *file); - #endif @@ -139,6 +139,22 @@ int git_mkstemp(char *path, size_t len, const char *template) return mkstemp(path); } +/* git_mkstemps() - create tmp file with suffix honoring TMPDIR variable. */ +int git_mkstemps(char *path, size_t len, const char *template, int suffix_len) +{ + const char *tmp; + size_t n; + + tmp = getenv("TMPDIR"); + if (!tmp) + tmp = "/tmp"; + n = snprintf(path, len, "%s/%s", tmp, template); + if (len <= n) { + errno = ENAMETOOLONG; + return -1; + } + return mkstemps(path, suffix_len); +} int validate_headref(const char *path) { diff --git a/perl/Git.pm b/perl/Git.pm index 291ff5b53c..e8df55d2f2 100644 --- a/perl/Git.pm +++ b/perl/Git.pm @@ -185,7 +185,7 @@ sub repository { if ($dir) { $dir =~ m#^/# or $dir = $opts{Directory} . '/' . $dir; - $opts{Repository} = $dir; + $opts{Repository} = abs_path($dir); # If --git-dir went ok, this shouldn't die either. my $prefix = $search->command_oneline('rev-parse', '--show-prefix'); @@ -1280,6 +1280,8 @@ sub _cmd_exec { my ($self, @args) = @_; if ($self) { $self->repo_path() and $ENV{'GIT_DIR'} = $self->repo_path(); + $self->repo_path() and $self->wc_path() + and $ENV{'GIT_WORK_TREE'} = $self->wc_path(); $self->wc_path() and chdir($self->wc_path()); $self->wc_subdir() and chdir($self->wc_subdir()); } diff --git a/pkt-line.c b/pkt-line.c index f5d00863a6..b691abebd7 100644 --- a/pkt-line.c +++ b/pkt-line.c @@ -28,7 +28,7 @@ ssize_t safe_write(int fd, const void *buf, ssize_t n) } if (!ret) die("write error (disk full?)"); - die("write error (%s)", strerror(errno)); + die_errno("write error"); } return nn; } @@ -67,7 +67,7 @@ static void safe_read(int fd, void *buffer, unsigned size) { ssize_t ret = read_in_full(fd, buffer, size); if (ret < 0) - die("read error (%s)", strerror(errno)); + die_errno("read error"); else if (ret < size) die("The remote end hung up unexpectedly"); } diff --git a/preload-index.c b/preload-index.c index 88edc5f8a9..92899333c2 100644 --- a/preload-index.c +++ b/preload-index.c @@ -34,7 +34,9 @@ static void *preload_thread(void *_data) struct thread_data *p = _data; struct index_state *index = p->index; struct cache_entry **cep = index->cache + p->offset; + struct cache_def cache; + memset(&cache, 0, sizeof(cache)); nr = p->nr; if (nr + p->offset > index->cache_nr) nr = index->cache_nr - p->offset; @@ -49,6 +51,8 @@ static void *preload_thread(void *_data) continue; if (!ce_path_match(ce, p->pathspec)) continue; + if (threaded_has_symlink_leading_path(&cache, ce->name, ce_namelen(ce))) + continue; if (lstat(ce->name, &st)) continue; if (ie_match_stat(index, ce, &st, CE_MATCH_RACY_IS_DIRTY)) @@ -72,7 +76,7 @@ static void preload_index(struct index_state *index, const char **pathspec) if (threads > MAX_PARALLEL) threads = MAX_PARALLEL; offset = 0; - work = (index->cache_nr + threads - 1) / threads; + work = DIV_ROUND_UP(index->cache_nr, threads); for (i = 0; i < threads; i++) { struct thread_data *p = data+i; p->index = index; @@ -86,6 +86,18 @@ int non_ascii(int ch) return !isascii(ch) || ch == '\033'; } +int has_non_ascii(const char *s) +{ + int ch; + if (!s) + return 0; + while ((ch = *s++) != '\0') { + if (non_ascii(ch)) + return 1; + } + return 0; +} + static int is_rfc2047_special(char ch) { return (non_ascii(ch) || (ch == '=') || (ch == '?') || (ch == '_')); @@ -284,7 +296,7 @@ static char *replace_encoding_header(char *buf, const char *encoding) static char *logmsg_reencode(const struct commit *commit, const char *output_encoding) { - static const char *utf8 = "utf-8"; + static const char *utf8 = "UTF-8"; const char *use_encoding; char *encoding; char *out; @@ -571,7 +583,7 @@ static void format_decoration(struct strbuf *sb, const struct commit *commit) struct name_decoration *d; const char *prefix = " ("; - load_ref_decorations(); + load_ref_decorations(DECORATE_SHORT_REFS); d = lookup_decoration(&name_decoration, &commit->object); while (d) { strbuf_addstr(sb, prefix); @@ -881,7 +893,7 @@ char *reencode_commit_message(const struct commit *commit, const char **encoding ? git_log_output_encoding : git_commit_encoding); if (!encoding) - encoding = "utf-8"; + encoding = "UTF-8"; if (encoding_p) *encoding_p = encoding; return logmsg_reencode(commit, encoding); @@ -272,8 +272,8 @@ void write_name_quoted(const char *name, FILE *fp, int terminator) fputc(terminator, fp); } -extern void write_name_quotedpfx(const char *pfx, size_t pfxlen, - const char *name, FILE *fp, int terminator) +void write_name_quotedpfx(const char *pfx, size_t pfxlen, + const char *name, FILE *fp, int terminator) { int needquote = 0; diff --git a/read-cache.c b/read-cache.c index 3f587110cb..4e3e272ee4 100644 --- a/read-cache.c +++ b/read-cache.c @@ -638,7 +638,7 @@ int add_file_to_index(struct index_state *istate, const char *path, int flags) { struct stat st; if (lstat(path, &st)) - die("%s: unable to stat (%s)", path, strerror(errno)); + die_errno("unable to stat '%s'", path); return add_to_index(istate, path, &st, flags); } @@ -1251,11 +1251,11 @@ int read_index_from(struct index_state *istate, const char *path) if (fd < 0) { if (errno == ENOENT) return 0; - die("index file open failed (%s)", strerror(errno)); + die_errno("index file open failed"); } if (fstat(fd, &st)) - die("cannot stat the open index (%s)", strerror(errno)); + die_errno("cannot stat the open index"); errno = EINVAL; mmap_size = xsize_t(st.st_size); @@ -1265,7 +1265,7 @@ int read_index_from(struct index_state *istate, const char *path) mmap = xmmap(NULL, mmap_size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0); close(fd); if (mmap == MAP_FAILED) - die("unable to map index file"); + die_errno("unable to map index file"); hdr = mmap; if (verify_hdr(hdr, mmap_size) < 0) @@ -683,12 +683,13 @@ int for_each_rawref(each_ref_fn fn, void *cb_data) * - it has ASCII control character, "~", "^", ":" or SP, anywhere, or * - it ends with a "/". * - it ends with ".lock" + * - it contains a "\" (backslash) */ static inline int bad_ref_char(int ch) { if (((unsigned) ch) <= ' ' || - ch == '~' || ch == '^' || ch == ':') + ch == '~' || ch == '^' || ch == ':' || ch == '\\') return 1; /* 2.13 Pattern Matching Notation */ if (ch == '?' || ch == '[') /* Unsupported */ @@ -751,9 +752,8 @@ int check_ref_format(const char *ref) } } -const char *prettify_ref(const struct ref *ref) +const char *prettify_refname(const char *name) { - const char *name = ref->name; return name + ( !prefixcmp(name, "refs/heads/") ? 11 : !prefixcmp(name, "refs/tags/") ? 10 : @@ -821,7 +821,7 @@ static int remove_empty_directories(const char *file) strbuf_init(&path, 20); strbuf_addstr(&path, file); - result = remove_dir_recursively(&path, 1); + result = remove_dir_recursively(&path, REMOVE_DIR_EMPTY_ONLY); strbuf_release(&path); @@ -1419,7 +1419,7 @@ int read_ref_at(const char *ref, unsigned long at_time, int cnt, unsigned char * logfile = git_path("logs/%s", ref); logfd = open(logfile, O_RDONLY, 0); if (logfd < 0) - die("Unable to read log %s: %s", logfile, strerror(errno)); + die_errno("Unable to read log '%s'", logfile); fstat(logfd, &st); if (!st.st_size) die("Log %s is empty.", logfile); @@ -80,7 +80,7 @@ extern int for_each_reflog(each_ref_fn, void *); #define CHECK_REF_FORMAT_WILDCARD (-3) extern int check_ref_format(const char *target); -extern const char *prettify_ref(const struct ref *ref); +extern const char *prettify_refname(const char *refname); extern char *shorten_unambiguous_ref(const char *ref, int strict); /** rename ref, return 0 on success **/ @@ -106,6 +106,12 @@ static void add_url_alias(struct remote *remote, const char *url) add_url(remote, alias_url(url)); } +static void add_pushurl(struct remote *remote, const char *pushurl) +{ + ALLOC_GROW(remote->pushurl, remote->pushurl_nr + 1, remote->pushurl_alloc); + remote->pushurl[remote->pushurl_nr++] = pushurl; +} + static struct remote *make_remote(const char *name, int len) { struct remote *ret; @@ -301,7 +307,7 @@ static void read_branches_file(struct remote *remote) strbuf_addstr(&branch, "HEAD:"); } add_url_alias(remote, p); - add_fetch_refspec(remote, strbuf_detach(&branch, 0)); + add_fetch_refspec(remote, strbuf_detach(&branch, NULL)); /* * Cogito compatible push: push current HEAD to remote #branch * (master if missing) @@ -312,7 +318,7 @@ static void read_branches_file(struct remote *remote) strbuf_addf(&branch, ":refs/heads/%s", frag); else strbuf_addstr(&branch, ":refs/heads/master"); - add_push_refspec(remote, strbuf_detach(&branch, 0)); + add_push_refspec(remote, strbuf_detach(&branch, NULL)); remote->fetch_tags = 1; /* always auto-follow */ } @@ -379,6 +385,11 @@ static int handle_config(const char *key, const char *value, void *cb) if (git_config_string(&v, key, value)) return -1; add_url(remote, v); + } else if (!strcmp(subkey, ".pushurl")) { + const char *v; + if (git_config_string(&v, key, value)) + return -1; + add_pushurl(remote, v); } else if (!strcmp(subkey, ".push")) { const char *v; if (git_config_string(&v, key, value)) @@ -424,6 +435,9 @@ static void alias_all_urls(void) for (j = 0; j < remotes[i]->url_nr; j++) { remotes[i]->url[j] = alias_url(remotes[i]->url[j]); } + for (j = 0; j < remotes[i]->pushurl_nr; j++) { + remotes[i]->pushurl[j] = alias_url(remotes[i]->pushurl[j]); + } } } @@ -1085,26 +1099,35 @@ static const struct refspec *check_pattern_match(const struct refspec *rs, return NULL; } +static struct ref **tail_ref(struct ref **head) +{ + struct ref **tail = head; + while (*tail) + tail = &((*tail)->next); + return tail; +} + /* * Note. This is used only by "push"; refspec matching rules for * push and fetch are subtly different, so do not try to reuse it * without thinking. */ -int match_refs(struct ref *src, struct ref *dst, struct ref ***dst_tail, +int match_refs(struct ref *src, struct ref **dst, int nr_refspec, const char **refspec, int flags) { struct refspec *rs; int send_all = flags & MATCH_REFS_ALL; int send_mirror = flags & MATCH_REFS_MIRROR; int errs; - static const char *default_refspec[] = { ":", 0 }; + static const char *default_refspec[] = { ":", NULL }; + struct ref **dst_tail = tail_ref(dst); if (!nr_refspec) { nr_refspec = 1; refspec = default_refspec; } rs = parse_push_refspec(nr_refspec, (const char **) refspec); - errs = match_explicit_refs(src, dst, dst_tail, rs, nr_refspec); + errs = match_explicit_refs(src, *dst, &dst_tail, rs, nr_refspec); /* pick the remainder */ for ( ; src; src = src->next) { @@ -1134,7 +1157,7 @@ int match_refs(struct ref *src, struct ref *dst, struct ref ***dst_tail, dst_side, &dst_name)) die("Didn't think it matches any more"); } - dst_peer = find_ref_by_name(dst, dst_name); + dst_peer = find_ref_by_name(*dst, dst_name); if (dst_peer) { if (dst_peer->peer_ref) /* We're already sending something to this ref. */ @@ -1150,7 +1173,7 @@ int match_refs(struct ref *src, struct ref *dst, struct ref ***dst_tail, goto free_name; /* Create a new one and link it */ - dst_peer = make_linked_ref(dst_name, dst_tail); + dst_peer = make_linked_ref(dst_name, &dst_tail); hashcpy(dst_peer->new_sha1, src->new_sha1); } dst_peer->peer_ref = copy_ref(src); @@ -1399,13 +1422,13 @@ int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs) base = branch->merge[0]->dst; if (!resolve_ref(base, sha1, 1, NULL)) return 0; - theirs = lookup_commit(sha1); + theirs = lookup_commit_reference(sha1); if (!theirs) return 0; if (!resolve_ref(branch->refname, sha1, 1, NULL)) return 0; - ours = lookup_commit(sha1); + ours = lookup_commit_reference(sha1); if (!ours) return 0; @@ -15,6 +15,10 @@ struct remote { int url_nr; int url_alloc; + const char **pushurl; + int pushurl_nr; + int pushurl_alloc; + const char **push_refspec; struct refspec *push; int push_refspec_nr; @@ -85,7 +89,7 @@ void ref_remove_duplicates(struct ref *ref_map); int valid_fetch_refspec(const char *refspec); struct refspec *parse_fetch_refspec(int nr_refspec, const char **refspec); -int match_refs(struct ref *src, struct ref *dst, struct ref ***dst_tail, +int match_refs(struct ref *src, struct ref **dst, int nr_refspec, const char **refspec, int all); /* diff --git a/revision.c b/revision.c index 18b7ebbbd5..ce24ad9a8d 100644 --- a/revision.c +++ b/revision.c @@ -133,7 +133,7 @@ void mark_parents_uninteresting(struct commit *commit) static void add_pending_object_with_mode(struct rev_info *revs, struct object *obj, const char *name, unsigned mode) { if (revs->no_walk && (obj->flags & UNINTERESTING)) - die("object ranges do not make sense when not walking revisions"); + revs->no_walk = 0; if (revs->reflog_info && obj->type == OBJ_COMMIT && add_reflog_for_walk(revs->reflog_info, (struct commit *)obj, name)) @@ -256,10 +256,12 @@ static int everybody_uninteresting(struct commit_list *orig) /* * The goal is to get REV_TREE_NEW as the result only if the - * diff consists of all '+' (and no other changes), and - * REV_TREE_DIFFERENT otherwise (of course if the trees are - * the same we want REV_TREE_SAME). That means that once we - * get to REV_TREE_DIFFERENT, we do not have to look any further. + * diff consists of all '+' (and no other changes), REV_TREE_OLD + * if the whole diff is removal of old data, and otherwise + * REV_TREE_DIFFERENT (of course if the trees are the same we + * want REV_TREE_SAME). + * That means that once we get to REV_TREE_DIFFERENT, we do not + * have to look any further. */ static int tree_difference = REV_TREE_SAME; @@ -268,22 +270,9 @@ static void file_add_remove(struct diff_options *options, const unsigned char *sha1, const char *fullpath) { - int diff = REV_TREE_DIFFERENT; + int diff = addremove == '+' ? REV_TREE_NEW : REV_TREE_OLD; - /* - * Is it an add of a new file? It means that the old tree - * didn't have it at all, so we will turn "REV_TREE_SAME" -> - * "REV_TREE_NEW", but leave any "REV_TREE_DIFFERENT" alone - * (and if it already was "REV_TREE_NEW", we'll keep it - * "REV_TREE_NEW" of course). - */ - if (addremove == '+') { - diff = tree_difference; - if (diff != REV_TREE_SAME) - return; - diff = REV_TREE_NEW; - } - tree_difference = diff; + tree_difference |= diff; if (tree_difference == REV_TREE_DIFFERENT) DIFF_OPT_SET(options, HAS_CHANGES); } @@ -305,6 +294,8 @@ static int rev_compare_tree(struct rev_info *revs, struct commit *parent, struct if (!t1) return REV_TREE_NEW; + if (!t2) + return REV_TREE_OLD; if (revs->simplify_by_decoration) { /* @@ -323,8 +314,7 @@ static int rev_compare_tree(struct rev_info *revs, struct commit *parent, struct if (!revs->prune_data) return REV_TREE_SAME; } - if (!t2) - return REV_TREE_DIFFERENT; + tree_difference = REV_TREE_SAME; DIFF_OPT_CLR(&revs->pruning, HAS_CHANGES); if (diff_tree_sha1(t1->object.sha1, t2->object.sha1, "", @@ -429,6 +419,7 @@ static void try_to_simplify_commit(struct rev_info *revs, struct commit *commit) p->parents = NULL; } /* fallthrough */ + case REV_TREE_OLD: case REV_TREE_DIFFERENT: tree_changed = 1; pp = &parent->next; @@ -1061,7 +1052,7 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg revs->simplify_by_decoration = 1; revs->limited = 1; revs->prune = 1; - load_ref_decorations(); + load_ref_decorations(DECORATE_SHORT_REFS); } else if (!strcmp(arg, "--date-order")) { revs->lifo = 0; revs->topo_order = 1; @@ -1086,6 +1077,8 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg revs->show_all = 1; } else if (!strcmp(arg, "--remove-empty")) { revs->remove_empty_trees = 1; + } else if (!strcmp(arg, "--merges")) { + revs->merges_only = 1; } else if (!strcmp(arg, "--no-merges")) { revs->no_merges = 1; } else if (!strcmp(arg, "--boundary")) { @@ -1685,6 +1678,8 @@ enum commit_action simplify_commit(struct rev_info *revs, struct commit *commit) return commit_ignore; if (revs->no_merges && commit->parents && commit->parents->next) return commit_ignore; + if (revs->merges_only && !(commit->parents && commit->parents->next)) + return commit_ignore; if (!commit_match(commit, revs)) return commit_ignore; if (revs->prune && revs->dense) { diff --git a/revision.h b/revision.h index be39e7d386..b10984b603 100644 --- a/revision.h +++ b/revision.h @@ -15,6 +15,9 @@ #define SYMMETRIC_LEFT (1u<<8) #define ALL_REV_FLAGS ((1u<<9)-1) +#define DECORATE_SHORT_REFS 1 +#define DECORATE_FULL_REFS 2 + struct rev_info; struct log_info; @@ -36,6 +39,7 @@ struct rev_info { unsigned int dense:1, prune:1, no_merges:1, + merges_only:1, no_walk:1, show_all:1, remove_empty_trees:1, @@ -118,8 +122,9 @@ struct rev_info { }; #define REV_TREE_SAME 0 -#define REV_TREE_NEW 1 -#define REV_TREE_DIFFERENT 2 +#define REV_TREE_NEW 1 /* Only new files */ +#define REV_TREE_OLD 2 /* Only files removed */ +#define REV_TREE_DIFFERENT 3 /* Mixed changes */ /* revision.c */ void read_revisions_from_stdin(struct rev_info *revs); diff --git a/run-command.c b/run-command.c index eb2efc3307..ff3d8e2d8b 100644 --- a/run-command.c +++ b/run-command.c @@ -101,8 +101,8 @@ int start_command(struct child_process *cmd) } if (cmd->dir && chdir(cmd->dir)) - die("exec %s: cd to %s failed (%s)", cmd->argv[0], - cmd->dir, strerror(errno)); + die_errno("exec '%s': cd to '%s' failed", cmd->argv[0], + cmd->dir); if (cmd->env) { for (; *cmd->env; cmd->env++) { if (strchr(*cmd->env, '=')) @@ -81,7 +81,7 @@ void verify_filename(const char *prefix, const char *arg) if (errno == ENOENT) die("ambiguous argument '%s': unknown revision or path not in the working tree.\n" "Use '--' to separate paths from revisions", arg); - die("'%s': %s", arg, strerror(errno)); + die_errno("failed to stat '%s'", arg); } /* @@ -103,7 +103,7 @@ void verify_non_filename(const char *prefix, const char *arg) die("ambiguous argument '%s': both revision and filename\n" "Use '--' to separate filenames from revisions", arg); if (errno != ENOENT && errno != ENOTDIR) - die("'%s': %s", arg, strerror(errno)); + die_errno("failed to stat '%s'", arg); } const char **get_pathspec(const char *prefix, const char **pathspec) @@ -257,7 +257,7 @@ const char *read_gitfile_gently(const char *path) return NULL; fd = open(path, O_RDONLY); if (fd < 0) - die("Error opening %s: %s", path, strerror(errno)); + die_errno("Error opening '%s'", path); buf = xmalloc(st.st_size + 1); len = read_in_full(fd, buf, st.st_size); close(fd); @@ -327,7 +327,7 @@ const char *setup_git_directory_gently(int *nongit_ok) return NULL; set_git_dir(make_absolute_path(gitdirenv)); if (chdir(work_tree_env) < 0) - die ("Could not chdir to %s", work_tree_env); + die_errno ("Could not chdir to '%s'", work_tree_env); strcat(buffer, "/"); return retval; } @@ -339,7 +339,7 @@ const char *setup_git_directory_gently(int *nongit_ok) } if (!getcwd(cwd, sizeof(cwd)-1)) - die("Unable to read current working directory"); + die_errno("Unable to read current working directory"); ceil_offset = longest_ancestor_length(cwd, env_ceiling_dirs); if (ceil_offset < 0 && has_dos_drive_prefix(cwd)) @@ -382,14 +382,14 @@ const char *setup_git_directory_gently(int *nongit_ok) if (offset <= ceil_offset) { if (nongit_ok) { if (chdir(cwd)) - die("Cannot come back to cwd"); + die_errno("Cannot come back to cwd"); *nongit_ok = 1; return NULL; } die("Not a git repository (or any of the parent directories): %s", DEFAULT_GIT_DIR_ENVIRONMENT); } if (chdir("..")) - die("Cannot change to %s/..: %s", cwd, strerror(errno)); + die_errno("Cannot change to '%s/..'", cwd); } inside_git_dir = 0; @@ -493,10 +493,10 @@ const char *setup_git_directory(void) static char buffer[PATH_MAX + 1]; char *rel; if (retval && chdir(retval)) - die ("Could not jump back into original cwd"); + die_errno ("Could not jump back into original cwd"); rel = get_relative_cwd(buffer, PATH_MAX, get_git_work_tree()); if (rel && *rel && chdir(get_git_work_tree())) - die ("Could not jump to working directory"); + die_errno ("Could not jump to working directory"); return rel && *rel ? strcat(rel, "/") : NULL; } diff --git a/sha1_file.c b/sha1_file.c index 8f5fe62d54..1d996a1990 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -1170,7 +1170,7 @@ unsigned long unpack_object_header_buffer(const unsigned char *buf, size = c & 15; shift = 4; while (c & 0x80) { - if (len <= used || sizeof(long) * 8 <= shift) { + if (len <= used || bitsizeof(long) <= shift) { error("bad object header"); return 0; } @@ -2286,7 +2286,7 @@ static void close_sha1_file(int fd) if (fsync_object_files) fsync_or_die(fd, "sha1 file"); if (close(fd) != 0) - die("error when closing sha1 file (%s)", strerror(errno)); + die_errno("error when closing sha1 file"); } /* Size of directory component, including the ending '/' */ @@ -60,7 +60,7 @@ int main(int argc, char **argv) while (devnull_fd >= 0 && devnull_fd <= 2) devnull_fd = dup(devnull_fd); if (devnull_fd == -1) - die("opening /dev/null failed (%s)", strerror(errno)); + die_errno("opening /dev/null failed"); close (devnull_fd); /* diff --git a/symlinks.c b/symlinks.c index 1d6b35b858..7b0a86d357 100644 --- a/symlinks.c +++ b/symlinks.c @@ -32,19 +32,13 @@ static int longest_path_match(const char *name_a, int len_a, return match_len; } -static struct cache_def { - char path[PATH_MAX + 1]; - int len; - int flags; - int track_flags; - int prefix_len_stat_func; -} cache; +static struct cache_def default_cache; -static inline void reset_lstat_cache(void) +static inline void reset_lstat_cache(struct cache_def *cache) { - cache.path[0] = '\0'; - cache.len = 0; - cache.flags = 0; + cache->path[0] = '\0'; + cache->len = 0; + cache->flags = 0; /* * The track_flags and prefix_len_stat_func members is only * set by the safeguard rule inside lstat_cache() @@ -70,23 +64,23 @@ static inline void reset_lstat_cache(void) * of the prefix, where the cache should use the stat() function * instead of the lstat() function to test each path component. */ -static int lstat_cache(const char *name, int len, +static int lstat_cache(struct cache_def *cache, const char *name, int len, int track_flags, int prefix_len_stat_func) { int match_len, last_slash, last_slash_dir, previous_slash; int match_flags, ret_flags, save_flags, max_len, ret; struct stat st; - if (cache.track_flags != track_flags || - cache.prefix_len_stat_func != prefix_len_stat_func) { + if (cache->track_flags != track_flags || + cache->prefix_len_stat_func != prefix_len_stat_func) { /* * As a safeguard rule we clear the cache if the * values of track_flags and/or prefix_len_stat_func * does not match with the last supplied values. */ - reset_lstat_cache(); - cache.track_flags = track_flags; - cache.prefix_len_stat_func = prefix_len_stat_func; + reset_lstat_cache(cache); + cache->track_flags = track_flags; + cache->prefix_len_stat_func = prefix_len_stat_func; match_len = last_slash = 0; } else { /* @@ -94,10 +88,14 @@ static int lstat_cache(const char *name, int len, * the 2 "excluding" path types. */ match_len = last_slash = - longest_path_match(name, len, cache.path, cache.len, + longest_path_match(name, len, cache->path, cache->len, &previous_slash); - match_flags = cache.flags & track_flags & (FL_NOENT|FL_SYMLINK); - if (match_flags && match_len == cache.len) + match_flags = cache->flags & track_flags & (FL_NOENT|FL_SYMLINK); + + if (!(track_flags & FL_FULLPATH) && match_len == len) + match_len = last_slash = previous_slash; + + if (match_flags && match_len == cache->len) return match_flags; /* * If we now have match_len > 0, we would know that @@ -121,18 +119,18 @@ static int lstat_cache(const char *name, int len, max_len = len < PATH_MAX ? len : PATH_MAX; while (match_len < max_len) { do { - cache.path[match_len] = name[match_len]; + cache->path[match_len] = name[match_len]; match_len++; } while (match_len < max_len && name[match_len] != '/'); if (match_len >= max_len && !(track_flags & FL_FULLPATH)) break; last_slash = match_len; - cache.path[last_slash] = '\0'; + cache->path[last_slash] = '\0'; if (last_slash <= prefix_len_stat_func) - ret = stat(cache.path, &st); + ret = stat(cache->path, &st); else - ret = lstat(cache.path, &st); + ret = lstat(cache->path, &st); if (ret) { ret_flags = FL_LSTATERR; @@ -156,9 +154,9 @@ static int lstat_cache(const char *name, int len, */ save_flags = ret_flags & track_flags & (FL_NOENT|FL_SYMLINK); if (save_flags && last_slash > 0 && last_slash <= PATH_MAX) { - cache.path[last_slash] = '\0'; - cache.len = last_slash; - cache.flags = save_flags; + cache->path[last_slash] = '\0'; + cache->len = last_slash; + cache->flags = save_flags; } else if ((track_flags & FL_DIR) && last_slash_dir > 0 && last_slash_dir <= PATH_MAX) { /* @@ -172,11 +170,11 @@ static int lstat_cache(const char *name, int len, * can still cache the path components before the last * one (the found symlink or non-existing component). */ - cache.path[last_slash_dir] = '\0'; - cache.len = last_slash_dir; - cache.flags = FL_DIR; + cache->path[last_slash_dir] = '\0'; + cache->len = last_slash_dir; + cache->flags = FL_DIR; } else { - reset_lstat_cache(); + reset_lstat_cache(cache); } return ret_flags; } @@ -188,16 +186,18 @@ static int lstat_cache(const char *name, int len, void invalidate_lstat_cache(const char *name, int len) { int match_len, previous_slash; + struct cache_def *cache = &default_cache; /* FIXME */ - match_len = longest_path_match(name, len, cache.path, cache.len, + match_len = longest_path_match(name, len, cache->path, cache->len, &previous_slash); if (len == match_len) { - if ((cache.track_flags & FL_DIR) && previous_slash > 0) { - cache.path[previous_slash] = '\0'; - cache.len = previous_slash; - cache.flags = FL_DIR; - } else - reset_lstat_cache(); + if ((cache->track_flags & FL_DIR) && previous_slash > 0) { + cache->path[previous_slash] = '\0'; + cache->len = previous_slash; + cache->flags = FL_DIR; + } else { + reset_lstat_cache(cache); + } } } @@ -206,7 +206,8 @@ void invalidate_lstat_cache(const char *name, int len) */ void clear_lstat_cache(void) { - reset_lstat_cache(); + struct cache_def *cache = &default_cache; /* FIXME */ + reset_lstat_cache(cache); } #define USE_ONLY_LSTAT 0 @@ -214,11 +215,17 @@ void clear_lstat_cache(void) /* * Return non-zero if path 'name' has a leading symlink component */ +int threaded_has_symlink_leading_path(struct cache_def *cache, const char *name, int len) +{ + return lstat_cache(cache, name, len, FL_SYMLINK|FL_DIR, USE_ONLY_LSTAT) & FL_SYMLINK; +} + +/* + * Return non-zero if path 'name' has a leading symlink component + */ int has_symlink_leading_path(const char *name, int len) { - return lstat_cache(name, len, - FL_SYMLINK|FL_DIR, USE_ONLY_LSTAT) & - FL_SYMLINK; + return threaded_has_symlink_leading_path(&default_cache, name, len); } /* @@ -227,7 +234,8 @@ int has_symlink_leading_path(const char *name, int len) */ int has_symlink_or_noent_leading_path(const char *name, int len) { - return lstat_cache(name, len, + struct cache_def *cache = &default_cache; /* FIXME */ + return lstat_cache(cache, name, len, FL_SYMLINK|FL_NOENT|FL_DIR, USE_ONLY_LSTAT) & (FL_SYMLINK|FL_NOENT); } @@ -241,7 +249,8 @@ int has_symlink_or_noent_leading_path(const char *name, int len) */ int has_dirs_only_path(const char *name, int len, int prefix_len) { - return lstat_cache(name, len, + struct cache_def *cache = &default_cache; /* FIXME */ + return lstat_cache(cache, name, len, FL_DIR|FL_FULLPATH, prefix_len) & FL_DIR; } @@ -263,7 +272,6 @@ static void do_remove_scheduled_dirs(int new_len) removal.path[removal.len] != '/'); } removal.len = new_len; - return; } void schedule_dir_for_removal(const char *name, int len) @@ -296,11 +304,9 @@ void schedule_dir_for_removal(const char *name, int len) last_slash - match_len); removal.len = last_slash; } - return; } void remove_scheduled_dirs(void) { do_remove_scheduled_dirs(0); - return; } diff --git a/t/lib-git-svn.sh b/t/lib-git-svn.sh index 773d47cf3c..5654962343 100644 --- a/t/lib-git-svn.sh +++ b/t/lib-git-svn.sh @@ -26,6 +26,8 @@ fi svnrepo=$PWD/svnrepo export svnrepo +svnconf=$PWD/svnconf +export svnconf perl -w -e " use SVN::Core; @@ -54,6 +56,19 @@ poke() { test-chmtime +1 "$1" } +# We need this, because we should pass empty configuration directory to +# the 'svn commit' to avoid automated property changes and other stuff +# that could be set from user's configuration files in ~/.subversion. +svn_cmd () { + [ -d "$svnconf" ] || mkdir "$svnconf" + orig_svncmd="$1"; shift + if [ -z "$orig_svncmd" ]; then + svn + return + fi + svn "$orig_svncmd" --config-dir "$svnconf" "$@" +} + for d in \ "$SVN_HTTPD_PATH" \ /usr/sbin/apache2 \ diff --git a/t/lib-httpd.sh b/t/lib-httpd.sh index cde659d14a..6765b08065 100644 --- a/t/lib-httpd.sh +++ b/t/lib-httpd.sh @@ -93,14 +93,16 @@ prepare_httpd() { start_httpd() { prepare_httpd >&3 2>&4 - trap 'stop_httpd; die' EXIT + trap 'code=$?; stop_httpd; (exit $code); die' EXIT "$LIB_HTTPD_PATH" -d "$HTTPD_ROOT_PATH" \ -f "$TEST_PATH/apache.conf" $HTTPD_PARA \ -c "Listen 127.0.0.1:$LIB_HTTPD_PORT" -k start \ >&3 2>&4 - if ! test $? = 0; then + if test $? -ne 0 + then say "skipping test, web server setup failed" + trap 'die' EXIT test_done fi } diff --git a/t/t0040-parse-options.sh b/t/t0040-parse-options.sh index e38241c80a..bbc821ef97 100755 --- a/t/t0040-parse-options.sh +++ b/t/t0040-parse-options.sh @@ -12,12 +12,14 @@ usage: test-parse-options <options> -b, --boolean get a boolean -4, --or4 bitwise-or boolean with ...0100 + --neg-or4 same as --no-or4 -i, --integer <n> get a integer -j <n> get a integer, too --set23 set integer to 23 -t <time> get timestamp of <time> -L, --length <str> get length of <str> + -F, --file <FILE> set file to <FILE> String options -s, --string <string> @@ -29,6 +31,8 @@ String options Magic arguments --quux means --quux + -NUM set integer to NUM + + same as -b Standard options --abbrev[=<n>] use <n> digits to display SHA-1s @@ -53,10 +57,12 @@ abbrev: 7 verbose: 2 quiet: no dry run: yes +file: prefix/my.file EOF test_expect_success 'short options' ' - test-parse-options -s123 -b -i 1729 -b -vv -n > output 2> output.err && + test-parse-options -s123 -b -i 1729 -b -vv -n -F my.file \ + > output 2> output.err && test_cmp expect output && test ! -s output.err ' @@ -70,11 +76,12 @@ abbrev: 10 verbose: 2 quiet: no dry run: no +file: prefix/fi.le EOF test_expect_success 'long options' ' test-parse-options --boolean --integer 1729 --boolean --string2=321 \ - --verbose --verbose --no-dry-run --abbrev=10 \ + --verbose --verbose --no-dry-run --abbrev=10 --file fi.le\ > output 2> output.err && test ! -s output.err && test_cmp expect output @@ -84,6 +91,8 @@ test_expect_success 'missing required value' ' test-parse-options -s; test $? = 129 && test-parse-options --string; + test $? = 129 && + test-parse-options --file; test $? = 129 ' @@ -96,6 +105,7 @@ abbrev: 7 verbose: 0 quiet: no dry run: no +file: (not set) arg 00: a1 arg 01: b1 arg 02: --boolean @@ -117,6 +127,7 @@ abbrev: 7 verbose: 0 quiet: no dry run: no +file: (not set) EOF test_expect_success 'unambiguously abbreviated option' ' @@ -145,6 +156,7 @@ abbrev: 7 verbose: 0 quiet: no dry run: no +file: (not set) EOF test_expect_success 'non ambiguous option (after two options it abbreviates)' ' @@ -172,6 +184,7 @@ abbrev: 7 verbose: 0 quiet: no dry run: no +file: (not set) arg 00: --quux EOF @@ -190,6 +203,7 @@ abbrev: 7 verbose: 0 quiet: yes dry run: no +file: (not set) arg 00: foo EOF @@ -210,6 +224,7 @@ abbrev: 7 verbose: 0 quiet: no dry run: no +file: (not set) EOF test_expect_success 'OPT_CALLBACK() and OPT_BIT() work' ' @@ -237,6 +252,7 @@ abbrev: 7 verbose: 0 quiet: no dry run: no +file: (not set) EOF test_expect_success 'OPT_BIT() and OPT_SET_INT() work' ' @@ -245,7 +261,58 @@ test_expect_success 'OPT_BIT() and OPT_SET_INT() work' ' test_cmp expect output ' -# --or4 -# --no-or4 +test_expect_success 'OPT_NEGBIT() and OPT_SET_INT() work' ' + test-parse-options --set23 -bbbbb --neg-or4 > output 2> output.err && + test ! -s output.err && + test_cmp expect output +' + +cat > expect <<EOF +boolean: 6 +integer: 0 +timestamp: 0 +string: (not set) +abbrev: 7 +verbose: 0 +quiet: no +dry run: no +file: (not set) +EOF + +test_expect_success 'OPT_BIT() works' ' + test-parse-options -bb --or4 > output 2> output.err && + test ! -s output.err && + test_cmp expect output +' + +test_expect_success 'OPT_NEGBIT() works' ' + test-parse-options -bb --no-neg-or4 > output 2> output.err && + test ! -s output.err && + test_cmp expect output +' + +test_expect_success 'OPT_BOOLEAN() with PARSE_OPT_NODASH works' ' + test-parse-options + + + + + + > output 2> output.err && + test ! -s output.err && + test_cmp expect output +' + +cat > expect <<EOF +boolean: 0 +integer: 12345 +timestamp: 0 +string: (not set) +abbrev: 7 +verbose: 0 +quiet: no +dry run: no +file: (not set) +EOF + +test_expect_success 'OPT_NUMBER_CALLBACK() works' ' + test-parse-options -12345 > output 2> output.err && + test ! -s output.err && + test_cmp expect output +' test_done diff --git a/t/t1010-mktree.sh b/t/t1010-mktree.sh new file mode 100755 index 0000000000..9956e3ad62 --- /dev/null +++ b/t/t1010-mktree.sh @@ -0,0 +1,71 @@ +#!/bin/sh + +test_description='git mktree' + +. ./test-lib.sh + +test_expect_success setup ' + for d in a a. a0 + do + mkdir "$d" && echo "$d/one" >"$d/one" && + git add "$d" + done && + echo zero >one && + git update-index --add --info-only one && + git write-tree --missing-ok >tree.missing && + git ls-tree $(cat tree.missing) >top.missing && + git ls-tree -r $(cat tree.missing) >all.missing && + echo one >one && + git add one && + git write-tree >tree && + git ls-tree $(cat tree) >top && + git ls-tree -r $(cat tree) >all && + test_tick && + git commit -q -m one && + H=$(git rev-parse HEAD) && + git update-index --add --cacheinfo 160000 $H sub && + test_tick && + git commit -q -m two && + git rev-parse HEAD^{tree} >tree.withsub && + git ls-tree HEAD >top.withsub && + git ls-tree -r HEAD >all.withsub +' + +test_expect_success 'ls-tree piped to mktree (1)' ' + git mktree <top >actual && + test_cmp tree actual +' + +test_expect_success 'ls-tree piped to mktree (2)' ' + git mktree <top.withsub >actual && + test_cmp tree.withsub actual +' + +test_expect_success 'ls-tree output in wrong order given to mktree (1)' ' + perl -e "print reverse <>" <top | + git mktree >actual && + test_cmp tree actual +' + +test_expect_success 'ls-tree output in wrong order given to mktree (2)' ' + perl -e "print reverse <>" <top.withsub | + git mktree >actual && + test_cmp tree.withsub actual +' + +test_expect_success 'allow missing object with --missing' ' + git mktree --missing <top.missing >actual && + test_cmp tree.missing actual +' + +test_expect_failure 'mktree reads ls-tree -r output (1)' ' + git mktree <all >actual && + test_cmp tree actual +' + +test_expect_failure 'mktree reads ls-tree -r output (2)' ' + git mktree <all.withsub >actual && + test_cmp tree.withsub actual +' + +test_done diff --git a/t/t1300-repo-config.sh b/t/t1300-repo-config.sh index 43ea283242..83b7294010 100755 --- a/t/t1300-repo-config.sh +++ b/t/t1300-repo-config.sh @@ -460,6 +460,28 @@ EOF test_expect_success "rename succeeded" "test_cmp expect .git/config" cat >> .git/config << EOF +[branch "vier"] z = 1 +EOF + +test_expect_success "rename a section with a var on the same line" \ + 'git config --rename-section branch.vier branch.zwei' + +cat > expect << EOF +# Hallo + #Bello +[branch "zwei"] + x = 1 +[branch "zwei"] + y = 1 +[branch "drei"] +weird +[branch "zwei"] + z = 1 +EOF + +test_expect_success "rename succeeded" "test_cmp expect .git/config" + +cat >> .git/config << EOF [branch "zwei"] a = 1 [branch "vier"] EOF @@ -733,6 +755,11 @@ echo >>result test_expect_success '--null --get-regexp' 'cmp result expect' +test_expect_success 'inner whitespace kept verbatim' ' + git config section.val "foo bar" && + test "z$(git config section.val)" = "zfoo bar" +' + test_expect_success SYMLINKS 'symlinked configuration' ' ln -s notyet myconfig && diff --git a/t/t1502-rev-parse-parseopt.sh b/t/t1502-rev-parse-parseopt.sh index 997002d4c4..e504058062 100755 --- a/t/t1502-rev-parse-parseopt.sh +++ b/t/t1502-rev-parse-parseopt.sh @@ -20,8 +20,7 @@ Extras EOF -test_expect_success 'test --parseopt help output' ' - git rev-parse --parseopt -- -h 2> output.err <<EOF +cat > optionspec << EOF some-command [options] <args>... some-command does foo and bar! @@ -37,7 +36,47 @@ C? option C with an optional argument Extras extra1 line above used to cause a segfault but no longer does EOF + +test_expect_success 'test --parseopt help output' ' + git rev-parse --parseopt -- -h 2> output.err < optionspec test_cmp expect.err output.err ' +cat > expect <<EOF +set -- --foo --bar 'ham' -- 'arg' +EOF + +test_expect_success 'test --parseopt' ' + git rev-parse --parseopt -- --foo --bar=ham arg < optionspec > output && + test_cmp expect output +' + +test_expect_success 'test --parseopt with mixed options and arguments' ' + git rev-parse --parseopt -- --foo arg --bar=ham < optionspec > output && + test_cmp expect output +' + +cat > expect <<EOF +set -- --foo -- 'arg' '--bar=ham' +EOF + +test_expect_success 'test --parseopt with --' ' + git rev-parse --parseopt -- --foo -- arg --bar=ham < optionspec > output && + test_cmp expect output +' + +test_expect_success 'test --parseopt --stop-at-non-option' ' + git rev-parse --parseopt --stop-at-non-option -- --foo arg --bar=ham < optionspec > output && + test_cmp expect output +' + +cat > expect <<EOF +set -- --foo -- '--' 'arg' '--bar=ham' +EOF + +test_expect_success 'test --parseopt --keep-dashdash' ' + git rev-parse --parseopt --keep-dashdash -- --foo -- arg --bar=ham < optionspec > output && + test_cmp expect output +' + test_done diff --git a/t/t3400-rebase.sh b/t/t3400-rebase.sh index 6e391a3702..c5c29ccc4f 100755 --- a/t/t3400-rebase.sh +++ b/t/t3400-rebase.sh @@ -41,9 +41,40 @@ test_expect_success \ git tag topic ' +test_expect_success 'rebase on dirty worktree' ' + echo dirty >> A && + test_must_fail git rebase master' + +test_expect_success 'rebase on dirty cache' ' + git add A && + test_must_fail git rebase master' + test_expect_success 'rebase against master' ' + git reset --hard HEAD && git rebase master' +test_expect_success 'rebase against master twice' ' + git rebase master >out && + grep "Current branch my-topic-branch is up to date" out +' + +test_expect_success 'rebase against master twice with --force' ' + git rebase --force-rebase master >out && + grep "Current branch my-topic-branch is up to date, rebase forced" out +' + +test_expect_success 'rebase against master twice from another branch' ' + git checkout my-topic-branch^ && + git rebase master my-topic-branch >out && + grep "Current branch my-topic-branch is up to date" out +' + +test_expect_success 'rebase fast-forward to master' ' + git checkout my-topic-branch^ && + git rebase my-topic-branch >out && + grep "Fast-forwarded HEAD to my-topic-branch" out +' + test_expect_success \ 'the rebase operation should not have destroyed author information' \ '! (git log | grep "Author:" | grep "<>")' @@ -95,4 +126,11 @@ test_expect_success 'Show verbose error when HEAD could not be detached' ' grep "Untracked working tree file .B. would be overwritten" output.err ' +test_expect_success 'rebase -q is quiet' ' + rm B && + git checkout -b quiet topic && + git rebase -q master > output.out 2>&1 && + test ! -s output.out +' + test_done diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh index c32ff6682b..a973628e8e 100755 --- a/t/t3404-rebase-interactive.sh +++ b/t/t3404-rebase-interactive.sh @@ -119,11 +119,11 @@ index e69de29..00750ed 100644 EOF cat > expect2 << EOF -<<<<<<< HEAD:file1 +<<<<<<< HEAD 2 ======= 3 ->>>>>>> b7ca976... G:file1 +>>>>>>> b7ca976... G EOF test_expect_success 'stop on conflicting pick' ' diff --git a/t/t3409-rebase-preserve-merges.sh b/t/t3409-rebase-preserve-merges.sh index e6c832780f..297d165476 100755 --- a/t/t3409-rebase-preserve-merges.sh +++ b/t/t3409-rebase-preserve-merges.sh @@ -71,7 +71,7 @@ test_expect_success 'rebase -p fakes interactive rebase' ' git fetch && git rebase -p origin/topic && test 1 = $(git rev-list --all --pretty=oneline | grep "Modify A" | wc -l) && - test 1 = $(git rev-list --all --pretty=oneline | grep "Merge commit" | wc -l) + test 1 = $(git rev-list --all --pretty=oneline | grep "Merge remote branch " | wc -l) ) ' diff --git a/t/t3414-rebase-preserve-onto.sh b/t/t3414-rebase-preserve-onto.sh new file mode 100755 index 0000000000..80019ee072 --- /dev/null +++ b/t/t3414-rebase-preserve-onto.sh @@ -0,0 +1,80 @@ +#!/bin/sh +# +# Copyright (c) 2009 Greg Price +# + +test_description='git rebase -p should respect --onto + +In a rebase with --onto, we should rewrite all the commits that +aren'"'"'t on top of $ONTO, even if they are on top of $UPSTREAM. +' +. ./test-lib.sh + +. ../lib-rebase.sh + +# Set up branches like this: +# A1---B1---E1---F1---G1 +# \ \ / +# \ \--C1---D1--/ +# H1 + +test_expect_success 'setup' ' + test_commit A1 && + test_commit B1 && + test_commit C1 && + test_commit D1 && + git reset --hard B1 && + test_commit E1 && + test_commit F1 && + test_merge G1 D1 && + git reset --hard A1 && + test_commit H1 +' + +# Now rebase merge G1 from both branches' base B1, both should move: +# A1---B1---E1---F1---G1 +# \ \ / +# \ \--C1---D1--/ +# \ +# H1---E2---F2---G2 +# \ / +# \--C2---D2--/ + +test_expect_success 'rebase from B1 onto H1' ' + git checkout G1 && + git rebase -p --onto H1 B1 && + test "$(git rev-parse HEAD^1^1^1)" = "$(git rev-parse H1)" && + test "$(git rev-parse HEAD^2^1^1)" = "$(git rev-parse H1)" +' + +# On the other hand if rebase from E1 which is within one branch, +# then the other branch stays: +# A1---B1---E1---F1---G1 +# \ \ / +# \ \--C1---D1--/ +# \ \ +# H1-----F3-----G3 + +test_expect_success 'rebase from E1 onto H1' ' + git checkout G1 && + git rebase -p --onto H1 E1 && + test "$(git rev-parse HEAD^1^1)" = "$(git rev-parse H1)" && + test "$(git rev-parse HEAD^2)" = "$(git rev-parse D1)" +' + +# And the same if we rebase from a commit in the second-parent branch. +# A1---B1---E1---F1----G1 +# \ \ \ / +# \ \--C1---D1-\-/ +# \ \ +# H1------D3------G4 + +test_expect_success 'rebase from C1 onto H1' ' + git checkout G1 && + git rev-list --first-parent --pretty=oneline C1..G1 && + git rebase -p --onto H1 C1 && + test "$(git rev-parse HEAD^2^1)" = "$(git rev-parse H1)" && + test "$(git rev-parse HEAD^1)" = "$(git rev-parse F1)" +' + +test_done diff --git a/t/t3700-add.sh b/t/t3700-add.sh index fe93ce52e7..85eb0fbf96 100755 --- a/t/t3700-add.sh +++ b/t/t3700-add.sh @@ -243,4 +243,16 @@ test_expect_success BSLASHPSPEC "git add 'fo\\[ou\\]bar' ignores foobar" ' ! ( git ls-files foobar | grep foobar ) ' +test_expect_success 'git add to resolve conflicts on otherwise ignored path' ' + git reset --hard && + H=$(git rev-parse :1/2/a) && + ( + echo "100644 $H 1 track-this" + echo "100644 $H 3 track-this" + ) | git update-index --index-info && + echo track-this >>.gitignore && + echo resolved >track-this && + git add track-this +' + test_done diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh index fd2a55a5c2..62fd65e18d 100755 --- a/t/t3701-add-interactive.sh +++ b/t/t3701-add-interactive.sh @@ -163,6 +163,17 @@ test_expect_success FILEMODE 'stage mode but not hunk' ' git diff file | grep "+content" ' + +test_expect_success FILEMODE 'stage mode and hunk' ' + git reset --hard && + echo content >>file && + chmod +x file && + printf "y\\ny\\n" | git add -p && + git diff --cached file | grep "new mode" && + git diff --cached file | grep "+content" && + test -z "$(git diff file)" +' + # end of tests disabled when filemode is not usable test_expect_success 'setup again' ' diff --git a/t/t3702-add-edit.sh b/t/t3702-add-edit.sh new file mode 100755 index 0000000000..4ee47cc9a8 --- /dev/null +++ b/t/t3702-add-edit.sh @@ -0,0 +1,121 @@ +#!/bin/sh +# +# Copyright (c) 2007 Johannes E. Schindelin +# + +test_description='add -e basic tests' +. ./test-lib.sh + + +cat > file << EOF +LO, praise of the prowess of people-kings +of spear-armed Danes, in days long sped, +we have heard, and what honor the athelings won! +Oft Scyld the Scefing from squadroned foes, +from many a tribe, the mead-bench tore, +awing the earls. Since erst he lay +friendless, a foundling, fate repaid him: +for he waxed under welkin, in wealth he throve, +till before him the folk, both far and near, +who house by the whale-path, heard his mandate, +gave him gifts: a good king he! +EOF + +cat > second-part << EOF +To him an heir was afterward born, +a son in his halls, whom heaven sent +to favor the folk, feeling their woe +that erst they had lacked an earl for leader +so long a while; the Lord endowed him, +the Wielder of Wonder, with world's renown. +EOF + +test_expect_success 'setup' ' + + git add file && + test_tick && + git commit -m initial file + +' + +cat > expected-patch << EOF +diff --git a/file b/file +index b9834b5..9020acb 100644 +--- a/file ++++ b/file +@@ -1,11 +1,6 @@ +-LO, praise of the prowess of people-kings +-of spear-armed Danes, in days long sped, +-we have heard, and what honor the athelings won! +-Oft Scyld the Scefing from squadroned foes, +-from many a tribe, the mead-bench tore, +-awing the earls. Since erst he lay +-friendless, a foundling, fate repaid him: +-for he waxed under welkin, in wealth he throve, +-till before him the folk, both far and near, +-who house by the whale-path, heard his mandate, +-gave him gifts: a good king he! ++To him an heir was afterward born, ++a son in his halls, whom heaven sent ++to favor the folk, feeling their woe ++that erst they had lacked an earl for leader ++so long a while; the Lord endowed him, ++the Wielder of Wonder, with world's renown. +EOF + +cat > patch << EOF +diff --git a/file b/file +index b9834b5..ef6e94c 100644 +--- a/file ++++ b/file +@@ -3,1 +3,333 @@ of spear-armed Danes, in days long sped, + we have heard, and what honor the athelings won! ++ + Oft Scyld the Scefing from squadroned foes, +@@ -2,7 +1,5 @@ awing the earls. Since erst he lay + friendless, a foundling, fate repaid him: ++ + for he waxed under welkin, in wealth he throve, +EOF + +cat > expected << EOF +diff --git a/file b/file +index b9834b5..ef6e94c 100644 +--- a/file ++++ b/file +@@ -1,10 +1,12 @@ + LO, praise of the prowess of people-kings + of spear-armed Danes, in days long sped, + we have heard, and what honor the athelings won! ++ + Oft Scyld the Scefing from squadroned foes, + from many a tribe, the mead-bench tore, + awing the earls. Since erst he lay + friendless, a foundling, fate repaid him: ++ + for he waxed under welkin, in wealth he throve, + till before him the folk, both far and near, + who house by the whale-path, heard his mandate, +EOF + +echo "#!$SHELL_PATH" >fake-editor.sh +cat >> fake-editor.sh <<\EOF +mv -f "$1" orig-patch && +mv -f patch "$1" +EOF + +test_set_editor "$(pwd)/fake-editor.sh" +chmod a+x fake-editor.sh + +test_expect_success 'add -e' ' + + cp second-part file && + git add -e && + test_cmp second-part file && + test_cmp orig-patch expected-patch && + git diff --cached > out && + test_cmp out expected + +' + +test_done diff --git a/t/t3900-i18n-commit.sh b/t/t3900-i18n-commit.sh index 784c31aec9..256c4c9701 100755 --- a/t/t3900-i18n-commit.sh +++ b/t/t3900-i18n-commit.sh @@ -9,7 +9,15 @@ test_description='commit and log output encodings' compare_with () { git show -s $1 | sed -e '1,/^$/d' -e 's/^ //' >current && - test_cmp current "$2" + case "$3" in + '') + test_cmp "$2" current ;; + ?*) + iconv -f "$3" -t UTF-8 >current.utf8 <current && + iconv -f "$3" -t UTF-8 >expect.utf8 <"$2" && + test_cmp expect.utf8 current.utf8 + ;; + esac } test_expect_success setup ' @@ -26,7 +34,7 @@ test_expect_success 'no encoding header for base case' ' test z = "z$E" ' -for H in ISO-8859-1 EUCJP ISO-2022-JP +for H in ISO8859-1 eucJP ISO-2022-JP do test_expect_success "$H setup" ' git config i18n.commitencoding $H && @@ -36,7 +44,7 @@ do ' done -for H in ISO-8859-1 EUCJP ISO-2022-JP +for H in ISO8859-1 eucJP ISO-2022-JP do test_expect_success "check encoding header for $H" ' E=$(git cat-file commit '$H' | sed -ne "s/^encoding //p") && @@ -53,14 +61,14 @@ test_expect_success 'config to remove customization' ' else test z = "z$Z" fi && - git config i18n.commitencoding utf-8 + git config i18n.commitencoding UTF-8 ' -test_expect_success 'ISO-8859-1 should be shown in UTF-8 now' ' - compare_with ISO-8859-1 "$TEST_DIRECTORY"/t3900/1-UTF-8.txt +test_expect_success 'ISO8859-1 should be shown in UTF-8 now' ' + compare_with ISO8859-1 "$TEST_DIRECTORY"/t3900/1-UTF-8.txt ' -for H in EUCJP ISO-2022-JP +for H in eucJP ISO-2022-JP do test_expect_success "$H should be shown in UTF-8 now" ' compare_with '$H' "$TEST_DIRECTORY"/t3900/2-UTF-8.txt @@ -78,7 +86,7 @@ test_expect_success 'config to add customization' ' fi ' -for H in ISO-8859-1 EUCJP ISO-2022-JP +for H in ISO8859-1 eucJP ISO-2022-JP do test_expect_success "$H should be shown in itself now" ' git config i18n.commitencoding '$H' && @@ -87,32 +95,38 @@ do done test_expect_success 'config to tweak customization' ' - git config i18n.logoutputencoding utf-8 + git config i18n.logoutputencoding UTF-8 ' -test_expect_success 'ISO-8859-1 should be shown in UTF-8 now' ' - compare_with ISO-8859-1 "$TEST_DIRECTORY"/t3900/1-UTF-8.txt +test_expect_success 'ISO8859-1 should be shown in UTF-8 now' ' + compare_with ISO8859-1 "$TEST_DIRECTORY"/t3900/1-UTF-8.txt ' -for H in EUCJP ISO-2022-JP +for H in eucJP ISO-2022-JP do test_expect_success "$H should be shown in UTF-8 now" ' compare_with '$H' "$TEST_DIRECTORY"/t3900/2-UTF-8.txt ' done -for J in EUCJP ISO-2022-JP +for J in eucJP ISO-2022-JP do + if test "$J" = ISO-2022-JP + then + ICONV=$J + else + ICONV= + fi git config i18n.logoutputencoding $J - for H in EUCJP ISO-2022-JP + for H in eucJP ISO-2022-JP do test_expect_success "$H should be shown in $J now" ' - compare_with '$H' "$TEST_DIRECTORY"/t3900/'$J'.txt + compare_with '$H' "$TEST_DIRECTORY"/t3900/'$J'.txt $ICONV ' done done -for H in ISO-8859-1 EUCJP ISO-2022-JP +for H in ISO8859-1 eucJP ISO-2022-JP do test_expect_success "No conversion with $H" ' compare_with "--encoding=none '$H'" "$TEST_DIRECTORY"/t3900/'$H'.txt diff --git a/t/t3900/ISO-8859-1.txt b/t/t3900/ISO8859-1.txt index 7cbef0ee6f..7cbef0ee6f 100644 --- a/t/t3900/ISO-8859-1.txt +++ b/t/t3900/ISO8859-1.txt diff --git a/t/t3900/EUCJP.txt b/t/t3900/eucJP.txt index 546f2aac01..546f2aac01 100644 --- a/t/t3900/EUCJP.txt +++ b/t/t3900/eucJP.txt diff --git a/t/t3901-i18n-patch.sh b/t/t3901-i18n-patch.sh index 7655da3f8d..31a5770b34 100755 --- a/t/t3901-i18n-patch.sh +++ b/t/t3901-i18n-patch.sh @@ -17,9 +17,9 @@ check_encoding () { git cat-file commit HEAD~$j | case "$header" in 8859) - grep "^encoding ISO-8859-1" ;; + grep "^encoding ISO8859-1" ;; *) - ! grep "^encoding ISO-8859-1" ;; + grep "^encoding ISO8859-1"; test "$?" != 0 ;; esac || { bad=1 break @@ -55,7 +55,7 @@ test_expect_success setup ' git commit -s -m "Second on side" && # the second one on the side branch is ISO-8859-1 - git config i18n.commitencoding ISO-8859-1 && + git config i18n.commitencoding ISO8859-1 && # use author and committer name in ISO-8859-1 to match it. . "$TEST_DIRECTORY"/t3901-8859-1.txt && test_tick && @@ -68,14 +68,14 @@ test_expect_success setup ' ' test_expect_success 'format-patch output (ISO-8859-1)' ' - git config i18n.logoutputencoding ISO-8859-1 && + git config i18n.logoutputencoding ISO8859-1 && git format-patch --stdout master..HEAD^ >out-l1 && git format-patch --stdout HEAD^ >out-l2 && - grep "^Content-Type: text/plain; charset=ISO-8859-1" out-l1 && - grep "^From: =?ISO-8859-1?q?=C1=E9=ED=20=F3=FA?=" out-l1 && - grep "^Content-Type: text/plain; charset=ISO-8859-1" out-l2 && - grep "^From: =?ISO-8859-1?q?=C1=E9=ED=20=F3=FA?=" out-l2 + grep "^Content-Type: text/plain; charset=ISO8859-1" out-l1 && + grep "^From: =?ISO8859-1?q?=C1=E9=ED=20=F3=FA?=" out-l1 && + grep "^Content-Type: text/plain; charset=ISO8859-1" out-l2 && + grep "^From: =?ISO8859-1?q?=C1=E9=ED=20=F3=FA?=" out-l2 ' test_expect_success 'format-patch output (UTF-8)' ' @@ -110,7 +110,7 @@ test_expect_success 'rebase (U/U)' ' test_expect_success 'rebase (U/L)' ' git config i18n.commitencoding UTF-8 && - git config i18n.logoutputencoding ISO-8859-1 && + git config i18n.logoutputencoding ISO8859-1 && . "$TEST_DIRECTORY"/t3901-utf8.txt && git reset --hard side && @@ -121,8 +121,8 @@ test_expect_success 'rebase (U/L)' ' test_expect_success 'rebase (L/L)' ' # In this test we want ISO-8859-1 encoded commits as the result - git config i18n.commitencoding ISO-8859-1 && - git config i18n.logoutputencoding ISO-8859-1 && + git config i18n.commitencoding ISO8859-1 && + git config i18n.logoutputencoding ISO8859-1 && . "$TEST_DIRECTORY"/t3901-8859-1.txt && git reset --hard side && @@ -134,7 +134,7 @@ test_expect_success 'rebase (L/L)' ' test_expect_success 'rebase (L/U)' ' # This is pathological -- use UTF-8 as intermediate form # to get ISO-8859-1 results. - git config i18n.commitencoding ISO-8859-1 && + git config i18n.commitencoding ISO8859-1 && git config i18n.logoutputencoding UTF-8 && . "$TEST_DIRECTORY"/t3901-8859-1.txt && @@ -162,8 +162,8 @@ test_expect_success 'cherry-pick(U/U)' ' test_expect_success 'cherry-pick(L/L)' ' # Both the commitencoding and logoutputencoding is set to ISO-8859-1 - git config i18n.commitencoding ISO-8859-1 && - git config i18n.logoutputencoding ISO-8859-1 && + git config i18n.commitencoding ISO8859-1 && + git config i18n.logoutputencoding ISO8859-1 && . "$TEST_DIRECTORY"/t3901-8859-1.txt && git reset --hard master && @@ -178,7 +178,7 @@ test_expect_success 'cherry-pick(U/L)' ' # Commitencoding is set to UTF-8 but logoutputencoding is ISO-8859-1 git config i18n.commitencoding UTF-8 && - git config i18n.logoutputencoding ISO-8859-1 && + git config i18n.logoutputencoding ISO8859-1 && . "$TEST_DIRECTORY"/t3901-utf8.txt && git reset --hard master && @@ -193,7 +193,7 @@ test_expect_success 'cherry-pick(L/U)' ' # Again, the commitencoding is set to ISO-8859-1 but # logoutputencoding is set to UTF-8. - git config i18n.commitencoding ISO-8859-1 && + git config i18n.commitencoding ISO8859-1 && git config i18n.logoutputencoding UTF-8 && . "$TEST_DIRECTORY"/t3901-8859-1.txt && @@ -218,7 +218,7 @@ test_expect_success 'rebase --merge (U/U)' ' test_expect_success 'rebase --merge (U/L)' ' git config i18n.commitencoding UTF-8 && - git config i18n.logoutputencoding ISO-8859-1 && + git config i18n.logoutputencoding ISO8859-1 && . "$TEST_DIRECTORY"/t3901-utf8.txt && git reset --hard side && @@ -229,8 +229,8 @@ test_expect_success 'rebase --merge (U/L)' ' test_expect_success 'rebase --merge (L/L)' ' # In this test we want ISO-8859-1 encoded commits as the result - git config i18n.commitencoding ISO-8859-1 && - git config i18n.logoutputencoding ISO-8859-1 && + git config i18n.commitencoding ISO8859-1 && + git config i18n.logoutputencoding ISO8859-1 && . "$TEST_DIRECTORY"/t3901-8859-1.txt && git reset --hard side && @@ -242,7 +242,7 @@ test_expect_success 'rebase --merge (L/L)' ' test_expect_success 'rebase --merge (L/U)' ' # This is pathological -- use UTF-8 as intermediate form # to get ISO-8859-1 results. - git config i18n.commitencoding ISO-8859-1 && + git config i18n.commitencoding ISO8859-1 && git config i18n.logoutputencoding UTF-8 && . "$TEST_DIRECTORY"/t3901-8859-1.txt && diff --git a/t/t3903-stash.sh b/t/t3903-stash.sh index 7484cbede6..7a3fb67957 100755 --- a/t/t3903-stash.sh +++ b/t/t3903-stash.sh @@ -177,4 +177,27 @@ test_expect_success 'stash branch' ' test 0 = $(git stash list | wc -l) ' +test_expect_success 'apply -q is quiet' ' + echo foo > file && + git stash && + git stash apply -q > output.out 2>&1 && + test ! -s output.out +' + +test_expect_success 'save -q is quiet' ' + git stash save --quiet > output.out 2>&1 && + test ! -s output.out +' + +test_expect_success 'pop -q is quiet' ' + git stash pop -q > output.out 2>&1 && + test ! -s output.out +' + +test_expect_success 'drop -q is quiet' ' + git stash && + git stash drop -q > output.out 2>&1 && + test ! -s output.out +' + test_done diff --git a/t/t4007-rename-3.sh b/t/t4007-rename-3.sh index 42072d724e..11502b7509 100755 --- a/t/t4007-rename-3.sh +++ b/t/t4007-rename-3.sh @@ -9,32 +9,36 @@ test_description='Rename interaction with pathspec. . ./test-lib.sh . "$TEST_DIRECTORY"/diff-lib.sh ;# test-lib chdir's into trash -test_expect_success \ - 'prepare reference tree' \ - 'mkdir path0 path1 && - cp "$TEST_DIRECTORY"/../COPYING path0/COPYING && - git update-index --add path0/COPYING && - tree=$(git write-tree) && - echo $tree' - -test_expect_success \ - 'prepare work tree' \ - 'cp path0/COPYING path1/COPYING && - git update-index --add --remove path0/COPYING path1/COPYING' +test_expect_success 'prepare reference tree' ' + mkdir path0 path1 && + cp "$TEST_DIRECTORY"/../COPYING path0/COPYING && + git update-index --add path0/COPYING && + tree=$(git write-tree) && + echo $tree +' + +test_expect_success 'prepare work tree' ' + cp path0/COPYING path1/COPYING && + git update-index --add --remove path0/COPYING path1/COPYING +' # In the tree, there is only path0/COPYING. In the cache, path0 and # path1 both have COPYING and the latter is a copy of path0/COPYING. # Comparing the full tree with cache should tell us so. -git diff-index -C --find-copies-harder $tree >current - cat >expected <<\EOF :100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 6ff87c4664981e4397625791c8ea3bbb5f2279a3 C100 path0/COPYING path1/COPYING EOF -test_expect_success \ - 'validate the result (#1)' \ - 'compare_diff_raw current expected' +test_expect_success 'copy detection' ' + git diff-index -C --find-copies-harder $tree >current && + compare_diff_raw current expected +' + +test_expect_success 'copy detection, cached' ' + git diff-index -C --find-copies-harder --cached $tree >current && + compare_diff_raw current expected +' # In the tree, there is only path0/COPYING. In the cache, path0 and # path1 both have COPYING and the latter is a copy of path0/COPYING. @@ -42,49 +46,45 @@ test_expect_success \ # path1/COPYING suddenly appearing from nowhere, not detected as # a copy from path0/COPYING. -git diff-index -C $tree path1 >current - cat >expected <<\EOF :000000 100644 0000000000000000000000000000000000000000 6ff87c4664981e4397625791c8ea3bbb5f2279a3 A path1/COPYING EOF -test_expect_success \ - 'validate the result (#2)' \ - 'compare_diff_raw current expected' - -test_expect_success \ - 'tweak work tree' \ - 'rm -f path0/COPYING && - git update-index --remove path0/COPYING' +test_expect_success 'copy, limited to a subtree' ' + git diff-index -C --find-copies-harder $tree path1 >current && + compare_diff_raw current expected +' +test_expect_success 'tweak work tree' ' + rm -f path0/COPYING && + git update-index --remove path0/COPYING +' # In the tree, there is only path0/COPYING. In the cache, path0 does # not have COPYING anymore and path1 has COPYING which is a copy of # path0/COPYING. Showing the full tree with cache should tell us about # the rename. -git diff-index -C $tree >current - cat >expected <<\EOF :100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 6ff87c4664981e4397625791c8ea3bbb5f2279a3 R100 path0/COPYING path1/COPYING EOF -test_expect_success \ - 'validate the result (#3)' \ - 'compare_diff_raw current expected' +test_expect_success 'rename detection' ' + git diff-index -C --find-copies-harder $tree >current && + compare_diff_raw current expected +' # In the tree, there is only path0/COPYING. In the cache, path0 does # not have COPYING anymore and path1 has COPYING which is a copy of # path0/COPYING. When we say we care only about path1, we should just # see path1/COPYING appearing from nowhere. -git diff-index -C $tree path1 >current - cat >expected <<\EOF :000000 100644 0000000000000000000000000000000000000000 6ff87c4664981e4397625791c8ea3bbb5f2279a3 A path1/COPYING EOF -test_expect_success \ - 'validate the result (#4)' \ - 'compare_diff_raw current expected' +test_expect_success 'rename, limited to a subtree' ' + git diff-index -C --find-copies-harder $tree path1 >current && + compare_diff_raw current expected +' test_done diff --git a/t/t4013-diff-various.sh b/t/t4013-diff-various.sh index 8b33321f8c..8e3694ed5b 100755 --- a/t/t4013-diff-various.sh +++ b/t/t4013-diff-various.sh @@ -207,6 +207,7 @@ log --root --cc --patch-with-stat --summary master log -SF master log -SF -p master log --decorate --all +log --decorate=full --all rev-list --parents HEAD rev-list --children HEAD diff --git a/t/t4013/diff.log_--decorate=full_--all b/t/t4013/diff.log_--decorate=full_--all new file mode 100644 index 0000000000..903d9d9659 --- /dev/null +++ b/t/t4013/diff.log_--decorate=full_--all @@ -0,0 +1,34 @@ +$ git log --decorate=full --all +commit 59d314ad6f356dd08601a4cd5e530381da3e3c64 (refs/heads/master) +Merge: 9a6d494 c7a2ab9 +Author: A U Thor <author@example.com> +Date: Mon Jun 26 00:04:00 2006 +0000 + + Merge branch 'side' + +commit c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a (refs/heads/side) +Author: A U Thor <author@example.com> +Date: Mon Jun 26 00:03:00 2006 +0000 + + Side + +commit 9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0 +Author: A U Thor <author@example.com> +Date: Mon Jun 26 00:02:00 2006 +0000 + + Third + +commit 1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44 +Author: A U Thor <author@example.com> +Date: Mon Jun 26 00:01:00 2006 +0000 + + Second + + This is the second commit. + +commit 444ac553ac7612cc88969031b02b3767fb8a353a (refs/heads/initial) +Author: A U Thor <author@example.com> +Date: Mon Jun 26 00:00:00 2006 +0000 + + Initial +$ diff --git a/t/t4013/diff.log_--decorate_--all b/t/t4013/diff.log_--decorate_--all index 12da8ac07d..954210ea90 100644 --- a/t/t4013/diff.log_--decorate_--all +++ b/t/t4013/diff.log_--decorate_--all @@ -1,12 +1,12 @@ $ git log --decorate --all -commit 59d314ad6f356dd08601a4cd5e530381da3e3c64 (refs/heads/master) +commit 59d314ad6f356dd08601a4cd5e530381da3e3c64 (master) Merge: 9a6d494 c7a2ab9 Author: A U Thor <author@example.com> Date: Mon Jun 26 00:04:00 2006 +0000 Merge branch 'side' -commit c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a (refs/heads/side) +commit c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a (side) Author: A U Thor <author@example.com> Date: Mon Jun 26 00:03:00 2006 +0000 @@ -26,7 +26,7 @@ Date: Mon Jun 26 00:01:00 2006 +0000 This is the second commit. -commit 444ac553ac7612cc88969031b02b3767fb8a353a (refs/heads/initial) +commit 444ac553ac7612cc88969031b02b3767fb8a353a (initial) Author: A U Thor <author@example.com> Date: Mon Jun 26 00:00:00 2006 +0000 diff --git a/t/t4020-diff-external.sh b/t/t4020-diff-external.sh index 0720001281..4ea42e00da 100755 --- a/t/t4020-diff-external.sh +++ b/t/t4020-diff-external.sh @@ -136,6 +136,15 @@ test_expect_success 'GIT_EXTERNAL_DIFF with more than one changed files' ' GIT_EXTERNAL_DIFF=echo git diff ' +test_expect_success 'GIT_EXTERNAL_DIFF generates pretty paths' ' + touch file.ext && + git add file.ext && + echo with extension > file.ext && + GIT_EXTERNAL_DIFF=echo git diff file.ext | grep ......_file\.ext && + git update-index --force-remove file.ext && + rm file.ext +' + echo "#!$SHELL_PATH" >fake-diff.sh cat >> fake-diff.sh <<\EOF cat $2 >> crlfed.txt diff --git a/t/t4037-diff-r-t-dirs.sh b/t/t4037-diff-r-t-dirs.sh new file mode 100755 index 0000000000..f5ce3b29a2 --- /dev/null +++ b/t/t4037-diff-r-t-dirs.sh @@ -0,0 +1,53 @@ +#!/bin/sh + +test_description='diff -r -t shows directory additions and deletions' + +. ./test-lib.sh + +test_expect_success setup ' + mkdir dc dr dt && + >dc/1 && + >dr/2 && + >dt/3 && + >fc && + >fr && + >ft && + git add . && + test_tick && + git commit -m initial && + + rm -fr dt dr ft fr && + mkdir da ft && + for p in dc/1 da/4 dt ft/5 fc + do + echo hello >$p || exit + done && + git add -u && + git add . && + test_tick && + git commit -m second +' + +cat >expect <<\EOF +A da +A da/4 +M dc +M dc/1 +D dr +D dr/2 +A dt +D dt +D dt/3 +M fc +D fr +D ft +A ft +A ft/5 +EOF + +test_expect_success verify ' + git diff-tree -r -t --name-status HEAD^ HEAD >actual && + test_cmp expect actual +' + +test_done diff --git a/t/t4132-apply-removal.sh b/t/t4132-apply-removal.sh new file mode 100755 index 0000000000..bb1ffe3b6c --- /dev/null +++ b/t/t4132-apply-removal.sh @@ -0,0 +1,95 @@ +#!/bin/sh +# +# Copyright (c) 2009 Junio C Hamano + +test_description='git-apply notices removal patches generated by GNU diff' + +. ./test-lib.sh + +test_expect_success setup ' + cat <<-EOF >c && + diff -ruN a/file b/file + --- a/file TS0 + +++ b/file TS1 + @@ -0,0 +1 @@ + +something + EOF + + cat <<-EOF >d && + diff -ruN a/file b/file + --- a/file TS0 + +++ b/file TS1 + @@ -1 +0,0 @@ + -something + EOF + + timeWest="1982-09-16 07:00:00.000000000 -0800" && + timeGMT="1982-09-16 15:00:00.000000000 +0000" && + timeEast="1982-09-17 00:00:00.000000000 +0900" && + + epocWest="1969-12-31 16:00:00.000000000 -0800" && + epocGMT="1970-01-01 00:00:00.000000000 +0000" && + epocEast="1970-01-01 09:00:00.000000000 +0900" && + + sed -e "s/TS0/$epocWest/" -e "s/TS1/$timeWest/" <c >createWest.patch && + sed -e "s/TS0/$epocEast/" -e "s/TS1/$timeEast/" <c >createEast.patch && + sed -e "s/TS0/$epocGMT/" -e "s/TS1/$timeGMT/" <c >createGMT.patch && + + sed -e "s/TS0/$timeWest/" -e "s/TS1/$timeWest/" <c >addWest.patch && + sed -e "s/TS0/$timeEast/" -e "s/TS1/$timeEast/" <c >addEast.patch && + sed -e "s/TS0/$timeGMT/" -e "s/TS1/$timeGMT/" <c >addGMT.patch && + + sed -e "s/TS0/$timeWest/" -e "s/TS1/$timeWest/" <d >emptyWest.patch && + sed -e "s/TS0/$timeEast/" -e "s/TS1/$timeEast/" <d >emptyEast.patch && + sed -e "s/TS0/$timeGMT/" -e "s/TS1/$timeGMT/" <d >emptyGMT.patch && + + sed -e "s/TS0/$timeWest/" -e "s/TS1/$epocWest/" <d >removeWest.patch && + sed -e "s/TS0/$timeEast/" -e "s/TS1/$epocEast/" <d >removeEast.patch && + sed -e "s/TS0/$timeGMT/" -e "s/TS1/$epocGMT/" <d >removeGMT.patch && + + echo something >something && + >empty +' + +for patch in *.patch +do + test_expect_success "test $patch" ' + rm -f file .git/index && + case "$patch" in + create*) + # must be able to create + git apply --index $patch && + test_cmp file something && + # must notice the file is already there + >file && + git add file && + test_must_fail git apply $patch + ;; + add*) + # must be able to create or patch + git apply $patch && + test_cmp file something && + >file && + git apply $patch && + test_cmp file something + ;; + empty*) + # must leave an empty file + cat something >file && + git add file && + git apply --index $patch && + test -f file && + test_cmp empty file + ;; + remove*) + # must remove the file + cat something >file && + git add file && + git apply --index $patch && + ! test -f file + ;; + esac + ' +done + +test_done diff --git a/t/t4150-am.sh b/t/t4150-am.sh index d6ebbaebe2..8296605234 100755 --- a/t/t4150-am.sh +++ b/t/t4150-am.sh @@ -77,6 +77,12 @@ test_expect_success setup ' git commit -s -F msg && git tag second && git format-patch --stdout first >patch1 && + { + echo "X-Fake-Field: Line One" && + echo "X-Fake-Field: Line Two" && + echo "X-Fake-Field: Line Three" && + git format-patch --stdout first | sed -e "1d" + } > patch1.eml && sed -n -e "3,\$p" msg >file && git add file && test_tick && @@ -108,6 +114,15 @@ test_expect_success 'am applies patch correctly' ' test "$(git rev-parse second^)" = "$(git rev-parse HEAD^)" ' +test_expect_success 'am applies patch e-mail not in a mbox' ' + git checkout first && + git am patch1.eml && + ! test -d .git/rebase-apply && + test -z "$(git diff second)" && + test "$(git rev-parse second)" = "$(git rev-parse HEAD)" && + test "$(git rev-parse second^)" = "$(git rev-parse HEAD^)" +' + GIT_AUTHOR_NAME="Another Thor" GIT_AUTHOR_EMAIL="a.thor@example.com" GIT_COMMITTER_NAME="Co M Miter" @@ -180,6 +195,17 @@ test_expect_success 'am -3 falls back to 3-way merge' ' test -z "$(git diff lorem)" ' +test_expect_success 'am -3 -q is quiet' ' + git reset master2 --hard && + sed -n -e "3,\$p" msg >file && + head -n 9 msg >>file && + git add file && + test_tick && + git commit -m "copied stuff" && + git am -3 -q lorem-move.patch > output.out 2>&1 && + ! test -s output.out +' + test_expect_success 'am pauses on conflict' ' git checkout lorem2^^ && test_must_fail git am lorem-move.patch && @@ -305,4 +331,19 @@ test_expect_success 'am into an unborn branch' ' test "z$result" = "z$(git rev-parse first^{tree})" ' +test_expect_success 'am newline in subject' ' + git checkout first && + test_tick && + sed -e "s/second/second \\\n foo/" patch1 > patchnl && + git am < patchnl > output.out 2>&1 && + grep "^Applying: second \\\n foo$" output.out +' + +test_expect_success 'am -q is quiet' ' + git checkout first && + test_tick && + git am -q < patch1 > output.out 2>&1 && + ! test -s output.out +' + test_done diff --git a/t/t4202-log.sh b/t/t4202-log.sh index 64502e2be7..1e952ca55b 100755 --- a/t/t4202-log.sh +++ b/t/t4202-log.sh @@ -149,6 +149,26 @@ test_expect_success 'git log --follow' ' ' +cat > expect << EOF +804a787 sixth +394ef78 fifth +5d31159 fourth +EOF +test_expect_success 'git log --no-walk <commits> sorts by commit time' ' + git log --no-walk --oneline 5d31159 804a787 394ef78 > actual && + test_cmp expect actual +' + +cat > expect << EOF +5d31159 fourth +804a787 sixth +394ef78 fifth +EOF +test_expect_success 'git show <commits> leaves list of commits as given' ' + git show --oneline -s 5d31159 804a787 394ef78 > actual && + test_cmp expect actual +' + test_expect_success 'setup case sensitivity tests' ' echo case >one && test_tick && @@ -300,11 +320,11 @@ test_expect_success 'set up more tangled history' ' ' cat > expect <<\EOF -* Merge branch 'reach' +* Merge commit 'reach' |\ | \ | \ -*-. \ Merge branches 'octopus-a' and 'octopus-b' +*-. \ Merge commit 'octopus-a'; commit 'octopus-b' |\ \ \ * | | | seventh | | * | octopus-b @@ -324,14 +344,12 @@ cat > expect <<\EOF * | | | Merge branch 'side' |\ \ \ \ | * | | | side-2 -| | | |/ -| | |/| +| | |_|/ | |/| | | * | | side-1 * | | | Second * | | | sixth -| | |/ -| |/| +| |_|/ |/| | * | | fifth * | | fourth diff --git a/t/t5100/rfc2047-samples.mbox b/t/t5100/rfc2047-samples.mbox index 3ca2470da2..1fc224810d 100644 --- a/t/t5100/rfc2047-samples.mbox +++ b/t/t5100/rfc2047-samples.mbox @@ -1,48 +1,48 @@ From nobody Mon Sep 17 00:00:00 2001 From: =?US-ASCII?Q?Keith_Moore?= <moore@cs.utk.edu> -To: =?ISO-8859-1?Q?Keld_J=F8rn_Simonsen?= <keld@dkuug.dk> -CC: =?ISO-8859-1?Q?Andr=E9?= Pirard <PIRARD@vm1.ulg.ac.be> -Subject: =?ISO-8859-1?B?SWYgeW91IGNhbiByZWFkIHRoaXMgeW8=?= - =?ISO-8859-2?B?dSB1bmRlcnN0YW5kIHRoZSBleGFtcGxlLg==?= +To: =?ISO8859-1?Q?Keld_J=F8rn_Simonsen?= <keld@dkuug.dk> +CC: =?ISO8859-1?Q?Andr=E9?= Pirard <PIRARD@vm1.ulg.ac.be> +Subject: =?ISO8859-1?B?SWYgeW91IGNhbiByZWFkIHRoaXMgeW8=?= + =?ISO8859-2?B?dSB1bmRlcnN0YW5kIHRoZSBleGFtcGxlLg==?= From nobody Mon Sep 17 00:00:00 2001 -From: =?ISO-8859-1?Q?Olle_J=E4rnefors?= <ojarnef@admin.kth.se> +From: =?ISO8859-1?Q?Olle_J=E4rnefors?= <ojarnef@admin.kth.se> To: ietf-822@dimacs.rutgers.edu, ojarnef@admin.kth.se Subject: Time for ISO 10646? From nobody Mon Sep 17 00:00:00 2001 To: Dave Crocker <dcrocker@mordor.stanford.edu> Cc: ietf-822@dimacs.rutgers.edu, paf@comsol.se -From: =?ISO-8859-1?Q?Patrik_F=E4ltstr=F6m?= <paf@nada.kth.se> +From: =?ISO8859-1?Q?Patrik_F=E4ltstr=F6m?= <paf@nada.kth.se> Subject: Re: RFC-HDR care and feeding From nobody Mon Sep 17 00:00:00 2001 From: Nathaniel Borenstein <nsb@thumper.bellcore.com> - (=?iso-8859-8?b?7eXs+SDv4SDp7Oj08A==?=) + (=?ISO8859-8?b?7eXs+SDv4SDp7Oj08A==?=) To: Greg Vaudreuil <gvaudre@NRI.Reston.VA.US>, Ned Freed <ned@innosoft.com>, Keith Moore <moore@cs.utk.edu> Subject: Test of new header generator MIME-Version: 1.0 -Content-type: text/plain; charset=ISO-8859-1 +Content-type: text/plain; charset=ISO8859-1 From nobody Mon Sep 17 00:00:00 2001 -Subject: (=?ISO-8859-1?Q?a?=) +Subject: (=?ISO8859-1?Q?a?=) From nobody Mon Sep 17 00:00:00 2001 -Subject: (=?ISO-8859-1?Q?a?= b) +Subject: (=?ISO8859-1?Q?a?= b) From nobody Mon Sep 17 00:00:00 2001 -Subject: (=?ISO-8859-1?Q?a?= =?ISO-8859-1?Q?b?=) +Subject: (=?ISO8859-1?Q?a?= =?ISO8859-1?Q?b?=) From nobody Mon Sep 17 00:00:00 2001 -Subject: (=?ISO-8859-1?Q?a?= =?ISO-8859-1?Q?b?=) +Subject: (=?ISO8859-1?Q?a?= =?ISO8859-1?Q?b?=) From nobody Mon Sep 17 00:00:00 2001 -Subject: (=?ISO-8859-1?Q?a?= - =?ISO-8859-1?Q?b?=) +Subject: (=?ISO8859-1?Q?a?= + =?ISO8859-1?Q?b?=) From nobody Mon Sep 17 00:00:00 2001 -Subject: (=?ISO-8859-1?Q?a_b?=) +Subject: (=?ISO8859-1?Q?a_b?=) From nobody Mon Sep 17 00:00:00 2001 -Subject: (=?ISO-8859-1?Q?a?= =?ISO-8859-2?Q?_b?=) +Subject: (=?ISO8859-1?Q?a?= =?ISO8859-2?Q?_b?=) diff --git a/t/t5100/sample.mbox b/t/t5100/sample.mbox index c5ad206b40..c3074ac573 100644 --- a/t/t5100/sample.mbox +++ b/t/t5100/sample.mbox @@ -99,7 +99,7 @@ index 9123cdc..918dcf8 100644 From nobody Sat Aug 27 23:07:49 2005 Path: news.gmane.org!not-for-mail Message-ID: <20050721.091036.01119516.yoshfuji@linux-ipv6.org> -From: YOSHIFUJI Hideaki / =?iso-2022-jp?B?GyRCNUhGIzFRTEAbKEI=?= +From: YOSHIFUJI Hideaki / =?ISO-2022-JP?B?GyRCNUhGIzFRTEAbKEI=?= <yoshfuji@linux-ipv6.org> Newsgroups: gmane.comp.version-control.git Subject: [PATCH 1/2] GIT: Try all addresses for given remote name @@ -218,7 +218,7 @@ GPG-FP : 9022 65EB 1ECF 3AD1 0BDF 80D8 4807 F894 E062 0EEA From nobody Sat Aug 27 23:07:49 2005 Path: news.gmane.org!not-for-mail Message-ID: <u5tacjjdpxq.fsf@lysator.liu.se> -From: =?iso-8859-1?Q?David_K=E5gedal?= <davidk@lysator.liu.se> +From: =?ISO8859-1?Q?David_K=E5gedal?= <davidk@lysator.liu.se> Newsgroups: gmane.comp.version-control.git Subject: [PATCH] Fixed two bugs in git-cvsimport-script. Date: Mon, 15 Aug 2005 20:18:25 +0200 @@ -226,7 +226,7 @@ Lines: 83 Approved: news@gmane.org NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 -Content-Type: text/plain; charset=iso-8859-1 +Content-Type: text/plain; charset=ISO8859-1 Content-Transfer-Encoding: QUOTED-PRINTABLE X-Trace: sea.gmane.org 1124130247 31839 80.91.229.2 (15 Aug 2005 18:24:07 GMT) X-Complaints-To: usenet@sea.gmane.org @@ -476,7 +476,7 @@ MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= -Content-Type: text/plain; charset=iso-8859-15 +Content-Type: text/plain; charset=ISO8859-15 Content-Transfer-Encoding: quoted-printable Here comes a commit log message, and diff --git a/t/t5500-fetch-pack.sh b/t/t5500-fetch-pack.sh index c450f33f33..a8c2ca2a78 100755 --- a/t/t5500-fetch-pack.sh +++ b/t/t5500-fetch-pack.sh @@ -3,9 +3,8 @@ # Copyright (c) 2005 Johannes Schindelin # -test_description='Testing multi_ack pack fetching +test_description='Testing multi_ack pack fetching' -' . ./test-lib.sh # Test fetch-pack/upload-pack pair. @@ -13,77 +12,60 @@ test_description='Testing multi_ack pack fetching # Some convenience functions add () { - name=$1 - text="$@" - branch=`echo $name | sed -e 's/^\(.\).*$/\1/'` - parents="" + name=$1 && + text="$@" && + branch=`echo $name | sed -e 's/^\(.\).*$/\1/'` && + parents="" && - shift + shift && while test $1; do - parents="$parents -p $1" + parents="$parents -p $1" && shift - done + done && - echo "$text" > test.txt - git update-index --add test.txt - tree=$(git write-tree) + echo "$text" > test.txt && + git update-index --add test.txt && + tree=$(git write-tree) && # make sure timestamps are in correct order - sec=$(($sec+1)) - commit=$(echo "$text" | GIT_AUTHOR_DATE=$sec \ - git commit-tree $tree $parents 2>>log2.txt) - eval "$name=$commit; export $name" - echo $commit > .git/refs/heads/$branch + test_tick && + commit=$(echo "$text" | git commit-tree $tree $parents) && + eval "$name=$commit; export $name" && + echo $commit > .git/refs/heads/$branch && eval ${branch}TIP=$commit } -count_objects () { - ls .git/objects/??/* 2>>log2.txt | wc -l | tr -d " " -} - -test_expect_object_count () { - message=$1 - count=$2 - - output="$(count_objects)" - test_expect_success \ - "new object count $message" \ - "test $count = $output" -} - pull_to_client () { - number=$1 - heads=$2 - count=$3 - no_strict_count_check=$4 - - cd client - test_expect_success "$number pull" \ - "git fetch-pack -k -v .. $heads" - case "$heads" in *A*) echo $ATIP > .git/refs/heads/A;; esac - case "$heads" in *B*) echo $BTIP > .git/refs/heads/B;; esac - git symbolic-ref HEAD refs/heads/`echo $heads | sed -e 's/^\(.\).*$/\1/'` - - test_expect_success "fsck" 'git fsck --full > fsck.txt 2>&1' - - test_expect_success 'check downloaded results' \ - 'mv .git/objects/pack/pack-* . && - p=`ls -1 pack-*.pack` && - git unpack-objects <$p && - git fsck --full' - - test_expect_success "new object count after $number pull" \ - 'idx=`echo pack-*.idx` && - pack_count=`git show-index <$idx | wc -l` && - test $pack_count = $count' - test -z "$pack_count" && pack_count=0 - if [ -z "$no_strict_count_check" ]; then - test_expect_success "minimal count" "test $count = $pack_count" - else - test $count != $pack_count && \ - echo "WARNING: $pack_count objects transmitted, only $count of which were needed" - fi - rm -f pack-* - cd .. + number=$1 && + heads=$2 && + count=$3 && + test_expect_success "$number pull" ' + ( + cd client && + git fetch-pack -k -v .. $heads && + + case "$heads" in + *A*) + echo $ATIP > .git/refs/heads/A;; + esac && + case "$heads" in *B*) + echo $BTIP > .git/refs/heads/B;; + esac && + git symbolic-ref HEAD refs/heads/`echo $heads \ + | sed -e "s/^\(.\).*$/\1/"` && + + git fsck --full && + + mv .git/objects/pack/pack-* . && + p=`ls -1 pack-*.pack` && + git unpack-objects <$p && + git fsck --full && + + idx=`echo pack-*.idx` && + pack_count=`git show-index <$idx | wc -l` && + test $pack_count = $count && + rm -f pack-* + ) + ' } # Here begins the actual testing @@ -94,89 +76,129 @@ pull_to_client () { # client pulls A20, B1. Then tracks only B. Then pulls A. -( +test_expect_success 'setup' ' mkdir client && - cd client && - git init 2>> log2.txt && - git config transfer.unpacklimit 0 -) - -add A1 - -prev=1; cur=2; while [ $cur -le 10 ]; do - add A$cur $(eval echo \$A$prev) - prev=$cur - cur=$(($cur+1)) -done - -add B1 $A1 - -echo $ATIP > .git/refs/heads/A -echo $BTIP > .git/refs/heads/B -git symbolic-ref HEAD refs/heads/B + ( + cd client && + git init && + git config transfer.unpacklimit 0 + ) && + add A1 && + prev=1 && + cur=2 && + while [ $cur -le 10 ]; do + add A$cur $(eval echo \$A$prev) && + prev=$cur && + cur=$(($cur+1)) + done && + add B1 $A1 + echo $ATIP > .git/refs/heads/A && + echo $BTIP > .git/refs/heads/B && + git symbolic-ref HEAD refs/heads/B +' pull_to_client 1st "B A" $((11*3)) -add A11 $A10 - -prev=1; cur=2; while [ $cur -le 65 ]; do - add B$cur $(eval echo \$B$prev) - prev=$cur - cur=$(($cur+1)) -done +test_expect_success 'post 1st pull setup' ' + add A11 $A10 && + prev=1 && + cur=2 && + while [ $cur -le 65 ]; do + add B$cur $(eval echo \$B$prev) && + prev=$cur && + cur=$(($cur+1)) + done +' pull_to_client 2nd "B" $((64*3)) -pull_to_client 3rd "A" $((1*3)) # old fails - -test_expect_success "clone shallow" 'git clone --depth 2 "file://$(pwd)/." shallow' +pull_to_client 3rd "A" $((1*3)) -(cd shallow; git count-objects -v) > count.shallow - -test_expect_success "clone shallow object count" \ - "test \"in-pack: 18\" = \"$(grep in-pack count.shallow)\"" - -count_output () { - sed -e '/^in-pack:/d' -e '/^packs:/d' -e '/^size-pack:/d' -e '/: 0$/d' "$1" -} +test_expect_success 'clone shallow' ' + git clone --depth 2 "file://$(pwd)/." shallow +' -test_expect_success "clone shallow object count (part 2)" ' - test -z "$(count_output count.shallow)" +test_expect_success 'clone shallow object count' ' + ( + cd shallow && + git count-objects -v + ) > count.shallow && + grep "^in-pack: 18" count.shallow ' -test_expect_success "fsck in shallow repo" \ - "(cd shallow; git fsck --full)" +test_expect_success 'clone shallow object count (part 2)' ' + sed -e "/^in-pack:/d" -e "/^packs:/d" -e "/^size-pack:/d" \ + -e "/: 0$/d" count.shallow > count_output && + ! test -s count_output +' -#test_done; exit +test_expect_success 'fsck in shallow repo' ' + ( + cd shallow && + git fsck --full + ) +' -add B66 $B65 -add B67 $B66 +test_expect_success 'add two more' ' + add B66 $B65 && + add B67 $B66 +' -test_expect_success "pull in shallow repo" \ - "(cd shallow; git pull .. B)" +test_expect_success 'pull in shallow repo' ' + ( + cd shallow && + git pull .. B + ) +' -(cd shallow; git count-objects -v) > count.shallow -test_expect_success "clone shallow object count" \ - "test \"count: 6\" = \"$(grep count count.shallow)\"" +test_expect_success 'clone shallow object count' ' + ( + cd shallow && + git count-objects -v + ) > count.shallow && + grep "^count: 6" count.shallow +' -add B68 $B67 -add B69 $B68 +test_expect_success 'add two more (part 2)' ' + add B68 $B67 && + add B69 $B68 +' -test_expect_success "deepening pull in shallow repo" \ - "(cd shallow; git pull --depth 4 .. B)" +test_expect_success 'deepening pull in shallow repo' ' + ( + cd shallow && + git pull --depth 4 .. B + ) +' -(cd shallow; git count-objects -v) > count.shallow -test_expect_success "clone shallow object count" \ - "test \"count: 12\" = \"$(grep count count.shallow)\"" +test_expect_success 'clone shallow object count' ' + ( + cd shallow && + git count-objects -v + ) > count.shallow && + grep "^count: 12" count.shallow +' -test_expect_success "deepening fetch in shallow repo" \ - "(cd shallow; git fetch --depth 4 .. A:A)" +test_expect_success 'deepening fetch in shallow repo' ' + ( + cd shallow && + git fetch --depth 4 .. A:A + ) +' -(cd shallow; git count-objects -v) > count.shallow -test_expect_success "clone shallow object count" \ - "test \"count: 18\" = \"$(grep count count.shallow)\"" +test_expect_success 'clone shallow object count' ' + ( + cd shallow && + git count-objects -v + ) > count.shallow && + grep "^count: 18" count.shallow +' -test_expect_success "pull in shallow repo with missing merge base" \ - "(cd shallow && test_must_fail git pull --depth 4 .. A)" +test_expect_success 'pull in shallow repo with missing merge base' ' + ( + cd shallow && + test_must_fail git pull --depth 4 .. A + ) +' test_done diff --git a/t/t5502-quickfetch.sh b/t/t5502-quickfetch.sh index 16eadd6b68..1037a723fe 100755 --- a/t/t5502-quickfetch.sh +++ b/t/t5502-quickfetch.sh @@ -119,4 +119,24 @@ test_expect_success 'quickfetch should not copy from alternate' ' ' +test_expect_success 'quickfetch should handle ~1000 refs (on Windows)' ' + + git gc && + head=$(git rev-parse HEAD) && + branchprefix="$head refs/heads/branch" && + for i in 0 1 2 3 4 5 6 7 8 9; do + for j in 0 1 2 3 4 5 6 7 8 9; do + for k in 0 1 2 3 4 5 6 7 8 9; do + echo "$branchprefix$i$j$k" >> .git/packed-refs + done + done + done && + ( + cd cloned && + git fetch && + git fetch + ) + +' + test_done diff --git a/t/t5505-remote.sh b/t/t5505-remote.sh index e70246b3fb..852ccb5d7d 100755 --- a/t/t5505-remote.sh +++ b/t/t5505-remote.sh @@ -135,7 +135,8 @@ EOF cat > test/expect << EOF * remote origin - URL: $(pwd)/one + Fetch URL: $(pwd)/one + Push URL: $(pwd)/one HEAD branch: master Remote branches: master new (next fetch will store in remotes/origin) @@ -151,7 +152,8 @@ cat > test/expect << EOF master pushes to master (local out of date) master pushes to upstream (create) * remote two - URL: ../two + Fetch URL: ../two + Push URL: ../three HEAD branch (remote HEAD is ambiguous, may be one of the following): another master @@ -173,6 +175,7 @@ test_expect_success 'show' ' git branch --track rebase origin/master && git branch -d -r origin/master && git config --add remote.two.url ../two && + git config --add remote.two.pushurl ../three && git config branch.rebase.rebase true && git config branch.octopus.merge "topic-a topic-b topic-c" && (cd ../one && @@ -191,7 +194,8 @@ test_expect_success 'show' ' cat > test/expect << EOF * remote origin - URL: $(pwd)/one + Fetch URL: $(pwd)/one + Push URL: $(pwd)/one HEAD branch: (not queried) Remote branches: (status not queried) master diff --git a/t/t5510-fetch.sh b/t/t5510-fetch.sh index bee3424fed..d13c806624 100755 --- a/t/t5510-fetch.sh +++ b/t/t5510-fetch.sh @@ -9,6 +9,11 @@ test_description='Per branch config variables affects "git fetch". D=`pwd` +test_bundle_object_count () { + git verify-pack -v "$1" >verify.out && + test "$2" = $(grep '^[0-9a-f]\{40\} ' verify.out | wc -l) +} + test_expect_success setup ' echo >file original && git add file && @@ -146,6 +151,7 @@ test_expect_success 'unbundle 1' ' test_must_fail git fetch "$D/bundle1" master:master ' + test_expect_success 'bundle 1 has only 3 files ' ' cd "$D" && ( @@ -156,8 +162,7 @@ test_expect_success 'bundle 1 has only 3 files ' ' cat ) <bundle1 >bundle.pack && git index-pack bundle.pack && - verify=$(git verify-pack -v bundle.pack) && - test 4 = $(echo "$verify" | wc -l) + test_bundle_object_count bundle.pack 3 ' test_expect_success 'unbundle 2' ' @@ -180,7 +185,7 @@ test_expect_success 'bundle does not prerequisite objects' ' cat ) <bundle3 >bundle.pack && git index-pack bundle.pack && - test 4 = $(git verify-pack -v bundle.pack | wc -l) + test_bundle_object_count bundle.pack 3 ' test_expect_success 'bundle should be able to create a full history' ' diff --git a/t/t5516-fetch-push.sh b/t/t5516-fetch-push.sh index 89649e7a9b..2d2633f3f8 100755 --- a/t/t5516-fetch-push.sh +++ b/t/t5516-fetch-push.sh @@ -419,6 +419,19 @@ test_expect_success 'push with config remote.*.push = HEAD' ' git config --remove-section remote.there git config --remove-section branch.master +test_expect_success 'push with config remote.*.pushurl' ' + + mk_test heads/master && + git checkout master && + git config remote.there.url test2repo && + git config remote.there.pushurl testrepo && + git push there && + check_push_result $the_commit heads/master +' + +# clean up the cruft left with the previous one +git config --remove-section remote.there + test_expect_success 'push with dry-run' ' mk_test heads/master && diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh index 725771fac1..e78d40242a 100755 --- a/t/t5520-pull.sh +++ b/t/t5520-pull.sh @@ -92,20 +92,47 @@ test_expect_success '--rebase with rebased upstream' ' git remote add -f me . && git checkout copy && + git tag copy-orig && git reset --hard HEAD^ && echo conflicting modification > file && git commit -m conflict file && git checkout to-rebase && echo file > file2 && git commit -m to-rebase file2 && + git tag to-rebase-orig && git pull --rebase me copy && test "conflicting modification" = "$(cat file)" && test file = $(cat file2) ' +test_expect_success '--rebase with rebased default upstream' ' + + git update-ref refs/remotes/me/copy copy-orig && + git checkout --track -b to-rebase2 me/copy && + git reset --hard to-rebase-orig && + git pull --rebase && + test "conflicting modification" = "$(cat file)" && + test file = $(cat file2) + +' + +test_expect_success 'rebased upstream + fetch + pull --rebase' ' + + git update-ref refs/remotes/me/copy copy-orig && + git reset --hard to-rebase-orig && + git checkout --track -b to-rebase3 me/copy && + git reset --hard to-rebase-orig && + git fetch && + git pull --rebase && + test "conflicting modification" = "$(cat file)" && + test file = "$(cat file2)" + +' + test_expect_success 'pull --rebase dies early with dirty working directory' ' + git checkout to-rebase && git update-ref refs/remotes/me/copy copy^ && COPY=$(git rev-parse --verify me/copy) && git rebase --onto $COPY copy && diff --git a/t/t5540-http-push.sh b/t/t5540-http-push.sh index 5fe479e1c2..f4a2cf6c17 100755 --- a/t/t5540-http-push.sh +++ b/t/t5540-http-push.sh @@ -67,6 +67,42 @@ test_expect_success ' push to remote repository with unpacked refs' ' test $HEAD = $(git rev-parse --verify HEAD)) ' +test_expect_success 'http-push fetches unpacked objects' ' + cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \ + "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo_unpacked.git && + + git clone $HTTPD_URL/test_repo_unpacked.git \ + "$ROOT_PATH"/fetch_unpacked && + + # By reset, we force git to retrieve the object + (cd "$ROOT_PATH"/fetch_unpacked && + git reset --hard HEAD^ && + git remote rm origin && + git reflog expire --expire=0 --all && + git prune && + git push -f -v $HTTPD_URL/test_repo_unpacked.git master) +' + +test_expect_success 'http-push fetches packed objects' ' + cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \ + "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo_packed.git && + + git clone $HTTPD_URL/test_repo_packed.git \ + "$ROOT_PATH"/test_repo_clone_packed && + + (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo_packed.git && + git --bare repack && + git --bare prune-packed) && + + # By reset, we force git to retrieve the packed object + (cd "$ROOT_PATH"/test_repo_clone_packed && + git reset --hard HEAD^ && + git remote rm origin && + git reflog expire --expire=0 --all && + git prune && + git push -f -v $HTTPD_URL/test_repo_packed.git master) +' + test_expect_success 'create and delete remote branch' ' cd "$ROOT_PATH"/test_repo_clone && git checkout -b dev && diff --git a/t/t5550-http-fetch.sh b/t/t5550-http-fetch.sh index 05b1b62cb6..0e69324652 100755 --- a/t/t5550-http-fetch.sh +++ b/t/t5550-http-fetch.sh @@ -53,5 +53,13 @@ test_expect_success 'http remote detects correct HEAD' ' ) ' +test_expect_success 'fetch packed objects' ' + cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/repo.git "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git && + cd "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git && + git --bare repack && + git --bare prune-packed && + git clone $HTTPD_URL/repo_pack.git +' + stop_httpd test_done diff --git a/t/t5601-clone.sh b/t/t5601-clone.sh index 2335d8bc85..214756731b 100755 --- a/t/t5601-clone.sh +++ b/t/t5601-clone.sh @@ -149,11 +149,13 @@ test_expect_success 'clone a void' ' ( cd src-0 && git init ) && - git clone src-0 target-6 && + git clone "file://$(pwd)/src-0" target-6 2>err-6 && + ! grep "fatal:" err-6 && ( cd src-0 && test_commit A ) && - git clone src-0 target-7 && + git clone "file://$(pwd)/src-0" target-7 2>err-7 && + ! grep "fatal:" err-7 && # There is no reason to insist they are bit-for-bit # identical, but this test should suffice for now. test_cmp target-6/.git/config target-7/.git/config diff --git a/t/t6024-recursive-merge.sh b/t/t6024-recursive-merge.sh index 129fa3000c..b3fbf659c0 100755 --- a/t/t6024-recursive-merge.sh +++ b/t/t6024-recursive-merge.sh @@ -65,18 +65,18 @@ test_expect_success "combined merge conflicts" " " cat > expect << EOF -<<<<<<< HEAD:a1 +<<<<<<< HEAD F ======= G ->>>>>>> G:a1 +>>>>>>> G EOF test_expect_success "result contains a conflict" "test_cmp expect a1" git ls-files --stage > out cat > expect << EOF -100644 da056ce14a2241509897fa68bb2b3b6e6194ef9e 1 a1 +100644 439cc46de773d8a83c77799b7cc9191c128bfcff 1 a1 100644 cf84443e49e1b366fac938711ddf4be2d4d1d9e9 2 a1 100644 fd7923529855d0b274795ae3349c5e0438333979 3 a1 EOF @@ -93,8 +93,7 @@ test_expect_success 'refuse to merge binary files' ' git add binary-file && git commit -m binary2 && test_must_fail git merge F > merge.out 2> merge.err && - grep "Cannot merge binary files: HEAD:binary-file vs. F:binary-file" \ - merge.err + grep "Cannot merge binary files: binary-file (HEAD vs. F)" merge.err ' test_expect_success 'mark rename/delete as unmerged' ' diff --git a/t/t6030-bisect-porcelain.sh b/t/t6030-bisect-porcelain.sh index 54b7ea6505..def397c53a 100755 --- a/t/t6030-bisect-porcelain.sh +++ b/t/t6030-bisect-porcelain.sh @@ -175,7 +175,7 @@ test_expect_success 'bisect skip: successfull result' ' git bisect start $HASH4 $HASH1 && git bisect skip && git bisect bad > my_bisect_log.txt && - grep "$HASH2 is first bad commit" my_bisect_log.txt && + grep "$HASH2 is the first bad commit" my_bisect_log.txt && git bisect reset ' @@ -261,7 +261,7 @@ test_expect_success \ git bisect good $HASH1 && git bisect bad $HASH4 && git bisect run ./test_script.sh > my_bisect_log.txt && - grep "$HASH3 is first bad commit" my_bisect_log.txt && + grep "$HASH3 is the first bad commit" my_bisect_log.txt && git bisect reset' # We want to automatically find the commit that @@ -274,7 +274,7 @@ test_expect_success \ chmod +x test_script.sh && git bisect start $HASH4 $HASH1 && git bisect run ./test_script.sh > my_bisect_log.txt && - grep "$HASH4 is first bad commit" my_bisect_log.txt && + grep "$HASH4 is the first bad commit" my_bisect_log.txt && git bisect reset' # $HASH1 is good, $HASH5 is bad, we skip $HASH3 @@ -287,14 +287,14 @@ test_expect_success 'bisect skip: add line and then a new test' ' git bisect start $HASH5 $HASH1 && git bisect skip && git bisect good > my_bisect_log.txt && - grep "$HASH5 is first bad commit" my_bisect_log.txt && + grep "$HASH5 is the first bad commit" my_bisect_log.txt && git bisect log > log_to_replay.txt && git bisect reset ' test_expect_success 'bisect skip and bisect replay' ' git bisect replay log_to_replay.txt > my_bisect_log.txt && - grep "$HASH5 is first bad commit" my_bisect_log.txt && + grep "$HASH5 is the first bad commit" my_bisect_log.txt && git bisect reset ' @@ -335,7 +335,7 @@ test_expect_success 'bisect run & skip: find first bad' ' chmod +x test_script.sh && git bisect start $HASH7 $HASH1 && git bisect run ./test_script.sh > my_bisect_log.txt && - grep "$HASH6 is first bad commit" my_bisect_log.txt + grep "$HASH6 is the first bad commit" my_bisect_log.txt ' test_expect_success 'bisect skip only one range' ' @@ -385,7 +385,7 @@ test_expect_success 'bisect does not create a "bisect" branch' ' rev_hash6=$(git rev-parse --verify HEAD) && test "$rev_hash6" = "$HASH6" && git bisect good > my_bisect_log.txt && - grep "$HASH7 is first bad commit" my_bisect_log.txt && + grep "$HASH7 is the first bad commit" my_bisect_log.txt && git bisect reset && rev_hash6=$(git rev-parse --verify bisect) && test "$rev_hash6" = "$HASH6" && @@ -482,28 +482,17 @@ test_expect_success 'good merge bases when good and bad are siblings' ' git bisect reset ' -check_trace() { - grep "$1" "$GIT_TRACE" | grep "\^$2" | grep "$3" >/dev/null -} - test_expect_success 'optimized merge base checks' ' - GIT_TRACE="$(pwd)/trace.log" && - export GIT_TRACE && git bisect start "$HASH7" "$SIDE_HASH7" > my_bisect_log.txt && grep "merge base must be tested" my_bisect_log.txt && grep "$HASH4" my_bisect_log.txt && - check_trace "rev-list" "$HASH7" "$SIDE_HASH7" && git bisect good > my_bisect_log2.txt && test -f ".git/BISECT_ANCESTORS_OK" && test "$HASH6" = $(git rev-parse --verify HEAD) && - : > "$GIT_TRACE" && git bisect bad > my_bisect_log3.txt && - test_must_fail check_trace "rev-list" "$HASH6" "$SIDE_HASH7" && git bisect good "$A_HASH" > my_bisect_log4.txt && grep "merge base must be tested" my_bisect_log4.txt && - test_must_fail test -f ".git/BISECT_ANCESTORS_OK" && - check_trace "rev-list" "$HASH6" "$A_HASH" && - unset GIT_TRACE + test_must_fail test -f ".git/BISECT_ANCESTORS_OK" ' # This creates another side branch called "parallel" with some files @@ -545,7 +534,7 @@ test_expect_success 'restricting bisection on one dir' ' para1=$(git rev-parse --verify HEAD) && test "$para1" = "$PARA_HASH1" && git bisect bad > my_bisect_log.txt && - grep "$PARA_HASH1 is first bad commit" my_bisect_log.txt + grep "$PARA_HASH1 is the first bad commit" my_bisect_log.txt ' test_expect_success 'restricting bisection on one dir and a file' ' @@ -563,7 +552,19 @@ test_expect_success 'restricting bisection on one dir and a file' ' para1=$(git rev-parse --verify HEAD) && test "$para1" = "$PARA_HASH1" && git bisect good > my_bisect_log.txt && - grep "$PARA_HASH4 is first bad commit" my_bisect_log.txt + grep "$PARA_HASH4 is the first bad commit" my_bisect_log.txt +' + +test_expect_success 'skipping away from skipped commit' ' + git bisect start $PARA_HASH7 $HASH1 && + para4=$(git rev-parse --verify HEAD) && + test "$para4" = "$PARA_HASH4" && + git bisect skip && + hash7=$(git rev-parse --verify HEAD) && + test "$hash7" = "$HASH7" && + git bisect skip && + para3=$(git rev-parse --verify HEAD) && + test "$para3" = "$PARA_HASH3" ' # diff --git a/t/t6035-merge-dir-to-symlink.sh b/t/t6035-merge-dir-to-symlink.sh new file mode 100755 index 0000000000..5b96fb0b37 --- /dev/null +++ b/t/t6035-merge-dir-to-symlink.sh @@ -0,0 +1,93 @@ +#!/bin/sh + +test_description='merging when a directory was replaced with a symlink' +. ./test-lib.sh + +if ! test_have_prereq SYMLINKS +then + say 'Symbolic links not supported, skipping tests.' + test_done +fi + +test_expect_success 'create a commit where dir a/b changed to symlink' ' + mkdir -p a/b/c a/b-2/c && + > a/b/c/d && + > a/b-2/c/d && + > a/x && + git add -A && + git commit -m base && + git tag start && + rm -rf a/b && + ln -s b-2 a/b && + git add -A && + git commit -m "dir to symlink" +' + +test_expect_success 'keep a/b-2/c/d across checkout' ' + git checkout HEAD^0 && + git reset --hard master && + git rm --cached a/b && + git commit -m "untracked symlink remains" && + git checkout start^0 && + test -f a/b-2/c/d +' + +test_expect_success 'checkout should not have deleted a/b-2/c/d' ' + git checkout HEAD^0 && + git reset --hard master && + git checkout start^0 && + test -f a/b-2/c/d +' + +test_expect_success 'setup for merge test' ' + git reset --hard && + test -f a/b-2/c/d && + echo x > a/x && + git add a/x && + git commit -m x && + git tag baseline +' + +test_expect_success 'do not lose a/b-2/c/d in merge (resolve)' ' + git reset --hard && + git checkout baseline^0 && + git merge -s resolve master && + test -h a/b && + test -f a/b-2/c/d +' + +test_expect_failure 'do not lose a/b-2/c/d in merge (recursive)' ' + git reset --hard && + git checkout baseline^0 && + git merge -s recursive master && + test -h a/b && + test -f a/b-2/c/d +' + +test_expect_success 'setup a merge where dir a/b-2 changed to symlink' ' + git reset --hard && + git checkout start^0 && + rm -rf a/b-2 && + ln -s b a/b-2 && + git add -A && + git commit -m "dir a/b-2 to symlink" && + git tag test2 +' + +test_expect_failure 'merge should not have conflicts (resolve)' ' + git reset --hard && + git checkout baseline^0 && + git merge -s resolve test2 && + test -h a/b-2 && + test -f a/b/c/d +' + +test_expect_failure 'merge should not have conflicts (recursive)' ' + git reset --hard && + git checkout baseline^0 && + git merge -s recursive test2 && + test -h a/b-2 && + test -f a/b/c/d +' + +test_done diff --git a/t/t6036-recursive-corner-cases.sh b/t/t6036-recursive-corner-cases.sh new file mode 100755 index 0000000000..b874141658 --- /dev/null +++ b/t/t6036-recursive-corner-cases.sh @@ -0,0 +1,55 @@ +#!/bin/sh + +test_description='recursive merge corner cases' + +. ./test-lib.sh + +# +# L1 L2 +# o---o +# / \ / \ +# o X ? +# \ / \ / +# o---o +# R1 R2 +# + +test_expect_success setup ' + ten="0 1 2 3 4 5 6 7 8 9" + for i in $ten + do + echo line $i in a sample file + done >one && + for i in $ten + do + echo line $i in another sample file + done >two && + git add one two && + test_tick && git commit -m initial && + + git branch L1 && + git checkout -b R1 && + git mv one three && + test_tick && git commit -m R1 && + + git checkout L1 && + git mv two three && + test_tick && git commit -m L1 && + + git checkout L1^0 && + test_tick && git merge -s ours R1 && + git tag L2 && + + git checkout R1^0 && + test_tick && git merge -s ours L1 && + git tag R2 +' + +test_expect_success merge ' + git reset --hard && + git checkout L2^0 && + + test_must_fail git merge -s recursive R2^0 +' + +test_done diff --git a/t/t6040-tracking-info.sh b/t/t6040-tracking-info.sh index 3d6db4d386..00e1de9627 100755 --- a/t/t6040-tracking-info.sh +++ b/t/t6040-tracking-info.sh @@ -74,5 +74,19 @@ test_expect_success 'status' ' grep "have 1 and 1 different" actual ' +test_expect_success 'status when tracking lightweight tags' ' + git checkout master && + git tag light && + git branch --track lighttrack light >actual && + grep "set up to track" actual && + git checkout lighttrack +' +test_expect_success 'status when tracking annotated tags' ' + git checkout master && + git tag -m heavy heavy && + git branch --track heavytrack heavy >actual && + grep "set up to track" actual && + git checkout heavytrack +' test_done diff --git a/t/t7002-grep.sh b/t/t7002-grep.sh index fe87834fbe..6ca11d7146 100755 --- a/t/t7002-grep.sh +++ b/t/t7002-grep.sh @@ -8,6 +8,15 @@ test_description='git grep various. . ./test-lib.sh +cat >hello.c <<EOF +#include <stdio.h> +int main(int argc, const char **argv) +{ + printf("Hello world.\n"); + return 0; +} +EOF + test_expect_success setup ' { echo foo mmap bar @@ -22,7 +31,7 @@ test_expect_success setup ' echo zzz > z && mkdir t && echo test >t/t && - git add file w x y z t/t && + git add file w x y z t/t hello.c && test_tick && git commit -m initial ' @@ -155,6 +164,28 @@ test_expect_success 'grep -e A --and --not -e B' ' test_cmp expected actual ' +cat >expected <<EOF +y:y yy +-- +z:zzz +EOF + +# Create 1024 file names that sort between "y" and "z" to make sure +# the two files are handled by different calls to an external grep. +# This depends on MAXARGS in builtin-grep.c being 1024 or less. +c32="0 1 2 3 4 5 6 7 8 9 a b c d e f g h i j k l m n o p q r s t u v" +test_expect_success 'grep -C1, hunk mark between files' ' + for a in $c32; do for b in $c32; do : >y-$a$b; done; done && + git add y-?? && + git grep -C1 "^[yz]" >actual && + test_cmp expected actual +' + +test_expect_success 'grep -C1 --no-ext-grep, hunk mark between files' ' + git grep -C1 --no-ext-grep "^[yz]" >actual && + test_cmp expected actual +' + test_expect_success 'log grep setup' ' echo a >>file && test_tick && @@ -207,11 +238,47 @@ test_expect_success 'log grep (6)' ' test_expect_success 'grep with CE_VALID file' ' git update-index --assume-unchanged t/t && rm t/t && - test "$(git grep --no-ext-grep t)" = "t/t:test" && + test "$(git grep --no-ext-grep test)" = "t/t:test" && git update-index --no-assume-unchanged t/t && git checkout t/t ' +cat >expected <<EOF +hello.c=#include <stdio.h> +hello.c: return 0; +EOF + +test_expect_success 'grep -p with userdiff' ' + git config diff.custom.funcname "^#" && + echo "hello.c diff=custom" >.gitattributes && + git grep -p return >actual && + test_cmp expected actual +' + +cat >expected <<EOF +hello.c=int main(int argc, const char **argv) +hello.c: return 0; +EOF + +test_expect_success 'grep -p' ' + rm -f .gitattributes && + git grep -p return >actual && + test_cmp expected actual +' + +cat >expected <<EOF +hello.c-#include <stdio.h> +hello.c=int main(int argc, const char **argv) +hello.c-{ +hello.c- printf("Hello world.\n"); +hello.c: return 0; +EOF + +test_expect_success 'grep -p -B5' ' + git grep -p -B5 return >actual && + test_cmp expected actual +' + test_expect_success 'grep from a subdirectory to search wider area (1)' ' mkdir -p s && ( diff --git a/t/t7300-clean.sh b/t/t7300-clean.sh index 929d5d4d3b..118c6ebb18 100755 --- a/t/t7300-clean.sh +++ b/t/t7300-clean.sh @@ -380,4 +380,43 @@ test_expect_success 'removal failure' ' ' chmod 755 foo +test_expect_success 'nested git work tree' ' + rm -fr foo bar && + mkdir foo bar && + ( + cd foo && + git init && + >hello.world + git add . && + git commit -a -m nested + ) && + ( + cd bar && + >goodbye.people + ) && + git clean -f -d && + test -f foo/.git/index && + test -f foo/hello.world && + ! test -d bar +' + +test_expect_success 'force removal of nested git work tree' ' + rm -fr foo bar && + mkdir foo bar && + ( + cd foo && + git init && + >hello.world + git add . && + git commit -a -m nested + ) && + ( + cd bar && + >goodbye.people + ) && + git clean -f -f -d && + ! test -d foo && + ! test -d bar +' + test_done diff --git a/t/t7406-submodule-reference.sh b/t/t7406-submodule-reference.sh new file mode 100755 index 0000000000..cc16d3f05d --- /dev/null +++ b/t/t7406-submodule-reference.sh @@ -0,0 +1,81 @@ +#!/bin/sh +# +# Copyright (c) 2009, Red Hat Inc, Author: Michael S. Tsirkin (mst@redhat.com) +# + +test_description='test clone --reference' +. ./test-lib.sh + +base_dir=`pwd` + +U=$base_dir/UPLOAD_LOG + +test_expect_success 'preparing first repository' \ +'test_create_repo A && cd A && +echo first > file1 && +git add file1 && +git commit -m A-initial' + +cd "$base_dir" + +test_expect_success 'preparing second repository' \ +'git clone A B && cd B && +echo second > file2 && +git add file2 && +git commit -m B-addition && +git repack -a -d && +git prune' + +cd "$base_dir" + +test_expect_success 'preparing supermodule' \ +'test_create_repo super && cd super && +echo file > file && +git add file && +git commit -m B-super-initial' + +cd "$base_dir" + +test_expect_success 'submodule add --reference' \ +'cd super && git submodule add --reference ../B "file://$base_dir/A" sub && +git commit -m B-super-added' + +cd "$base_dir" + +test_expect_success 'after add: existence of info/alternates' \ +'test `wc -l <super/sub/.git/objects/info/alternates` = 1' + +cd "$base_dir" + +test_expect_success 'that reference gets used with add' \ +'cd super/sub && +echo "0 objects, 0 kilobytes" > expected && +git count-objects > current && +diff expected current' + +cd "$base_dir" + +test_expect_success 'cloning supermodule' \ +'git clone super super-clone' + +cd "$base_dir" + +test_expect_success 'update with reference' \ +'cd super-clone && git submodule update --init --reference ../B' + +cd "$base_dir" + +test_expect_success 'after update: existence of info/alternates' \ +'test `wc -l <super-clone/sub/.git/objects/info/alternates` = 1' + +cd "$base_dir" + +test_expect_success 'that reference gets used with update' \ +'cd super-clone/sub && +echo "0 objects, 0 kilobytes" > expected && +git count-objects > current && +diff expected current' + +cd "$base_dir" + +test_done diff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh new file mode 100755 index 0000000000..2d33d9efec --- /dev/null +++ b/t/t7406-submodule-update.sh @@ -0,0 +1,198 @@ +#!/bin/sh +# +# Copyright (c) 2009 Red Hat, Inc. +# + +test_description='Test updating submodules + +This test verifies that "git submodule update" detaches the HEAD of the +submodule and "git submodule update --rebase/--merge" does not detach the HEAD. +' + +. ./test-lib.sh + + +compare_head() +{ + sha_master=`git-rev-list --max-count=1 master` + sha_head=`git-rev-list --max-count=1 HEAD` + + test "$sha_master" = "$sha_head" +} + + +test_expect_success 'setup a submodule tree' ' + echo file > file && + git add file && + test_tick && + git commit -m upstream + git clone . super && + git clone super submodule && + (cd super && + git submodule add ../submodule submodule && + test_tick && + git commit -m "submodule" && + git submodule init submodule + ) && + (cd submodule && + echo "line2" > file && + git add file && + git commit -m "Commit 2" + ) && + (cd super && + (cd submodule && + git pull --rebase origin + ) && + git add submodule && + git commit -m "submodule update" + ) +' + +test_expect_success 'submodule update detaching the HEAD ' ' + (cd super/submodule && + git reset --hard HEAD~1 + ) && + (cd super && + (cd submodule && + compare_head + ) && + git submodule update submodule && + cd submodule && + ! compare_head + ) +' + +test_expect_success 'submodule update --rebase staying on master' ' + (cd super/submodule && + git checkout master + ) && + (cd super && + (cd submodule && + compare_head + ) && + git submodule update --rebase submodule && + cd submodule && + compare_head + ) +' + +test_expect_success 'submodule update --merge staying on master' ' + (cd super/submodule && + git reset --hard HEAD~1 + ) && + (cd super && + (cd submodule && + compare_head + ) && + git submodule update --merge submodule && + cd submodule && + compare_head + ) +' + +test_expect_success 'submodule update - rebase in .git/config' ' + (cd super && + git config submodule.submodule.update rebase + ) && + (cd super/submodule && + git reset --hard HEAD~1 + ) && + (cd super && + (cd submodule && + compare_head + ) && + git submodule update submodule && + cd submodule && + compare_head + ) +' + +test_expect_success 'submodule update - checkout in .git/config but --rebase given' ' + (cd super && + git config submodule.submodule.update checkout + ) && + (cd super/submodule && + git reset --hard HEAD~1 + ) && + (cd super && + (cd submodule && + compare_head + ) && + git submodule update --rebase submodule && + cd submodule && + compare_head + ) +' + +test_expect_success 'submodule update - merge in .git/config' ' + (cd super && + git config submodule.submodule.update merge + ) && + (cd super/submodule && + git reset --hard HEAD~1 + ) && + (cd super && + (cd submodule && + compare_head + ) && + git submodule update submodule && + cd submodule && + compare_head + ) +' + +test_expect_success 'submodule update - checkout in .git/config but --merge given' ' + (cd super && + git config submodule.submodule.update checkout + ) && + (cd super/submodule && + git reset --hard HEAD~1 + ) && + (cd super && + (cd submodule && + compare_head + ) && + git submodule update --merge submodule && + cd submodule && + compare_head + ) +' + +test_expect_success 'submodule update - checkout in .git/config' ' + (cd super && + git config submodule.submodule.update checkout + ) && + (cd super/submodule && + git reset --hard HEAD^ + ) && + (cd super && + (cd submodule && + compare_head + ) && + git submodule update submodule && + cd submodule && + ! compare_head + ) +' + +test_expect_success 'submodule init picks up rebase' ' + (cd super && + git config submodule.rebasing.url git://non-existing/git && + git config submodule.rebasing.path does-not-matter && + git config submodule.rebasing.update rebase && + git submodule init rebasing && + test "rebase" = $(git config submodule.rebasing.update) + ) +' + +test_expect_success 'submodule init picks up merge' ' + (cd super && + git config submodule.merging.url git://non-existing/git && + git config submodule.merging.path does-not-matter && + git config submodule.merging.update merge && + git submodule init merging && + test "merge" = $(git config submodule.merging.update) + ) +' + +test_done diff --git a/t/t7608-merge-messages.sh b/t/t7608-merge-messages.sh new file mode 100755 index 0000000000..28d56797b1 --- /dev/null +++ b/t/t7608-merge-messages.sh @@ -0,0 +1,60 @@ +#!/bin/sh + +test_description='test auto-generated merge messages' +. ./test-lib.sh + +check_oneline() { + echo "$1" | sed "s/Q/'/g" >expect && + git log -1 --pretty=tformat:%s >actual && + test_cmp expect actual +} + +test_expect_success 'merge local branch' ' + test_commit master-1 && + git checkout -b local-branch && + test_commit branch-1 && + git checkout master && + test_commit master-2 && + git merge local-branch && + check_oneline "Merge branch Qlocal-branchQ" +' + +test_expect_success 'merge octopus branches' ' + git checkout -b octopus-a master && + test_commit octopus-1 && + git checkout -b octopus-b master && + test_commit octopus-2 && + git checkout master && + git merge octopus-a octopus-b && + check_oneline "Merge branches Qoctopus-aQ and Qoctopus-bQ" +' + +test_expect_success 'merge tag' ' + git checkout -b tag-branch master && + test_commit tag-1 && + git checkout master && + test_commit master-3 && + git merge tag-1 && + check_oneline "Merge commit Qtag-1Q" +' + +test_expect_success 'ambiguous tag' ' + git checkout -b ambiguous master && + test_commit ambiguous && + git checkout master && + test_commit master-4 && + git merge ambiguous && + check_oneline "Merge commit QambiguousQ" +' + +test_expect_success 'remote branch' ' + git checkout -b remote master && + test_commit remote-1 && + git update-ref refs/remotes/origin/master remote && + git checkout master && + test_commit master-5 && + git merge origin/master && + check_oneline "Merge remote branch Qorigin/masterQ" +' + +test_done diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh index 87c9b0e121..f4aa054750 100755 --- a/t/t7700-repack.sh +++ b/t/t7700-repack.sh @@ -149,5 +149,17 @@ test_expect_success 'local packed unreachable obs that exist in alternate ODB ar test_must_fail git show $csha1 ' +test_expect_success 'objects made unreachable by grafts only are kept' ' + test_tick && + git commit --allow-empty -m "commit 4" && + H0=$(git rev-parse HEAD) && + H1=$(git rev-parse HEAD^) && + H2=$(git rev-parse HEAD^^) && + echo "$H0 $H2" > .git/info/grafts && + git reflog expire --expire=now --expire-unreachable=now --all && + git repack -a -d && + git cat-file -t $H1 + ' + test_done diff --git a/t/t8005-blame-i18n.sh b/t/t8005-blame-i18n.sh index 9c1e21a60b..cb390559f9 100755 --- a/t/t8005-blame-i18n.sh +++ b/t/t8005-blame-i18n.sh @@ -20,7 +20,7 @@ test_expect_success 'setup the repository' ' echo "SJIS LINE" >> file && git add file && - git config i18n.commitencoding shift-jis && + git config i18n.commitencoding SJIS && git commit --author "$SJIS_NAME <sjis@localhost>" -m "$SJIS_MSG" ' @@ -67,8 +67,8 @@ summary $UTF8_MSG EOF test_expect_success \ - 'blame respects --encoding=utf-8' ' - git blame --incremental --encoding=utf-8 file | \ + 'blame respects --encoding=UTF-8' ' + git blame --incremental --encoding=UTF-8 file | \ egrep "^(author|summary) " > actual && test_cmp actual expected ' diff --git a/t/t8005/cp1251.txt b/t/t8005/cp1251.txt deleted file mode 100644 index ce41e98b81..0000000000 --- a/t/t8005/cp1251.txt +++ /dev/null @@ -1,2 +0,0 @@ -CP1251_NAME="Èâàí Ïåòðîâè÷ Ñèäîðîâ" -CP1251_MSG="Òåñòîâîå ñîîáùåíèå" diff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh index ce26ea4ac5..fb606a9f05 100755 --- a/t/t9001-send-email.sh +++ b/t/t9001-send-email.sh @@ -148,6 +148,25 @@ test_expect_success 'Prompting works' ' grep "^To: to@example.com$" msgtxt1 ' +test_expect_success 'cccmd works' ' + clean_fake_sendmail && + cp $patches cccmd.patch && + echo cccmd--cccmd@example.com >>cccmd.patch && + { + echo "#!$SHELL_PATH" + echo sed -n -e s/^cccmd--//p \"\$1\" + } > cccmd-sed && + chmod +x cccmd-sed && + git send-email \ + --from="Example <nobody@example.com>" \ + --to=nobody@example.com \ + --cc-cmd=./cccmd-sed \ + --smtp-server="$(pwd)/fake.sendmail" \ + cccmd.patch \ + && + grep ^Cc:.*cccmd@example.com msgtxt1 +' + z8=zzzzzzzz z64=$z8$z8$z8$z8$z8$z8$z8$z8 z512=$z64$z64$z64$z64$z64$z64$z64$z64 @@ -274,7 +293,7 @@ EOF test_suppression () { git send-email \ --dry-run \ - --suppress-cc=$1 \ + --suppress-cc=$1 ${2+"--suppress-cc=$2"} \ --from="Example <from@example.com>" \ --to=to@example.com \ --smtp-server relay.example.com \ @@ -282,8 +301,8 @@ test_suppression () { sed -e "s/^\(Date:\).*/\1 DATE-STRING/" \ -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \ -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \ - >actual-suppress-$1 && - test_cmp expected-suppress-$1 actual-suppress-$1 + >actual-suppress-$1${2+"-$2"} && + test_cmp expected-suppress-$1${2+"-$2"} actual-suppress-$1${2+"-$2"} } test_expect_success 'sendemail.cc set' ' @@ -316,6 +335,34 @@ test_expect_success 'sendemail.cc unset' ' test_suppression sob ' +cat >expected-suppress-cccmd <<\EOF +0001-Second.patch +(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>' +(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com' +(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com' +(body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>' +Dry-OK. Log says: +Server: relay.example.com +MAIL FROM:<from@example.com> +RCPT TO:<to@example.com>,<author@example.com>,<one@example.com>,<two@example.com>,<committer@example.com> +From: Example <from@example.com> +To: to@example.com +Cc: A <author@example.com>, One <one@example.com>, two@example.com, C O Mitter <committer@example.com> +Subject: [PATCH 1/1] Second. +Date: DATE-STRING +Message-Id: MESSAGE-ID-STRING +X-Mailer: X-MAILER-STRING + +Result: OK +EOF + +test_expect_success 'sendemail.cccmd' ' + echo echo cc-cmd@example.com > cccmd && + chmod +x cccmd && + git config sendemail.cccmd ./cccmd && + test_suppression cccmd +' + cat >expected-suppress-all <<\EOF 0001-Second.patch Dry-OK. Log says: @@ -341,13 +388,14 @@ cat >expected-suppress-body <<\EOF (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>' (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com' (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com' +(cc-cmd) Adding cc: cc-cmd@example.com from: './cccmd' Dry-OK. Log says: Server: relay.example.com MAIL FROM:<from@example.com> -RCPT TO:<to@example.com>,<author@example.com>,<one@example.com>,<two@example.com> +RCPT TO:<to@example.com>,<author@example.com>,<one@example.com>,<two@example.com>,<cc-cmd@example.com> From: Example <from@example.com> To: to@example.com -Cc: A <author@example.com>, One <one@example.com>, two@example.com +Cc: A <author@example.com>, One <one@example.com>, two@example.com, cc-cmd@example.com Subject: [PATCH 1/1] Second. Date: DATE-STRING Message-Id: MESSAGE-ID-STRING @@ -360,6 +408,30 @@ test_expect_success '--suppress-cc=body' ' test_suppression body ' +cat >expected-suppress-body-cccmd <<\EOF +0001-Second.patch +(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>' +(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com' +(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com' +Dry-OK. Log says: +Server: relay.example.com +MAIL FROM:<from@example.com> +RCPT TO:<to@example.com>,<author@example.com>,<one@example.com>,<two@example.com> +From: Example <from@example.com> +To: to@example.com +Cc: A <author@example.com>, One <one@example.com>, two@example.com +Subject: [PATCH 1/1] Second. +Date: DATE-STRING +Message-Id: MESSAGE-ID-STRING +X-Mailer: X-MAILER-STRING + +Result: OK +EOF + +test_expect_success '--suppress-cc=body --suppress-cc=cccmd' ' + test_suppression body cccmd +' + cat >expected-suppress-sob <<\EOF 0001-Second.patch (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>' @@ -381,6 +453,7 @@ Result: OK EOF test_expect_success '--suppress-cc=sob' ' + git config --unset sendemail.cccmd test_suppression sob ' @@ -533,7 +606,7 @@ test_expect_success 'utf8 Cc is rfc2047 encoded' ' --smtp-server="$(pwd)/fake.sendmail" \ outdir/*.patch && grep "^Cc:" msgtxt1 | - grep "=?utf-8?q?=C3=A0=C3=A9=C3=AC=C3=B6=C3=BA?= <utf8@example.com>" + grep "=?UTF-8?q?=C3=A0=C3=A9=C3=AC=C3=B6=C3=BA?= <utf8@example.com>" ' test_expect_success '--compose adds MIME for utf8 body' ' @@ -550,7 +623,7 @@ test_expect_success '--compose adds MIME for utf8 body' ' --smtp-server="$(pwd)/fake.sendmail" \ $patches && grep "^utf8 body" msgtxt1 && - grep "^Content-Type: text/plain; charset=utf-8" msgtxt1 + grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1 ' test_expect_success '--compose respects user mime type' ' @@ -573,7 +646,7 @@ test_expect_success '--compose respects user mime type' ' $patches && grep "^utf8 body" msgtxt1 && grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1 && - ! grep "^Content-Type: text/plain; charset=utf-8" msgtxt1 + ! grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1 ' test_expect_success '--compose adds MIME for utf8 subject' ' @@ -586,7 +659,7 @@ test_expect_success '--compose adds MIME for utf8 subject' ' --smtp-server="$(pwd)/fake.sendmail" \ $patches && grep "^fake edit" msgtxt1 && - grep "^Subject: =?utf-8?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1 + grep "^Subject: =?UTF-8?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1 ' test_expect_success 'detects ambiguous reference/file conflict' ' @@ -621,4 +694,25 @@ test_expect_success 'in-reply-to but no threading' ' grep "In-Reply-To: <in-reply-id@example.com>" ' +test_expect_success 'no in-reply-to and no threading' ' + git send-email \ + --dry-run \ + --from="Example <nobody@example.com>" \ + --to=nobody@example.com \ + --nothread \ + $patches $patches >stdout && + ! grep "In-Reply-To: " stdout +' + +test_expect_success 'threading but no chain-reply-to' ' + git send-email \ + --dry-run \ + --from="Example <nobody@example.com>" \ + --to=nobody@example.com \ + --thread \ + --nochain-reply-to \ + $patches $patches >stdout && + grep "In-Reply-To: " stdout +' + test_done diff --git a/t/t9100-git-svn-basic.sh b/t/t9100-git-svn-basic.sh index 4eee2e9fa6..570e0359e4 100755 --- a/t/t9100-git-svn-basic.sh +++ b/t/t9100-git-svn-basic.sh @@ -31,7 +31,7 @@ test_expect_success \ echo "zzz" > bar/zzz && echo "#!/bin/sh" > exec.sh && chmod +x exec.sh && - svn import -m "import for git svn" . "$svnrepo" >/dev/null && + svn_cmd import -m "import for git svn" . "$svnrepo" >/dev/null && cd .. && rm -rf import && git svn init "$svnrepo"' @@ -51,7 +51,7 @@ test_expect_success "$name" ' git commit -m "$name" && git svn set-tree --find-copies-harder --rmdir \ ${remotes_git_svn}..mybranch && - svn up "$SVN_TREE" && + svn_cmd up "$SVN_TREE" && test -d "$SVN_TREE"/dir && test ! -d "$SVN_TREE"/dir/a' @@ -118,7 +118,7 @@ test_expect_success "$name" ' git commit -m "$name" && git svn set-tree --find-copies-harder --rmdir \ ${remotes_git_svn}..mybranch5 && - svn up "$SVN_TREE" && + svn_cmd up "$SVN_TREE" && test ! -x "$SVN_TREE"/exec.sh' @@ -129,7 +129,7 @@ test_expect_success "$name" ' git commit -m "$name" && git svn set-tree --find-copies-harder --rmdir \ ${remotes_git_svn}..mybranch5 && - svn up "$SVN_TREE" && + svn_cmd up "$SVN_TREE" && test -x "$SVN_TREE"/exec.sh' @@ -141,7 +141,7 @@ test_expect_success "$name" ' git commit -m "$name" && git svn set-tree --find-copies-harder --rmdir \ ${remotes_git_svn}..mybranch5 && - svn up "$SVN_TREE" && + svn_cmd up "$SVN_TREE" && test -L "$SVN_TREE"/exec.sh' name='new symlink is added to a file that was also just made executable' @@ -153,7 +153,7 @@ test_expect_success "$name" ' git commit -m "$name" && git svn set-tree --find-copies-harder --rmdir \ ${remotes_git_svn}..mybranch5 && - svn up "$SVN_TREE" && + svn_cmd up "$SVN_TREE" && test -x "$SVN_TREE"/bar/zzz && test -L "$SVN_TREE"/exec-2.sh' @@ -166,7 +166,7 @@ test_expect_success "$name" ' git commit -m "$name" && git svn set-tree --find-copies-harder --rmdir \ ${remotes_git_svn}..mybranch5 && - svn up "$SVN_TREE" && + svn_cmd up "$SVN_TREE" && test -f "$SVN_TREE"/exec-2.sh && test ! -L "$SVN_TREE"/exec-2.sh && test_cmp help "$SVN_TREE"/exec-2.sh' @@ -231,6 +231,25 @@ test_expect_success \ "^:refs/${remotes_git_svn}$" ' +test_expect_success 'dcommit $rev does not clobber current branch' ' + git svn fetch -i bar && + git checkout -b my-bar refs/remotes/bar && + echo 1 > foo && + git add foo && + git commit -m "change 1" && + echo 2 > foo && + git add foo && + git commit -m "change 2" && + old_head=$(git rev-parse HEAD) && + git svn dcommit -i bar HEAD^ && + test $old_head = $(git rev-parse HEAD) && + test refs/heads/my-bar = $(git symbolic-ref HEAD) && + git log refs/remotes/bar | grep "change 1" && + ! git log refs/remotes/bar | grep "change 2" && + git checkout master && + git branch -D my-bar + ' + test_expect_success 'able to dcommit to a subdirectory' " git svn fetch -i bar && git checkout -b my-bar refs/remotes/bar && diff --git a/t/t9101-git-svn-props.sh b/t/t9101-git-svn-props.sh index 1e31d6ea72..9da4178c94 100755 --- a/t/t9101-git-svn-props.sh +++ b/t/t9101-git-svn-props.sh @@ -48,7 +48,7 @@ EOF printf "\r\n" > empty_crlf a_empty_crlf=`git hash-object -w empty_crlf` - svn import --no-auto-props -m 'import for git svn' . "$svnrepo" >/dev/null + svn_cmd import --no-auto-props -m 'import for git svn' . "$svnrepo" >/dev/null cd .. rm -rf import @@ -57,13 +57,13 @@ test_expect_success 'setup some commits to svn' \ 'cd test_wc && echo Greetings >> kw.c && poke kw.c && - svn commit -m "Not yet an Id" && + svn_cmd commit -m "Not yet an Id" && echo Hello world >> kw.c && poke kw.c && - svn commit -m "Modified file, but still not yet an Id" && - svn propset svn:keywords Id kw.c && + svn_cmd commit -m "Modified file, but still not yet an Id" && + svn_cmd propset svn:keywords Id kw.c && poke kw.c && - svn commit -m "Propset Id" && + svn_cmd commit -m "Propset Id" && cd ..' test_expect_success 'initialize git svn' 'git svn init "$svnrepo"' @@ -83,16 +83,16 @@ test_expect_success 'raw $Id$ found in kw.c' "test '$expect' = '$got'" test_expect_success "propset CR on crlf files" \ 'cd test_wc && - svn propset svn:eol-style CR empty && - svn propset svn:eol-style CR crlf && - svn propset svn:eol-style CR ne_crlf && - svn commit -m "propset CR on crlf files" && + svn_cmd propset svn:eol-style CR empty && + svn_cmd propset svn:eol-style CR crlf && + svn_cmd propset svn:eol-style CR ne_crlf && + svn_cmd commit -m "propset CR on crlf files" && cd ..' test_expect_success 'fetch and pull latest from svn and checkout a new wc' \ 'git svn fetch && git pull . ${remotes_git_svn} && - svn co "$svnrepo" new_wc' + svn_cmd co "$svnrepo" new_wc' for i in crlf ne_crlf lf ne_lf cr ne_cr empty_cr empty_lf empty empty_crlf do @@ -106,11 +106,11 @@ cd test_wc a_cr=`printf '$Id$\r\nHello\r\nWorld\r\n' | git hash-object --stdin` a_ne_cr=`printf '$Id$\r\nHello\r\nWorld' | git hash-object --stdin` test_expect_success 'Set CRLF on cr files' \ - 'svn propset svn:eol-style CRLF cr && - svn propset svn:eol-style CRLF ne_cr && - svn propset svn:keywords Id cr && - svn propset svn:keywords Id ne_cr && - svn commit -m "propset CRLF on cr files"' + 'svn_cmd propset svn:eol-style CRLF cr && + svn_cmd propset svn:eol-style CRLF ne_cr && + svn_cmd propset svn:keywords Id cr && + svn_cmd propset svn:keywords Id ne_cr && + svn_cmd commit -m "propset CRLF on cr files"' cd .. test_expect_success 'fetch and pull latest from svn' \ 'git svn fetch && git pull . ${remotes_git_svn}' @@ -140,10 +140,10 @@ test_expect_success 'test show-ignore' " cd test_wc && mkdir -p deeply/nested/directory && touch deeply/nested/directory/.keep && - svn add deeply && - svn up && - svn propset -R svn:ignore 'no-such-file*' . - svn commit -m 'propset svn:ignore' + svn_cmd add deeply && + svn_cmd up && + svn_cmd propset -R svn:ignore 'no-such-file*' . + svn_cmd commit -m 'propset svn:ignore' cd .. && git svn show-ignore > show-ignore.got && cmp show-ignore.expect show-ignore.got diff --git a/t/t9102-git-svn-deep-rmdir.sh b/t/t9102-git-svn-deep-rmdir.sh index e223218015..028fb19e09 100755 --- a/t/t9102-git-svn-deep-rmdir.sh +++ b/t/t9102-git-svn-deep-rmdir.sh @@ -9,7 +9,7 @@ test_expect_success 'initialize repo' ' mkdir -p deeply/nested/directory/number/2 && echo foo > deeply/nested/directory/number/1/file && echo foo > deeply/nested/directory/number/2/another && - svn import -m "import for git svn" . "$svnrepo" && + svn_cmd import -m "import for git svn" . "$svnrepo" && cd .. ' @@ -23,7 +23,7 @@ test_expect_success 'Try a commit on rmdir' ' git rm -f deeply/nested/directory/number/2/another && git commit -a -m "remove another" && git svn set-tree --rmdir HEAD && - svn ls -R "$svnrepo" | grep ^deeply/nested/directory/number/1 + svn_cmd ls -R "$svnrepo" | grep ^deeply/nested/directory/number/1 ' diff --git a/t/t9103-git-svn-tracked-directory-removed.sh b/t/t9103-git-svn-tracked-directory-removed.sh index 963dd95e4a..3413164cb1 100755 --- a/t/t9103-git-svn-tracked-directory-removed.sh +++ b/t/t9103-git-svn-tracked-directory-removed.sh @@ -10,15 +10,15 @@ test_expect_success 'make history for tracking' ' mkdir import && mkdir import/trunk && echo hello >> import/trunk/README && - svn import -m initial import "$svnrepo" && + svn_cmd import -m initial import "$svnrepo" && rm -rf import && - svn co "$svnrepo"/trunk trunk && + svn_cmd co "$svnrepo"/trunk trunk && echo bye bye >> trunk/README && - svn rm -m "gone" "$svnrepo"/trunk && + svn_cmd rm -m "gone" "$svnrepo"/trunk && rm -rf trunk && mkdir trunk && echo "new" > trunk/FOLLOWME && - svn import -m "new trunk" trunk "$svnrepo"/trunk + svn_cmd import -m "new trunk" trunk "$svnrepo"/trunk ' test_expect_success 'clone repo with git' ' diff --git a/t/t9104-git-svn-follow-parent.sh b/t/t9104-git-svn-follow-parent.sh index ab9fa32220..78610b61e6 100755 --- a/t/t9104-git-svn-follow-parent.sh +++ b/t/t9104-git-svn-follow-parent.sh @@ -11,18 +11,18 @@ test_expect_success 'initialize repo' ' cd import && mkdir -p trunk && echo hello > trunk/readme && - svn import -m "initial" . "$svnrepo" && + svn_cmd import -m "initial" . "$svnrepo" && cd .. && - svn co "$svnrepo" wc && + svn_cmd co "$svnrepo" wc && cd wc && echo world >> trunk/readme && poke trunk/readme && - svn commit -m "another commit" && - svn up && - svn mv trunk thunk && + svn_cmd commit -m "another commit" && + svn_cmd up && + svn_cmd mv trunk thunk && echo goodbye >> thunk/readme && poke thunk/readme && - svn commit -m "bye now" && + svn_cmd commit -m "bye now" && cd .. ' @@ -51,7 +51,7 @@ test_expect_success 'init and fetch from one svn-remote' ' ' test_expect_success 'follow deleted parent' ' - (svn cp -m "resurrecting trunk as junk" \ + (svn_cmd cp -m "resurrecting trunk as junk" \ "$svnrepo"/trunk@2 "$svnrepo"/junk || svn cp -m "resurrecting trunk as junk" \ -r2 "$svnrepo"/trunk "$svnrepo"/junk) && @@ -97,8 +97,8 @@ test_expect_success 'follow higher-level parent' ' ' test_expect_success 'follow deleted directory' ' - svn mv -m "bye!" "$svnrepo"/glob/blob/hi "$svnrepo"/glob/blob/bye && - svn rm -m "remove glob" "$svnrepo"/glob && + svn_cmd mv -m "bye!" "$svnrepo"/glob/blob/hi "$svnrepo"/glob/blob/bye && + svn_cmd rm -m "remove glob" "$svnrepo"/glob && git svn init --minimize-url -i glob "$svnrepo"/glob && git svn fetch -i glob && test "`git cat-file blob refs/remotes/glob:blob/bye`" = hi && @@ -120,7 +120,7 @@ test_expect_success 'follow-parent avoids deleting relevant info' ' cd import && svn import -m "r9270 test" . "$svnrepo"/r9270 && cd .. && - svn co "$svnrepo"/r9270/trunk/subversion/bindings/swig/perl r9270 && + svn_cmd co "$svnrepo"/r9270/trunk/subversion/bindings/swig/perl r9270 && cd r9270 && svn mkdir native && svn mv t native/t && @@ -138,7 +138,7 @@ test_expect_success 'follow-parent avoids deleting relevant info' ' ' test_expect_success "track initial change if it was only made to parent" ' - svn cp -m "wheee!" "$svnrepo"/r9270/trunk "$svnrepo"/r9270/drunk && + svn_cmd cp -m "wheee!" "$svnrepo"/r9270/trunk "$svnrepo"/r9270/drunk && git svn init --minimize-url -i r9270-d \ "$svnrepo"/r9270/drunk/subversion/bindings/swig/perl/native/t && git svn fetch -i r9270-d && @@ -152,20 +152,20 @@ test_expect_success "track initial change if it was only made to parent" ' test_expect_success "follow-parent is atomic" ' ( cd wc && - svn up && - svn mkdir stunk && + svn_cmd up && + svn_cmd mkdir stunk && echo "trunk stunk" > stunk/readme && - svn add stunk/readme && - svn ci -m "trunk stunk" && + svn_cmd add stunk/readme && + svn_cmd ci -m "trunk stunk" && echo "stunk like junk" >> stunk/readme && - svn ci -m "really stunk" && + svn_cmd ci -m "really stunk" && echo "stink stank stunk" >> stunk/readme && - svn ci -m "even the grinch agrees" + svn_cmd ci -m "even the grinch agrees" ) && - svn copy -m "stunk flunked" "$svnrepo"/stunk "$svnrepo"/flunk && + svn_cmd copy -m "stunk flunked" "$svnrepo"/stunk "$svnrepo"/flunk && { svn cp -m "early stunk flunked too" \ "$svnrepo"/stunk@17 "$svnrepo"/flunked || - svn cp -m "early stunk flunked too" \ + svn_cmd cp -m "early stunk flunked too" \ -r17 "$svnrepo"/stunk "$svnrepo"/flunked; } && git svn init --minimize-url -i stunk "$svnrepo"/stunk && git svn fetch -i stunk && @@ -192,7 +192,7 @@ test_expect_success "follow-parent is atomic" ' ' test_expect_success "track multi-parent paths" ' - svn cp -m "resurrect /glob" "$svnrepo"/r9270 "$svnrepo"/glob && + svn_cmd cp -m "resurrect /glob" "$svnrepo"/r9270 "$svnrepo"/glob && git svn multi-fetch && test `git cat-file commit refs/remotes/glob | \ grep "^parent " | wc -l` -eq 2 diff --git a/t/t9105-git-svn-commit-diff.sh b/t/t9105-git-svn-commit-diff.sh index ba99abb6d9..dd48e9cba8 100755 --- a/t/t9105-git-svn-commit-diff.sh +++ b/t/t9105-git-svn-commit-diff.sh @@ -8,7 +8,7 @@ test_expect_success 'initialize repo' ' mkdir import && cd import && echo hello > readme && - svn import -m "initial" . "$svnrepo" && + svn_cmd import -m "initial" . "$svnrepo" && cd .. && echo hello > readme && git update-index --add readme && @@ -27,16 +27,16 @@ prev=`git rev-parse --verify HEAD^1` test_expect_success 'test the commit-diff command' ' test -n "$prev" && test -n "$head" && git svn commit-diff -r1 "$prev" "$head" "$svnrepo" && - svn co "$svnrepo" wc && + svn_cmd co "$svnrepo" wc && cmp readme wc/readme ' test_expect_success 'commit-diff to a sub-directory (with git svn config)' ' - svn import -m "sub-directory" import "$svnrepo"/subdir && + svn_cmd import -m "sub-directory" import "$svnrepo"/subdir && git svn init --minimize-url "$svnrepo"/subdir && git svn fetch && git svn commit-diff -r3 "$prev" "$head" && - svn cat "$svnrepo"/subdir/readme > readme.2 && + svn_cmd cat "$svnrepo"/subdir/readme > readme.2 && cmp readme readme.2 ' diff --git a/t/t9106-git-svn-commit-diff-clobber.sh b/t/t9106-git-svn-commit-diff-clobber.sh index 6eb0fd85c8..12f21b700e 100755 --- a/t/t9106-git-svn-commit-diff-clobber.sh +++ b/t/t9106-git-svn-commit-diff-clobber.sh @@ -8,18 +8,18 @@ test_expect_success 'initialize repo' ' mkdir import && cd import && echo initial > file && - svn import -m "initial" . "$svnrepo" && + svn_cmd import -m "initial" . "$svnrepo" && cd .. && echo initial > file && git update-index --add file && git commit -a -m "initial" ' test_expect_success 'commit change from svn side' ' - svn co "$svnrepo" t.svn && + svn_cmd co "$svnrepo" t.svn && cd t.svn && echo second line from svn >> file && poke file && - svn commit -m "second line from svn" && + svn_cmd commit -m "second line from svn" && cd .. && rm -rf t.svn ' @@ -43,11 +43,11 @@ test_expect_success 'dcommit fails to commit because of conflict' ' git svn init "$svnrepo" && git svn fetch && git reset --hard refs/${remotes_git_svn} && - svn co "$svnrepo" t.svn && + svn_cmd co "$svnrepo" t.svn && cd t.svn && echo fourth line from svn >> file && poke file && - svn commit -m "fourth line from svn" && + svn_cmd commit -m "fourth line from svn" && cd .. && rm -rf t.svn && echo "fourth line from git" >> file && @@ -67,11 +67,11 @@ test_expect_success 'dcommit does the svn equivalent of an index merge' " " test_expect_success 'commit another change from svn side' ' - svn co "$svnrepo" t.svn && + svn_cmd co "$svnrepo" t.svn && cd t.svn && echo third line from svn >> file && poke file && - svn commit -m "third line from svn" && + svn_cmd commit -m "third line from svn" && cd .. && rm -rf t.svn ' diff --git a/t/t9107-git-svn-migrate.sh b/t/t9107-git-svn-migrate.sh index acad16a6f0..3a9e07768d 100755 --- a/t/t9107-git-svn-migrate.sh +++ b/t/t9107-git-svn-migrate.sh @@ -12,7 +12,7 @@ test_expect_success 'setup old-looking metadata' ' mkdir -p $i && \ echo hello >> $i/README || exit 1 done && \ - svn import -m test . "$svnrepo" + svn_cmd import -m test . "$svnrepo" cd .. && git svn init "$svnrepo" && git svn fetch && diff --git a/t/t9108-git-svn-glob.sh b/t/t9108-git-svn-glob.sh index d8582b1aa5..d732d31302 100755 --- a/t/t9108-git-svn-glob.sh +++ b/t/t9108-git-svn-glob.sh @@ -14,30 +14,30 @@ test_expect_success 'test refspec globbing' ' mkdir -p trunk/src/a trunk/src/b trunk/doc && echo "hello world" > trunk/src/a/readme && echo "goodbye world" > trunk/src/b/readme && - svn import -m "initial" trunk "$svnrepo"/trunk && - svn co "$svnrepo" tmp && + svn_cmd import -m "initial" trunk "$svnrepo"/trunk && + svn_cmd co "$svnrepo" tmp && ( cd tmp && mkdir branches tags && - svn add branches tags && - svn cp trunk branches/start && - svn commit -m "start a new branch" && - svn up && + svn_cmd add branches tags && + svn_cmd cp trunk branches/start && + svn_cmd commit -m "start a new branch" && + svn_cmd up && echo "hi" >> branches/start/src/b/readme && poke branches/start/src/b/readme && echo "hey" >> branches/start/src/a/readme && poke branches/start/src/a/readme && - svn commit -m "hi" && - svn up && - svn cp branches/start tags/end && + svn_cmd commit -m "hi" && + svn_cmd up && + svn_cmd cp branches/start tags/end && echo "bye" >> tags/end/src/b/readme && poke tags/end/src/b/readme && echo "aye" >> tags/end/src/a/readme && poke tags/end/src/a/readme && - svn commit -m "the end" && + svn_cmd commit -m "the end" && echo "byebye" >> tags/end/src/b/readme && poke tags/end/src/b/readme && - svn commit -m "nothing to see here" + svn_cmd commit -m "nothing to see here" ) && git config --add svn-remote.svn.url "$svnrepo" && git config --add svn-remote.svn.fetch \ @@ -72,7 +72,7 @@ test_expect_success 'test left-hand-side only globbing' ' cd tmp && echo "try try" >> tags/end/src/b/readme && poke tags/end/src/b/readme && - svn commit -m "try to try" + svn_cmd commit -m "try to try" ) && git svn fetch two && test `git rev-list refs/remotes/two/tags/end | wc -l` -eq 6 && @@ -102,7 +102,7 @@ test_expect_success 'test disallow multi-globs' ' cd tmp && echo "try try" >> tags/end/src/b/readme && poke tags/end/src/b/readme && - svn commit -m "try to try" + svn_cmd commit -m "try to try" ) && test_must_fail git svn fetch three 2> stderr.three && test_cmp expect.three stderr.three diff --git a/t/t9109-git-svn-multi-glob.sh b/t/t9109-git-svn-multi-glob.sh index 8f79c3f251..c318f9f946 100755 --- a/t/t9109-git-svn-multi-glob.sh +++ b/t/t9109-git-svn-multi-glob.sh @@ -14,30 +14,30 @@ test_expect_success 'test refspec globbing' ' mkdir -p trunk/src/a trunk/src/b trunk/doc && echo "hello world" > trunk/src/a/readme && echo "goodbye world" > trunk/src/b/readme && - svn import -m "initial" trunk "$svnrepo"/trunk && - svn co "$svnrepo" tmp && + svn_cmd import -m "initial" trunk "$svnrepo"/trunk && + svn_cmd co "$svnrepo" tmp && ( cd tmp && mkdir branches branches/v1 tags && - svn add branches tags && - svn cp trunk branches/v1/start && - svn commit -m "start a new branch" && - svn up && + svn_cmd add branches tags && + svn_cmd cp trunk branches/v1/start && + svn_cmd commit -m "start a new branch" && + svn_cmd up && echo "hi" >> branches/v1/start/src/b/readme && poke branches/v1/start/src/b/readme && echo "hey" >> branches/v1/start/src/a/readme && poke branches/v1/start/src/a/readme && - svn commit -m "hi" && - svn up && - svn cp branches/v1/start tags/end && + svn_cmd commit -m "hi" && + svn_cmd up && + svn_cmd cp branches/v1/start tags/end && echo "bye" >> tags/end/src/b/readme && poke tags/end/src/b/readme && echo "aye" >> tags/end/src/a/readme && poke tags/end/src/a/readme && - svn commit -m "the end" && + svn_cmd commit -m "the end" && echo "byebye" >> tags/end/src/b/readme && poke tags/end/src/b/readme && - svn commit -m "nothing to see here" + svn_cmd commit -m "nothing to see here" ) && git config --add svn-remote.svn.url "$svnrepo" && git config --add svn-remote.svn.fetch \ @@ -72,7 +72,7 @@ test_expect_success 'test left-hand-side only globbing' ' cd tmp && echo "try try" >> tags/end/src/b/readme && poke tags/end/src/b/readme && - svn commit -m "try to try" + svn_cmd commit -m "try to try" ) && git svn fetch two && test `git rev-list refs/remotes/two/tags/end | wc -l` -eq 6 && @@ -97,25 +97,25 @@ test_expect_success 'test another branch' ' ( cd tmp && mkdir branches/v2 && - svn add branches/v2 && - svn cp trunk branches/v2/start && - svn commit -m "Another versioned branch" && - svn up && + svn_cmd add branches/v2 && + svn_cmd cp trunk branches/v2/start && + svn_cmd commit -m "Another versioned branch" && + svn_cmd up && echo "hello" >> branches/v2/start/src/b/readme && poke branches/v2/start/src/b/readme && echo "howdy" >> branches/v2/start/src/a/readme && poke branches/v2/start/src/a/readme && - svn commit -m "Changed 2 in v2/start" && - svn up && - svn cp branches/v2/start tags/next && + svn_cmd commit -m "Changed 2 in v2/start" && + svn_cmd up && + svn_cmd cp branches/v2/start tags/next && echo "bye" >> tags/next/src/b/readme && poke tags/next/src/b/readme && echo "aye" >> tags/next/src/a/readme && poke tags/next/src/a/readme && - svn commit -m "adding more" && + svn_cmd commit -m "adding more" && echo "byebye" >> tags/next/src/b/readme && poke tags/next/src/b/readme && - svn commit -m "adios" + svn_cmd commit -m "adios" ) && git config --add svn-remote.four.url "$svnrepo" && git config --add svn-remote.four.fetch trunk:refs/remotes/four/trunk && @@ -151,7 +151,7 @@ test_expect_success 'test disallow multiple globs' ' cd tmp && echo "try try" >> tags/end/src/b/readme && poke tags/end/src/b/readme && - svn commit -m "try to try" + svn_cmd commit -m "try to try" ) && test_must_fail git svn fetch three 2> stderr.three && test_cmp expect.three stderr.three diff --git a/t/t9113-git-svn-dcommit-new-file.sh b/t/t9113-git-svn-dcommit-new-file.sh index e9b6128b3f..e8479cec7a 100755 --- a/t/t9113-git-svn-dcommit-new-file.sh +++ b/t/t9113-git-svn-dcommit-new-file.sh @@ -15,7 +15,7 @@ test_description='git svn dcommit new files over svn:// test' require_svnserve test_expect_success 'start tracking an empty repo' ' - svn mkdir -m "empty dir" "$svnrepo"/empty-dir && + svn_cmd mkdir -m "empty dir" "$svnrepo"/empty-dir && echo "[general]" > "$rawsvnrepo"/conf/svnserve.conf && echo anon-access = write >> "$rawsvnrepo"/conf/svnserve.conf && start_svnserve && diff --git a/t/t9114-git-svn-dcommit-merge.sh b/t/t9114-git-svn-dcommit-merge.sh index 17b2855c4f..84f7c9b4bb 100755 --- a/t/t9114-git-svn-dcommit-merge.sh +++ b/t/t9114-git-svn-dcommit-merge.sh @@ -35,12 +35,12 @@ EOF } test_expect_success 'setup svn repository' ' - svn co "$svnrepo" mysvnwork && + svn_cmd co "$svnrepo" mysvnwork && mkdir -p mysvnwork/trunk && cd mysvnwork && big_text_block >> trunk/README && - svn add trunk && - svn ci -m "first commit" trunk && + svn_cmd add trunk && + svn_cmd ci -m "first commit" trunk && cd .. ' diff --git a/t/t9116-git-svn-log.sh b/t/t9116-git-svn-log.sh index fd6d1d2046..0374a7476b 100755 --- a/t/t9116-git-svn-log.sh +++ b/t/t9116-git-svn-log.sh @@ -14,7 +14,7 @@ test_expect_success 'setup repository and import' ' mkdir -p $i && \ echo hello >> $i/README || exit 1 done && \ - svn import -m test . "$svnrepo" + svn_cmd import -m test . "$svnrepo" cd .. && git svn init "$svnrepo" -T trunk -b branches -t tags && git svn fetch && diff --git a/t/t9117-git-svn-init-clone.sh b/t/t9117-git-svn-init-clone.sh index dde46cd92f..b7ef9e2589 100755 --- a/t/t9117-git-svn-init-clone.sh +++ b/t/t9117-git-svn-init-clone.sh @@ -16,7 +16,7 @@ cd tmp test_expect_success 'setup svnrepo' ' mkdir project project/trunk project/branches project/tags && echo foo > project/trunk/foo && - svn import -m "$test_description" project "$svnrepo"/project && + svn_cmd import -m "$test_description" project "$svnrepo"/project && rm -rf project ' diff --git a/t/t9118-git-svn-funky-branch-names.sh b/t/t9118-git-svn-funky-branch-names.sh index 7a7c128687..ac52bff0ef 100755 --- a/t/t9118-git-svn-funky-branch-names.sh +++ b/t/t9118-git-svn-funky-branch-names.sh @@ -13,13 +13,13 @@ scary_ref='Abo-Uebernahme%20(Bug%20#994)' test_expect_success 'setup svnrepo' ' mkdir project project/trunk project/branches project/tags && echo foo > project/trunk/foo && - svn import -m "$test_description" project "$svnrepo/pr ject" && + svn_cmd import -m "$test_description" project "$svnrepo/pr ject" && rm -rf project && - svn cp -m "fun" "$svnrepo/pr ject/trunk" \ + svn_cmd cp -m "fun" "$svnrepo/pr ject/trunk" \ "$svnrepo/pr ject/branches/fun plugin" && - svn cp -m "more fun!" "$svnrepo/pr ject/branches/fun plugin" \ + svn_cmd cp -m "more fun!" "$svnrepo/pr ject/branches/fun plugin" \ "$svnrepo/pr ject/branches/more fun plugin!" && - svn cp -m "scary" "$svnrepo/pr ject/branches/fun plugin" \ + svn_cmd cp -m "scary" "$svnrepo/pr ject/branches/fun plugin" \ "$svnrepo/pr ject/branches/$scary_uri" && start_httpd ' diff --git a/t/t9119-git-svn-info.sh b/t/t9119-git-svn-info.sh index 27dd7c273a..95741cbbac 100755 --- a/t/t9119-git-svn-info.sh +++ b/t/t9119-git-svn-info.sh @@ -7,7 +7,7 @@ test_description='git svn info' . ./lib-git-svn.sh # Tested with: svn, version 1.4.4 (r25188) -v=`svn --version | sed -n -e 's/^svn, version \(1\.[0-9]*\.[0-9]*\).*$/\1/p'` +v=`svn_cmd --version | sed -n -e 's/^svn, version \(1\.[0-9]*\.[0-9]*\).*$/\1/p'` case $v in 1.[45].*) ;; @@ -31,7 +31,7 @@ ptouch() { my $atime = $mtime; utime $atime, $mtime, $git_file; } - ' "`svn info $2 | grep '^Text Last Updated:'`" "$1" + ' "`svn_cmd info $2 | grep '^Text Last Updated:'`" "$1" } quoted_svnrepo="$(echo $svnrepo | sed 's/ /%20/')" @@ -45,14 +45,14 @@ test_expect_success 'setup repository and import' ' mkdir directory && touch directory/.placeholder && ln -s directory symlink-directory && - svn import -m "initial" . "$svnrepo" && + svn_cmd import -m "initial" . "$svnrepo" && cd .. && - svn co "$svnrepo" svnwc && + svn_cmd co "$svnrepo" svnwc && cd svnwc && echo foo > foo && - svn add foo && - svn commit -m "change outside directory" && - svn update && + svn_cmd add foo && + svn_cmd commit -m "change outside directory" && + svn_cmd update && cd .. && mkdir gitwc && cd gitwc && @@ -143,7 +143,7 @@ test_expect_success 'info added-file' " cp gitwc/added-file svnwc/added-file && ptouch gitwc/added-file svnwc/added-file && cd svnwc && - svn add added-file > /dev/null && + svn_cmd add added-file > /dev/null && cd .. && (cd svnwc; svn info added-file) > expected.info-added-file && (cd gitwc; git svn info added-file) > actual.info-added-file && @@ -160,7 +160,7 @@ test_expect_success 'info added-directory' " ptouch gitwc/added-directory svnwc/added-directory && touch gitwc/added-directory/.placeholder && cd svnwc && - svn add added-directory > /dev/null && + svn_cmd add added-directory > /dev/null && cd .. && cd gitwc && git add added-directory && @@ -184,7 +184,7 @@ test_expect_success 'info added-symlink-file' " cd .. && cd svnwc && ln -s added-file added-symlink-file && - svn add added-symlink-file > /dev/null && + svn_cmd add added-symlink-file > /dev/null && cd .. && ptouch gitwc/added-symlink-file svnwc/added-symlink-file && (cd svnwc; svn info added-symlink-file) \ @@ -207,7 +207,7 @@ test_expect_success 'info added-symlink-directory' " cd .. && cd svnwc && ln -s added-directory added-symlink-directory && - svn add added-symlink-directory > /dev/null && + svn_cmd add added-symlink-directory > /dev/null && cd .. && ptouch gitwc/added-symlink-directory svnwc/added-symlink-directory && (cd svnwc; svn info added-symlink-directory) \ @@ -233,7 +233,7 @@ test_expect_success 'info deleted-file' " git rm -f file > /dev/null && cd .. && cd svnwc && - svn rm --force file > /dev/null && + svn_cmd rm --force file > /dev/null && cd .. && (cd svnwc; svn info file) | sed -e 's/^\(Text Last Updated:\).*/\1 TEXT-LAST-UPDATED-STRING/' \ @@ -254,7 +254,7 @@ test_expect_success 'info deleted-directory' " git rm -r -f directory > /dev/null && cd .. && cd svnwc && - svn rm --force directory > /dev/null && + svn_cmd rm --force directory > /dev/null && cd .. && (cd svnwc; svn info directory) | sed -e 's/^\(Text Last Updated:\).*/\1 TEXT-LAST-UPDATED-STRING/' \ @@ -275,7 +275,7 @@ test_expect_success 'info deleted-symlink-file' " git rm -f symlink-file > /dev/null && cd .. && cd svnwc && - svn rm --force symlink-file > /dev/null && + svn_cmd rm --force symlink-file > /dev/null && cd .. && (cd svnwc; svn info symlink-file) | sed -e 's/^\(Text Last Updated:\).*/\1 TEXT-LAST-UPDATED-STRING/' \ @@ -297,7 +297,7 @@ test_expect_success 'info deleted-symlink-directory' " git rm -f symlink-directory > /dev/null && cd .. && cd svnwc && - svn rm --force symlink-directory > /dev/null && + svn_cmd rm --force symlink-directory > /dev/null && cd .. && (cd svnwc; svn info symlink-directory) | sed -e 's/^\(Text Last Updated:\).*/\1 TEXT-LAST-UPDATED-STRING/' \ diff --git a/t/t9120-git-svn-clone-with-percent-escapes.sh b/t/t9120-git-svn-clone-with-percent-escapes.sh index ef2c0523cd..f159ab689b 100755 --- a/t/t9120-git-svn-clone-with-percent-escapes.sh +++ b/t/t9120-git-svn-clone-with-percent-escapes.sh @@ -9,22 +9,17 @@ test_description='git svn clone with percent escapes' test_expect_success 'setup svnrepo' ' mkdir project project/trunk project/branches project/tags && echo foo > project/trunk/foo && - svn import -m "$test_description" project "$svnrepo/pr ject" && + svn_cmd import -m "$test_description" project "$svnrepo/pr ject" && rm -rf project && start_httpd ' -if test "$SVN_HTTPD_PORT" = "" -then - test_expect_failure 'test clone with percent escapes - needs SVN_HTTPD_PORT set' 'false' -else - test_expect_success 'test clone with percent escapes' ' - git svn clone "$svnrepo/pr%20ject" clone && - cd clone && - git rev-parse refs/${remotes_git_svn} && - cd .. - ' -fi +test_expect_success 'test clone with percent escapes' ' + git svn clone "$svnrepo/pr%20ject" clone && + cd clone && + git rev-parse refs/${remotes_git_svn} && + cd .. +' stop_httpd diff --git a/t/t9122-git-svn-author.sh b/t/t9122-git-svn-author.sh index 1b1cf47281..30013b7bb9 100755 --- a/t/t9122-git-svn-author.sh +++ b/t/t9122-git-svn-author.sh @@ -4,12 +4,12 @@ test_description='git svn authorship' . ./lib-git-svn.sh test_expect_success 'setup svn repository' ' - svn checkout "$svnrepo" work.svn && + svn_cmd checkout "$svnrepo" work.svn && ( cd work.svn && echo >file - svn add file - svn commit -m "first commit" file + svn_cmd add file + svn_cmd commit -m "first commit" file ) ' @@ -74,10 +74,10 @@ test_expect_success 'interact with it via git svn' ' # Make sure there are no svn commit messages with excess blank lines ( cd work.svn && - svn up && + svn_cmd up && - test $(svn log -r2:2 | wc -l) = 5 && - test $(svn log -r4:4 | wc -l) = 7 + test $(svn_cmd log -r2:2 | wc -l) = 5 && + test $(svn_cmd log -r4:4 | wc -l) = 7 ) ' diff --git a/t/t9123-git-svn-rebuild-with-rewriteroot.sh b/t/t9123-git-svn-rebuild-with-rewriteroot.sh index cf0415274c..045521615c 100755 --- a/t/t9123-git-svn-rebuild-with-rewriteroot.sh +++ b/t/t9123-git-svn-rebuild-with-rewriteroot.sh @@ -10,7 +10,7 @@ test_description='git svn respects rewriteRoot during rebuild' mkdir import cd import touch foo - svn import -m 'import for git svn' . "$svnrepo" >/dev/null + svn_cmd import -m 'import for git svn' . "$svnrepo" >/dev/null cd .. rm -rf import diff --git a/t/t9124-git-svn-dcommit-auto-props.sh b/t/t9124-git-svn-dcommit-auto-props.sh index 263dbf5fc2..d6b076f6b7 100755 --- a/t/t9124-git-svn-dcommit-auto-props.sh +++ b/t/t9124-git-svn-dcommit-auto-props.sh @@ -21,7 +21,7 @@ test_expect_success 'initialize git svn' ' ( cd import && echo foo >foo && - svn import -m "import for git svn" . "$svnrepo" + svn_cmd import -m "import for git svn" . "$svnrepo" ) && rm -rf import && git svn init "$svnrepo" @@ -61,23 +61,23 @@ test_expect_success 'check resulting svn repository' ' ( mkdir work && cd work && - svn co "$svnrepo" && + svn_cmd co "$svnrepo" && cd svnrepo && # Check properties from first commit. - test "x$(svn propget svn:executable exec1.sh)" = "x*" && - test "x$(svn propget svn:mime-type exec1.sh)" = \ + test "x$(svn_cmd propget svn:executable exec1.sh)" = "x*" && + test "x$(svn_cmd propget svn:mime-type exec1.sh)" = \ "xapplication/x-shellscript" && - test "x$(svn propget svn:mime-type hello.txt)" = "xtext/plain" && - test "x$(svn propget svn:eol-style hello.txt)" = "xnative" && - test "x$(svn propget svn:mime-type bar)" = "x" && + test "x$(svn_cmd propget svn:mime-type hello.txt)" = "xtext/plain" && + test "x$(svn_cmd propget svn:eol-style hello.txt)" = "xnative" && + test "x$(svn_cmd propget svn:mime-type bar)" = "x" && # Check properties from second commit. - test "x$(svn propget svn:executable exec2.sh)" = "x*" && - test "x$(svn propget svn:mime-type exec2.sh)" = "x" && - test "x$(svn propget svn:mime-type world.txt)" = "x" && - test "x$(svn propget svn:eol-style world.txt)" = "x" && - test "x$(svn propget svn:mime-type zot)" = "x" + test "x$(svn_cmd propget svn:executable exec2.sh)" = "x*" && + test "x$(svn_cmd propget svn:mime-type exec2.sh)" = "x" && + test "x$(svn_cmd propget svn:mime-type world.txt)" = "x" && + test "x$(svn_cmd propget svn:eol-style world.txt)" = "x" && + test "x$(svn_cmd propget svn:mime-type zot)" = "x" ) ' @@ -89,12 +89,12 @@ test_expect_success 'check renamed file' ' git svn dcommit --config-dir=user && ( cd work/svnrepo && - svn up && + svn_cmd up && test ! -e foo && test -e foo.sh && - test "x$(svn propget svn:mime-type foo.sh)" = \ + test "x$(svn_cmd propget svn:mime-type foo.sh)" = \ "xapplication/x-shellscript" && - test "x$(svn propget svn:eol-style foo.sh)" = "xLF" + test "x$(svn_cmd propget svn:eol-style foo.sh)" = "xLF" ) ' diff --git a/t/t9125-git-svn-multi-glob-branch-names.sh b/t/t9125-git-svn-multi-glob-branch-names.sh index 475c751c1c..c19418614f 100755 --- a/t/t9125-git-svn-multi-glob-branch-names.sh +++ b/t/t9125-git-svn-multi-glob-branch-names.sh @@ -8,11 +8,11 @@ test_expect_success 'setup svnrepo' ' mkdir project project/trunk project/branches \ project/branches/v14.1 project/tags && echo foo > project/trunk/foo && - svn import -m "$test_description" project "$svnrepo/project" && + svn_cmd import -m "$test_description" project "$svnrepo/project" && rm -rf project && - svn cp -m "fun" "$svnrepo/project/trunk" \ + svn_cmd cp -m "fun" "$svnrepo/project/trunk" \ "$svnrepo/project/branches/v14.1/beta" && - svn cp -m "more fun!" "$svnrepo/project/branches/v14.1/beta" \ + svn_cmd cp -m "more fun!" "$svnrepo/project/branches/v14.1/beta" \ "$svnrepo/project/branches/v14.1/gold" ' diff --git a/t/t9127-git-svn-partial-rebuild.sh b/t/t9127-git-svn-partial-rebuild.sh index 87696a92dc..4aab8ecc14 100755 --- a/t/t9127-git-svn-partial-rebuild.sh +++ b/t/t9127-git-svn-partial-rebuild.sh @@ -14,21 +14,21 @@ test_expect_success 'initialize svnrepo' ' cd trunk && echo foo > foo && cd .. && - svn import -m "import for git-svn" . "$svnrepo" >/dev/null && - svn copy "$svnrepo"/trunk "$svnrepo"/branches/a \ + svn_cmd import -m "import for git-svn" . "$svnrepo" >/dev/null && + svn_cmd copy "$svnrepo"/trunk "$svnrepo"/branches/a \ -m "created branch a" && cd .. && rm -rf import && - svn co "$svnrepo"/trunk trunk && + svn_cmd co "$svnrepo"/trunk trunk && cd trunk && echo bar >> foo && - svn ci -m "updated trunk" && + svn_cmd ci -m "updated trunk" && cd .. && - svn co "$svnrepo"/branches/a a && + svn_cmd co "$svnrepo"/branches/a a && cd a && echo baz >> a && - svn add a && - svn ci -m "updated a" && + svn_cmd add a && + svn_cmd ci -m "updated a" && cd .. && git svn init --stdlayout "$svnrepo" ) diff --git a/t/t9128-git-svn-cmd-branch.sh b/t/t9128-git-svn-cmd-branch.sh index 252daa7e1a..807e494a3a 100755 --- a/t/t9128-git-svn-cmd-branch.sh +++ b/t/t9128-git-svn-cmd-branch.sh @@ -14,13 +14,13 @@ test_expect_success 'initialize svnrepo' ' cd trunk && echo foo > foo && cd .. && - svn import -m "import for git-svn" . "$svnrepo" >/dev/null && + svn_cmd import -m "import for git-svn" . "$svnrepo" >/dev/null && cd .. && rm -rf import && - svn co "$svnrepo"/trunk trunk && + svn_cmd co "$svnrepo"/trunk trunk && cd trunk && echo bar >> foo && - svn ci -m "updated trunk" && + svn_cmd ci -m "updated trunk" && cd .. && rm -rf trunk ) @@ -57,14 +57,14 @@ test_expect_success 'git svn branch tests' ' ' test_expect_success 'branch uses correct svn-remote' ' - (svn co "$svnrepo" svn && + (svn_cmd co "$svnrepo" svn && cd svn && mkdir mirror && - svn add mirror && - svn copy trunk mirror/ && - svn copy tags mirror/ && - svn copy branches mirror/ && - svn ci -m "made mirror" ) && + svn_cmd add mirror && + svn_cmd copy trunk mirror/ && + svn_cmd copy tags mirror/ && + svn_cmd copy branches mirror/ && + svn_cmd ci -m "made mirror" ) && rm -rf svn && git svn init -s -R mirror --prefix=mirror/ "$svnrepo"/mirror && git svn fetch -R mirror && diff --git a/t/t9129-git-svn-i18n-commitencoding.sh b/t/t9129-git-svn-i18n-commitencoding.sh index 3200ab38ef..b9224bdb20 100755 --- a/t/t9129-git-svn-i18n-commitencoding.sh +++ b/t/t9129-git-svn-i18n-commitencoding.sh @@ -29,16 +29,16 @@ compare_svn_head_with () { test_cmp current "$1" } -for H in ISO-8859-1 EUCJP ISO-2022-JP +for H in ISO8859-1 eucJP ISO-2022-JP do test_expect_success "$H setup" ' mkdir $H && - svn import -m "$H test" $H "$svnrepo"/$H && + svn_cmd import -m "$H test" $H "$svnrepo"/$H && git svn clone "$svnrepo"/$H $H ' done -for H in ISO-8859-1 EUCJP ISO-2022-JP +for H in ISO8859-1 eucJP ISO-2022-JP do test_expect_success "$H commit on git side" ' ( @@ -55,7 +55,7 @@ do ' done -for H in ISO-8859-1 EUCJP ISO-2022-JP +for H in ISO8859-1 eucJP ISO-2022-JP do test_expect_success "$H dcommit to svn" ' ( @@ -77,12 +77,12 @@ fi test_expect_success UTF8 'ISO-8859-1 should match UTF-8 in svn' ' ( - cd ISO-8859-1 && + cd ISO8859-1 && compare_svn_head_with "$TEST_DIRECTORY"/t3900/1-UTF-8.txt ) ' -for H in EUCJP ISO-2022-JP +for H in eucJP ISO-2022-JP do test_expect_success UTF8 "$H should match UTF-8 in svn" ' ( diff --git a/t/t9130-git-svn-authors-file.sh b/t/t9130-git-svn-authors-file.sh index b8fb277562..f5abdb3c7f 100755 --- a/t/t9130-git-svn-authors-file.sh +++ b/t/t9130-git-svn-authors-file.sh @@ -15,7 +15,7 @@ EOF test_expect_success 'setup svnrepo' ' for i in aa bb cc dd do - svn mkdir -m $i --username $i "$svnrepo"/$i + svn_cmd mkdir -m $i --username $i "$svnrepo"/$i done ' @@ -52,13 +52,13 @@ test_expect_success 'continues to import once authors have been added' ' ' test_expect_success 'authors-file against globs' ' - svn mkdir -m globs --username aa \ + svn_cmd mkdir -m globs --username aa \ "$svnrepo"/aa/trunk "$svnrepo"/aa/branches "$svnrepo"/aa/tags && git svn clone --authors-file=svn-authors -s "$svnrepo"/aa aa-work && for i in bb ee cc do branch="aa/branches/$i" - svn mkdir -m "$branch" --username $i "$svnrepo/$branch" + svn_cmd mkdir -m "$branch" --username $i "$svnrepo/$branch" done ' diff --git a/t/t9133-git-svn-nested-git-repo.sh b/t/t9133-git-svn-nested-git-repo.sh index 893f57ef73..f3c30e63b7 100755 --- a/t/t9133-git-svn-nested-git-repo.sh +++ b/t/t9133-git-svn-nested-git-repo.sh @@ -7,19 +7,19 @@ test_description='git svn property tests' . ./lib-git-svn.sh test_expect_success 'setup repo with a git repo inside it' ' - svn co "$svnrepo" s && + svn_cmd co "$svnrepo" s && ( cd s && git init && test -f .git/HEAD && > .git/a && echo a > a && - svn add .git a && - svn commit -m "create a nested git repo" && - svn up && + svn_cmd add .git a && + svn_cmd commit -m "create a nested git repo" && + svn_cmd up && echo hi >> .git/a && - svn commit -m "modify .git/a" && - svn up + svn_cmd commit -m "modify .git/a" && + svn_cmd up ) ' @@ -33,9 +33,9 @@ test_expect_success 'SVN-side change outside of .git' ' ( cd s && echo b >> a && - svn commit -m "SVN-side change outside of .git" && - svn up && - svn log -v | fgrep "SVN-side change outside of .git" + svn_cmd commit -m "SVN-side change outside of .git" && + svn_cmd up && + svn_cmd log -v | fgrep "SVN-side change outside of .git" ) ' @@ -56,10 +56,10 @@ test_expect_success 'SVN-side change inside of .git' ' git add a && git commit -m "add a inside an SVN repo" && git log && - svn add --force .git && - svn commit -m "SVN-side change inside of .git" && - svn up && - svn log -v | fgrep "SVN-side change inside of .git" + svn_cmd add --force .git && + svn_cmd commit -m "SVN-side change inside of .git" && + svn_cmd up && + svn_cmd log -v | fgrep "SVN-side change inside of .git" ) ' @@ -80,9 +80,9 @@ test_expect_success 'SVN-side change in and out of .git' ' echo c >> a && git add a && git commit -m "add a inside an SVN repo" && - svn commit -m "SVN-side change in and out of .git" && - svn up && - svn log -v | fgrep "SVN-side change in and out of .git" + svn_cmd commit -m "SVN-side change in and out of .git" && + svn_cmd up && + svn_cmd log -v | fgrep "SVN-side change in and out of .git" ) ' diff --git a/t/t9134-git-svn-ignore-paths.sh b/t/t9134-git-svn-ignore-paths.sh index 71fdc4a69d..09ff10cd9b 100755 --- a/t/t9134-git-svn-ignore-paths.sh +++ b/t/t9134-git-svn-ignore-paths.sh @@ -8,19 +8,19 @@ test_description='git svn property tests' . ./lib-git-svn.sh test_expect_success 'setup test repository' ' - svn co "$svnrepo" s && + svn_cmd co "$svnrepo" s && ( cd s && mkdir qqq www && echo test_qqq > qqq/test_qqq.txt && echo test_www > www/test_www.txt && - svn add qqq && - svn add www && - svn commit -m "create some files" && - svn up && + svn_cmd add qqq && + svn_cmd add www && + svn_cmd commit -m "create some files" && + svn_cmd up && echo hi >> www/test_www.txt && - svn commit -m "modify www/test_www.txt" && - svn up + svn_cmd commit -m "modify www/test_www.txt" && + svn_cmd up ) ' @@ -51,9 +51,9 @@ test_expect_success 'SVN-side change outside of www' ' ( cd s && echo b >> qqq/test_qqq.txt && - svn commit -m "SVN-side change outside of www" && - svn up && - svn log -v | fgrep "SVN-side change outside of www" + svn_cmd commit -m "SVN-side change outside of www" && + svn_cmd up && + svn_cmd log -v | fgrep "SVN-side change outside of www" ) ' @@ -83,9 +83,9 @@ test_expect_success 'SVN-side change inside of ignored www' ' ( cd s && echo zaq >> www/test_www.txt - svn commit -m "SVN-side change inside of www/test_www.txt" && - svn up && - svn log -v | fgrep "SVN-side change inside of www/test_www.txt" + svn_cmd commit -m "SVN-side change inside of www/test_www.txt" && + svn_cmd up && + svn_cmd log -v | fgrep "SVN-side change inside of www/test_www.txt" ) ' @@ -116,9 +116,9 @@ test_expect_success 'SVN-side change in and out of ignored www' ' cd s && echo cvf >> www/test_www.txt echo ygg >> qqq/test_qqq.txt - svn commit -m "SVN-side change in and out of ignored www" && - svn up && - svn log -v | fgrep "SVN-side change in and out of ignored www" + svn_cmd commit -m "SVN-side change in and out of ignored www" && + svn_cmd up && + svn_cmd log -v | fgrep "SVN-side change in and out of ignored www" ) ' diff --git a/t/t9137-git-svn-dcommit-clobber-series.sh b/t/t9137-git-svn-dcommit-clobber-series.sh index fd185011b7..636ca0abb9 100755 --- a/t/t9137-git-svn-dcommit-clobber-series.sh +++ b/t/t9137-git-svn-dcommit-clobber-series.sh @@ -8,7 +8,7 @@ test_expect_success 'initialize repo' ' mkdir import && cd import && awk "BEGIN { for (i = 1; i < 64; i++) { print i } }" > file - svn import -m "initial" . "$svnrepo" && + svn_cmd import -m "initial" . "$svnrepo" && cd .. && git svn init "$svnrepo" && git svn fetch && @@ -18,14 +18,14 @@ test_expect_success 'initialize repo' ' test_expect_success '(supposedly) non-conflicting change from SVN' ' test x"`sed -n -e 58p < file`" = x58 && test x"`sed -n -e 61p < file`" = x61 && - svn co "$svnrepo" tmp && + svn_cmd co "$svnrepo" tmp && cd tmp && perl -i.bak -p -e "s/^58$/5588/" file && perl -i.bak -p -e "s/^61$/6611/" file && poke file && test x"`sed -n -e 58p < file`" = x5588 && test x"`sed -n -e 61p < file`" = x6611 && - svn commit -m "58 => 5588, 61 => 6611" && + svn_cmd commit -m "58 => 5588, 61 => 6611" && cd .. ' @@ -46,7 +46,7 @@ test_expect_success 'change file but in unrelated area' " test x\"\`sed -n -e 7p < file\`\" = x7777 && git commit -m '4 => 4444, 7 => 7777' file && git svn dcommit && - svn up tmp && + svn_cmd up tmp && cd tmp && test x\"\`sed -n -e 4p < file\`\" = x4444 && test x\"\`sed -n -e 7p < file\`\" = x7777 && diff --git a/t/t9138-git-svn-authors-prog.sh b/t/t9138-git-svn-authors-prog.sh new file mode 100755 index 0000000000..a4b00f2a3f --- /dev/null +++ b/t/t9138-git-svn-authors-prog.sh @@ -0,0 +1,69 @@ +#!/bin/sh +# +# Copyright (c) 2009 Eric Wong, Mark Lodato +# + +test_description='git svn authors prog tests' + +. ./lib-git-svn.sh + +cat > svn-authors-prog <<'EOF' +#!/usr/bin/perl +$_ = shift; +if (s/-sub$//) { + print "$_ <$_\@sub.example.com>\n"; +} +else { + print "$_ <$_\@example.com>\n"; +} +EOF +chmod +x svn-authors-prog + +cat > svn-authors <<'EOF' +ff = FFFFFFF FFFFFFF <fFf@other.example.com> +EOF + +test_expect_success 'setup svnrepo' ' + for i in aa bb cc-sub dd-sub ee-foo ff + do + svn mkdir -m $i --username $i "$svnrepo"/$i + done + ' + +test_expect_success 'import authors with prog and file' ' + git svn clone --authors-prog=./svn-authors-prog \ + --authors-file=svn-authors "$svnrepo" x + ' + +test_expect_success 'imported 6 revisions successfully' ' + ( + cd x + test "`git rev-list refs/remotes/git-svn | wc -l`" -eq 6 + ) + ' + +test_expect_success 'authors-prog ran correctly' ' + ( + cd x + git rev-list -1 --pretty=raw refs/remotes/git-svn~1 | \ + grep "^author ee-foo <ee-foo@example\.com> " && + git rev-list -1 --pretty=raw refs/remotes/git-svn~2 | \ + grep "^author dd <dd@sub\.example\.com> " && + git rev-list -1 --pretty=raw refs/remotes/git-svn~3 | \ + grep "^author cc <cc@sub\.example\.com> " && + git rev-list -1 --pretty=raw refs/remotes/git-svn~4 | \ + grep "^author bb <bb@example\.com> " && + git rev-list -1 --pretty=raw refs/remotes/git-svn~5 | \ + grep "^author aa <aa@example\.com> " + ) + ' + +test_expect_success 'authors-file overrode authors-prog' ' + ( + cd x + git rev-list -1 --pretty=raw refs/remotes/git-svn | \ + grep "^author FFFFFFF FFFFFFF <fFf@other\.example\.com> " + ) + ' + +test_done diff --git a/t/t9139-git-svn-non-utf8-commitencoding.sh b/t/t9139-git-svn-non-utf8-commitencoding.sh new file mode 100755 index 0000000000..f337959ccc --- /dev/null +++ b/t/t9139-git-svn-non-utf8-commitencoding.sh @@ -0,0 +1,47 @@ +#!/bin/sh +# +# Copyright (c) 2009 Eric Wong + +test_description='git svn refuses to dcommit non-UTF8 messages' + +. ./lib-git-svn.sh + +# ISO-2022-JP can pass for valid UTF-8, so skipping that in this test + +for H in ISO8859-1 eucJP +do + test_expect_success "$H setup" ' + mkdir $H && + svn_cmd import -m "$H test" $H "$svnrepo"/$H && + git svn clone "$svnrepo"/$H $H + ' +done + +for H in ISO8859-1 eucJP +do + test_expect_success "$H commit on git side" ' + ( + cd $H && + git config i18n.commitencoding $H && + git checkout -b t refs/remotes/git-svn && + echo $H >F && + git add F && + git commit -a -F "$TEST_DIRECTORY"/t3900/$H.txt && + E=$(git cat-file commit HEAD | sed -ne "s/^encoding //p") && + test "z$E" = "z$H" + ) + ' +done + +for H in ISO8859-1 eucJP +do + test_expect_success "$H dcommit to svn" ' + ( + cd $H && + git config --unset i18n.commitencoding && + ! git svn dcommit + ) + ' +done + +test_done diff --git a/t/t9140-git-svn-reset.sh b/t/t9140-git-svn-reset.sh new file mode 100755 index 0000000000..0735526d4b --- /dev/null +++ b/t/t9140-git-svn-reset.sh @@ -0,0 +1,66 @@ +#!/bin/sh +# +# Copyright (c) 2009 Ben Jackson +# + +test_description='git svn reset' +. ./lib-git-svn.sh + +test_expect_success 'setup test repository' ' + svn_cmd co "$svnrepo" s && + ( + cd s && + mkdir vis && + echo always visible > vis/vis.txt && + svn_cmd add vis && + svn_cmd commit -m "create visible files" && + mkdir hid && + echo initially hidden > hid/hid.txt && + svn_cmd add hid && + svn_cmd commit -m "create initially hidden files" && + svn_cmd up && + echo mod >> vis/vis.txt && + svn_cmd commit -m "modify vis" && + svn_cmd up + ) +' + +test_expect_success 'clone SVN repository with hidden directory' ' + git svn init "$svnrepo" g && + ( cd g && git svn fetch --ignore-paths="^hid" ) +' + +test_expect_success 'modify hidden file in SVN repo' ' + ( cd s && + echo mod hidden >> hid/hid.txt && + svn_cmd commit -m "modify hid" && + svn_cmd up + ) +' + +test_expect_success 'fetch fails on modified hidden file' ' + ( cd g && + git svn find-rev refs/remotes/git-svn > ../expect && + ! git svn fetch 2> ../errors && + git svn find-rev refs/remotes/git-svn > ../expect2 ) && + fgrep "not found in commit" errors && + test_cmp expect expect2 +' + +test_expect_success 'reset unwinds back to r1' ' + ( cd g && + git svn reset -r1 && + git svn find-rev refs/remotes/git-svn > ../expect2 ) && + echo 1 >expect && + test_cmp expect expect2 +' + +test_expect_success 'refetch succeeds not ignoring any files' ' + ( cd g && + git svn fetch && + git svn rebase && + fgrep "mod hidden" hid/hid.txt + ) +' + +test_done diff --git a/t/t9141-git-svn-multiple-branches.sh b/t/t9141-git-svn-multiple-branches.sh new file mode 100755 index 0000000000..3cd06718eb --- /dev/null +++ b/t/t9141-git-svn-multiple-branches.sh @@ -0,0 +1,122 @@ +#!/bin/sh +# +# Copyright (c) 2009 Marc Branchaud +# + +test_description='git svn multiple branch and tag paths in the svn repo' +. ./lib-git-svn.sh + +test_expect_success 'setup svnrepo' ' + mkdir project \ + project/trunk \ + project/b_one \ + project/b_two \ + project/tags_A \ + project/tags_B && + echo 1 > project/trunk/a.file && + svn_cmd import -m "$test_description" project "$svnrepo/project" && + rm -rf project && + svn_cmd cp -m "Branch 1" "$svnrepo/project/trunk" \ + "$svnrepo/project/b_one/first" && + svn_cmd cp -m "Tag 1" "$svnrepo/project/trunk" \ + "$svnrepo/project/tags_A/1.0" && + svn_cmd co "$svnrepo/project" svn_project && + ( cd svn_project && + echo 2 > trunk/a.file && + svn_cmd ci -m "Change 1" trunk/a.file && + svn_cmd cp -m "Branch 2" "$svnrepo/project/trunk" \ + "$svnrepo/project/b_one/second" && + svn_cmd cp -m "Tag 2" "$svnrepo/project/trunk" \ + "$svnrepo/project/tags_A/2.0" && + echo 3 > trunk/a.file && + svn_cmd ci -m "Change 2" trunk/a.file && + svn_cmd cp -m "Branch 3" "$svnrepo/project/trunk" \ + "$svnrepo/project/b_two/1" && + svn_cmd cp -m "Tag 3" "$svnrepo/project/trunk" \ + "$svnrepo/project/tags_A/3.0" && + echo 4 > trunk/a.file && + svn_cmd ci -m "Change 3" trunk/a.file && + svn_cmd cp -m "Branch 4" "$svnrepo/project/trunk" \ + "$svnrepo/project/b_two/2" && + svn_cmd cp -m "Tag 4" "$svnrepo/project/trunk" \ + "$svnrepo/project/tags_A/4.0" && + svn_cmd up && + echo 5 > b_one/first/a.file && + svn_cmd ci -m "Change 4" b_one/first/a.file && + svn_cmd cp -m "Tag 5" "$svnrepo/project/b_one/first" \ + "$svnrepo/project/tags_B/v5" && + echo 6 > b_one/second/a.file && + svn_cmd ci -m "Change 5" b_one/second/a.file && + svn_cmd cp -m "Tag 6" "$svnrepo/project/b_one/second" \ + "$svnrepo/project/tags_B/v6" && + echo 7 > b_two/1/a.file && + svn_cmd ci -m "Change 6" b_two/1/a.file && + svn_cmd cp -m "Tag 7" "$svnrepo/project/b_two/1" \ + "$svnrepo/project/tags_B/v7" && + echo 8 > b_two/2/a.file && + svn_cmd ci -m "Change 7" b_two/2/a.file && + svn_cmd cp -m "Tag 8" "$svnrepo/project/b_two/2" \ + "$svnrepo/project/tags_B/v8" + ) +' + +test_expect_success 'clone multiple branch and tag paths' ' + git svn clone -T trunk \ + -b b_one/* --branches b_two/* \ + -t tags_A/* --tags tags_B \ + "$svnrepo/project" git_project && + ( cd git_project && + git rev-parse refs/remotes/first && + git rev-parse refs/remotes/second && + git rev-parse refs/remotes/1 && + git rev-parse refs/remotes/2 && + git rev-parse refs/remotes/tags/1.0 && + git rev-parse refs/remotes/tags/2.0 && + git rev-parse refs/remotes/tags/3.0 && + git rev-parse refs/remotes/tags/4.0 && + git rev-parse refs/remotes/tags/v5 && + git rev-parse refs/remotes/tags/v6 && + git rev-parse refs/remotes/tags/v7 && + git rev-parse refs/remotes/tags/v8 + ) +' + +test_expect_success 'Multiple branch or tag paths require -d' ' + ( cd git_project && + test_must_fail git svn branch -m "No new branch" Nope && + test_must_fail git svn tag -m "No new tag" Tagless && + test_must_fail git rev-parse refs/remotes/Nope && + test_must_fail git rev-parse refs/remotes/tags/Tagless + ) && + ( cd svn_project && + svn_cmd up && + test_must_fail test -d b_one/Nope && + test_must_fail test -d b_two/Nope && + test_must_fail test -d tags_A/Tagless && + test_must_fail test -d tags_B/Tagless + ) +' + +test_expect_success 'create new branches and tags' ' + ( cd git_project && + git svn branch -m "New branch 1" -d b_one New1 ) && + ( cd svn_project && + svn_cmd up && test -e b_one/New1/a.file ) && + + ( cd git_project && + git svn branch -m "New branch 2" -d b_two New2 ) && + ( cd svn_project && + svn_cmd up && test -e b_two/New2/a.file ) && + + ( cd git_project && + git svn branch -t -m "New tag 1" -d tags_A Tag1 ) && + ( cd svn_project && + svn_cmd up && test -e tags_A/Tag1/a.file ) && + + ( cd git_project && + git svn tag -m "New tag 2" -d tags_B Tag2 ) && + ( cd svn_project && + svn_cmd up && test -e tags_B/Tag2/a.file ) +' + +test_done diff --git a/t/t9142-git-svn-shallow-clone.sh b/t/t9142-git-svn-shallow-clone.sh new file mode 100755 index 0000000000..1236accd99 --- /dev/null +++ b/t/t9142-git-svn-shallow-clone.sh @@ -0,0 +1,32 @@ +#!/bin/sh +# +# Copyright (c) 2009 Eric Wong +# + +test_description='git svn shallow clone' +. ./lib-git-svn.sh + +test_expect_success 'setup test repository' ' + svn_cmd mkdir -m "create standard layout" \ + "$svnrepo"/trunk "$svnrepo"/branches "$svnrepo"/tags && + svn_cmd cp -m "branch off trunk" \ + "$svnrepo"/trunk "$svnrepo"/branches/a && + svn_cmd co "$svnrepo"/branches/a && + ( + cd a && + > foo && + svn_cmd add foo && + svn_cmd commit -m "add foo" + ) +' + +start_httpd + +test_expect_success 'clone trunk with "-r HEAD"' ' + git svn clone -r HEAD "$svnrepo/trunk" g && + ( cd g && git rev-parse --symbolic --verify HEAD ) +' + +stop_httpd + +test_done diff --git a/t/t9143-git-svn-gc.sh b/t/t9143-git-svn-gc.sh new file mode 100755 index 0000000000..f2ba2d1da3 --- /dev/null +++ b/t/t9143-git-svn-gc.sh @@ -0,0 +1,53 @@ +#!/bin/sh +# +# Copyright (c) 2009 Robert Allan Zeh + +test_description='git svn gc basic tests' + +. ./lib-git-svn.sh + +test_expect_success 'setup directories and test repo' ' + mkdir import && + mkdir tmp && + echo "Sample text for Subversion repository." > import/test.txt && + svn_cmd import -m "import for git svn" import "$svnrepo" > /dev/null + ' + +test_expect_success 'checkout working copy from svn' \ + 'svn_cmd co "$svnrepo" test_wc' + +test_expect_success 'set some properties to create an unhandled.log file' ' + ( + cd test_wc && + svn_cmd propset foo bar test.txt && + svn_cmd commit -m "property set" + )' + +test_expect_success 'Setup repo' 'git svn init "$svnrepo"' + +test_expect_success 'Fetch repo' 'git svn fetch' + +test_expect_success 'make backup copy of unhandled.log' ' + cp .git/svn/git-svn/unhandled.log tmp + ' + +test_expect_success 'create leftover index' '> .git/svn/git-svn/index' + +test_expect_success 'git svn gc runs' 'git svn gc' + +test_expect_success 'git svn index removed' '! test -f .git/svn/git-svn/index' + +if perl -MCompress::Zlib -e 0 2>/dev/null +then + test_expect_success 'git svn gc produces a valid gzip file' ' + gunzip .git/svn/git-svn/unhandled.log.gz + ' +else + say "Perl Compress::Zlib unavailable, skipping gunzip test" +fi + +test_expect_success 'git svn gc does not change unhandled.log files' ' + test_cmp .git/svn/git-svn/unhandled.log tmp/unhandled.log + ' + +test_done diff --git a/t/t9200-git-cvsexportcommit.sh b/t/t9200-git-cvsexportcommit.sh index 56b7c06921..fc3795dc98 100755 --- a/t/t9200-git-cvsexportcommit.sh +++ b/t/t9200-git-cvsexportcommit.sh @@ -288,6 +288,27 @@ test_expect_success 'check files before directories' ' ' +test_expect_success 're-commit a removed filename which remains in CVS attic' ' + + (cd "$CVSWORK" && + echo >attic_gremlin && + cvs -Q add attic_gremlin && + cvs -Q ci -m "added attic_gremlin" && + rm attic_gremlin && + cvs -Q rm attic_gremlin && + cvs -Q ci -m "removed attic_gremlin") && + + echo > attic_gremlin && + git add attic_gremlin && + git commit -m "Added attic_gremlin" && + git cvsexportcommit -w "$CVSWORK" -c HEAD && + (cd "$CVSWORK"; cvs -Q update -d) && + test -f "$CVSWORK/attic_gremlin" +' + +# the state of the CVS sandbox may be indeterminate for ' space' +# after this test on some platforms / with some versions of CVS +# consider adding new tests above this point test_expect_success 'commit a file with leading spaces in the name' ' echo space > " space" && @@ -295,7 +316,7 @@ test_expect_success 'commit a file with leading spaces in the name' ' git commit -m "Add a file with a leading space" && id=$(git rev-parse HEAD) && git cvsexportcommit -w "$CVSWORK" -c $id && - check_entries "$CVSWORK" " space/1.1/|DS/1.1/|release-notes/1.2/" && + check_entries "$CVSWORK" " space/1.1/|DS/1.1/|attic_gremlin/1.3/|release-notes/1.2/" && test_cmp "$CVSWORK/ space" " space" ' diff --git a/t/t9301-fast-export.sh b/t/t9301-fast-export.sh index 8da9ce5459..356964e53a 100755 --- a/t/t9301-fast-export.sh +++ b/t/t9301-fast-export.sh @@ -68,7 +68,7 @@ test_expect_success 'fast-export master~2..master' ' test_expect_success 'iso-8859-1' ' - git config i18n.commitencoding ISO-8859-1 && + git config i18n.commitencoding ISO8859-1 && # use author and committer name in ISO-8859-1 to match it. . "$TEST_DIRECTORY"/t3901-8859-1.txt && test_tick && @@ -262,6 +262,94 @@ test_expect_success 'cope with tagger-less tags' ' ' +test_expect_success 'setup for limiting exports by PATH' ' + mkdir limit-by-paths && + cd limit-by-paths && + git init && + echo hi > there && + git add there && + git commit -m "First file" && + echo foo > bar && + git add bar && + git commit -m "Second file" && + git tag -a -m msg mytag && + echo morefoo >> bar && + git add bar && + git commit -m "Change to second file" && + cd .. +' + +cat > limit-by-paths/expected << EOF +blob +mark :1 +data 3 +hi + +reset refs/tags/mytag +commit refs/tags/mytag +mark :2 +author A U Thor <author@example.com> 1112912713 -0700 +committer C O Mitter <committer@example.com> 1112912713 -0700 +data 11 +First file +M 100644 :1 there + +EOF + +test_expect_success 'dropping tag of filtered out object' ' + cd limit-by-paths && + git fast-export --tag-of-filtered-object=drop mytag -- there > output && + test_cmp output expected && + cd .. +' + +cat >> limit-by-paths/expected << EOF +tag mytag +from :2 +tagger C O Mitter <committer@example.com> 1112912713 -0700 +data 4 +msg + +EOF + +test_expect_success 'rewriting tag of filtered out object' ' + cd limit-by-paths && + git fast-export --tag-of-filtered-object=rewrite mytag -- there > output && + test_cmp output expected && + cd .. +' + +cat > limit-by-paths/expected << EOF +blob +mark :1 +data 4 +foo + +blob +mark :2 +data 3 +hi + +reset refs/heads/master +commit refs/heads/master +mark :3 +author A U Thor <author@example.com> 1112912713 -0700 +committer C O Mitter <committer@example.com> 1112912713 -0700 +data 12 +Second file +M 100644 :1 bar +M 100644 :2 there + +EOF + +test_expect_failure 'no exact-ref revisions included' ' + cd limit-by-paths && + git fast-export master~2..master~1 > output && + test_cmp output expected && + cd .. +' + + test_expect_success 'set-up a few more tags for tag export tests' ' git checkout -f master && HEAD_TREE=`git show -s --pretty=raw HEAD | grep tree | sed "s/tree //"` && @@ -271,8 +359,14 @@ test_expect_success 'set-up a few more tags for tag export tests' ' git tag -a tag-obj_tag-obj -m "tagging a tag" tree_tag-obj ' +test_expect_success 'tree_tag' ' + mkdir result && + (cd result && git init) && + git fast-export tree_tag > fe-stream && + (cd result && git fast-import < ../fe-stream) +' + # NEEDSWORK: not just check return status, but validate the output -test_expect_success 'tree_tag' 'git fast-export tree_tag' test_expect_success 'tree_tag-obj' 'git fast-export tree_tag-obj' test_expect_success 'tag-obj_tag' 'git fast-export tag-obj_tag' test_expect_success 'tag-obj_tag-obj' 'git fast-export tag-obj_tag-obj' diff --git a/t/t9500-gitweb-standalone-no-errors.sh b/t/t9500-gitweb-standalone-no-errors.sh index f4210fbb04..627518108a 100755 --- a/t/t9500-gitweb-standalone-no-errors.sh +++ b/t/t9500-gitweb-standalone-no-errors.sh @@ -590,7 +590,7 @@ test_expect_success \ echo "ISO-8859-1" >> file && git add file && git config i18n.commitencoding ISO-8859-1 && - git commit -F "$TEST_DIRECTORY"/t3900/ISO-8859-1.txt && + git commit -F "$TEST_DIRECTORY"/t3900/ISO8859-1.txt && git config --unset i18n.commitencoding && gitweb_run "p=.git;a=commit"' test_debug 'cat gitweb.log' @@ -660,6 +660,7 @@ cat >>gitweb_config.perl <<EOF \$feature{'blame'}{'override'} = 1; \$feature{'snapshot'}{'override'} = 1; +\$feature{'avatar'}{'override'} = 1; EOF test_expect_success \ @@ -671,6 +672,7 @@ test_expect_success \ 'config override: tree view, features disabled in repo config' \ 'git config gitweb.blame no && git config gitweb.snapshot none && + git config gitweb.avatar gravatar && gitweb_run "p=.git;a=tree"' test_debug 'cat gitweb.log' diff --git a/t/t9700-perl-git.sh b/t/t9700-perl-git.sh index b4ca244626..4eb7d3f7f0 100755 --- a/t/t9700-perl-git.sh +++ b/t/t9700-perl-git.sh @@ -29,6 +29,10 @@ test_expect_success \ git add . && git commit -m "first commit" && + echo "new file in subdir 2" > directory2/file2 && + git add . && + git commit -m "commit in directory2" && + echo "changed file 1" > file1 && git commit -a -m "second commit" && diff --git a/t/t9700/test.pl b/t/t9700/test.pl index 697daf3ffd..6c70aec020 100755 --- a/t/t9700/test.pl +++ b/t/t9700/test.pl @@ -86,15 +86,22 @@ close TEMPFILE; unlink $tmpfile; # paths -is($r->repo_path, "./.git", "repo_path"); +is($r->repo_path, $abs_repo_dir . "/.git", "repo_path"); is($r->wc_path, $abs_repo_dir . "/", "wc_path"); is($r->wc_subdir, "", "wc_subdir initial"); $r->wc_chdir("directory1"); is($r->wc_subdir, "directory1", "wc_subdir after wc_chdir"); -TODO: { - local $TODO = "commands do not work after wc_chdir"; - # Failure output is active even in non-verbose mode and thus - # annoying. Hence we skip these tests as long as they fail. - todo_skip 'config after wc_chdir', 1; - is($r->config("color.string"), "value", "config after wc_chdir"); -} +is($r->config("test.string"), "value", "config after wc_chdir"); + +# Object generation in sub directory +chdir("directory2"); +my $r2 = Git->repository(); +is($r2->repo_path, $abs_repo_dir . "/.git", "repo_path (2)"); +is($r2->wc_path, $abs_repo_dir . "/", "wc_path (2)"); +is($r2->wc_subdir, "directory2/", "wc_subdir initial (2)"); + +# commands in sub directory +my $last_commit = $r2->command_oneline(qw(rev-parse --verify HEAD)); +like($last_commit, qr/^[0-9a-fA-F]{40}$/, 'rev-parse returned hash'); +my $dir_commit = $r2->command_oneline('log', '-n1', '--pretty=format:%H', '.'); +isnt($last_commit, $dir_commit, 'log . does not show last commit'); diff --git a/t/test-lib.sh b/t/test-lib.sh index dad1437fa4..5fdc5d94a2 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -115,7 +115,7 @@ do --tee) shift ;; # was handled already *) - break ;; + echo "error: unknown test option '$1'" >&2; exit 1 ;; esac done @@ -147,7 +147,7 @@ fi error () { say_color error "error: $*" - trap - EXIT + GIT_EXIT_OK=t exit 1 } @@ -179,10 +179,17 @@ test_broken=0 test_success=0 die () { - echo >&5 "FATAL: Unexpected exit with code $?" - exit 1 + code=$? + if test -n "$GIT_EXIT_OK" + then + exit $code + else + echo >&5 "FATAL: Unexpected exit with code $code" + exit 1 + fi } +GIT_EXIT_OK= trap 'die' EXIT # The semantics of the editor variables are that of invoking @@ -285,7 +292,7 @@ test_failure_ () { say_color error "FAIL $test_count: $1" shift echo "$@" | sed -e 's/^/ /' - test "$immediate" = "" || { trap - EXIT; exit 1; } + test "$immediate" = "" || { GIT_EXIT_OK=t; exit 1; } } test_known_broken_ok_ () { @@ -347,7 +354,7 @@ test_expect_failure () { then test_known_broken_ok_ "$1" else - test_known_broken_failure_ "$1" + test_known_broken_failure_ "$1" fi fi echo >&3 "" @@ -498,7 +505,7 @@ test_create_repo () { } test_done () { - trap - EXIT + GIT_EXIT_OK=t test_results_dir="$TEST_DIRECTORY/test-results" mkdir -p "$test_results_dir" test_results_path="$test_results_dir/${0%.sh}-$$" @@ -640,7 +647,7 @@ fi test="trash directory.$(basename "$0" .sh)" test ! -z "$debug" || remove_trash="$TEST_DIRECTORY/$test" rm -fr "$test" || { - trap - EXIT + GIT_EXIT_OK=t echo >&5 "FATAL: Cannot prepare test area" exit 1 } diff --git a/templates/hooks--pre-commit.sample b/templates/hooks--pre-commit.sample index 0ba62076fb..b11ad6a6fb 100755 --- a/templates/hooks--pre-commit.sample +++ b/templates/hooks--pre-commit.sample @@ -7,6 +7,31 @@ # # To enable this hook, rename this file to "pre-commit". +# If you want to allow non-ascii filenames set this variable to true. +allownonascii=$(git config hooks.allownonascii) + +# Cross platform projects tend to avoid non-ascii filenames; prevent +# them from being added to the repository. We exploit the fact that the +# printable range starts at the space character and ends with tilde. +if [ "$allownonascii" != "true" ] && + test "$(git diff --cached --name-only --diff-filter=A -z | + LC_ALL=C tr -d '[ -~]\0')" +then + echo "Error: Attempt to add a non-ascii filename." + echo + echo "This can cause problems if you want to work together" + echo "with people on other platforms than you." + echo + echo "To be portable it is adviseable to rename the file ..." + echo + echo "If you know what you are doing you can disable this" + echo "check using:" + echo + echo " git config hooks.allownonascii true" + echo + exit 1 +fi + if git-rev-parse --verify HEAD >/dev/null 2>&1 then against=HEAD diff --git a/templates/hooks--update.sample b/templates/hooks--update.sample index f8bf490cff..fd63b2d662 100755 --- a/templates/hooks--update.sample +++ b/templates/hooks--update.sample @@ -13,6 +13,9 @@ # hooks.allowdeletetag # This boolean sets whether deleting tags will be allowed in the # repository. By default they won't be. +# hooks.allowmodifytag +# This boolean sets whether a tag may be modified after creation. By default +# it won't be. # hooks.allowdeletebranch # This boolean sets whether deleting branches will be allowed in the # repository. By default they won't be. @@ -44,6 +47,7 @@ allowunannotated=$(git config --bool hooks.allowunannotated) allowdeletebranch=$(git config --bool hooks.allowdeletebranch) denycreatebranch=$(git config --bool hooks.denycreatebranch) allowdeletetag=$(git config --bool hooks.allowdeletetag) +allowmodifytag=$(git config --bool hooks.allowmodifytag) # check for no description projectdesc=$(sed -e '1q' "$GIT_DIR/description") @@ -82,6 +86,12 @@ case "$refname","$newrev_type" in ;; refs/tags/*,tag) # annotated tag + if [ "$allowmodifytag" != "true" ] && git rev-parse $refname > /dev/null 2>&1 + then + echo "*** Tag '$refname' already exists." >&2 + echo "*** Modifying a tag is not allowed in this repository." >&2 + exit 1 + fi ;; refs/heads/*,commit) # branch diff --git a/test-chmtime.c b/test-chmtime.c index d5358cbaac..fe476cb618 100644 --- a/test-chmtime.c +++ b/test-chmtime.c @@ -87,6 +87,15 @@ int main(int argc, const char *argv[]) return -1; } +#ifdef WIN32 + if (!(sb.st_mode & S_IWUSR) && + chmod(argv[i], sb.st_mode | S_IWUSR)) { + fprintf(stderr, "Could not make user-writable %s: %s", + argv[i], strerror(errno)); + return -1; + } +#endif + utb.actime = sb.st_atime; utb.modtime = set_eq ? set_time : sb.st_mtime + set_time; diff --git a/test-parse-options.c b/test-parse-options.c index 61d2c39814..efa734b42e 100644 --- a/test-parse-options.c +++ b/test-parse-options.c @@ -7,8 +7,9 @@ static unsigned long timestamp; static int abbrev = 7; static int verbose = 0, dry_run = 0, quiet = 0; static char *string = NULL; +static char *file = NULL; -int length_callback(const struct option *opt, const char *arg, int unset) +static int length_callback(const struct option *opt, const char *arg, int unset) { printf("Callback: \"%s\", %d\n", (arg ? arg : "not set"), unset); @@ -19,8 +20,15 @@ int length_callback(const struct option *opt, const char *arg, int unset) return 0; } +static int number_callback(const struct option *opt, const char *arg, int unset) +{ + *(int *)opt->value = strtol(arg, NULL, 10); + return 0; +} + int main(int argc, const char **argv) { + const char *prefix = "prefix/"; const char *usage[] = { "test-parse-options <options>", NULL @@ -29,6 +37,7 @@ int main(int argc, const char **argv) OPT_BOOLEAN('b', "boolean", &boolean, "get a boolean"), OPT_BIT('4', "or4", &boolean, "bitwise-or boolean with ...0100", 4), + OPT_NEGBIT(0, "neg-or4", &boolean, "same as --no-or4", 4), OPT_GROUP(""), OPT_INTEGER('i', "integer", &integer, "get a integer"), OPT_INTEGER('j', NULL, &integer, "get a integer, too"), @@ -36,6 +45,7 @@ int main(int argc, const char **argv) OPT_DATE('t', NULL, ×tamp, "get timestamp of <time>"), OPT_CALLBACK('L', "length", &integer, "str", "get length of <str>", length_callback), + OPT_FILENAME('F', "file", &file, "set file to <FILE>"), OPT_GROUP("String options"), OPT_STRING('s', "string", &string, "string", "get a string"), OPT_STRING(0, "string2", &string, "str", "get another string"), @@ -45,6 +55,10 @@ int main(int argc, const char **argv) "set string to default", (unsigned long)"default"), OPT_GROUP("Magic arguments"), OPT_ARGUMENT("quux", "means --quux"), + OPT_NUMBER_CALLBACK(&integer, "set integer to NUM", + number_callback), + { OPTION_BOOLEAN, '+', NULL, &boolean, NULL, "same as -b", + PARSE_OPT_NOARG | PARSE_OPT_NONEG | PARSE_OPT_NODASH }, OPT_GROUP("Standard options"), OPT__ABBREV(&abbrev), OPT__VERBOSE(&verbose), @@ -54,7 +68,7 @@ int main(int argc, const char **argv) }; int i; - argc = parse_options(argc, argv, options, usage, 0); + argc = parse_options(argc, argv, prefix, options, usage, 0); printf("boolean: %d\n", boolean); printf("integer: %u\n", integer); @@ -64,6 +78,7 @@ int main(int argc, const char **argv) printf("verbose: %d\n", verbose); printf("quiet: %s\n", quiet ? "yes" : "no"); printf("dry run: %s\n", dry_run ? "yes" : "no"); + printf("file: %s\n", file ? file : "(not set)"); for (i = 0; i < argc; i++) printf("arg %02d: %s\n", i, argv[i]); diff --git a/test-sha1.c b/test-sha1.c index 9b98d07c78..80daba980e 100644 --- a/test-sha1.c +++ b/test-sha1.c @@ -32,7 +32,7 @@ int main(int ac, char **av) if (sz == 0) break; if (sz < 0) - die("test-sha1: %s", strerror(errno)); + die_errno("test-sha1"); this_sz += sz; cp += sz; room -= sz; diff --git a/transport.c b/transport.c index efecb65258..f231b355f2 100644 --- a/transport.c +++ b/transport.c @@ -158,7 +158,7 @@ static struct ref *get_refs_via_rsync(struct transport *transport, int for_push) strbuf_addstr(&temp_dir, git_path("rsync-refs-XXXXXX")); if (!mkdtemp(temp_dir.buf)) - die ("Could not make temporary directory"); + die_errno ("Could not make temporary directory"); temp_dir_len = temp_dir.len; strbuf_addstr(&buf, rsync_url(transport->url)); @@ -321,7 +321,7 @@ static int rsync_transport_push(struct transport *transport, strbuf_addstr(&temp_dir, git_path("rsync-refs-XXXXXX")); if (!mkdtemp(temp_dir.buf)) - die ("Could not make temporary directory"); + die_errno ("Could not make temporary directory"); strbuf_addch(&temp_dir, '/'); if (flags & TRANSPORT_PUSH_ALL) { @@ -439,9 +439,7 @@ static struct ref *get_refs_via_curl(struct transport *transport, int for_push) char *ref_name; char *refs_url; int i = 0; - - struct active_request_slot *slot; - struct slot_results results; + int http_ret; struct ref *refs = NULL; struct ref *ref = NULL; @@ -461,25 +459,16 @@ static struct ref *get_refs_via_curl(struct transport *transport, int for_push) refs_url = xmalloc(strlen(transport->url) + 11); sprintf(refs_url, "%s/info/refs", transport->url); - slot = get_active_slot(); - slot->results = &results; - curl_easy_setopt(slot->curl, CURLOPT_FILE, &buffer); - curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_buffer); - curl_easy_setopt(slot->curl, CURLOPT_URL, refs_url); - curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, NULL); - - if (start_active_slot(slot)) { - run_active_slot(slot); - if (results.curl_result != CURLE_OK) { - strbuf_release(&buffer); - if (missing_target(&results)) - die("%s not found: did you run git update-server-info on the server?", refs_url); - else - die("%s download error - %s", refs_url, curl_errorstr); - } - } else { - strbuf_release(&buffer); - die("Unable to start HTTP request"); + http_ret = http_get_strbuf(refs_url, &buffer, HTTP_NO_CACHE); + switch (http_ret) { + case HTTP_OK: + break; + case HTTP_MISSING_TARGET: + die("%s not found: did you run git update-server-info on the" + " server?", refs_url); + default: + http_error(refs_url, http_ret); + die("HTTP request failed"); } data = buffer.buf; @@ -519,6 +508,8 @@ static struct ref *get_refs_via_curl(struct transport *transport, int for_push) free(ref); } + strbuf_release(&buffer); + free(refs_url); return refs; } @@ -728,19 +719,30 @@ static void update_tracking_ref(struct remote *remote, struct ref *ref, int verb #define SUMMARY_WIDTH (2 * DEFAULT_ABBREV + 3) -static void print_ref_status(char flag, const char *summary, struct ref *to, struct ref *from, const char *msg) +static void print_ref_status(char flag, const char *summary, struct ref *to, struct ref *from, const char *msg, int porcelain) { - fprintf(stderr, " %c %-*s ", flag, SUMMARY_WIDTH, summary); - if (from) - fprintf(stderr, "%s -> %s", prettify_ref(from), prettify_ref(to)); - else - fputs(prettify_ref(to), stderr); - if (msg) { - fputs(" (", stderr); - fputs(msg, stderr); - fputc(')', stderr); + if (porcelain) { + if (from) + fprintf(stdout, "%c\t%s:%s\t", flag, from->name, to->name); + else + fprintf(stdout, "%c\t:%s\t", flag, to->name); + if (msg) + fprintf(stdout, "%s (%s)\n", summary, msg); + else + fprintf(stdout, "%s\n", summary); + } else { + fprintf(stderr, " %c %-*s ", flag, SUMMARY_WIDTH, summary); + if (from) + fprintf(stderr, "%s -> %s", prettify_refname(from->name), prettify_refname(to->name)); + else + fputs(prettify_refname(to->name), stderr); + if (msg) { + fputs(" (", stderr); + fputs(msg, stderr); + fputc(')', stderr); + } + fputc('\n', stderr); } - fputc('\n', stderr); } static const char *status_abbrev(unsigned char sha1[20]) @@ -748,15 +750,15 @@ static const char *status_abbrev(unsigned char sha1[20]) return find_unique_abbrev(sha1, DEFAULT_ABBREV); } -static void print_ok_ref_status(struct ref *ref) +static void print_ok_ref_status(struct ref *ref, int porcelain) { if (ref->deletion) - print_ref_status('-', "[deleted]", ref, NULL, NULL); + print_ref_status('-', "[deleted]", ref, NULL, NULL, porcelain); else if (is_null_sha1(ref->old_sha1)) print_ref_status('*', (!prefixcmp(ref->name, "refs/tags/") ? "[new tag]" : - "[new branch]"), - ref, ref->peer_ref, NULL); + "[new branch]"), + ref, ref->peer_ref, NULL, porcelain); else { char quickref[84]; char type; @@ -774,50 +776,51 @@ static void print_ok_ref_status(struct ref *ref) } strcat(quickref, status_abbrev(ref->new_sha1)); - print_ref_status(type, quickref, ref, ref->peer_ref, msg); + print_ref_status(type, quickref, ref, ref->peer_ref, msg, porcelain); } } -static int print_one_push_status(struct ref *ref, const char *dest, int count) +static int print_one_push_status(struct ref *ref, const char *dest, int count, int porcelain) { if (!count) fprintf(stderr, "To %s\n", dest); switch(ref->status) { case REF_STATUS_NONE: - print_ref_status('X', "[no match]", ref, NULL, NULL); + print_ref_status('X', "[no match]", ref, NULL, NULL, porcelain); break; case REF_STATUS_REJECT_NODELETE: print_ref_status('!', "[rejected]", ref, NULL, - "remote does not support deleting refs"); + "remote does not support deleting refs", porcelain); break; case REF_STATUS_UPTODATE: print_ref_status('=', "[up to date]", ref, - ref->peer_ref, NULL); + ref->peer_ref, NULL, porcelain); break; case REF_STATUS_REJECT_NONFASTFORWARD: print_ref_status('!', "[rejected]", ref, ref->peer_ref, - "non-fast forward"); + "non-fast forward", porcelain); break; case REF_STATUS_REMOTE_REJECT: print_ref_status('!', "[remote rejected]", ref, - ref->deletion ? NULL : ref->peer_ref, - ref->remote_status); + ref->deletion ? NULL : ref->peer_ref, + ref->remote_status, porcelain); break; case REF_STATUS_EXPECTING_REPORT: print_ref_status('!', "[remote failure]", ref, - ref->deletion ? NULL : ref->peer_ref, - "remote failed to report status"); + ref->deletion ? NULL : ref->peer_ref, + "remote failed to report status", porcelain); break; case REF_STATUS_OK: - print_ok_ref_status(ref); + print_ok_ref_status(ref, porcelain); break; } return 1; } -static void print_push_status(const char *dest, struct ref *refs, int verbose) +static void print_push_status(const char *dest, struct ref *refs, + int verbose, int porcelain, int * nonfastforward) { struct ref *ref; int n = 0; @@ -825,18 +828,21 @@ static void print_push_status(const char *dest, struct ref *refs, int verbose) if (verbose) { for (ref = refs; ref; ref = ref->next) if (ref->status == REF_STATUS_UPTODATE) - n += print_one_push_status(ref, dest, n); + n += print_one_push_status(ref, dest, n, porcelain); } for (ref = refs; ref; ref = ref->next) if (ref->status == REF_STATUS_OK) - n += print_one_push_status(ref, dest, n); + n += print_one_push_status(ref, dest, n, porcelain); + *nonfastforward = 0; for (ref = refs; ref; ref = ref->next) { if (ref->status != REF_STATUS_NONE && ref->status != REF_STATUS_UPTODATE && ref->status != REF_STATUS_OK) - n += print_one_push_status(ref, dest, n); + n += print_one_push_status(ref, dest, n, porcelain); + if (ref->status == REF_STATUS_REJECT_NONFASTFORWARD) + *nonfastforward = 1; } } @@ -994,7 +1000,8 @@ int transport_set_option(struct transport *transport, } int transport_push(struct transport *transport, - int refspec_nr, const char **refspec, int flags) + int refspec_nr, const char **refspec, int flags, + int * nonfastforward) { verify_remote_names(refspec_nr, refspec); @@ -1003,10 +1010,10 @@ int transport_push(struct transport *transport, if (transport->push_refs) { struct ref *remote_refs = transport->get_refs_list(transport, 1); - struct ref **remote_tail; struct ref *local_refs = get_local_heads(); int match_flags = MATCH_REFS_NONE; int verbose = flags & TRANSPORT_PUSH_VERBOSE; + int porcelain = flags & TRANSPORT_PUSH_PORCELAIN; int ret; if (flags & TRANSPORT_PUSH_ALL) @@ -1014,17 +1021,14 @@ int transport_push(struct transport *transport, if (flags & TRANSPORT_PUSH_MIRROR) match_flags |= MATCH_REFS_MIRROR; - remote_tail = &remote_refs; - while (*remote_tail) - remote_tail = &((*remote_tail)->next); - if (match_refs(local_refs, remote_refs, &remote_tail, + if (match_refs(local_refs, &remote_refs, refspec_nr, refspec, match_flags)) { return -1; } ret = transport->push_refs(transport, remote_refs, flags); - print_push_status(transport->url, remote_refs, verbose); + print_push_status(transport->url, remote_refs, verbose | porcelain, porcelain, nonfastforward); if (!(flags & TRANSPORT_PUSH_DRY_RUN)) { struct ref *ref; @@ -1083,3 +1087,51 @@ int transport_disconnect(struct transport *transport) free(transport); return ret; } + +/* + * Strip username (and password) from an url and return + * it in a newly allocated string. + */ +char *transport_anonymize_url(const char *url) +{ + char *anon_url, *scheme_prefix, *anon_part; + size_t anon_len, prefix_len = 0; + + anon_part = strchr(url, '@'); + if (is_local(url) || !anon_part) + goto literal_copy; + + anon_len = strlen(++anon_part); + scheme_prefix = strstr(url, "://"); + if (!scheme_prefix) { + if (!strchr(anon_part, ':')) + /* cannot be "me@there:/path/name" */ + goto literal_copy; + } else { + const char *cp; + /* make sure scheme is reasonable */ + for (cp = url; cp < scheme_prefix; cp++) { + switch (*cp) { + /* RFC 1738 2.1 */ + case '+': case '.': case '-': + break; /* ok */ + default: + if (isalnum(*cp)) + break; + /* it isn't */ + goto literal_copy; + } + } + /* @ past the first slash does not count */ + cp = strchr(scheme_prefix + 3, '/'); + if (cp && cp < anon_part) + goto literal_copy; + prefix_len = scheme_prefix - url + 3; + } + anon_url = xcalloc(1, 1 + prefix_len + anon_len); + memcpy(anon_url, url, prefix_len); + memcpy(anon_url + prefix_len, anon_part, anon_len); + return anon_url; +literal_copy: + return xstrdup(url); +} diff --git a/transport.h b/transport.h index b1c2252766..639f13dcfe 100644 --- a/transport.h +++ b/transport.h @@ -35,6 +35,7 @@ struct transport { #define TRANSPORT_PUSH_DRY_RUN 4 #define TRANSPORT_PUSH_MIRROR 8 #define TRANSPORT_PUSH_VERBOSE 16 +#define TRANSPORT_PUSH_PORCELAIN 32 /* Returns a transport suitable for the url */ struct transport *transport_get(struct remote *, const char *); @@ -67,12 +68,14 @@ int transport_set_option(struct transport *transport, const char *name, const char *value); int transport_push(struct transport *connection, - int refspec_nr, const char **refspec, int flags); + int refspec_nr, const char **refspec, int flags, + int * nonfastforward); const struct ref *transport_get_remote_refs(struct transport *transport); int transport_fetch_refs(struct transport *transport, const struct ref *refs); void transport_unlock_pack(struct transport *transport); int transport_disconnect(struct transport *transport); +char *transport_anonymize_url(const char *url); #endif diff --git a/tree-diff.c b/tree-diff.c index edd83949bf..0459e54d3d 100644 --- a/tree-diff.c +++ b/tree-diff.c @@ -239,6 +239,12 @@ static void show_entry(struct diff_options *opt, const char *prefix, struct tree if (!tree || type != OBJ_TREE) die("corrupt tree sha %s", sha1_to_hex(sha1)); + if (DIFF_OPT_TST(opt, TREE_IN_RECURSIVE)) { + newbase[baselen + pathlen] = 0; + opt->add_remove(opt, *prefix, mode, sha1, newbase); + newbase[baselen + pathlen] = '/'; + } + init_tree_desc(&inner, tree, size); show_tree(opt, prefix, &inner, newbase, baselen + 1 + pathlen); diff --git a/unpack-file.c b/unpack-file.c index 75cd2f1a6a..ac9cbf7cd8 100644 --- a/unpack-file.c +++ b/unpack-file.c @@ -17,7 +17,7 @@ static char *create_temp_file(unsigned char *sha1) strcpy(path, ".merge_file_XXXXXX"); fd = xmkstemp(path); if (write_in_full(fd, buf, size) != size) - die("unable to write temp-file"); + die_errno("unable to write temp-file"); close(fd); return path; } diff --git a/unpack-trees.c b/unpack-trees.c index a0697d2412..720f7a1616 100644 --- a/unpack-trees.c +++ b/unpack-trees.c @@ -128,7 +128,7 @@ static inline int call_unpack_fn(struct cache_entry **src, struct unpack_trees_o static int unpack_index_entry(struct cache_entry *ce, struct unpack_trees_options *o) { - struct cache_entry *src[5] = { ce, }; + struct cache_entry *src[5] = { ce, NULL, }; o->pos++; if (ce_stage(ce)) { @@ -140,7 +140,7 @@ static int unpack_index_entry(struct cache_entry *ce, struct unpack_trees_option return call_unpack_fn(src, o); } -int traverse_trees_recursive(int n, unsigned long dirmask, unsigned long df_conflicts, struct name_entry *names, struct traverse_info *info) +static int traverse_trees_recursive(int n, unsigned long dirmask, unsigned long df_conflicts, struct name_entry *names, struct traverse_info *info) { int i; struct tree_desc t[MAX_UNPACK_TREES]; @@ -326,6 +326,23 @@ static int unpack_callback(int n, unsigned long mask, unsigned long dirmask, str if (src[0]) conflicts |= 1; } + + /* special case: "diff-index --cached" looking at a tree */ + if (o->diff_index_cached && + n == 1 && dirmask == 1 && S_ISDIR(names->mode)) { + int matches; + matches = cache_tree_matches_traversal(o->src_index->cache_tree, + names, info); + /* + * Everything under the name matches. Adjust o->pos to + * skip the entire hierarchy. + */ + if (matches) { + o->pos += matches; + return mask; + } + } + if (traverse_trees_recursive(n, dirmask, conflicts, names, info) < 0) return -1; @@ -534,7 +551,7 @@ static int verify_clean_subdirectory(struct cache_entry *ce, const char *action, memset(&d, 0, sizeof(d)); if (o->dir) d.exclude_per_dir = o->dir->exclude_per_dir; - i = read_directory(&d, ce->name, pathbuf, namelen+1, NULL); + i = read_directory(&d, pathbuf, namelen+1, NULL); if (i) return o->gently ? -1 : error(ERRORMSG(o, not_uptodate_dir), ce->name); @@ -987,7 +1004,7 @@ int oneway_merge(struct cache_entry **src, struct unpack_trees_options *o) if (old && same(old, a)) { int update = 0; - if (o->reset) { + if (o->reset && !ce_uptodate(old)) { struct stat st; if (lstat(old->name, &st) || ie_match_stat(o->src_index, old, &st, CE_MATCH_IGNORE_VALID)) diff --git a/unpack-trees.h b/unpack-trees.h index 0d26f3d73e..1e0e2325f1 100644 --- a/unpack-trees.h +++ b/unpack-trees.h @@ -27,6 +27,7 @@ struct unpack_trees_options { aggressive:1, skip_unmerged:1, initial_checkout:1, + diff_index_cached:1, gently:1; const char *prefix; int pos; diff --git a/upload-pack.c b/upload-pack.c index edc7861228..841ebb534a 100644 --- a/upload-pack.c +++ b/upload-pack.c @@ -28,7 +28,7 @@ static unsigned long oldest_have; static int multi_ack, nr_our_refs; static int use_thin_pack, use_ofs_delta, use_include_tag; -static int no_progress; +static int no_progress, daemon_mode; static struct object_array have_obj; static struct object_array want_obj; static unsigned int timeout; @@ -521,6 +521,10 @@ static void receive_needs(void) } if (debug_fd) write_in_full(debug_fd, "#E\n", 3); + + if (!use_sideband && daemon_mode) + no_progress = 1; + if (depth == 0 && shallows.nr == 0) return; if (depth > 0) { @@ -630,6 +634,7 @@ int main(int argc, char **argv) } if (!prefixcmp(arg, "--timeout=")) { timeout = atoi(arg+10); + daemon_mode = 1; continue; } if (!strcmp(arg, "--")) { @@ -60,6 +60,34 @@ void die(const char *err, ...) va_end(params); } +void die_errno(const char *fmt, ...) +{ + va_list params; + char fmt_with_err[1024]; + char str_error[256], *err; + int i, j; + + err = strerror(errno); + for (i = j = 0; err[i] && j < sizeof(str_error) - 1; ) { + if ((str_error[j++] = err[i++]) != '%') + continue; + if (j < sizeof(str_error) - 1) { + str_error[j++] = '%'; + } else { + /* No room to double the '%', so we overwrite it with + * '\0' below */ + j--; + break; + } + } + str_error[j] = 0; + snprintf(fmt_with_err, sizeof(fmt_with_err), "%s: %s", fmt, str_error); + + va_start(params, fmt); + die_routine(fmt_with_err, params); + va_end(params); +} + int error(const char *err, ...) { va_list params; @@ -354,7 +354,7 @@ int is_encoding_utf8(const char *name) * with iconv. If the conversion fails, returns NULL. */ #ifndef NO_ICONV -#ifdef OLD_ICONV +#if defined(OLD_ICONV) || (defined(__sun__) && !defined(_XPG6)) typedef const char * iconv_ibp; #else typedef char * iconv_ibp; @@ -245,7 +245,7 @@ void walker_targets_free(int targets, char **target, const char **write_ref) { while (targets--) { free(target[targets]); - if (write_ref && write_ref[targets]) + if (write_ref) free((char *) write_ref[targets]); } } @@ -96,7 +96,7 @@ void *xmmap(void *start, size_t length, release_pack_memory(length, fd); ret = mmap(start, length, prot, flags, fd, offset); if (ret == MAP_FAILED) - die("Out of memory? mmap failed: %s", strerror(errno)); + die_errno("Out of memory? mmap failed"); } return ret; } @@ -175,7 +175,7 @@ int xdup(int fd) { int ret = dup(fd); if (ret < 0) - die("dup failed: %s", strerror(errno)); + die_errno("dup failed"); return ret; } @@ -183,7 +183,7 @@ FILE *xfdopen(int fd, const char *mode) { FILE *stream = fdopen(fd, mode); if (stream == NULL) - die("Out of memory? fdopen failed: %s", strerror(errno)); + die_errno("Out of memory? fdopen failed"); return stream; } @@ -193,7 +193,7 @@ int xmkstemp(char *template) fd = mkstemp(template); if (fd < 0) - die("Unable to create temporary file: %s", strerror(errno)); + die_errno("Unable to create temporary file"); return fd; } diff --git a/write_or_die.c b/write_or_die.c index 4c29255df1..d45b536021 100644 --- a/write_or_die.c +++ b/write_or_die.c @@ -41,14 +41,14 @@ void maybe_flush_or_die(FILE *f, const char *desc) */ if (errno == EPIPE || errno == EINVAL) exit(0); - die("write failure on %s: %s", desc, strerror(errno)); + die_errno("write failure on '%s'", desc); } } void fsync_or_die(int fd, const char *msg) { if (fsync(fd) < 0) { - die("%s: fsync error (%s)", msg, strerror(errno)); + die_errno("fsync error on '%s'", msg); } } @@ -57,7 +57,7 @@ void write_or_die(int fd, const void *buf, size_t count) if (write_in_full(fd, buf, count) < 0) { if (errno == EPIPE) exit(0); - die("write error (%s)", strerror(errno)); + die_errno("write error"); } } diff --git a/wt-status.c b/wt-status.c index 1b6df45450..47735d8129 100644 --- a/wt-status.c +++ b/wt-status.c @@ -13,7 +13,7 @@ int wt_status_relative_paths = 1; int wt_status_use_color = -1; -int wt_status_submodule_summary; +static int wt_status_submodule_summary; static char wt_status_colors[][COLOR_MAXLEN] = { GIT_COLOR_NORMAL, /* WT_STATUS_HEADER */ GIT_COLOR_GREEN, /* WT_STATUS_UPDATED */ @@ -255,7 +255,7 @@ static void wt_status_print_untracked(struct wt_status *s) DIR_SHOW_OTHER_DIRECTORIES | DIR_HIDE_EMPTY_DIRECTORIES; setup_standard_excludes(&dir); - read_directory(&dir, ".", "", 0, NULL); + fill_directory(&dir, NULL); for(i = 0; i < dir.nr; i++) { struct dir_entry *ent = dir.entries[i]; if (!cache_name_is_other(ent->name, ent->len)) diff --git a/xdiff-interface.c b/xdiff-interface.c index b9b0db8d86..01f14fb50f 100644 --- a/xdiff-interface.c +++ b/xdiff-interface.c @@ -309,6 +309,21 @@ void xdiff_set_find_func(xdemitconf_t *xecfg, const char *value, int cflags) } } +void xdiff_clear_find_func(xdemitconf_t *xecfg) +{ + if (xecfg->find_func) { + int i; + struct ff_regs *regs = xecfg->find_func_priv; + + for (i = 0; i < regs->nr; i++) + regfree(®s->array[i].re); + free(regs->array); + free(regs); + xecfg->find_func = NULL; + xecfg->find_func_priv = NULL; + } +} + int git_xmerge_style = -1; int git_xmerge_config(const char *var, const char *value, void *cb) diff --git a/xdiff-interface.h b/xdiff-interface.h index 7352b9a9c2..55572c39a1 100644 --- a/xdiff-interface.h +++ b/xdiff-interface.h @@ -21,6 +21,7 @@ int read_mmfile(mmfile_t *ptr, const char *filename); int buffer_is_binary(const char *ptr, unsigned long size); extern void xdiff_set_find_func(xdemitconf_t *xecfg, const char *line, int cflags); +extern void xdiff_clear_find_func(xdemitconf_t *xecfg); extern int git_xmerge_config(const char *var, const char *value, void *cb); extern int git_xmerge_style; diff --git a/xdiff/xdiffi.c b/xdiff/xdiffi.c index 1ebab687f7..da67c04357 100644 --- a/xdiff/xdiffi.c +++ b/xdiff/xdiffi.c @@ -26,7 +26,7 @@ #define XDL_MAX_COST_MIN 256 #define XDL_HEUR_MIN_COST 256 -#define XDL_LINE_MAX (long)((1UL << (8 * sizeof(long) - 1)) - 1) +#define XDL_LINE_MAX (long)((1UL << (CHAR_BIT * sizeof(long) - 1)) - 1) #define XDL_SNAKE_CNT 20 #define XDL_K_HEUR 4 |