Code

Merge branch 'db/host-alias'
authorJunio C Hamano <gitster@pobox.com>
Wed, 27 Feb 2008 19:54:13 +0000 (11:54 -0800)
committerJunio C Hamano <gitster@pobox.com>
Wed, 27 Feb 2008 19:54:13 +0000 (11:54 -0800)
* db/host-alias:
  url rewriting: take longest and first match
  Add support for url aliases in config files
  Use ALLOC_GROW in remote.{c,h}

116 files changed:
Documentation/RelNotes-1.5.4.3.txt [new file with mode: 0644]
Documentation/config.txt
Documentation/git-add.txt
Documentation/git-am.txt
Documentation/git-bundle.txt
Documentation/git-describe.txt
Documentation/git-filter-branch.txt
Documentation/git-grep.txt
Documentation/git-merge-index.txt
Documentation/git-pack-objects.txt
Documentation/git-pull.txt
Documentation/git-push.txt
Documentation/git-rev-list.txt
Documentation/git-stash.txt
Documentation/git.txt
Documentation/rev-list-options.txt
Documentation/technical/api-remote.txt [new file with mode: 0644]
Documentation/technical/api-run-command.txt
GIT-VERSION-GEN
Makefile
builtin-add.c
builtin-apply.c
builtin-blame.c
builtin-branch.c
builtin-clean.c
builtin-commit.c
builtin-describe.c
builtin-diff.c
builtin-fast-export.c
builtin-fmt-merge-msg.c
builtin-for-each-ref.c
builtin-grep.c
builtin-init-db.c
builtin-log.c
builtin-ls-files.c
builtin-mv.c
builtin-pack-objects.c
builtin-push.c
builtin-read-tree.c
builtin-reflog.c
builtin-rerere.c
builtin-rev-list.c
builtin-rev-parse.c
builtin-shortlog.c
builtin-show-ref.c
builtin-tag.c
bundle.c
cache.h
color.c
color.h
commit.c
compat/fopen.c [new file with mode: 0644]
config.c
contrib/completion/git-completion.bash
contrib/emacs/git.el
copy.c
date.c
diff.c
diff.h
git-add--interactive.perl
git-bisect.sh
git-checkout.sh
git-clone.sh
git-compat-util.h
git-cvsexportcommit.perl
git-gui/Makefile
git-gui/git-gui.sh
git-gui/lib/choose_repository.tcl
git-gui/lib/error.tcl
git-pull.sh
git-send-email.perl
git-sh-setup.sh
git.spec.in
gitweb/README
gitweb/gitweb.perl
hash.c
help.c
http-push.c
list-objects.c
log-tree.c
merge-index.c
merge-recursive.c
pager.c
pretty.c
reachable.c
read-cache.c
refs.c
revision.c
revision.h
setup.c
sha1_file.c
sha1_name.c
shallow.c
strbuf.c
strbuf.h
t/t0050-filesystem.sh [new file with mode: 0755]
t/t1502-rev-parse-parseopt.sh [new file with mode: 0755]
t/t3404-rebase-interactive.sh
t/t3701-add-interactive.sh [new file with mode: 0755]
t/t4019-diff-wserror.sh
t/t4105-apply-fuzz.sh [new file with mode: 0755]
t/t4125-apply-ws-fuzz.sh [new file with mode: 0755]
t/t5701-clone-local.sh
t/t7001-mv.sh
t/t7010-setup.sh [new file with mode: 0755]
t/t7104-reset.sh [new file with mode: 0755]
t/t7300-clean.sh
t/t9001-send-email.sh
t/t9200-git-cvsexportcommit.sh
tag.c
thread-utils.c [new file with mode: 0644]
thread-utils.h [new file with mode: 0644]
unpack-trees.c
upload-pack.c
ws.c
wt-status.c

diff --git a/Documentation/RelNotes-1.5.4.3.txt b/Documentation/RelNotes-1.5.4.3.txt
new file mode 100644 (file)
index 0000000..b0fc67f
--- /dev/null
@@ -0,0 +1,27 @@
+GIT v1.5.4.3 Release Notes
+==========================
+
+Fixes since v1.5.4.2
+--------------------
+
+ * RPM spec used to pull in everything with 'git'.  This has been
+   changed so that 'git' package contains just the core parts,
+   and we now supply 'git-all' metapackage to slurp in everything.
+   This should match end user's expectation better.
+
+ * When some refs failed to update, git-push reported "failure"
+   which was unclear if some other refs were updated or all of
+   them failed atomically (the answer is the former).  Reworded
+   the message to clarify this.
+
+ * "git clone" from a repository whose HEAD was misconfigured
+   did not set up the remote properly.  Now it tries to do
+   better.
+
+ * Updated git-push documentation to clarify what "matching"
+   means, in order to reduce user confusion.
+
+ * Updated git-add documentation to clarify "add -u" operates in
+   the current subdirectory you are in, just like other commands.
+
+ * git-gui updates to work on OSX and Windows better.
index 57b9b998639d509e0d092fa860ba1eaeee688c76..8e361a1e771a7b3537c63bf1b9fc4cee63141a8d 100644 (file)
@@ -353,6 +353,10 @@ core.whitespace::
   error (enabled by default).
 * `indent-with-non-tab` treats a line that is indented with 8 or more
   space characters as an error (not enabled by default).
+* `cr-at-eol` treats a carriage-return at the end of line as
+  part of the line terminator, i.e. with it, `trailing-space`
+  does not trigger if the character before such a carriage-return
+  is not a whitespace (not enabled by default).
 
 alias.*::
        Command aliases for the linkgit:git[1] command wrapper - e.g.
@@ -489,6 +493,13 @@ color.status.<slot>::
 commit.template::
        Specify a file to use as the template for new commit messages.
 
+color.ui::
+       When set to `always`, always use colors in all git commands which
+       are capable of colored output. When false (or `never`), never. When
+       set to `true` or `auto`, use colors only when the output is to the
+       terminal. When more specific variables of color.* are set, they always
+       take precedence over this setting. Defaults to false.
+
 diff.autorefreshindex::
        When using `git diff` to compare with work tree
        files, do not consider stat-only change as changed.
@@ -801,6 +812,8 @@ pack.threads::
        warning. This is meant to reduce packing time on multiprocessor
        machines. The required amount of memory for the delta search window
        is however multiplied by the number of threads.
+       Specifying 0 will cause git to auto-detect the number of CPU's
+       and set the number of threads accordingly.
 
 pack.indexVersion::
        Specify the default pack index version.  Valid values are 1 for
index 9d2ac865d29164dd594c801dd42e3492128f7b91..47799097ce97da34fac60eafabd25576e077e362 100644 (file)
@@ -74,8 +74,8 @@ OPTIONS
        Update only files that git already knows about. This is similar
        to what "git commit -a" does in preparation for making a commit,
        except that the update is limited to paths specified on the
-       command line. If no paths are specified, all tracked files are
-       updated.
+       command line. If no paths are specified, all tracked files in the
+       current directory and its subdirectories are updated.
 
 \--refresh::
        Don't add the file(s), but only refresh their stat()
index 2ffba2102b1c2a7dbd093fed89a15b2e644aa398..e640fc75cd3c463370f62b623a4060b014d9371a 100644 (file)
@@ -138,7 +138,7 @@ aborts in the middle,.  You can recover from this in one of two ways:
 
 The command refuses to process new mailboxes while `.dotest`
 directory exists, so if you decide to start over from scratch,
-run `rm -f .dotest` before running the command with mailbox
+run `rm -f -r .dotest` before running the command with mailbox
 names.
 
 
index 72f080a9728e076de21c19e77fc760a038e9885e..505ac056e6586e0b4b19e5a8bbbb4bef86b6faf0 100644 (file)
@@ -99,36 +99,62 @@ Assume two repositories exist as R1 on machine A, and R2 on machine B.
 For whatever reason, direct connection between A and B is not allowed,
 but we can move data from A to B via some mechanism (CD, email, etc).
 We want to update R2 with developments made on branch master in R1.
+
+To create the bundle you have to specify the basis. You have some options:
+
+- Without basis.
++
+This is useful when sending the whole history.
+
+------------
+$ git bundle create mybundle master
+------------
+
+- Using temporally tags.
++
 We set a tag in R1 (lastR2bundle) after the previous such transport,
 and move it afterwards to help build the bundle.
 
-in R1 on A:
-
 ------------
 $ git-bundle create mybundle master ^lastR2bundle
 $ git tag -f lastR2bundle master
 ------------
 
-(move mybundle from A to B by some mechanism)
+- Using a tag present in both repositories
+
+------------
+$ git bundle create mybundle master ^v1.0.0
+------------
+
+- A basis based on time.
+
+------------
+$ git bundle create mybundle master --since=10.days.ago
+------------
 
-in R2 on B:
+- With a limit on the number of commits
 
 ------------
-$ git-bundle verify mybundle
-$ git-fetch mybundle  refspec
+$ git bundle create mybundle master -n 10
 ------------
 
-where refspec is refInBundle:localRef
+Then you move mybundle from A to B, and in R2 on B:
 
+------------
+$ git-bundle verify mybundle
+$ git-fetch mybundle master:localRef
+------------
 
-Also, with something like this in your config:
+With something like this in the config in R2:
 
+------------------------
 [remote "bundle"]
     url = /home/me/tmp/file.bdl
     fetch = refs/heads/*:refs/remotes/origin/*
+------------------------
 
 You can first sneakernet the bundle file to ~/tmp/file.bdl and
-then these commands:
+then these commands on machine B:
 
 ------------
 $ git ls-remote bundle
index 1c3dfb40c63350651efb570ed540b69c34ccbc81..fbb40a29165a47e627358b5b9f8afb50e84958cd 100644 (file)
@@ -45,6 +45,11 @@ OPTIONS
        candidates to describe the input committish consider
        up to <n> candidates.  Increasing <n> above 10 will take
        slightly longer but may produce a more accurate result.
+       An <n> of 0 will cause only exact matches to be output.
+
+--exact-match::
+       Only output exact matches (a tag directly references the
+       supplied commit).  This is a synonym for --candidates=0.
 
 --debug::
        Verbosely display information about the searching strategy
index e22dfa580383c0a7af00d9d56e01a1869fb6ce75..543a1cf105b6df5953e529ecb4f9f88db273164f 100644 (file)
@@ -56,7 +56,9 @@ notable exception of the commit filter, for technical reasons).
 Prior to that, the $GIT_COMMIT environment variable will be set to contain
 the id of the commit being rewritten.  Also, GIT_AUTHOR_NAME,
 GIT_AUTHOR_EMAIL, GIT_AUTHOR_DATE, GIT_COMMITTER_NAME, GIT_COMMITTER_EMAIL,
-and GIT_COMMITTER_DATE are set according to the current commit.
+and GIT_COMMITTER_DATE are set according to the current commit. If any
+evaluation of <command> returns a non-zero exit status, the whole operation
+will be aborted.
 
 A 'map' function is available that takes an "original sha1 id" argument
 and outputs a "rewritten sha1 id" if the commit has been already
@@ -197,7 +199,7 @@ happened).  If this is not the case, use:
 
 --------------------------------------------------------------------------
 git filter-branch --parent-filter \
-       'cat; test $GIT_COMMIT = <commit-id> && echo "-p <graft-id>"' HEAD
+       'test $GIT_COMMIT = <commit-id> && echo "-p <graft-id>" || cat' HEAD
 --------------------------------------------------------------------------
 
 or even simpler:
@@ -240,6 +242,15 @@ committed a merge between P1 and P2, it will be propagated properly
 and all children of the merge will become merge commits with P1,P2
 as their parents instead of the merge commit.
 
+You can rewrite the commit log messages using `--message-filter`.  For
+example, `git-svn-id` strings in a repository created by `git-svn` can
+be removed this way:
+
+-------------------------------------------------------
+git filter-branch --message-filter '
+       sed -e "/^git-svn-id:/d"
+'
+-------------------------------------------------------
 
 To restrict rewriting to only part of the history, specify a revision
 range in addition to the new branch name.  The new branch name will
index f3cb24f252e2091d4d2f346b61ce87088fa7b02e..71a73354f8cfa960f641d9563ee8af405b4f881f 100644 (file)
@@ -75,9 +75,11 @@ OPTIONS
 -n::
        Prefix the line number to matching lines.
 
--l | --files-with-matches | -L | --files-without-match::
+-l | --files-with-matches | --name-only | -L | --files-without-match::
        Instead of showing every matched line, show only the
        names of files that contain (or do not contain) matches.
+       For better compatability with git-diff, --name-only is a
+       synonym for --files-with-matches.
 
 -c | --count::
        Instead of showing every matched line, show the number of
index 5d816d0d8b02222517cd4bf320dc3d345fb8d94b..19ee017aede4bf8fa0a0046b2bf347e3d75c4a12 100644 (file)
@@ -8,7 +8,7 @@ git-merge-index - Run a merge for files needing merging
 
 SYNOPSIS
 --------
-'git-merge-index' [-o] [-q] <merge-program> (-a | \-- | <file>\*)
+'git-merge-index' [-o] [-q] <merge-program> (-a | [--] <file>\*)
 
 DESCRIPTION
 -----------
index 8353be186fcc83092acac16b4fc164d6ea669621..5c1bd3b0813a95ee0c1831a2e10f5512a9330793 100644 (file)
@@ -177,6 +177,8 @@ base-name::
        This is meant to reduce packing time on multiprocessor machines.
        The required amount of memory for the delta search window is
        however multiplied by the number of threads.
+       Specifying 0 will cause git to auto-detect the number of CPU's
+       and set the number of threads accordingly.
 
 --index-version=<version>[,<offset>]::
        This is intended to be used by the test suite only. It allows
index 179bdfc69ddfeff9d272ec309721e4098f3b051e..737894390d8033bf470b3bfe3aeade858f38717e 100644 (file)
@@ -15,6 +15,7 @@ DESCRIPTION
 -----------
 Runs `git-fetch` with the given parameters, and calls `git-merge`
 to merge the retrieved head(s) into the current branch.
+With `--rebase`, calls `git-rebase` instead of `git-merge`.
 
 Note that you can use `.` (current directory) as the
 <repository> to pull from the local repository -- this is useful
@@ -26,19 +27,14 @@ OPTIONS
 include::merge-options.txt[]
 
 :git-pull: 1
-include::fetch-options.txt[]
-
-include::pull-fetch-param.txt[]
-
-include::urls-remotes.txt[]
-
-include::merge-strategies.txt[]
 
 \--rebase::
        Instead of a merge, perform a rebase after fetching.  If
        there is a remote ref for the upstream branch, and this branch
        was rebased since last fetched, the rebase uses that information
-       to avoid rebasing non-local changes.
+       to avoid rebasing non-local changes. To make this the default
+       for branch `<name>`, set configuration `branch.<name>.rebase`
+       to `true`.
 +
 *NOTE:* This is a potentially _dangerous_ mode of operation.
 It rewrites history, which does not bode well when you
@@ -48,6 +44,14 @@ unless you have read linkgit:git-rebase[1] carefully.
 \--no-rebase::
        Override earlier \--rebase.
 
+include::fetch-options.txt[]
+
+include::pull-fetch-param.txt[]
+
+include::urls-remotes.txt[]
+
+include::merge-strategies.txt[]
+
 DEFAULT BEHAVIOUR
 -----------------
 
index 5f2494495bcec47d0de2daf109d46ec3c76cd912..3128170bcd1c3e3eb5981ed4c2f35221dfb06658 100644 (file)
@@ -47,9 +47,9 @@ even if it does not result in a fast forward update.
 +
 Note: If no explicit refspec is found, (that is neither
 on the command line nor in any Push line of the
-corresponding remotes file---see below), then all the
-heads that exist both on the local side and on the remote
-side are updated.
+corresponding remotes file---see below), then "matching" heads are
+pushed: for every head that exists on the local side, the remote side is
+updated if a head of the same name already exists on the remote side.
 +
 `tag <tag>` means the same as `refs/tags/<tag>:refs/tags/<tag>`.
 +
@@ -108,6 +108,55 @@ the remote repository.
 
 include::urls-remotes.txt[]
 
+OUTPUT
+------
+
+The output of "git push" depends on the transport method used; this
+section describes the output when pushing over the git protocol (either
+locally or via ssh).
+
+The status of the push is output in tabular form, with each line
+representing the status of a single ref. Each line is of the form:
+
+-------------------------------
+ <flag> <summary> <from> -> <to> (<reason>)
+-------------------------------
+
+flag::
+       A single character indicating the status of the ref. This is
+       blank for a successfully pushed ref, `!` for a ref that was
+       rejected or failed to push, and '=' for a ref that was up to
+       date and did not need pushing (note that the status of up to
+       date refs is shown only when `git push` is running verbosely).
+
+summary::
+       For a successfully pushed ref, the summary shows the old and new
+       values of the ref in a form suitable for using as an argument to
+       `git log` (this is `<old>..<new>` in most cases, and
+       `<old>...<new>` for forced non-fast forward updates). For a
+       failed update, more details are given for the failure.
+       The string `rejected` indicates that git did not try to send the
+       ref at all (typically because it is not a fast forward). The
+       string `remote rejected` indicates that the remote end refused
+       the update; this rejection is typically caused by a hook on the
+       remote side. The string `remote failure` indicates that the
+       remote end did not report the successful update of the ref
+       (perhaps because of a temporary error on the remote side, a
+       break in the network connection, or other transient error).
+
+from::
+       The name of the local ref being pushed, minus its
+       `refs/<type>/` prefix. In the case of deletion, the
+       name of the local ref is omitted.
+
+to::
+       The name of the remote ref being updated, minus its
+       `refs/<type>/` prefix.
+
+reason::
+       A human-readable explanation. In the case of successfully pushed
+       refs, no explanation is needed. For a failed ref, the reason for
+       failure is described.
 
 Examples
 --------
index 5b96eabfce9eecbfccaff16096c616105a040c3d..a8d489f9f29034d732a67375b617f3315109aa05 100644 (file)
@@ -31,6 +31,7 @@ SYNOPSIS
             [ \--(author|committer|grep)=<pattern> ]
             [ \--regexp-ignore-case | \-i ]
             [ \--extended-regexp | \-E ]
+            [ \--fixed-strings | \-F ]
             [ \--date={local|relative|default|iso|rfc|short} ]
             [ [\--objects | \--objects-edge] [ \--unpacked ] ]
             [ \--pretty | \--header ]
index cd0dc1bd9d53282d65c52e6b9ded6d40fe087598..48e6f5a3f7a85e886639381dfa70434ecdeccfc2 100644 (file)
@@ -43,7 +43,7 @@ save [<message>]::
        subcommand is given. The <message> part is optional and gives
        the description along with the stashed state.
 
-list::
+list [<options>]::
 
        List the stashes that you currently have.  Each 'stash' is listed
        with its name (e.g. `stash@\{0}` is the latest stash, `stash@\{1}` is
@@ -55,6 +55,9 @@ list::
 stash@{0}: WIP on submit: 6ebd0e2... Update git-stash documentation
 stash@{1}: On master: 9cc0589... Add git-stash
 ----------------------------------------------------------------
++
+The command takes options applicable to the linkgit:git-log[1]
+command to control what is shown and how.
 
 show [<stash>]::
 
index d57bed618fa6be93be64c19a9f6d8a6bc51a5d49..741ae0e4c8ec9a3aaaef19430b0f76e4baedb546 100644 (file)
@@ -43,9 +43,10 @@ unreleased) version of git, that is available from 'master'
 branch of the `git.git` repository.
 Documentation for older releases are available here:
 
-* link:v1.5.4.2/git.html[documentation for release 1.5.4.2]
+* link:v1.5.4.3/git.html[documentation for release 1.5.4.3]
 
 * release notes for
+  link:RelNotes-1.5.4.3.txt[1.5.4.3],
   link:RelNotes-1.5.4.2.txt[1.5.4.2],
   link:RelNotes-1.5.4.1.txt[1.5.4.1],
   link:RelNotes-1.5.4.txt[1.5.4].
index a8138e27a1a10fb0c93608af149ef22323ba9dc5..259072c07883cf15db4162737a63a6506b7443b4 100644 (file)
@@ -153,6 +153,11 @@ limiting may be applied.
        Consider the limiting patterns to be extended regular expressions
        instead of the default basic regular expressions.
 
+-F, --fixed-strings::
+
+       Consider the limiting patterns to be fixed strings (don't interpret
+       pattern as a regular expression).
+
 --remove-empty::
 
        Stop when a given path disappears from the tree.
diff --git a/Documentation/technical/api-remote.txt b/Documentation/technical/api-remote.txt
new file mode 100644 (file)
index 0000000..073b22b
--- /dev/null
@@ -0,0 +1,123 @@
+Remotes configuration API
+=========================
+
+The API in remote.h gives access to the configuration related to
+remotes. It handles all three configuration mechanisms historically
+and currently used by git, and presents the information in a uniform
+fashion. Note that the code also handles plain URLs without any
+configuration, giving them just the default information.
+
+struct remote
+-------------
+
+`name`::
+
+       The user's nickname for the remote
+
+`url`::
+
+       An array of all of the url_nr URLs configured for the remote
+
+`push`::
+
+        An array of refspecs configured for pushing, with
+        push_refspec being the literal strings, and push_refspec_nr
+        being the quantity.
+
+`fetch`::
+
+       An array of refspecs configured for fetching, with
+       fetch_refspec being the literal strings, and fetch_refspec_nr
+       being the quantity.
+
+`fetch_tags`::
+
+       The setting for whether to fetch tags (as a separate rule from
+       the configured refspecs); -1 means never to fetch tags, 0
+       means to auto-follow tags based on the default heuristic, 1
+       means to always auto-follow tags, and 2 means to fetch all
+       tags.
+
+`receivepack`, `uploadpack`::
+
+       The configured helper programs to run on the remote side, for
+       git-native protocols.
+
+`http_proxy`::
+
+       The proxy to use for curl (http, https, ftp, etc.) URLs.
+
+struct remotes can be found by name with remote_get(), and iterated
+through with for_each_remote(). remote_get(NULL) will return the
+default remote, given the current branch and configuration.
+
+struct refspec
+--------------
+
+A struct refspec holds the parsed interpretation of a refspec. If it
+will force updates (starts with a '+'), force is true. If it is a
+pattern (sides end with '*') pattern is true. src and dest are the two
+sides (if a pattern, only the part outside of the wildcards); if there
+is only one side, it is src, and dst is NULL; if sides exist but are
+empty (i.e., the refspec either starts or ends with ':'), the
+corresponding side is "".
+
+This parsing can be done to an array of strings to give an array of
+struct refpsecs with parse_ref_spec().
+
+remote_find_tracking(), given a remote and a struct refspec with
+either src or dst filled out, will fill out the other such that the
+result is in the "fetch" specification for the remote (note that this
+evaluates patterns and returns a single result).
+
+struct branch
+-------------
+
+Note that this may end up moving to branch.h
+
+struct branch holds the configuration for a branch. It can be looked
+up with branch_get(name) for "refs/heads/{name}", or with
+branch_get(NULL) for HEAD.
+
+It contains:
+
+`name`::
+
+       The short name of the branch.
+
+`refname`::
+
+       The full path for the branch ref.
+
+`remote_name`::
+
+       The name of the remote listed in the configuration.
+
+`remote`::
+
+       The struct remote for that remote.
+
+`merge_name`::
+
+       An array of the "merge" lines in the configuration.
+
+`merge`::
+
+       An array of the struct refspecs used for the merge lines. That
+       is, merge[i]->dst is a local tracking ref which should be
+       merged into this branch by default.
+
+`merge_nr`::
+
+       The number of merge configurations
+
+branch_has_merge_config() returns true if the given branch has merge
+configuration given.
+
+Other stuff
+-----------
+
+There is other stuff in remote.h that is related, in general, to the
+process of interacting with remotes.
+
+(Daniel Barkalow)
index 19d2f64f73f34b12c6fdb954174b33946562b304..dfbf9ac5d06e32a7961afdd08910df6eccb912c7 100644 (file)
 run-command API
 ===============
 
-Talk about <run-command.h>, and things like:
+The run-command API offers a versatile tool to run sub-processes with
+redirected input and output as well as with a modified environment
+and an alternate current directory.
 
-* Environment the command runs with (e.g. GIT_DIR);
-* File descriptors and pipes;
-* Exit status;
+A similar API offers the capability to run a function asynchronously,
+which is primarily used to capture the output that the function
+produces in the caller in order to process it.
 
-(Hannes, Dscho, Shawn)
+
+Functions
+---------
+
+`start_command`::
+
+       Start a sub-process. Takes a pointer to a `struct child_process`
+       that specifies the details and returns pipe FDs (if requested).
+       See below for details.
+
+`finish_command`::
+
+       Wait for the completion of a sub-process that was started with
+       start_command().
+
+`run_command`::
+
+       A convenience function that encapsulates a sequence of
+       start_command() followed by finish_command(). Takes a pointer
+       to a `struct child_process` that specifies the details.
+
+`run_command_v_opt`, `run_command_v_opt_dir`, `run_command_v_opt_cd_env`::
+
+       Convenience functions that encapsulate a sequence of
+       start_command() followed by finish_command(). The argument argv
+       specifies the program and its arguments. The argument opt is zero
+       or more of the flags `RUN_COMMAND_NO_STDIN`, `RUN_GIT_CMD`, or
+       `RUN_COMMAND_STDOUT_TO_STDERR` that correspond to the members
+       .no_stdin, .git_cmd, .stdout_to_stderr of `struct child_process`.
+       The argument dir corresponds the member .dir. The argument env
+       corresponds to the member .env.
+
+`start_async`::
+
+       Run a function asynchronously. Takes a pointer to a `struct
+       async` that specifies the details and returns a pipe FD
+       from which the caller reads. See below for details.
+
+`finish_async`::
+
+       Wait for the completeion of an asynchronous function that was
+       started with start_async().
+
+
+Data structures
+---------------
+
+* `struct child_process`
+
+This describes the arguments, redirections, and environment of a
+command to run in a sub-process.
+
+The caller:
+
+1. allocates and clears (memset(&chld, '0', sizeof(chld));) a
+   struct child_process variable;
+2. initializes the members;
+3. calls start_command();
+4. processes the data;
+5. closes file descriptors (if necessary; see below);
+6. calls finish_command().
+
+The .argv member is set up as an array of string pointers (NULL
+terminated), of which .argv[0] is the program name to run (usually
+without a path). If the command to run is a git command, set argv[0] to
+the command name without the 'git-' prefix and set .git_cmd = 1.
+
+The members .in, .out, .err are used to redirect stdin, stdout,
+stderr as follows:
+
+. Specify 0 to request no special redirection. No new file descriptor
+  is allocated. The child process simply inherits the channel from the
+  parent.
+
+. Specify -1 to have a pipe allocated; start_command() replaces -1
+  by the pipe FD in the following way:
+
+       .in: Returns the writable pipe end into which the caller writes;
+               the readable end of the pipe becomes the child's stdin.
+
+       .out, .err: Returns the readable pipe end from which the caller
+               reads; the writable end of the pipe end becomes child's
+               stdout/stderr.
+
+  The caller of start_command() must close the so returned FDs
+  after it has completed reading from/writing to it!
+
+. Specify a file descriptor > 0 to be used by the child:
+
+       .in: The FD must be readable; it becomes child's stdin.
+       .out: The FD must be writable; it becomes child's stdout.
+       .err > 0 is not supported.
+
+  The specified FD is closed by start_command(), even if it fails to
+  run the sub-process!
+
+. Special forms of redirection are available by setting these members
+  to 1:
+
+       .no_stdin, .no_stdout, .no_stderr: The respective channel is
+               redirected to /dev/null.
+
+       .stdout_to_stderr: stdout of the child is redirected to the
+               parent's stderr (i.e. *not* to what .err or
+               .no_stderr specify).
+
+To modify the environment of the sub-process, specify an array of
+string pointers (NULL terminated) in .env:
+
+. If the string is of the form "VAR=value", i.e. it contains '='
+  the variable is added to the child process's environment.
+
+. If the string does not contain '=', it names an environement
+  variable that will be removed from the child process's envionment.
+
+To specify a new initial working directory for the sub-process,
+specify it in the .dir member.
+
+
+* `struct async`
+
+This describes a function to run asynchronously, whose purpose is
+to produce output that the caller reads.
+
+The caller:
+
+1. allocates and clears (memset(&asy, '0', sizeof(asy));) a
+   struct async variable;
+2. initializes .proc and .data;
+3. calls start_async();
+4. processes the data by reading from the fd in .out;
+5. closes .out;
+6. calls finish_async().
+
+The function pointer in .proc has the following signature:
+
+       int proc(int fd, void *data);
+
+. fd specifies a writable file descriptor to which the function must
+  write the data that it produces. The function *must* close this
+  descriptor before it returns.
+
+. data is the value that the caller has specified in the .data member
+  of struct async.
+
+. The return value of the function is 0 on success and non-zero
+  on failure. If the function indicates failure, finish_async() will
+  report failure as well.
+
+
+There are serious restrictions on what the asynchronous function can do
+because this facility is implemented by a pipe to a forked process on
+UNIX, but by a thread in the same address space on Windows:
+
+. It cannot change the program's state (global variables, environment,
+  etc.) in a way that the caller notices; in other words, .out is the
+  only communication channel to the caller.
+
+. It must not change the program's state that the caller of the
+  facility also uses.
index 1ad324e23696f66451a9ffc05d77f459bf106e83..6ddf04d2161e5fd959c2fd69a7331520e8075d98 100755 (executable)
@@ -16,7 +16,8 @@ elif test -d .git &&
        case "$VN" in
        *$LF*) (exit 1) ;;
        v[0-9]*)
-               git diff-index --quiet HEAD || VN="$VN-dirty" ;;
+               test -z "$(git diff-index --name-only HEAD)" ||
+               VN="$VN-dirty" ;;
        esac
 then
        VN=$(echo "$VN" | sed -e 's/-/./g');
index 83c359acde102c653b197001b3272781f9fd2697..cc635296a379292f325d61f4cf4488c0239ab2fa 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -3,6 +3,9 @@ all::
 
 # Define V=1 to have a more verbose compile.
 #
+# Define FREAD_READS_DIRECTORIES if your are on a system which succeeds
+# when attempting to read from an fopen'ed directory.
+#
 # Define NO_OPENSSL environment variable if you do not have OpenSSL.
 # This also implies MOZILLA_SHA1.
 #
@@ -622,6 +625,10 @@ endif
 ifdef NO_C99_FORMAT
        BASIC_CFLAGS += -DNO_C99_FORMAT
 endif
+ifdef FREAD_READS_DIRECTORIES
+       COMPAT_CFLAGS += -DFREAD_READS_DIRECTORIES
+       COMPAT_OBJS += compat/fopen.o
+endif
 ifdef NO_SYMLINK_HEAD
        BASIC_CFLAGS += -DNO_SYMLINK_HEAD
 endif
@@ -734,6 +741,7 @@ endif
 ifdef THREADED_DELTA_SEARCH
        BASIC_CFLAGS += -DTHREADED_DELTA_SEARCH
        EXTLIBS += -lpthread
+       LIB_OBJS += thread-utils.o
 endif
 
 ifeq ($(TCLTK_PATH),)
@@ -1095,7 +1103,7 @@ git.spec: git.spec.in
        mv $@+ $@
 
 GIT_TARNAME=git-$(GIT_VERSION)
-dist: git.spec git-archive configure
+dist: git.spec git-archive$(X) configure
        ./git-archive --format=tar \
                --prefix=$(GIT_TARNAME)/ HEAD^{tree} > $(GIT_TARNAME).tar
        @mkdir -p $(GIT_TARNAME)
index 4a91e3eb118850882fbc22e8d8f37e8bbfaa7617..820110e085f20d8615c74167cf3ae4cfd1fe6912 100644 (file)
@@ -228,6 +228,18 @@ int cmd_add(int argc, const char **argv, const char *prefix)
                goto finish;
        }
 
+       if (*argv) {
+               /* Was there an invalid path? */
+               if (pathspec) {
+                       int num;
+                       for (num = 0; pathspec[num]; num++)
+                               ; /* just counting */
+                       if (argc != num)
+                               exit(1); /* error message already given */
+               } else
+                       exit(1); /* error message already given */
+       }
+
        fill_directory(&dir, pathspec, ignored_too);
 
        if (show_only) {
index 6a88ff018df8890af8ef2e17340d5969dc1e396b..a3f075df4bd91de8d3423420cfcffd9722ad9586 100644 (file)
@@ -161,6 +161,84 @@ struct patch {
        struct patch *next;
 };
 
+/*
+ * A line in a file, len-bytes long (includes the terminating LF,
+ * except for an incomplete line at the end if the file ends with
+ * one), and its contents hashes to 'hash'.
+ */
+struct line {
+       size_t len;
+       unsigned hash : 24;
+       unsigned flag : 8;
+#define LINE_COMMON     1
+};
+
+/*
+ * This represents a "file", which is an array of "lines".
+ */
+struct image {
+       char *buf;
+       size_t len;
+       size_t nr;
+       size_t alloc;
+       struct line *line_allocated;
+       struct line *line;
+};
+
+static uint32_t hash_line(const char *cp, size_t len)
+{
+       size_t i;
+       uint32_t h;
+       for (i = 0, h = 0; i < len; i++) {
+               if (!isspace(cp[i])) {
+                       h = h * 3 + (cp[i] & 0xff);
+               }
+       }
+       return h;
+}
+
+static void add_line_info(struct image *img, const char *bol, size_t len, unsigned flag)
+{
+       ALLOC_GROW(img->line_allocated, img->nr + 1, img->alloc);
+       img->line_allocated[img->nr].len = len;
+       img->line_allocated[img->nr].hash = hash_line(bol, len);
+       img->line_allocated[img->nr].flag = flag;
+       img->nr++;
+}
+
+static void prepare_image(struct image *image, char *buf, size_t len,
+                         int prepare_linetable)
+{
+       const char *cp, *ep;
+
+       memset(image, 0, sizeof(*image));
+       image->buf = buf;
+       image->len = len;
+
+       if (!prepare_linetable)
+               return;
+
+       ep = image->buf + image->len;
+       cp = image->buf;
+       while (cp < ep) {
+               const char *next;
+               for (next = cp; next < ep && *next != '\n'; next++)
+                       ;
+               if (next < ep)
+                       next++;
+               add_line_info(image, cp, next - cp, 0);
+               cp = next;
+       }
+       image->line = image->line_allocated;
+}
+
+static void clear_image(struct image *image)
+{
+       free(image->buf);
+       image->buf = NULL;
+       image->len = 0;
+}
+
 static void say_patch_name(FILE *output, const char *pre,
                           struct patch *patch, const char *post)
 {
@@ -1437,227 +1515,338 @@ static int read_old_data(struct stat *st, const char *path, struct strbuf *buf)
        }
 }
 
-static int find_offset(const char *buf, unsigned long size,
-                      const char *fragment, unsigned long fragsize,
-                      int line, int *lines)
+static void update_pre_post_images(struct image *preimage,
+                                  struct image *postimage,
+                                  char *buf,
+                                  size_t len)
 {
-       int i;
-       unsigned long start, backwards, forwards;
+       int i, ctx;
+       char *new, *old, *fixed;
+       struct image fixed_preimage;
 
-       if (fragsize > size)
-               return -1;
+       /*
+        * Update the preimage with whitespace fixes.  Note that we
+        * are not losing preimage->buf -- apply_one_fragment() will
+        * free "oldlines".
+        */
+       prepare_image(&fixed_preimage, buf, len, 1);
+       assert(fixed_preimage.nr == preimage->nr);
+       for (i = 0; i < preimage->nr; i++)
+               fixed_preimage.line[i].flag = preimage->line[i].flag;
+       free(preimage->line_allocated);
+       *preimage = fixed_preimage;
 
-       start = 0;
-       if (line > 1) {
-               unsigned long offset = 0;
-               i = line-1;
-               while (offset + fragsize <= size) {
-                       if (buf[offset++] == '\n') {
-                               start = offset;
-                               if (!--i)
-                                       break;
-                       }
+       /*
+        * Adjust the common context lines in postimage, in place.
+        * This is possible because whitespace fixing does not make
+        * the string grow.
+        */
+       new = old = postimage->buf;
+       fixed = preimage->buf;
+       for (i = ctx = 0; i < postimage->nr; i++) {
+               size_t len = postimage->line[i].len;
+               if (!(postimage->line[i].flag & LINE_COMMON)) {
+                       /* an added line -- no counterparts in preimage */
+                       memmove(new, old, len);
+                       old += len;
+                       new += len;
+                       continue;
                }
+
+               /* a common context -- skip it in the original postimage */
+               old += len;
+
+               /* and find the corresponding one in the fixed preimage */
+               while (ctx < preimage->nr &&
+                      !(preimage->line[ctx].flag & LINE_COMMON)) {
+                       fixed += preimage->line[ctx].len;
+                       ctx++;
+               }
+               if (preimage->nr <= ctx)
+                       die("oops");
+
+               /* and copy it in, while fixing the line length */
+               len = preimage->line[ctx].len;
+               memcpy(new, fixed, len);
+               new += len;
+               fixed += len;
+               postimage->line[i].len = len;
+               ctx++;
        }
 
-       /* Exact line number? */
-       if ((start + fragsize <= size) &&
-           !memcmp(buf + start, fragment, fragsize))
-               return start;
+       /* Fix the length of the whole thing */
+       postimage->len = new - postimage->buf;
+}
+
+static int match_fragment(struct image *img,
+                         struct image *preimage,
+                         struct image *postimage,
+                         unsigned long try,
+                         int try_lno,
+                         unsigned ws_rule,
+                         int match_beginning, int match_end)
+{
+       int i;
+       char *fixed_buf, *buf, *orig, *target;
+
+       if (preimage->nr + try_lno > img->nr)
+               return 0;
+
+       if (match_beginning && try_lno)
+               return 0;
+
+       if (match_end && preimage->nr + try_lno != img->nr)
+               return 0;
+
+       /* Quick hash check */
+       for (i = 0; i < preimage->nr; i++)
+               if (preimage->line[i].hash != img->line[try_lno + i].hash)
+                       return 0;
+
+       /*
+        * Do we have an exact match?  If we were told to match
+        * at the end, size must be exactly at try+fragsize,
+        * otherwise try+fragsize must be still within the preimage,
+        * and either case, the old piece should match the preimage
+        * exactly.
+        */
+       if ((match_end
+            ? (try + preimage->len == img->len)
+            : (try + preimage->len <= img->len)) &&
+           !memcmp(img->buf + try, preimage->buf, preimage->len))
+               return 1;
+
+       if (ws_error_action != correct_ws_error)
+               return 0;
+
+       /*
+        * The hunk does not apply byte-by-byte, but the hash says
+        * it might with whitespace fuzz.
+        */
+       fixed_buf = xmalloc(preimage->len + 1);
+       buf = fixed_buf;
+       orig = preimage->buf;
+       target = img->buf + try;
+       for (i = 0; i < preimage->nr; i++) {
+               size_t fixlen; /* length after fixing the preimage */
+               size_t oldlen = preimage->line[i].len;
+               size_t tgtlen = img->line[try_lno + i].len;
+               size_t tgtfixlen; /* length after fixing the target line */
+               char tgtfixbuf[1024], *tgtfix;
+               int match;
+
+               /* Try fixing the line in the preimage */
+               fixlen = ws_fix_copy(buf, orig, oldlen, ws_rule, NULL);
+
+               /* Try fixing the line in the target */
+               if (sizeof(tgtfixbuf) < tgtlen)
+                       tgtfix = tgtfixbuf;
+               else
+                       tgtfix = xmalloc(tgtlen);
+               tgtfixlen = ws_fix_copy(tgtfix, target, tgtlen, ws_rule, NULL);
+
+               /*
+                * If they match, either the preimage was based on
+                * a version before our tree fixed whitespace breakage,
+                * or we are lacking a whitespace-fix patch the tree
+                * the preimage was based on already had (i.e. target
+                * has whitespace breakage, the preimage doesn't).
+                * In either case, we are fixing the whitespace breakages
+                * so we might as well take the fix together with their
+                * real change.
+                */
+               match = (tgtfixlen == fixlen && !memcmp(tgtfix, buf, fixlen));
+
+               if (tgtfix != tgtfixbuf)
+                       free(tgtfix);
+               if (!match)
+                       goto unmatch_exit;
+
+               orig += oldlen;
+               buf += fixlen;
+               target += tgtlen;
+       }
+
+       /*
+        * Yes, the preimage is based on an older version that still
+        * has whitespace breakages unfixed, and fixing them makes the
+        * hunk match.  Update the context lines in the postimage.
+        */
+       update_pre_post_images(preimage, postimage,
+                              fixed_buf, buf - fixed_buf);
+       return 1;
+
+ unmatch_exit:
+       free(fixed_buf);
+       return 0;
+}
+
+static int find_pos(struct image *img,
+                   struct image *preimage,
+                   struct image *postimage,
+                   int line,
+                   unsigned ws_rule,
+                   int match_beginning, int match_end)
+{
+       int i;
+       unsigned long backwards, forwards, try;
+       int backwards_lno, forwards_lno, try_lno;
+
+       if (preimage->nr > img->nr)
+               return -1;
+
+       /*
+        * If match_begining or match_end is specified, there is no
+        * point starting from a wrong line that will never match and
+        * wander around and wait for a match at the specified end.
+        */
+       if (match_beginning)
+               line = 0;
+       else if (match_end)
+               line = img->nr - preimage->nr;
+
+       if (line > img->nr)
+               line = img->nr;
+
+       try = 0;
+       for (i = 0; i < line; i++)
+               try += img->line[i].len;
 
        /*
         * There's probably some smart way to do this, but I'll leave
         * that to the smart and beautiful people. I'm simple and stupid.
         */
-       backwards = start;
-       forwards = start;
+       backwards = try;
+       backwards_lno = line;
+       forwards = try;
+       forwards_lno = line;
+       try_lno = line;
+
        for (i = 0; ; i++) {
-               unsigned long try;
-               int n;
+               if (match_fragment(img, preimage, postimage,
+                                  try, try_lno, ws_rule,
+                                  match_beginning, match_end))
+                       return try_lno;
+
+       again:
+               if (backwards_lno == 0 && forwards_lno == img->nr)
+                       break;
 
-               /* "backward" */
                if (i & 1) {
-                       if (!backwards) {
-                               if (forwards + fragsize > size)
-                                       break;
-                               continue;
+                       if (backwards_lno == 0) {
+                               i++;
+                               goto again;
                        }
-                       do {
-                               --backwards;
-                       } while (backwards && buf[backwards-1] != '\n');
+                       backwards_lno--;
+                       backwards -= img->line[backwards_lno].len;
                        try = backwards;
+                       try_lno = backwards_lno;
                } else {
-                       while (forwards + fragsize <= size) {
-                               if (buf[forwards++] == '\n')
-                                       break;
+                       if (forwards_lno == img->nr) {
+                               i++;
+                               goto again;
                        }
+                       forwards += img->line[forwards_lno].len;
+                       forwards_lno++;
                        try = forwards;
+                       try_lno = forwards_lno;
                }
 
-               if (try + fragsize > size)
-                       continue;
-               if (memcmp(buf + try, fragment, fragsize))
-                       continue;
-               n = (i >> 1)+1;
-               if (i & 1)
-                       n = -n;
-               *lines = n;
-               return try;
        }
-
-       /*
-        * We should start searching forward and backward.
-        */
        return -1;
 }
 
-static void remove_first_line(const char **rbuf, int *rsize)
+static void remove_first_line(struct image *img)
 {
-       const char *buf = *rbuf;
-       int size = *rsize;
-       unsigned long offset;
-       offset = 0;
-       while (offset <= size) {
-               if (buf[offset++] == '\n')
-                       break;
-       }
-       *rsize = size - offset;
-       *rbuf = buf + offset;
+       img->buf += img->line[0].len;
+       img->len -= img->line[0].len;
+       img->line++;
+       img->nr--;
 }
 
-static void remove_last_line(const char **rbuf, int *rsize)
+static void remove_last_line(struct image *img)
 {
-       const char *buf = *rbuf;
-       int size = *rsize;
-       unsigned long offset;
-       offset = size - 1;
-       while (offset > 0) {
-               if (buf[--offset] == '\n')
-                       break;
-       }
-       *rsize = offset + 1;
+       img->len -= img->line[--img->nr].len;
 }
 
-static int apply_line(char *output, const char *patch, int plen,
-                     unsigned ws_rule)
+static void update_image(struct image *img,
+                        int applied_pos,
+                        struct image *preimage,
+                        struct image *postimage)
 {
        /*
-        * plen is number of bytes to be copied from patch,
-        * starting at patch+1 (patch[0] is '+').  Typically
-        * patch[plen] is '\n', unless this is the incomplete
-        * last line.
+        * remove the copy of preimage at offset in img
+        * and replace it with postimage
         */
-       int i;
-       int add_nl_to_tail = 0;
-       int fixed = 0;
-       int last_tab_in_indent = 0;
-       int last_space_in_indent = 0;
-       int need_fix_leading_space = 0;
-       char *buf;
-
-       if ((ws_error_action != correct_ws_error) || !whitespace_error ||
-           *patch != '+') {
-               memcpy(output, patch + 1, plen);
-               return plen;
-       }
-
-       /*
-        * Strip trailing whitespace
-        */
-       if ((ws_rule & WS_TRAILING_SPACE) &&
-           (1 < plen && isspace(patch[plen-1]))) {
-               if (patch[plen] == '\n')
-                       add_nl_to_tail = 1;
-               plen--;
-               while (0 < plen && isspace(patch[plen]))
-                       plen--;
-               fixed = 1;
-       }
-
-       /*
-        * Check leading whitespaces (indent)
-        */
-       for (i = 1; i < plen; i++) {
-               char ch = patch[i];
-               if (ch == '\t') {
-                       last_tab_in_indent = i;
-                       if ((ws_rule & WS_SPACE_BEFORE_TAB) &&
-                           0 < last_space_in_indent)
-                           need_fix_leading_space = 1;
-               } else if (ch == ' ') {
-                       last_space_in_indent = i;
-                       if ((ws_rule & WS_INDENT_WITH_NON_TAB) &&
-                           8 <= i - last_tab_in_indent)
-                               need_fix_leading_space = 1;
-               }
-               else
-                       break;
-       }
-
-       buf = output;
-       if (need_fix_leading_space) {
-               int consecutive_spaces = 0;
-               int last = last_tab_in_indent + 1;
-
-               if (ws_rule & WS_INDENT_WITH_NON_TAB) {
-                       /* have "last" point at one past the indent */
-                       if (last_tab_in_indent < last_space_in_indent)
-                               last = last_space_in_indent + 1;
-                       else
-                               last = last_tab_in_indent + 1;
-               }
+       int i, nr;
+       size_t remove_count, insert_count, applied_at = 0;
+       char *result;
 
+       for (i = 0; i < applied_pos; i++)
+               applied_at += img->line[i].len;
+
+       remove_count = 0;
+       for (i = 0; i < preimage->nr; i++)
+               remove_count += img->line[applied_pos + i].len;
+       insert_count = postimage->len;
+
+       /* Adjust the contents */
+       result = xmalloc(img->len + insert_count - remove_count + 1);
+       memcpy(result, img->buf, applied_at);
+       memcpy(result + applied_at, postimage->buf, postimage->len);
+       memcpy(result + applied_at + postimage->len,
+              img->buf + (applied_at + remove_count),
+              img->len - (applied_at + remove_count));
+       free(img->buf);
+       img->buf = result;
+       img->len += insert_count - remove_count;
+       result[img->len] = '\0';
+
+       /* Adjust the line table */
+       nr = img->nr + postimage->nr - preimage->nr;
+       if (preimage->nr < postimage->nr) {
                /*
-                * between patch[1..last], strip the funny spaces,
-                * updating them to tab as needed.
+                * NOTE: this knows that we never call remove_first_line()
+                * on anything other than pre/post image.
                 */
-               for (i = 1; i < last; i++, plen--) {
-                       char ch = patch[i];
-                       if (ch != ' ') {
-                               consecutive_spaces = 0;
-                               *output++ = ch;
-                       } else {
-                               consecutive_spaces++;
-                               if (consecutive_spaces == 8) {
-                                       *output++ = '\t';
-                                       consecutive_spaces = 0;
-                               }
-                       }
-               }
-               while (0 < consecutive_spaces--)
-                       *output++ = ' ';
-               fixed = 1;
-               i = last;
+               img->line = xrealloc(img->line, nr * sizeof(*img->line));
+               img->line_allocated = img->line;
        }
-       else
-               i = 1;
-
-       memcpy(output, patch + i, plen);
-       if (add_nl_to_tail)
-               output[plen++] = '\n';
-       if (fixed)
-               applied_after_fixing_ws++;
-       return output + plen - buf;
+       if (preimage->nr != postimage->nr)
+               memmove(img->line + applied_pos + postimage->nr,
+                       img->line + applied_pos + preimage->nr,
+                       (img->nr - (applied_pos + preimage->nr)) *
+                       sizeof(*img->line));
+       memcpy(img->line + applied_pos,
+              postimage->line,
+              postimage->nr * sizeof(*img->line));
+       img->nr = nr;
 }
 
-static int apply_one_fragment(struct strbuf *buf, struct fragment *frag,
+static int apply_one_fragment(struct image *img, struct fragment *frag,
                              int inaccurate_eof, unsigned ws_rule)
 {
        int match_beginning, match_end;
        const char *patch = frag->patch;
-       int offset, size = frag->size;
-       char *old = xmalloc(size);
-       char *new = xmalloc(size);
-       const char *oldlines, *newlines;
-       int oldsize = 0, newsize = 0;
+       int size = frag->size;
+       char *old, *new, *oldlines, *newlines;
        int new_blank_lines_at_end = 0;
        unsigned long leading, trailing;
-       int pos, lines;
+       int pos, applied_pos;
+       struct image preimage;
+       struct image postimage;
+
+       memset(&preimage, 0, sizeof(preimage));
+       memset(&postimage, 0, sizeof(postimage));
+       oldlines = xmalloc(size);
+       newlines = xmalloc(size);
 
+       old = oldlines;
+       new = newlines;
        while (size > 0) {
                char first;
                int len = linelen(patch, size);
-               int plen;
+               int plen, added;
                int added_blank_line = 0;
 
                if (!len)
@@ -1670,7 +1859,7 @@ static int apply_one_fragment(struct strbuf *buf, struct fragment *frag,
                 * followed by "\ No newline", then we also remove the
                 * last one (which is the newline, of course).
                 */
-               plen = len-1;
+               plen = len - 1;
                if (len < size && patch[len] == '\\')
                        plen--;
                first = *patch;
@@ -1687,25 +1876,40 @@ static int apply_one_fragment(struct strbuf *buf, struct fragment *frag,
                        if (plen < 0)
                                /* ... followed by '\No newline'; nothing */
                                break;
-                       old[oldsize++] = '\n';
-                       new[newsize++] = '\n';
+                       *old++ = '\n';
+                       *new++ = '\n';
+                       add_line_info(&preimage, "\n", 1, LINE_COMMON);
+                       add_line_info(&postimage, "\n", 1, LINE_COMMON);
                        break;
                case ' ':
                case '-':
-                       memcpy(old + oldsize, patch + 1, plen);
-                       oldsize += plen;
+                       memcpy(old, patch + 1, plen);
+                       add_line_info(&preimage, old, plen,
+                                     (first == ' ' ? LINE_COMMON : 0));
+                       old += plen;
                        if (first == '-')
                                break;
                /* Fall-through for ' ' */
                case '+':
-                       if (first != '+' || !no_add) {
-                               int added = apply_line(new + newsize, patch,
-                                                      plen, ws_rule);
-                               newsize += added;
-                               if (first == '+' &&
-                                   added == 1 && new[newsize-1] == '\n')
-                                       added_blank_line = 1;
+                       /* --no-add does not add new lines */
+                       if (first == '+' && no_add)
+                               break;
+
+                       if (first != '+' ||
+                           !whitespace_error ||
+                           ws_error_action != correct_ws_error) {
+                               memcpy(new, patch + 1, plen);
+                               added = plen;
                        }
+                       else {
+                               added = ws_fix_copy(new, patch + 1, plen, ws_rule, &applied_after_fixing_ws);
+                       }
+                       add_line_info(&postimage, new, added,
+                                     (first == '+' ? 0 : LINE_COMMON));
+                       new += added;
+                       if (first == '+' &&
+                           added == 1 && new[-1] == '\n')
+                               added_blank_line = 1;
                        break;
                case '@': case '\\':
                        /* Ignore it, we already handled it */
@@ -1722,16 +1926,13 @@ static int apply_one_fragment(struct strbuf *buf, struct fragment *frag,
                patch += len;
                size -= len;
        }
-
        if (inaccurate_eof &&
-           oldsize > 0 && old[oldsize - 1] == '\n' &&
-           newsize > 0 && new[newsize - 1] == '\n') {
-               oldsize--;
-               newsize--;
+           old > oldlines && old[-1] == '\n' &&
+           new > newlines && new[-1] == '\n') {
+               old--;
+               new--;
        }
 
-       oldlines = old;
-       newlines = new;
        leading = frag->leading;
        trailing = frag->trailing;
 
@@ -1752,33 +1953,21 @@ static int apply_one_fragment(struct strbuf *buf, struct fragment *frag,
                match_end = !trailing;
        }
 
-       lines = 0;
-       pos = frag->newpos;
+       pos = frag->newpos ? (frag->newpos - 1) : 0;
+       preimage.buf = oldlines;
+       preimage.len = old - oldlines;
+       postimage.buf = newlines;
+       postimage.len = new - newlines;
+       preimage.line = preimage.line_allocated;
+       postimage.line = postimage.line_allocated;
+
        for (;;) {
-               offset = find_offset(buf->buf, buf->len,
-                                    oldlines, oldsize, pos, &lines);
-               if (match_end && offset + oldsize != buf->len)
-                       offset = -1;
-               if (match_beginning && offset)
-                       offset = -1;
-               if (offset >= 0) {
-                       if (ws_error_action == correct_ws_error &&
-                           (buf->len - oldsize - offset == 0)) /* end of file? */
-                               newsize -= new_blank_lines_at_end;
-
-                       /* Warn if it was necessary to reduce the number
-                        * of context lines.
-                        */
-                       if ((leading != frag->leading) ||
-                           (trailing != frag->trailing))
-                               fprintf(stderr, "Context reduced to (%ld/%ld)"
-                                       " to apply fragment at %d\n",
-                                       leading, trailing, pos + lines);
-
-                       strbuf_splice(buf, offset, oldsize, newlines, newsize);
-                       offset = 0;
+
+               applied_pos = find_pos(img, &preimage, &postimage, pos,
+                                      ws_rule, match_beginning, match_end);
+
+               if (applied_pos >= 0)
                        break;
-               }
 
                /* Am I at my context limits? */
                if ((leading <= p_context) && (trailing <= p_context))
@@ -1787,33 +1976,64 @@ static int apply_one_fragment(struct strbuf *buf, struct fragment *frag,
                        match_beginning = match_end = 0;
                        continue;
                }
+
                /*
                 * Reduce the number of context lines; reduce both
                 * leading and trailing if they are equal otherwise
                 * just reduce the larger context.
                 */
                if (leading >= trailing) {
-                       remove_first_line(&oldlines, &oldsize);
-                       remove_first_line(&newlines, &newsize);
+                       remove_first_line(&preimage);
+                       remove_first_line(&postimage);
                        pos--;
                        leading--;
                }
                if (trailing > leading) {
-                       remove_last_line(&oldlines, &oldsize);
-                       remove_last_line(&newlines, &newsize);
+                       remove_last_line(&preimage);
+                       remove_last_line(&postimage);
                        trailing--;
                }
        }
 
-       if (offset && apply_verbosely)
-               error("while searching for:\n%.*s", oldsize, oldlines);
+       if (applied_pos >= 0) {
+               if (ws_error_action == correct_ws_error &&
+                   new_blank_lines_at_end &&
+                   postimage.nr + applied_pos == img->nr) {
+                       /*
+                        * If the patch application adds blank lines
+                        * at the end, and if the patch applies at the
+                        * end of the image, remove those added blank
+                        * lines.
+                        */
+                       while (new_blank_lines_at_end--)
+                               remove_last_line(&postimage);
+               }
 
-       free(old);
-       free(new);
-       return offset;
+               /*
+                * Warn if it was necessary to reduce the number
+                * of context lines.
+                */
+               if ((leading != frag->leading) ||
+                   (trailing != frag->trailing))
+                       fprintf(stderr, "Context reduced to (%ld/%ld)"
+                               " to apply fragment at %d\n",
+                               leading, trailing, applied_pos+1);
+               update_image(img, applied_pos, &preimage, &postimage);
+       } else {
+               if (apply_verbosely)
+                       error("while searching for:\n%.*s",
+                             (int)(old - oldlines), oldlines);
+       }
+
+       free(oldlines);
+       free(newlines);
+       free(preimage.line_allocated);
+       free(postimage.line_allocated);
+
+       return (applied_pos < 0);
 }
 
-static int apply_binary_fragment(struct strbuf *buf, struct patch *patch)
+static int apply_binary_fragment(struct image *img, struct patch *patch)
 {
        struct fragment *fragment = patch->fragments;
        unsigned long len;
@@ -1830,22 +2050,26 @@ static int apply_binary_fragment(struct strbuf *buf, struct patch *patch)
        }
        switch (fragment->binary_patch_method) {
        case BINARY_DELTA_DEFLATED:
-               dst = patch_delta(buf->buf, buf->len, fragment->patch,
+               dst = patch_delta(img->buf, img->len, fragment->patch,
                                  fragment->size, &len);
                if (!dst)
                        return -1;
-               /* XXX patch_delta NUL-terminates */
-               strbuf_attach(buf, dst, len, len + 1);
+               clear_image(img);
+               img->buf = dst;
+               img->len = len;
                return 0;
        case BINARY_LITERAL_DEFLATED:
-               strbuf_reset(buf);
-               strbuf_add(buf, fragment->patch, fragment->size);
+               clear_image(img);
+               img->len = fragment->size;
+               img->buf = xmalloc(img->len+1);
+               memcpy(img->buf, fragment->patch, img->len);
+               img->buf[img->len] = '\0';
                return 0;
        }
        return -1;
 }
 
-static int apply_binary(struct strbuf *buf, struct patch *patch)
+static int apply_binary(struct image *img, struct patch *patch)
 {
        const char *name = patch->old_name ? patch->old_name : patch->new_name;
        unsigned char sha1[20];
@@ -1866,7 +2090,7 @@ static int apply_binary(struct strbuf *buf, struct patch *patch)
                 * See if the old one matches what the patch
                 * applies to.
                 */
-               hash_sha1_file(buf->buf, buf->len, blob_type, sha1);
+               hash_sha1_file(img->buf, img->len, blob_type, sha1);
                if (strcmp(sha1_to_hex(sha1), patch->old_sha1_prefix))
                        return error("the patch applies to '%s' (%s), "
                                     "which does not match the "
@@ -1875,14 +2099,14 @@ static int apply_binary(struct strbuf *buf, struct patch *patch)
        }
        else {
                /* Otherwise, the old one must be empty. */
-               if (buf->len)
+               if (img->len)
                        return error("the patch applies to an empty "
                                     "'%s' but it is not empty", name);
        }
 
        get_sha1_hex(patch->new_sha1_prefix, sha1);
        if (is_null_sha1(sha1)) {
-               strbuf_release(buf);
+               clear_image(img);
                return 0; /* deletion patch */
        }
 
@@ -1897,20 +2121,21 @@ static int apply_binary(struct strbuf *buf, struct patch *patch)
                        return error("the necessary postimage %s for "
                                     "'%s' cannot be read",
                                     patch->new_sha1_prefix, name);
-               /* XXX read_sha1_file NUL-terminates */
-               strbuf_attach(buf, result, size, size + 1);
+               clear_image(img);
+               img->buf = result;
+               img->len = size;
        } else {
                /*
                 * We have verified buf matches the preimage;
                 * apply the patch data to it, which is stored
                 * in the patch->fragments->{patch,size}.
                 */
-               if (apply_binary_fragment(buf, patch))
+               if (apply_binary_fragment(img, patch))
                        return error("binary patch does not apply to '%s'",
                                     name);
 
                /* verify that the result matches */
-               hash_sha1_file(buf->buf, buf->len, blob_type, sha1);
+               hash_sha1_file(img->buf, img->len, blob_type, sha1);
                if (strcmp(sha1_to_hex(sha1), patch->new_sha1_prefix))
                        return error("binary patch to '%s' creates incorrect result (expecting %s, got %s)",
                                name, patch->new_sha1_prefix, sha1_to_hex(sha1));
@@ -1919,7 +2144,7 @@ static int apply_binary(struct strbuf *buf, struct patch *patch)
        return 0;
 }
 
-static int apply_fragments(struct strbuf *buf, struct patch *patch)
+static int apply_fragments(struct image *img, struct patch *patch)
 {
        struct fragment *frag = patch->fragments;
        const char *name = patch->old_name ? patch->old_name : patch->new_name;
@@ -1927,10 +2152,10 @@ static int apply_fragments(struct strbuf *buf, struct patch *patch)
        unsigned inaccurate_eof = patch->inaccurate_eof;
 
        if (patch->is_binary)
-               return apply_binary(buf, patch);
+               return apply_binary(img, patch);
 
        while (frag) {
-               if (apply_one_fragment(buf, frag, inaccurate_eof, ws_rule)) {
+               if (apply_one_fragment(img, frag, inaccurate_eof, ws_rule)) {
                        error("patch failed: %s:%ld", name, frag->oldpos);
                        if (!apply_with_reject)
                                return -1;
@@ -1966,6 +2191,9 @@ static int read_file_or_gitlink(struct cache_entry *ce, struct strbuf *buf)
 static int apply_data(struct patch *patch, struct stat *st, struct cache_entry *ce)
 {
        struct strbuf buf;
+       struct image image;
+       size_t len;
+       char *img;
 
        strbuf_init(&buf, 0);
        if (cached) {
@@ -1988,9 +2216,14 @@ static int apply_data(struct patch *patch, struct stat *st, struct cache_entry *
                }
        }
 
-       if (apply_fragments(&buf, patch) < 0)
+       img = strbuf_detach(&buf, &len);
+       prepare_image(&image, img, len, !patch->is_binary);
+
+       if (apply_fragments(&image, patch) < 0)
                return -1; /* note with --reject this succeeds. */
-       patch->result = strbuf_detach(&buf, &patch->resultsize);
+       patch->result = image.buf;
+       patch->resultsize = image.len;
+       free(image.line_allocated);
 
        if (0 < patch->is_delete && patch->resultsize)
                return error("removal patch leaves file contents");
index 1cf254dcca7f814694741ce5ea1ec2b88a26706f..59d7237f21f406b71aabc66ea7997faf98981869 100644 (file)
@@ -1894,9 +1894,7 @@ static unsigned parse_score(const char *arg)
 
 static const char *add_prefix(const char *prefix, const char *path)
 {
-       if (!prefix || !prefix[0])
-               return path;
-       return prefix_path(prefix, strlen(prefix), path);
+       return prefix_path(prefix, prefix ? strlen(prefix) : 0, path);
 }
 
 /*
@@ -2369,7 +2367,8 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
         * bottom commits we would reach while traversing as
         * uninteresting.
         */
-       prepare_revision_walk(&revs);
+       if (prepare_revision_walk(&revs))
+               die("revision walk setup failed");
 
        if (is_null_sha1(sb.final->object.sha1)) {
                char *buf;
index e414c8898317736d632064d6c0545d7d128c6bc8..9edf2eb8162eb7214e1b4d76dca8949c63e72847 100644 (file)
@@ -31,7 +31,7 @@ static unsigned char head_sha1[20];
 
 static int branch_track = 1;
 
-static int branch_use_color;
+static int branch_use_color = -1;
 static char branch_colors[][COLOR_MAXLEN] = {
        "\033[m",       /* reset */
        "",             /* PLAIN (normal) */
@@ -79,12 +79,12 @@ static int git_branch_config(const char *var, const char *value)
                branch_track = git_config_bool(var, value);
                return 0;
        }
-       return git_default_config(var, value);
+       return git_color_default_config(var, value);
 }
 
 static const char *branch_get_color(enum color_branch ix)
 {
-       if (branch_use_color)
+       if (branch_use_color > 0)
                return branch_colors[ix];
        return "";
 }
@@ -588,6 +588,10 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
        };
 
        git_config(git_branch_config);
+
+       if (branch_use_color == -1)
+               branch_use_color = git_use_color_default;
+
        track = branch_track;
        argc = parse_options(argc, argv, options, builtin_branch_usage, 0);
        if (!!delete + !!rename + !!force_create > 1)
index eb853a37cf993a875f2acd1992ee5191783740a1..3b220d5060b90318e2d2331d3cd0f5b6a70164ee 100644 (file)
@@ -29,7 +29,7 @@ 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;
+       int ignored_only = 0, baselen = 0, config_set = 0, errors = 0;
        struct strbuf directory;
        struct dir_struct dir;
        const char *path, *base;
@@ -137,12 +137,15 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
                        if (show_only && (remove_directories || matches)) {
                                printf("Would remove %s\n",
                                       directory.buf + prefix_offset);
-                       } else if (quiet && (remove_directories || matches)) {
-                               remove_dir_recursively(&directory, 0);
                        } else if (remove_directories || matches) {
-                               printf("Removing %s\n",
-                                      directory.buf + prefix_offset);
-                               remove_dir_recursively(&directory, 0);
+                               if (!quiet)
+                                       printf("Removing %s\n",
+                                              directory.buf + prefix_offset);
+                               if (remove_dir_recursively(&directory, 0) != 0) {
+                                       warning("failed to remove '%s'",
+                                               directory.buf + prefix_offset);
+                                       errors++;
+                               }
                        } else if (show_only) {
                                printf("Would not remove %s\n",
                                       directory.buf + prefix_offset);
@@ -162,11 +165,14 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
                                printf("Removing %s\n",
                                       ent->name + prefix_offset);
                        }
-                       unlink(ent->name);
+                       if (unlink(ent->name) != 0) {
+                               warning("failed to remove '%s'", ent->name);
+                               errors++;
+                       }
                }
        }
        free(seen);
 
        strbuf_release(&directory);
-       return 0;
+       return (errors != 0);
 }
index 6612b4f40504fea0cd9aec4463c20d8982bfbaeb..065e1f7b7fbf426210d08062800ed81448a30d4a 100644 (file)
@@ -7,6 +7,7 @@
 
 #include "cache.h"
 #include "cache-tree.h"
+#include "color.h"
 #include "dir.h"
 #include "builtin.h"
 #include "diff.h"
@@ -771,6 +772,9 @@ int cmd_status(int argc, const char **argv, const char *prefix)
 
        git_config(git_status_config);
 
+       if (wt_status_use_color == -1)
+               wt_status_use_color = git_use_color_default;
+
        argc = parse_and_validate_options(argc, argv, builtin_status_usage);
 
        index_file = prepare_index(argc, argv, prefix);
index 3428483134156f4e1761aa47ed2e8098a294808c..05e309f5ad15f9a6f85df34322bb59152b4e37be 100644 (file)
@@ -46,19 +46,34 @@ static void add_to_known_names(const char *path,
 
 static int get_name(const char *path, const unsigned char *sha1, int flag, void *cb_data)
 {
-       struct commit *commit = lookup_commit_reference_gently(sha1, 1);
+       int might_be_tag = !prefixcmp(path, "refs/tags/");
+       struct commit *commit;
        struct object *object;
-       int prio;
+       unsigned char peeled[20];
+       int is_tag, prio;
 
-       if (!commit)
+       if (!all && !might_be_tag)
                return 0;
-       object = parse_object(sha1);
+
+       if (!peel_ref(path, peeled) && !is_null_sha1(peeled)) {
+               commit = lookup_commit_reference_gently(peeled, 1);
+               if (!commit)
+                       return 0;
+               is_tag = !!hashcmp(sha1, commit->object.sha1);
+       } else {
+               commit = lookup_commit_reference_gently(sha1, 1);
+               object = parse_object(sha1);
+               if (!commit || !object)
+                       return 0;
+               is_tag = object->type == OBJ_TAG;
+       }
+
        /* If --all, then any refs are used.
         * If --tags, then any tags are used.
         * Otherwise only annotated tags are used.
         */
-       if (!prefixcmp(path, "refs/tags/")) {
-               if (object->type == OBJ_TAG) {
+       if (might_be_tag) {
+               if (is_tag) {
                        prio = 2;
                        if (pattern && fnmatch(pattern, path + 10, 0))
                                prio = 0;
@@ -159,6 +174,8 @@ static void describe(const char *arg, int last_one)
                return;
        }
 
+       if (!max_candidates)
+               die("no tag exactly matches '%s'", sha1_to_hex(cmit->object.sha1));
        if (debug)
                fprintf(stderr, "searching to describe %s\n", arg);
 
@@ -255,6 +272,8 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
                OPT_BOOLEAN(0, "all",        &all, "use any ref in .git/refs"),
                OPT_BOOLEAN(0, "tags",       &tags, "use any tag in .git/refs/tags"),
                OPT__ABBREV(&abbrev),
+               OPT_SET_INT(0, "exact-match", &max_candidates,
+                           "only output exact matches", 0),
                OPT_INTEGER(0, "candidates", &max_candidates,
                            "consider <n> most recent tags (default: 10)"),
                OPT_STRING(0, "match",       &pattern, "pattern",
@@ -263,8 +282,8 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
        };
 
        argc = parse_options(argc, argv, options, describe_usage, 0);
-       if (max_candidates < 1)
-               max_candidates = 1;
+       if (max_candidates < 0)
+               max_candidates = 0;
        else if (max_candidates > MAX_TAGS)
                max_candidates = MAX_TAGS;
 
index 8d7a5697f2b429f6240a89e28422f48ef18aee3b..8f53f52dcbe74c1fdb6b7a54a8b250537bc821ee 100644 (file)
@@ -4,6 +4,7 @@
  * Copyright (c) 2006 Junio C Hamano
  */
 #include "cache.h"
+#include "color.h"
 #include "commit.h"
 #include "blob.h"
 #include "tag.h"
@@ -229,6 +230,10 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
 
        prefix = setup_git_directory_gently(&nongit);
        git_config(git_diff_ui_config);
+
+       if (diff_use_color_default == -1)
+               diff_use_color_default = git_use_color_default;
+
        init_revisions(&rev, prefix);
        rev.diffopt.skip_stat_unmatch = !!diff_auto_refresh_index;
 
index ef27eee71bdef2cac6f751e07b1da71588989b03..4bd1356d50508efab81066e79abd7abcc1443627 100755 (executable)
@@ -123,7 +123,7 @@ static void show_filemodify(struct diff_queue_struct *q,
                        printf("D %s\n", spec->path);
                else {
                        struct object *object = lookup_object(spec->sha1);
-                       printf("M 0%06o :%d %s\n", spec->mode,
+                       printf("M %06o :%d %s\n", spec->mode,
                               get_object_mark(object), spec->path);
                }
        }
@@ -383,7 +383,8 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix)
 
        get_tags_and_duplicates(&revs.pending, &extra_refs);
 
-       prepare_revision_walk(&revs);
+       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))) {
index 6163bd4975e3e361e36ffc89ea4c91d0edd02949..ebb3f37cf158dc479f364111893279805fa9a230 100644 (file)
@@ -187,7 +187,8 @@ static void shortlog(const char *name, unsigned char *sha1,
        add_pending_object(rev, branch, name);
        add_pending_object(rev, &head->object, "^HEAD");
        head->object.flags |= UNINTERESTING;
-       prepare_revision_walk(rev);
+       if (prepare_revision_walk(rev))
+               die("revision walk setup failed");
        while ((commit = get_revision(rev)) != NULL) {
                char *oneline, *bol, *eol;
 
index f36a43c26459bd386618e551e2e93743cd8030aa..07d9c572125523e2eb8f82e4cab907ee7dc94348 100644 (file)
@@ -165,7 +165,7 @@ static int verify_format(const char *format)
        for (cp = format; *cp && (sp = find_next(cp)); ) {
                const char *ep = strchr(sp, ')');
                if (!ep)
-                       return error("malformatted format string %s", sp);
+                       return error("malformed format string %s", sp);
                /* sp points at "%(" and ep points at the closing ")" */
                parse_atom(sp + 2, ep);
                cp = ep + 1;
index 9180b39e3f22e5d3805649c655c61aafc7861968..f4f4ecb11b587c74a009c94cb7b230e7c93590e4 100644 (file)
@@ -578,6 +578,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
                        continue;
                }
                if (!strcmp("-l", arg) ||
+                   !strcmp("--name-only", arg) ||
                    !strcmp("--files-with-matches", arg)) {
                        opt.name_only = 1;
                        continue;
index 5d7cdda93314b1d40f5f512897e8a35af0480a8f..79eaf8d6edf18675897f6eed571289fce450526a 100644 (file)
@@ -29,27 +29,6 @@ static void safe_create_dir(const char *dir, int share)
                die("Could not make %s writable by group\n", dir);
 }
 
-static int copy_file(const char *dst, const char *src, int mode)
-{
-       int fdi, fdo, status;
-
-       mode = (mode & 0111) ? 0777 : 0666;
-       if ((fdi = open(src, O_RDONLY)) < 0)
-               return fdi;
-       if ((fdo = open(dst, O_WRONLY | O_CREAT | O_EXCL, mode)) < 0) {
-               close(fdi);
-               return fdo;
-       }
-       status = copy_fd(fdi, fdo);
-       if (close(fdo) != 0)
-               return error("%s: write error: %s", dst, strerror(errno));
-
-       if (!status && adjust_shared_perm(dst))
-               return -1;
-
-       return status;
-}
-
 static void copy_templates_1(char *path, int baselen,
                             char *template, int template_baselen,
                             DIR *dir)
index 99d69f079132ed67e2d5bc83bf95e6e60ba22f6f..c67d63cb1cf588877fa10a7546757f2cd249c5c6 100644 (file)
@@ -5,6 +5,7 @@
  *              2006 Junio Hamano
  */
 #include "cache.h"
+#include "color.h"
 #include "commit.h"
 #include "diff.h"
 #include "revision.h"
@@ -197,7 +198,8 @@ static int cmd_log_walk(struct rev_info *rev)
        if (rev->early_output)
                setup_early_output(rev);
 
-       prepare_revision_walk(rev);
+       if (prepare_revision_walk(rev))
+               die("revision walk setup failed");
 
        if (rev->early_output)
                finish_early_output(rev);
@@ -235,6 +237,10 @@ int cmd_whatchanged(int argc, const char **argv, const char *prefix)
        struct rev_info rev;
 
        git_config(git_log_config);
+
+       if (diff_use_color_default == -1)
+               diff_use_color_default = git_use_color_default;
+
        init_revisions(&rev, prefix);
        rev.diff = 1;
        rev.simplify_history = 0;
@@ -307,6 +313,10 @@ int cmd_show(int argc, const char **argv, const char *prefix)
        int i, count, ret = 0;
 
        git_config(git_log_config);
+
+       if (diff_use_color_default == -1)
+               diff_use_color_default = git_use_color_default;
+
        init_revisions(&rev, prefix);
        rev.diff = 1;
        rev.combine_merges = 1;
@@ -367,6 +377,10 @@ int cmd_log_reflog(int argc, const char **argv, const char *prefix)
        struct rev_info rev;
 
        git_config(git_log_config);
+
+       if (diff_use_color_default == -1)
+               diff_use_color_default = git_use_color_default;
+
        init_revisions(&rev, prefix);
        init_reflog_walk(&rev.reflog_info);
        rev.abbrev_commit = 1;
@@ -395,6 +409,10 @@ int cmd_log(int argc, const char **argv, const char *prefix)
        struct rev_info rev;
 
        git_config(git_log_config);
+
+       if (diff_use_color_default == -1)
+               diff_use_color_default = git_use_color_default;
+
        init_revisions(&rev, prefix);
        rev.always_show_header = 1;
        cmd_log_init(argc, argv, prefix, &rev);
@@ -556,7 +574,8 @@ static void get_patch_ids(struct rev_info *rev, struct patch_ids *ids, const cha
        o2->flags ^= UNINTERESTING;
        add_pending_object(&check_rev, o1, "o1");
        add_pending_object(&check_rev, o2, "o2");
-       prepare_revision_walk(&check_rev);
+       if (prepare_revision_walk(&check_rev))
+               die("revision walk setup failed");
 
        while ((commit = get_revision(&check_rev)) != NULL) {
                /* ignore merges */
@@ -781,7 +800,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
        if (!use_stdout)
                realstdout = xfdopen(xdup(1), "w");
 
-       prepare_revision_walk(&rev);
+       if (prepare_revision_walk(&rev))
+               die("revision walk setup failed");
        while ((commit = get_revision(&rev)) != NULL) {
                /* ignore merges */
                if (commit->parents && commit->parents->next)
@@ -923,7 +943,8 @@ int cmd_cherry(int argc, const char **argv, const char *prefix)
                die("Unknown commit %s", limit);
 
        /* reverse the list of commits */
-       prepare_revision_walk(&revs);
+       if (prepare_revision_walk(&revs))
+               die("revision walk setup failed");
        while ((commit = get_revision(&revs)) != NULL) {
                /* ignore merges */
                if (commit->parents && commit->parents->next)
index dc7eab89b34fed32dbb198a9aa9a7503fc162216..25dbfb44999566d0491b3f870a47f7df80aa7649 100644 (file)
@@ -574,8 +574,17 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix)
        pathspec = get_pathspec(prefix, argv + i);
 
        /* Verify that the pathspec matches the prefix */
-       if (pathspec)
+       if (pathspec) {
+               if (argc != i) {
+                       int cnt;
+                       for (cnt = 0; pathspec[cnt]; cnt++)
+                               ;
+                       if (cnt != (argc - i))
+                               exit(1); /* error message already given */
+               }
                prefix = verify_pathspec(prefix);
+       } else if (argc != i)
+               exit(1); /* error message already given */
 
        /* Treat unmatching pathspec elements as errors */
        if (pathspec && error_unmatch) {
index 990e21355d189096bdc0c808fb536b7bfb85b0a1..68aa2a68bb8f4232732829ba7d9459bbef3c7ad5 100644 (file)
@@ -19,6 +19,7 @@ static const char **copy_pathspec(const char *prefix, const char **pathspec,
                                  int count, int base_name)
 {
        int i;
+       int len = prefix ? strlen(prefix) : 0;
        const char **result = xmalloc((count + 1) * sizeof(const char *));
        memcpy(result, pathspec, count * sizeof(const char *));
        result[count] = NULL;
@@ -32,8 +33,11 @@ static const char **copy_pathspec(const char *prefix, const char **pathspec,
                        if (last_slash)
                                result[i] = last_slash + 1;
                }
+               result[i] = prefix_path(prefix, len, result[i]);
+               if (!result[i])
+                       exit(1); /* error already given */
        }
-       return get_pathspec(prefix, result);
+       return result;
 }
 
 static void show_list(const char *label, struct path_list *list)
@@ -164,7 +168,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
                                }
 
                                dst = add_slash(dst);
-                               dst_len = strlen(dst) - 1;
+                               dst_len = strlen(dst);
 
                                for (j = 0; j < last - first; j++) {
                                        const char *path =
@@ -172,7 +176,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
                                        source[argc + j] = path;
                                        destination[argc + j] =
                                                prefix_path(dst, dst_len,
-                                                       path + length);
+                                                       path + length + 1);
                                        modes[argc + j] = INDEX;
                                }
                                argc += last - first;
index 692a76126b027133fd046f03003fe8e49218f192..586ae1197570d99fcbb8913003e8aa3c55b31777 100644 (file)
@@ -16,6 +16,7 @@
 #include "progress.h"
 
 #ifdef THREADED_DELTA_SEARCH
+#include "thread-utils.h"
 #include <pthread.h>
 #endif
 
@@ -1852,11 +1853,11 @@ static int git_pack_config(const char *k, const char *v)
        }
        if (!strcmp(k, "pack.threads")) {
                delta_search_threads = git_config_int(k, v);
-               if (delta_search_threads < 1)
+               if (delta_search_threads < 0)
                        die("invalid number of threads specified (%d)",
                            delta_search_threads);
 #ifndef THREADED_DELTA_SEARCH
-               if (delta_search_threads > 1)
+               if (delta_search_threads != 1)
                        warning("no threads support, ignoring %s", k);
 #endif
                return 0;
@@ -2033,7 +2034,8 @@ static void get_object_list(int ac, const char **av)
                        die("bad revision '%s'", line);
        }
 
-       prepare_revision_walk(&revs);
+       if (prepare_revision_walk(&revs))
+               die("revision walk setup failed");
        mark_edges_uninteresting(revs.commits, &revs, show_edge);
        traverse_commit_list(&revs, show_commit, show_object);
 
@@ -2121,10 +2123,10 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
                if (!prefixcmp(arg, "--threads=")) {
                        char *end;
                        delta_search_threads = strtoul(arg+10, &end, 0);
-                       if (!arg[10] || *end || delta_search_threads < 1)
+                       if (!arg[10] || *end || delta_search_threads < 0)
                                usage(pack_usage);
 #ifndef THREADED_DELTA_SEARCH
-                       if (delta_search_threads > 1)
+                       if (delta_search_threads != 1)
                                warning("no threads support, "
                                        "ignoring %s", arg);
 #endif
@@ -2234,6 +2236,11 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
        if (!pack_to_stdout && thin)
                die("--thin cannot be used to build an indexable pack.");
 
+#ifdef THREADED_DELTA_SEARCH
+       if (!delta_search_threads)      /* --threads=0 means autodetect */
+               delta_search_threads = online_cpus();
+#endif
+
        prepare_packed_git();
 
        if (progress)
index c8cb63e23840915ecd7445d1fe4a18f9c6cb694d..9f727c00f689ae23373502c7fb21b2234a1c1748 100644 (file)
@@ -90,7 +90,7 @@ static int do_push(const char *repo, int flags)
                if (!err)
                        continue;
 
-               error("failed to push to '%s'", remote->url[i]);
+               error("failed to push some refs to '%s'", remote->url[i]);
                errs++;
        }
        return !!errs;
index 57854017535a36fc1fcd7bb997f198956391199d..7bdc312e3861103fa83b20b939962a8bc8e6cc0a 100644 (file)
@@ -41,11 +41,12 @@ static int read_cache_unmerged(void)
        for (i = 0; i < active_nr; i++) {
                struct cache_entry *ce = active_cache[i];
                if (ce_stage(ce)) {
+                       remove_index_entry(ce);
                        if (last && !strcmp(ce->name, last->name))
                                continue;
                        cache_tree_invalidate_path(active_cache_tree, ce->name);
                        last = ce;
-                       ce->ce_flags |= CE_REMOVE;
+                       continue;
                }
                *dst++ = ce;
        }
index 4836ec951be727512bcd550dd3604c43c39aa557..ab53c8cb7c08298c3ab0f69bf600a70385dafa64 100644 (file)
@@ -276,10 +276,11 @@ static int expire_reflog(const char *ref, const unsigned char *sha1, int unused,
        for_each_reflog_ent(ref, expire_reflog_ent, &cb);
  finish:
        if (cb.newlog) {
-               if (fclose(cb.newlog))
+               if (fclose(cb.newlog)) {
                        status |= error("%s: %s", strerror(errno),
                                        newlog_path);
-               if (rename(newlog_path, log_file)) {
+                       unlink(newlog_path);
+               } else if (rename(newlog_path, log_file)) {
                        status |= error("cannot rename %s to %s",
                                        newlog_path, log_file);
                        unlink(newlog_path);
index b0c17bde879d42c16fe5c7f0756763cd638f8bac..c607aade637423f0129167163fa4055b08546248 100644 (file)
@@ -267,23 +267,6 @@ static int diff_two(const char *file1, const char *label1,
        return 0;
 }
 
-static int copy_file(const char *src, const char *dest)
-{
-       FILE *in, *out;
-       char buffer[32768];
-       int count;
-
-       if (!(in = fopen(src, "r")))
-               return error("Could not open %s", src);
-       if (!(out = fopen(dest, "w")))
-               return error("Could not open %s", dest);
-       while ((count = fread(buffer, 1, sizeof(buffer), in)))
-               fwrite(buffer, 1, count, out);
-       fclose(in);
-       fclose(out);
-       return 0;
-}
-
 static int do_plain_rerere(struct path_list *rr, int fd)
 {
        struct path_list conflict = { NULL, 0, 0, 1 };
@@ -343,7 +326,7 @@ static int do_plain_rerere(struct path_list *rr, int fd)
                        continue;
 
                fprintf(stderr, "Recorded resolution for '%s'.\n", path);
-               copy_file(path, rr_path(name, "postimage"));
+               copy_file(rr_path(name, "postimage"), path, 0666);
 tail_optimization:
                if (i < rr->nr - 1)
                        memmove(rr->items + i,
index de80158fd4762aa692193edb7c0f8e85e6189877..6f7d5f8214e54c24983e9c8c295edfefba54fb2b 100644 (file)
@@ -60,6 +60,8 @@ static void show_commit(struct commit *commit)
                fputs(header_prefix, stdout);
        if (commit->object.flags & BOUNDARY)
                putchar('-');
+       else if (commit->object.flags & UNINTERESTING)
+               putchar('^');
        else if (revs.left_right) {
                if (commit->object.flags & SYMMETRIC_LEFT)
                        putchar('<');
@@ -84,7 +86,7 @@ static void show_commit(struct commit *commit)
        else
                putchar('\n');
 
-       if (revs.verbose_header) {
+       if (revs.verbose_header && commit->buffer) {
                struct strbuf buf;
                strbuf_init(&buf, 0);
                pretty_print_commit(revs.commit_format, commit,
@@ -609,7 +611,8 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
        if (bisect_list)
                revs.limited = 1;
 
-       prepare_revision_walk(&revs);
+       if (prepare_revision_walk(&revs))
+               die("revision walk setup failed");
        if (revs.tree_objects)
                mark_edges_uninteresting(revs.commits, &revs, show_edge);
 
index b9af1a5a554e21338531b88cd34bcb767d5f3848..90dbb9d7c1a28fd463ba827cb8da2eab42e489df 100644 (file)
@@ -315,7 +315,7 @@ static int cmd_parseopt(int argc, const char **argv, const char *prefix)
                s = strchr(sb.buf, ' ');
                if (!s || *sb.buf == ' ') {
                        o->type = OPTION_GROUP;
-                       o->help = xstrdup(skipspaces(s));
+                       o->help = xstrdup(skipspaces(sb.buf));
                        continue;
                }
 
index fa8bc7d02a2268d99dcc829cb3adbee10c949306..0055a57aeb24392de0dcf337bb93f30fceccd88f 100644 (file)
@@ -136,7 +136,8 @@ static void get_from_rev(struct rev_info *rev, struct path_list *list)
 {
        struct commit *commit;
 
-       prepare_revision_walk(rev);
+       if (prepare_revision_walk(rev))
+               die("revision walk setup failed");
        while ((commit = get_revision(rev)) != NULL) {
                const char *author = NULL, *buffer;
 
index 65051d14fde44c14d12099df656ac423bc1c347e..a323633e296cef1797ab1d218cea83c891bc3b8d 100644 (file)
@@ -86,6 +86,9 @@ match:
                            sha1_to_hex(sha1));
                if (obj->type == OBJ_TAG) {
                        obj = deref_tag(obj, refname, 0);
+                       if (!obj)
+                               die("git-show-ref: bad tag at ref %s (%s)", refname,
+                                   sha1_to_hex(sha1));
                        hex = find_unique_abbrev(obj->sha1, abbrev);
                        printf("%s %s^{}\n", hex, refname);
                }
index 4a4a88c10b4b2f9e55662bd4c1c17051ae7e6aac..716b4fff323f7df638f8bed0940a1119e43c2590 100644 (file)
@@ -236,9 +236,6 @@ static int do_sign(struct strbuf *buffer)
        if (finish_command(&gpg) || !len || len < 0)
                return error("gpg failed to sign the tag");
 
-       if (len < 0)
-               return error("could not read the entire signature from gpg.");
-
        return 0;
 }
 
index 5c95eca07d19a6d3ed4e9000b5bb47eef90ff66e..bd12ec8537781c5c82e77637312ccabb708d5040 100644 (file)
--- a/bundle.c
+++ b/bundle.c
@@ -128,7 +128,8 @@ int verify_bundle(struct bundle_header *header, int verbose)
                add_object_array(e->item, e->name, &refs);
        }
 
-       prepare_revision_walk(&revs);
+       if (prepare_revision_walk(&revs))
+               die("revision walk setup failed");
 
        i = req_nr;
        while (i && (commit = get_revision(&revs)))
diff --git a/cache.h b/cache.h
index e1000bccb2470ad66038aabbf57b0af96e506f11..922bed921213e4cc0e40c6f14533024c240af9ed 100644 (file)
--- a/cache.h
+++ b/cache.h
@@ -110,7 +110,6 @@ struct ondisk_cache_entry {
 };
 
 struct cache_entry {
-       struct cache_entry *next;
        unsigned int ce_ctime;
        unsigned int ce_mtime;
        unsigned int ce_dev;
@@ -121,6 +120,7 @@ struct cache_entry {
        unsigned int ce_size;
        unsigned int ce_flags;
        unsigned char sha1[20];
+       struct cache_entry *next;
        char name[FLEX_ARRAY]; /* more */
 };
 
@@ -133,7 +133,39 @@ struct cache_entry {
 #define CE_UPDATE    (0x10000)
 #define CE_REMOVE    (0x20000)
 #define CE_UPTODATE  (0x40000)
-#define CE_UNHASHED  (0x80000)
+
+#define CE_HASHED    (0x100000)
+#define CE_UNHASHED  (0x200000)
+
+/*
+ * Copy the sha1 and stat state of a cache entry from one to
+ * another. But we never change the name, or the hash state!
+ */
+#define CE_STATE_MASK (CE_HASHED | CE_UNHASHED)
+static inline void copy_cache_entry(struct cache_entry *dst, struct cache_entry *src)
+{
+       unsigned int state = dst->ce_flags & CE_STATE_MASK;
+
+       /* Don't copy hash chain and name */
+       memcpy(dst, src, offsetof(struct cache_entry, next));
+
+       /* Restore the hash state */
+       dst->ce_flags = (dst->ce_flags & ~CE_STATE_MASK) | state;
+}
+
+/*
+ * We don't actually *remove* it, we can just mark it invalid so that
+ * we won't find it in lookups.
+ *
+ * Not only would we have to search the lists (simple enough), but
+ * we'd also have to rehash other hash buckets in case this makes the
+ * hash bucket empty (common). So it's much better to just mark
+ * it.
+ */
+static inline void remove_index_entry(struct cache_entry *ce)
+{
+       ce->ce_flags |= CE_UNHASHED;
+}
 
 static inline unsigned create_ce_flags(size_t len, unsigned stage)
 {
@@ -666,6 +698,7 @@ extern const char *git_log_output_encoding;
 /* IO helper functions */
 extern void maybe_flush_or_die(FILE *, const char *);
 extern int copy_fd(int ifd, int ofd);
+extern int copy_file(const char *dst, const char *src, int mode);
 extern int read_in_full(int fd, void *buf, size_t count);
 extern int write_in_full(int fd, const void *buf, size_t count);
 extern void write_or_die(int fd, const void *buf, size_t count);
@@ -719,6 +752,7 @@ void shift_tree(const unsigned char *, const unsigned char *, unsigned char *, i
 #define WS_TRAILING_SPACE      01
 #define WS_SPACE_BEFORE_TAB    02
 #define WS_INDENT_WITH_NON_TAB 04
+#define WS_CR_AT_EOL           010
 #define WS_DEFAULT_RULE (WS_TRAILING_SPACE|WS_SPACE_BEFORE_TAB)
 extern unsigned whitespace_rule_cfg;
 extern unsigned whitespace_rule(const char *);
@@ -727,6 +761,7 @@ extern unsigned check_and_emit_line(const char *line, int len, unsigned ws_rule,
     FILE *stream, const char *set,
     const char *reset, const char *ws);
 extern char *whitespace_error_string(unsigned ws);
+extern int ws_fix_copy(char *, const char *, int, unsigned, int *);
 
 /* ls-files */
 int pathspec_match(const char **spec, char *matched, const char *filename, int skiplen);
diff --git a/color.c b/color.c
index cb70340420b6285786b988d4a98d2023a37d4ffc..12a6453f90eb4ce2b39f85762bf3acd1cff2b9f2 100644 (file)
--- a/color.c
+++ b/color.c
@@ -3,6 +3,8 @@
 
 #define COLOR_RESET "\033[m"
 
+int git_use_color_default = 0;
+
 static int parse_color(const char *name, int len)
 {
        static const char * const color_names[] = {
@@ -143,6 +145,16 @@ int git_config_colorbool(const char *var, const char *value, int stdout_is_tty)
        return 0;
 }
 
+int git_color_default_config(const char *var, const char *value)
+{
+       if (!strcmp(var, "color.ui")) {
+               git_use_color_default = git_config_colorbool(var, value, -1);
+               return 0;
+       }
+
+       return git_default_config(var, value);
+}
+
 static int color_vfprintf(FILE *fp, const char *color, const char *fmt,
                va_list args, const char *trail)
 {
diff --git a/color.h b/color.h
index ff63513d39b1553e65230ef98583549506670950..ecda5569a2cccabaf16fcf0aad3bce57dfb3aca4 100644 (file)
--- a/color.h
+++ b/color.h
@@ -4,6 +4,17 @@
 /* "\033[1;38;5;2xx;48;5;2xxm\0" is 23 bytes */
 #define COLOR_MAXLEN 24
 
+/*
+ * This variable stores the value of color.ui
+ */
+extern int git_use_color_default;
+
+
+/*
+ * Use this instead of git_default_config if you need the value of color.ui.
+ */
+int git_color_default_config(const char *var, const char *value);
+
 int git_config_colorbool(const char *var, const char *value, int stdout_is_tty);
 void color_parse(const char *var, const char *value, char *dst);
 int color_fprintf(FILE *fp, const char *color, const char *fmt, ...);
index 8b8fb04d1f6107da15cb142485d80cabe7a3828e..22ce7768639465f896e52b08a73cf5605940700b 100644 (file)
--- a/commit.c
+++ b/commit.c
@@ -311,6 +311,8 @@ int parse_commit(struct commit *item)
        unsigned long size;
        int ret;
 
+       if (!item)
+               return -1;
        if (item->object.parsed)
                return 0;
        buffer = read_sha1_file(item->object.sha1, &type, &size);
@@ -385,8 +387,7 @@ struct commit *pop_most_recent_commit(struct commit_list **list,
 
        while (parents) {
                struct commit *commit = parents->item;
-               parse_commit(commit);
-               if (!(commit->object.flags & mark)) {
+               if (!parse_commit(commit) && !(commit->object.flags & mark)) {
                        commit->object.flags |= mark;
                        insert_by_date(commit, list);
                }
@@ -552,8 +553,10 @@ static struct commit_list *merge_bases(struct commit *one, struct commit *two)
                 */
                return commit_list_insert(one, &result);
 
-       parse_commit(one);
-       parse_commit(two);
+       if (parse_commit(one))
+               return NULL;
+       if (parse_commit(two))
+               return NULL;
 
        one->object.flags |= PARENT1;
        two->object.flags |= PARENT2;
@@ -586,7 +589,8 @@ static struct commit_list *merge_bases(struct commit *one, struct commit *two)
                        parents = parents->next;
                        if ((p->object.flags & flags) == flags)
                                continue;
-                       parse_commit(p);
+                       if (parse_commit(p))
+                               return NULL;
                        p->object.flags |= flags;
                        insert_by_date(p, &list);
                }
diff --git a/compat/fopen.c b/compat/fopen.c
new file mode 100644 (file)
index 0000000..ccb9e89
--- /dev/null
@@ -0,0 +1,26 @@
+#include "../git-compat-util.h"
+#undef fopen
+FILE *git_fopen(const char *path, const char *mode)
+{
+       FILE *fp;
+       struct stat st;
+
+       if (mode[0] == 'w' || mode[0] == 'a')
+               return fopen(path, mode);
+
+       if (!(fp = fopen(path, mode)))
+               return NULL;
+
+       if (fstat(fileno(fp), &st)) {
+               fclose(fp);
+               return NULL;
+       }
+
+       if (S_ISDIR(st.st_mode)) {
+               fclose(fp);
+               errno = EISDIR;
+               return NULL;
+       }
+
+       return fp;
+}
index 8064cae18290d66ee69f1a56e501391ecb317b3d..cba2bcfb6722bb26ed80e8b7e5a50616cb4702e1 100644 (file)
--- a/config.c
+++ b/config.c
@@ -280,11 +280,18 @@ int git_parse_ulong(const char *value, unsigned long *ret)
        return 0;
 }
 
+static void die_bad_config(const char *name)
+{
+       if (config_file_name)
+               die("bad config value for '%s' in %s", name, config_file_name);
+       die("bad config value for '%s'", name);
+}
+
 int git_config_int(const char *name, const char *value)
 {
        long ret;
        if (!git_parse_long(value, &ret))
-               die("bad config value for '%s' in %s", name, config_file_name);
+               die_bad_config(name);
        return ret;
 }
 
@@ -292,7 +299,7 @@ unsigned long git_config_ulong(const char *name, const char *value)
 {
        unsigned long ret;
        if (!git_parse_ulong(value, &ret))
-               die("bad config value for '%s' in %s", name, config_file_name);
+               die_bad_config(name);
        return ret;
 }
 
index 4ea727b14303e397117067993dbda446ed154ea1..8722a687954ec47a538eff45d41434deedf717fb 100755 (executable)
@@ -91,7 +91,10 @@ __git_ps1 ()
                        fi
                        if ! b="$(git symbolic-ref HEAD 2>/dev/null)"
                        then
-                               b="$(cut -c1-7 $g/HEAD)..."
+                               if ! b="$(git describe --exact-match HEAD 2>/dev/null)"
+                               then
+                                       b="$(cut -c1-7 $g/HEAD)..."
+                               fi
                        fi
                fi
 
index a8bf0ef883358c7eaf9a13dde8f371a86ff840f0..f69b697f8d5891b7a16e6d4769bdc3642209b747 100644 (file)
@@ -185,9 +185,8 @@ if there is already one that displays the same directory."
 
 (defun git-call-process-env (buffer env &rest args)
   "Wrapper for call-process that sets environment strings."
-  (if env
-      (apply #'call-process "env" nil buffer nil
-             (append (git-get-env-strings env) (list "git") args))
+  (let ((process-environment (append (git-get-env-strings env)
+                                     process-environment)))
     (apply #'call-process "git" nil buffer nil args)))
 
 (defun git-call-process-display-error (&rest args)
@@ -204,7 +203,7 @@ if there is already one that displays the same directory."
 
 (defun git-call-process-env-string (env &rest args)
   "Wrapper for call-process that sets environment strings,
-and returns the process output as a string."
+and returns the process output as a string, or nil if the git failed."
   (with-temp-buffer
     (and (eq 0 (apply #' git-call-process-env t env args))
          (buffer-string))))
diff --git a/copy.c b/copy.c
index c225d1b0ff0a67e637f7200ab5c2a917b550af4f..afc4fbf41405d42d2751ea35ec7a9a32f8df6274 100644 (file)
--- a/copy.c
+++ b/copy.c
@@ -34,3 +34,24 @@ int copy_fd(int ifd, int ofd)
        close(ifd);
        return 0;
 }
+
+int copy_file(const char *dst, const char *src, int mode)
+{
+       int fdi, fdo, status;
+
+       mode = (mode & 0111) ? 0777 : 0666;
+       if ((fdi = open(src, O_RDONLY)) < 0)
+               return fdi;
+       if ((fdo = open(dst, O_WRONLY | O_CREAT | O_EXCL, mode)) < 0) {
+               close(fdi);
+               return fdo;
+       }
+       status = copy_fd(fdi, fdo);
+       if (close(fdo) != 0)
+               return error("%s: write error: %s", dst, strerror(errno));
+
+       if (!status && adjust_shared_perm(dst))
+               return -1;
+
+       return status;
+}
diff --git a/date.c b/date.c
index 8f7050027053a4e2390097e341327b117404c26a..a74ed86422763e7d7e5dccf73530e52551a6929a 100644 (file)
--- a/date.c
+++ b/date.c
@@ -213,9 +213,9 @@ static const struct {
        { "EAST", +10, 0, },    /* Eastern Australian Standard */
        { "EADT", +10, 1, },    /* Eastern Australian Daylight */
        { "GST",  +10, 0, },    /* Guam Standard, USSR Zone 9 */
-       { "NZT",  +11, 0, },    /* New Zealand */
-       { "NZST", +11, 0, },    /* New Zealand Standard */
-       { "NZDT", +11, 1, },    /* New Zealand Daylight */
+       { "NZT",  +12, 0, },    /* New Zealand */
+       { "NZST", +12, 0, },    /* New Zealand Standard */
+       { "NZDT", +12, 1, },    /* New Zealand Daylight */
        { "IDLE", +12, 0, },    /* International Date Line East */
 };
 
diff --git a/diff.c b/diff.c
index 58fe7750f9ca7d63192164a3ac8da27553489d11..dff826b6347bfde01907c0c3b5f1873cd951c1fe 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -20,7 +20,7 @@
 
 static int diff_detect_rename_default;
 static int diff_rename_limit_default = 100;
-static int diff_use_color_default;
+int diff_use_color_default = -1;
 static const char *external_diff_cmd_cfg;
 int diff_auto_refresh_index = 1;
 
@@ -191,7 +191,7 @@ int git_diff_basic_config(const char *var, const char *value)
                }
        }
 
-       return git_default_config(var, value);
+       return git_color_default_config(var, value);
 }
 
 static char *quote_two(const char *one, const char *two)
@@ -272,8 +272,8 @@ static void print_line_count(int count)
        }
 }
 
-static void copy_file(int prefix, const char *data, int size,
-               const char *set, const char *reset)
+static void copy_file_with_prefix(int prefix, const char *data, int size,
+                                 const char *set, const char *reset)
 {
        int ch, nl_just_seen = 1;
        while (0 < size--) {
@@ -331,9 +331,9 @@ static void emit_rewrite_diff(const char *name_a,
        print_line_count(lc_b);
        printf(" @@%s\n", reset);
        if (lc_a)
-               copy_file('-', one->data, one->size, old, reset);
+               copy_file_with_prefix('-', one->data, one->size, old, reset);
        if (lc_b)
-               copy_file('+', two->data, two->size, new, reset);
+               copy_file_with_prefix('+', two->data, two->size, new, reset);
 }
 
 static int fill_mmfile(mmfile_t *mf, struct diff_filespec *one)
@@ -982,6 +982,90 @@ static void show_numstat(struct diffstat_t* data, struct diff_options *options)
        }
 }
 
+struct diffstat_dir {
+       struct diffstat_file **files;
+       int nr, percent, cumulative;
+};
+
+static long gather_dirstat(struct diffstat_dir *dir, unsigned long changed, const char *base, int baselen)
+{
+       unsigned long this_dir = 0;
+       unsigned int sources = 0;
+
+       while (dir->nr) {
+               struct diffstat_file *f = *dir->files;
+               int namelen = strlen(f->name);
+               unsigned long this;
+               char *slash;
+
+               if (namelen < baselen)
+                       break;
+               if (memcmp(f->name, base, baselen))
+                       break;
+               slash = strchr(f->name + baselen, '/');
+               if (slash) {
+                       int newbaselen = slash + 1 - f->name;
+                       this = gather_dirstat(dir, changed, f->name, newbaselen);
+                       sources++;
+               } else {
+                       if (f->is_unmerged || f->is_binary)
+                               this = 0;
+                       else
+                               this = f->added + f->deleted;
+                       dir->files++;
+                       dir->nr--;
+                       sources += 2;
+               }
+               this_dir += this;
+       }
+
+       /*
+        * We don't report dirstat's for
+        *  - the top level
+        *  - or cases where everything came from a single directory
+        *    under this directory (sources == 1).
+        */
+       if (baselen && sources != 1) {
+               int permille = this_dir * 1000 / changed;
+               if (permille) {
+                       int percent = permille / 10;
+                       if (percent >= dir->percent) {
+                               printf("%4d.%01d%% %.*s\n", percent, permille % 10, baselen, base);
+                               if (!dir->cumulative)
+                                       return 0;
+                       }
+               }
+       }
+       return this_dir;
+}
+
+static void show_dirstat(struct diffstat_t *data, struct diff_options *options)
+{
+       int i;
+       unsigned long changed;
+       struct diffstat_dir dir;
+
+       /* Calculate total changes */
+       changed = 0;
+       for (i = 0; i < data->nr; i++) {
+               if (data->files[i]->is_binary || data->files[i]->is_unmerged)
+                       continue;
+               changed += data->files[i]->added;
+               changed += data->files[i]->deleted;
+       }
+
+       /* This can happen even with many files, if everything was renames */
+       if (!changed)
+               return;
+
+       /* Show all directories with more than x% of the changes */
+       dir.files = data->files;
+       dir.nr = data->nr;
+       dir.percent = options->dirstat_percent;
+       dir.cumulative = options->output_format & DIFF_FORMAT_CUMULATIVE;
+       gather_dirstat(&dir, changed, "", 0);
+}
+
 static void free_diffstat_info(struct diffstat_t *diffstat)
 {
        int i;
@@ -1199,7 +1283,7 @@ static struct builtin_funcname_pattern {
                        "new\\|return\\|switch\\|throw\\|while\\)\n"
                        "^[     ]*\\(\\([       ]*"
                        "[A-Za-z_][A-Za-z_0-9]*\\)\\{2,\\}"
-                       "[      ]*([^;]*$\\)" },
+                       "[      ]*([^;]*\\)$" },
        { "tex", "^\\(\\\\\\(sub\\)*section{.*\\)$" },
 };
 
@@ -2050,12 +2134,13 @@ void diff_setup(struct diff_options *options)
        options->line_termination = '\n';
        options->break_opt = -1;
        options->rename_limit = -1;
+       options->dirstat_percent = 3;
        options->context = 3;
        options->msg_sep = "";
 
        options->change = diff_change;
        options->add_remove = diff_addremove;
-       if (diff_use_color_default)
+       if (diff_use_color_default > 0)
                DIFF_OPT_SET(options, COLOR_DIFF);
        else
                DIFF_OPT_CLR(options, COLOR_DIFF);
@@ -2091,6 +2176,7 @@ int diff_setup_done(struct diff_options *options)
                                            DIFF_FORMAT_NUMSTAT |
                                            DIFF_FORMAT_DIFFSTAT |
                                            DIFF_FORMAT_SHORTSTAT |
+                                           DIFF_FORMAT_DIRSTAT |
                                            DIFF_FORMAT_SUMMARY |
                                            DIFF_FORMAT_PATCH);
 
@@ -2102,6 +2188,7 @@ int diff_setup_done(struct diff_options *options)
                                      DIFF_FORMAT_NUMSTAT |
                                      DIFF_FORMAT_DIFFSTAT |
                                      DIFF_FORMAT_SHORTSTAT |
+                                     DIFF_FORMAT_DIRSTAT |
                                      DIFF_FORMAT_SUMMARY |
                                      DIFF_FORMAT_CHECKDIFF))
                DIFF_OPT_SET(options, RECURSIVE);
@@ -2212,6 +2299,10 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
                options->output_format |= DIFF_FORMAT_NUMSTAT;
        else if (!strcmp(arg, "--shortstat"))
                options->output_format |= DIFF_FORMAT_SHORTSTAT;
+       else if (opt_arg(arg, 'X', "dirstat", &options->dirstat_percent))
+               options->output_format |= DIFF_FORMAT_DIRSTAT;
+       else if (!strcmp(arg, "--cumulative"))
+               options->output_format |= DIFF_FORMAT_CUMULATIVE;
        else if (!strcmp(arg, "--check"))
                options->output_format |= DIFF_FORMAT_CHECKDIFF;
        else if (!strcmp(arg, "--summary"))
@@ -2930,7 +3021,7 @@ void diff_flush(struct diff_options *options)
                separator++;
        }
 
-       if (output_format & (DIFF_FORMAT_DIFFSTAT|DIFF_FORMAT_SHORTSTAT|DIFF_FORMAT_NUMSTAT)) {
+       if (output_format & (DIFF_FORMAT_DIFFSTAT|DIFF_FORMAT_SHORTSTAT|DIFF_FORMAT_NUMSTAT|DIFF_FORMAT_DIRSTAT)) {
                struct diffstat_t diffstat;
 
                memset(&diffstat, 0, sizeof(struct diffstat_t));
@@ -2940,6 +3031,8 @@ void diff_flush(struct diff_options *options)
                        if (check_pair_status(p))
                                diff_flush_stat(p, options, &diffstat);
                }
+               if (output_format & DIFF_FORMAT_DIRSTAT)
+                       show_dirstat(&diffstat, options);
                if (output_format & DIFF_FORMAT_NUMSTAT)
                        show_numstat(&diffstat, options);
                if (output_format & DIFF_FORMAT_DIFFSTAT)
diff --git a/diff.h b/diff.h
index 073d5cbf1ba97acf527770d912870cda01195489..c5d3a4f965380fd56791fc99864fa27b758da7ca 100644 (file)
--- a/diff.h
+++ b/diff.h
@@ -30,6 +30,8 @@ typedef void (*diff_format_fn_t)(struct diff_queue_struct *q,
 #define DIFF_FORMAT_SUMMARY    0x0008
 #define DIFF_FORMAT_PATCH      0x0010
 #define DIFF_FORMAT_SHORTSTAT  0x0020
+#define DIFF_FORMAT_DIRSTAT    0x0040
+#define DIFF_FORMAT_CUMULATIVE 0x0080
 
 /* These override all above */
 #define DIFF_FORMAT_NAME       0x0100
@@ -80,6 +82,7 @@ struct diff_options {
        int pickaxe_opts;
        int rename_score;
        int rename_limit;
+       int dirstat_percent;
        int setup;
        int abbrev;
        const char *msg_sep;
@@ -174,6 +177,7 @@ extern void diff_unmerge(struct diff_options *,
 
 extern int git_diff_basic_config(const char *var, const char *value);
 extern int git_diff_ui_config(const char *var, const char *value);
+extern int diff_use_color_default;
 extern void diff_setup(struct diff_options *);
 extern int diff_opt_parse(struct diff_options *, const char **, int);
 extern int diff_setup_done(struct diff_options *);
index 17ca5b84f0c077d61b9392bd7900954ce35d6cbf..a0a81f134a6288dfc1d87431698f29597ed5e488 100755 (executable)
@@ -82,6 +82,19 @@ sub list_untracked {
 my $status_fmt = '%12s %12s %s';
 my $status_head = sprintf($status_fmt, 'staged', 'unstaged', 'path');
 
+{
+       my $initial;
+       sub is_initial_commit {
+               $initial = system('git rev-parse HEAD -- >/dev/null 2>&1') != 0
+                       unless defined $initial;
+               return $initial;
+       }
+}
+
+sub get_empty_tree {
+       return '4b825dc642cb6eb9a060e54bf8d69288fbee4904';
+}
+
 # Returns list of hashes, contents of each of which are:
 # VALUE:       pathname
 # BINARY:      is a binary path
@@ -103,8 +116,10 @@ sub list_modified {
                return if (!@tracked);
        }
 
+       my $reference = is_initial_commit() ? get_empty_tree() : 'HEAD';
        for (run_cmd_pipe(qw(git diff-index --cached
-                            --numstat --summary HEAD --), @tracked)) {
+                            --numstat --summary), $reference,
+                            '--', @tracked)) {
                if (($add, $del, $file) =
                    /^([-\d]+)  ([-\d]+)        (.*)/) {
                        my ($change, $bin);
@@ -476,21 +491,27 @@ sub revert_cmd {
                                       HEADER => $status_head, },
                                     list_modified());
        if (@update) {
-               my @lines = run_cmd_pipe(qw(git ls-tree HEAD --),
-                                        map { $_->{VALUE} } @update);
-               my $fh;
-               open $fh, '| git update-index --index-info'
-                   or die;
-               for (@lines) {
-                       print $fh $_;
+               if (is_initial_commit()) {
+                       system(qw(git rm --cached),
+                               map { $_->{VALUE} } @update);
                }
-               close($fh);
-               for (@update) {
-                       if ($_->{INDEX_ADDDEL} &&
-                           $_->{INDEX_ADDDEL} eq 'create') {
-                               system(qw(git update-index --force-remove --),
-                                      $_->{VALUE});
-                               print "note: $_->{VALUE} is untracked now.\n";
+               else {
+                       my @lines = run_cmd_pipe(qw(git ls-tree HEAD --),
+                                                map { $_->{VALUE} } @update);
+                       my $fh;
+                       open $fh, '| git update-index --index-info'
+                           or die;
+                       for (@lines) {
+                               print $fh $_;
+                       }
+                       close($fh);
+                       for (@update) {
+                               if ($_->{INDEX_ADDDEL} &&
+                                   $_->{INDEX_ADDDEL} eq 'create') {
+                                       system(qw(git update-index --force-remove --),
+                                              $_->{VALUE});
+                                       print "note: $_->{VALUE} is untracked now.\n";
+                               }
                        }
                }
                refresh();
@@ -956,7 +977,9 @@ sub diff_cmd {
                                     HEADER => $status_head, },
                                   @mods);
        return if (!@them);
-       system(qw(git diff -p --cached HEAD --), map { $_->{VALUE} } @them);
+       my $reference = is_initial_commit() ? get_empty_tree() : 'HEAD';
+       system(qw(git diff -p --cached), $reference, '--',
+               map { $_->{VALUE} } @them);
 }
 
 sub quit_cmd {
index 6594a62919adcf2d1c524cc24435b6fe444f9d52..74715edf0b197376250e5d111407a36a6c237678 100755 (executable)
@@ -331,9 +331,9 @@ bisect_visualize() {
 
        if test $# = 0
        then
-               case "${DISPLAY+set}" in
+               case "${DISPLAY+set}${MSYSTEM+set}${SECURITYSESSIONID+set}" in
                '')     set git log ;;
-               set   set gitk ;;
+               set*)   set gitk ;;
                esac
        else
                case "$1" in
index bd74d701a1f0abb63e2bcdcb47035cb2c6eee745..1a7689a48f07a6ed2bb156f745bfea19a10e3eb9 100755 (executable)
@@ -210,11 +210,14 @@ then
     git read-tree $v --reset -u $new
 else
     git update-index --refresh >/dev/null
-    merge_error=$(git read-tree -m -u --exclude-per-directory=.gitignore $old $new 2>&1) || (
-       case "$merge" in
-       '')
-               echo >&2 "$merge_error"
+    git read-tree $v -m -u --exclude-per-directory=.gitignore $old $new || (
+       case "$merge,$v" in
+       ,*)
                exit 1 ;;
+       1,)
+               ;; # quiet
+       *)
+               echo >&2 "Falling back to 3-way merge..." ;;
        esac
 
        # Match the index to the working tree, and do a three-way.
index b4e858c3885dab55398670d9497304eb83545d1f..0d686c3a03a15d73e086d3a54afeee269365ffcd 100755 (executable)
@@ -409,11 +409,12 @@ else
        cd "$D" || exit
 fi
 
-if test -z "$bare" && test -f "$GIT_DIR/REMOTE_HEAD"
+if test -z "$bare"
 then
        # a non-bare repository is always in separate-remote layout
        remote_top="refs/remotes/$origin"
-       head_sha1=`cat "$GIT_DIR/REMOTE_HEAD"`
+       head_sha1=
+       test ! -r "$GIT_DIR/REMOTE_HEAD" || head_sha1=`cat "$GIT_DIR/REMOTE_HEAD"`
        case "$head_sha1" in
        'ref: refs/'*)
                # Uh-oh, the remote told us (http transport done against
@@ -470,9 +471,16 @@ then
                git config branch."$head_points_at".merge "refs/heads/$head_points_at"
                ;;
        '')
-               # Source had detached HEAD pointing nowhere
-               git update-ref --no-deref HEAD "$head_sha1" &&
-               rm -f "refs/remotes/$origin/HEAD"
+               if test -z "$head_sha1"
+               then
+                       # Source had nonexistent ref in HEAD
+                       echo >&2 "Warning: Remote HEAD refers to nonexistent ref, unable to checkout."
+                       no_checkout=t
+               else
+                       # Source had detached HEAD pointing nowhere
+                       git update-ref --no-deref HEAD "$head_sha1" &&
+                       rm -f "refs/remotes/$origin/HEAD"
+               fi
                ;;
        esac
 
index 05146047e0f33476df963e0e5aef30dd02a249fc..2a40703c851d7011723588dd7643dc034db49c31 100644 (file)
@@ -204,6 +204,11 @@ void *gitmemmem(const void *haystack, size_t haystacklen,
                 const void *needle, size_t needlelen);
 #endif
 
+#ifdef FREAD_READS_DIRECTORIES
+#define fopen(a,b) git_fopen(a,b)
+extern FILE *git_fopen(const char*, const char*);
+#endif
+
 #ifdef __GLIBC_PREREQ
 #if __GLIBC_PREREQ(2, 1)
 #define HAVE_STRCHRNUL
index 2a8ad1e9f4cbc2c21b83fd72fae1e0d2e582fbdc..b6036bd4d305215b4a70b6fd0fe54d7607dbe068 100755 (executable)
@@ -197,15 +197,39 @@ if (@canstatusfiles) {
       my @updated = xargs_safe_pipe_capture([@cvs, 'update'], @canstatusfiles);
       print @updated;
     }
-    my @cvsoutput;
-    @cvsoutput = xargs_safe_pipe_capture([@cvs, 'status'], @canstatusfiles);
-    my $matchcount = 0;
-    foreach my $l (@cvsoutput) {
-        chomp $l;
-        if ( $l =~ /^File:/ and  $l =~ /Status: (.*)$/ ) {
-            $cvsstat{$canstatusfiles[$matchcount]} = $1;
-            $matchcount++;
+    # "cvs status" reorders the parameters, notably when there are multiple
+    # arguments with the same basename.  So be precise here.
+
+    my %added = map { $_ => 1 } @afiles;
+    my %todo = map { $_ => 1 } @canstatusfiles;
+
+    while (%todo) {
+      my @canstatusfiles2 = ();
+      my %fullname = ();
+      foreach my $name (keys %todo) {
+       my $basename = basename($name);
+
+       $basename = "no file " . $basename if (exists($added{$basename}));
+       chomp($basename);
+
+       if (!exists($fullname{$basename})) {
+         $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;
+         }
+       }
+      }
     }
 }
 
index 081d7550a7dbc91d8360822a4da3ca51c66a33a2..01e0a46ba56faa8a17ed8710346b18dd215899c7 100644 (file)
@@ -92,8 +92,12 @@ ifndef V
        REMOVE_F1 = && echo '   ' REMOVE `basename "$$dst"` && $(RM_RF) "$$dst"
 endif
 
-TCL_PATH   ?= tclsh
 TCLTK_PATH ?= wish
+ifeq (./,$(dir $(TCLTK_PATH)))
+       TCL_PATH ?= $(subst wish,tclsh,$(TCLTK_PATH))
+else
+       TCL_PATH ?= $(dir $(TCLTK_PATH))$(notdir $(subst wish,tclsh,$(TCLTK_PATH)))
+endif
 
 ifeq ($(uname_S),Darwin)
        TKFRAMEWORK = /Library/Frameworks/Tk.framework/Resources/Wish.app
@@ -127,7 +131,17 @@ GITGUI_MACOSXAPP :=
 
 ifeq ($(uname_O),Cygwin)
        GITGUI_SCRIPT := `cygpath --windows --absolute "$(GITGUI_SCRIPT)"`
-       gg_libdir_sed_in := $(shell cygpath --windows --absolute "$(gg_libdir)")
+
+       # Is this a Cygwin Tcl/Tk binary?  If so it knows how to do
+       # POSIX path translation just like cygpath does and we must
+       # keep libdir in POSIX format so Cygwin packages of git-gui
+       # work no matter where the user installs them.
+       #
+       ifeq ($(shell echo 'puts [file normalize /]' | '$(TCL_PATH_SQ)'),$(shell cygpath --mixed --absolute /))
+               gg_libdir_sed_in := $(gg_libdir)
+       else
+               gg_libdir_sed_in := $(shell cygpath --windows --absolute "$(gg_libdir)")
+       endif
 else
        ifeq ($(exedir),$(gg_libdir))
                GITGUI_RELATIVE := 1
index 5d65272e26dd08fc3abb8bf8cdbf57065da53bcc..238a2393ff7811675003e0e846f3d9409fb04e0c 100755 (executable)
@@ -663,7 +663,7 @@ if {![regsub {^git version } $_git_version {} _git_version]} {
 }
 
 set _real_git_version $_git_version
-regsub -- {-dirty$} $_git_version {} _git_version
+regsub -- {[\-\.]dirty$} $_git_version {} _git_version
 regsub {\.[0-9]+\.g[0-9a-f]+$} $_git_version {} _git_version
 regsub {\.rc[0-9]+$} $_git_version {} _git_version
 regsub {\.GIT$} $_git_version {} _git_version
index 86faf24cc8788701983f4ff49dc407ecce6d3148..0adcf9d958b76b5a52386effe6afbca95f0abaf9 100644 (file)
@@ -11,6 +11,7 @@ field w_quit      ; # Quit button
 field o_cons      ; # Console object (if active)
 field w_types     ; # List of type buttons in clone
 field w_recentlist ; # Listbox containing recent repositories
+field w_localpath  ; # Entry widget bound to local_path
 
 field done              0 ; # Finished picking the repository?
 field local_path       {} ; # Where this repository is locally
@@ -385,6 +386,7 @@ method _do_new {} {
        button $w_body.where.b \
                -text [mc "Browse"] \
                -command [cb _new_local_path]
+       set w_localpath $w_body.where.t
 
        pack $w_body.where.b -side right
        pack $w_body.where.l -side left
@@ -416,6 +418,7 @@ method _new_local_path {} {
                return
        }
        set local_path $p
+       $w_localpath icursor end
 }
 
 method _do_new2 {} {
@@ -481,6 +484,7 @@ method _do_clone {} {
                -text [mc "Browse"] \
                -command [cb _new_local_path]
        grid $args.where_l $args.where_t $args.where_b -sticky ew
+       set w_localpath $args.where_t
 
        label $args.type_l -text [mc "Clone Type:"]
        frame $args.type_f
index 0fdd7531dac07e68315cebc2efa87e99947821b6..08a24622c7ff199399805ef34f0396f6cb81613c 100644 (file)
@@ -1,6 +1,14 @@
 # git-gui branch (create/delete) support
 # Copyright (C) 2006, 2007 Shawn Pearce
 
+proc _error_parent {} {
+       set p [grab current .]
+       if {$p eq {}} {
+               return .
+       }
+       return $p
+}
+
 proc error_popup {msg} {
        set title [appname]
        if {[reponame] ne {}} {
@@ -11,8 +19,8 @@ proc error_popup {msg} {
                -type ok \
                -title [append "$title: " [mc "error"]] \
                -message $msg]
-       if {[winfo ismapped .]} {
-               lappend cmd -parent .
+       if {[winfo ismapped [_error_parent]]} {
+               lappend cmd -parent [_error_parent]
        }
        eval $cmd
 }
@@ -27,13 +35,13 @@ proc warn_popup {msg} {
                -type ok \
                -title [append "$title: " [mc "warning"]] \
                -message $msg]
-       if {[winfo ismapped .]} {
-               lappend cmd -parent .
+       if {[winfo ismapped [_error_parent]]} {
+               lappend cmd -parent [_error_parent]
        }
        eval $cmd
 }
 
-proc info_popup {msg {parent .}} {
+proc info_popup {msg} {
        set title [appname]
        if {[reponame] ne {}} {
                append title " ([reponame])"
@@ -56,8 +64,8 @@ proc ask_popup {msg} {
                -type yesno \
                -title $title \
                -message $msg]
-       if {[winfo ismapped .]} {
-               lappend cmd -parent .
+       if {[winfo ismapped [_error_parent]]} {
+               lappend cmd -parent [_error_parent]
        }
        eval $cmd
 }
index 46da0f4ca2bfc2b30e4da8eb551565a06c876fb1..3ce32b5f211bd20f1d154c860eb5bf7f9005ca3c 100755 (executable)
@@ -174,6 +174,7 @@ fi
 
 merge_name=$(git fmt-merge-msg <"$GIT_DIR/FETCH_HEAD") || exit
 test true = "$rebase" &&
-       exec git-rebase --onto $merge_head ${oldremoteref:-$merge_head}
+       exec git-rebase $strategy_args --onto $merge_head \
+       ${oldremoteref:-$merge_head}
 exec git-merge $no_summary $no_commit $squash $no_ff $strategy_args \
        "$merge_name" HEAD $merge_head
index 59601e36e854195c93f0a49bc3884567ed502595..29b1105c4c3c83258ebdf53c8885f767baa0ace0 100755 (executable)
@@ -170,7 +170,9 @@ my $envelope_sender;
 
 my $repo = Git->repository();
 my $term = eval {
-       new Term::ReadLine 'git-send-email';
+       $ENV{"GIT_SEND_EMAIL_NOTTY"}
+               ? new Term::ReadLine 'git-send-email', \*STDIN, \*STDOUT
+               : new Term::ReadLine 'git-send-email';
 };
 if ($@) {
        $term = new FakeTerm "$@: going non-interactive";
@@ -475,9 +477,10 @@ if ($thread && !defined $initial_reply_to && $prompting) {
 
        $initial_reply_to = $_;
 }
-if (defined $initial_reply_to && $_ ne "") {
-       $initial_reply_to =~ s/^\s*<?/</;
-       $initial_reply_to =~ s/>?\s*$/>/;
+if (defined $initial_reply_to) {
+       $initial_reply_to =~ s/^\s*<?//;
+       $initial_reply_to =~ s/>?\s*$//;
+       $initial_reply_to = "<$initial_reply_to>" if $initial_reply_to ne '';
 }
 
 if (!defined $smtp_server) {
index f38827529f2fd60743f5571948742fada975cf93..a44b1c74a38d6310d7a1bde969cbbcb51f977188 100755 (executable)
@@ -127,20 +127,14 @@ get_author_ident_from_commit () {
 # if we require to be in a git repository.
 if test -z "$NONGIT_OK"
 then
+       GIT_DIR=$(git rev-parse --git-dir) || exit
        if [ -z "$SUBDIRECTORY_OK" ]
        then
-               : ${GIT_DIR=.git}
                test -z "$(git rev-parse --show-cdup)" || {
                        exit=$?
                        echo >&2 "You need to run this command from the toplevel of the working tree."
                        exit $exit
                }
-       else
-               GIT_DIR=$(git rev-parse --git-dir) || {
-                   exit=$?
-                   echo >&2 "Failed to find a valid git directory."
-                   exit $exit
-               }
        fi
        test -n "$GIT_DIR" && GIT_DIR=$(cd "$GIT_DIR" && pwd) || {
                echo >&2 "Unable to determine absolute path of git directory"
index 3f9f88815b865cb6c405268d83f67f1b2f858f88..97a26be29a5e6e64ca33760ba0010693e0fa07f9 100644 (file)
@@ -3,7 +3,7 @@
 Name:          git
 Version:       @@VERSION@@
 Release:       1%{?dist}
-Summary:       Git core and tools
+Summary:       Core git tools
 License:       GPL
 Group:                 Development/Tools
 URL:           http://kernel.org/pub/software/scm/git/
@@ -11,80 +11,86 @@ Source:     http://kernel.org/pub/software/scm/git/%{name}-%{version}.tar.gz
 BuildRequires: zlib-devel >= 1.2, openssl-devel, curl-devel, expat-devel, gettext  %{!?_without_docs:, xmlto, asciidoc > 6.0.3}
 BuildRoot:     %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
 
-Requires:      git-core = %{version}-%{release}
-Requires:      git-svn = %{version}-%{release}
-Requires:      git-cvs = %{version}-%{release}
-Requires:      git-arch = %{version}-%{release}
-Requires:      git-email = %{version}-%{release}
-Requires:      gitk = %{version}-%{release}
-Requires:      git-gui = %{version}-%{release}
 Requires:      perl-Git = %{version}-%{release}
+Requires:      zlib >= 1.2, rsync, curl, less, openssh-clients, expat
+Provides:      git-core = %{version}-%{release}
+Obsoletes:     git-core <= 1.5.4.2
+Obsoletes:     git-p4
 
 %description
 Git is a fast, scalable, distributed revision control system with an
 unusually rich command set that provides both high-level operations
 and full access to internals.
 
-This is a dummy package which brings in all subpackages.
+The git rpm installs the core tools with minimal dependencies.  To
+install all git packages, including tools for integrating with other
+SCMs, install the git-all meta-package.
 
-%package core
-Summary:       Core git tools
+%package all
+Summary:       Meta-package to pull in all git tools
 Group:         Development/Tools
-Requires:      zlib >= 1.2, rsync, curl, less, openssh-clients, expat
-Obsoletes:     git-p4
-%description core
+Requires:      git = %{version}-%{release}
+Requires:      git-svn = %{version}-%{release}
+Requires:      git-cvs = %{version}-%{release}
+Requires:      git-arch = %{version}-%{release}
+Requires:      git-email = %{version}-%{release}
+Requires:      gitk = %{version}-%{release}
+Requires:      git-gui = %{version}-%{release}
+Obsoletes:     git <= 1.5.4.2
+
+%description all
 Git is a fast, scalable, distributed revision control system with an
 unusually rich command set that provides both high-level operations
 and full access to internals.
 
-These are the core tools with minimal dependencies.
+This is a dummy package which brings in all subpackages.
 
 %package svn
 Summary:        Git tools for importing Subversion repositories
 Group:          Development/Tools
-Requires:       git-core = %{version}-%{release}, subversion
+Requires:       git = %{version}-%{release}, subversion
 %description svn
 Git tools for importing Subversion repositories.
 
 %package cvs
 Summary:        Git tools for importing CVS repositories
 Group:          Development/Tools
-Requires:       git-core = %{version}-%{release}, cvs, cvsps
+Requires:       git = %{version}-%{release}, cvs, cvsps
 %description cvs
 Git tools for importing CVS repositories.
 
 %package arch
 Summary:        Git tools for importing Arch repositories
 Group:          Development/Tools
-Requires:       git-core = %{version}-%{release}, tla
+Requires:       git = %{version}-%{release}, tla
 %description arch
 Git tools for importing Arch repositories.
 
 %package email
 Summary:        Git tools for sending email
 Group:          Development/Tools
-Requires:      git-core = %{version}-%{release}
+Requires:      git = %{version}-%{release}
 %description email
 Git tools for sending email.
 
 %package gui
 Summary:        Git GUI tool
 Group:          Development/Tools
-Requires:       git-core = %{version}-%{release}, tk >= 8.4
+Requires:       git = %{version}-%{release}, tk >= 8.4
 %description gui
 Git GUI tool
 
 %package -n gitk
 Summary:        Git revision tree visualiser ('gitk')
 Group:          Development/Tools
-Requires:       git-core = %{version}-%{release}, tk >= 8.4
+Requires:       git = %{version}-%{release}, tk >= 8.4
 %description -n gitk
 Git revision tree visualiser ('gitk')
 
 %package -n perl-Git
 Summary:        Perl interface to Git
 Group:          Development/Libraries
-Requires:       git-core = %{version}-%{release}
+Requires:       git = %{version}-%{release}
 Requires:       perl(:MODULE_COMPAT_%(eval "`%{__perl} -V:version`"; echo $version))
 BuildRequires:  perl(Error)
 
@@ -121,8 +127,12 @@ rm -rf $RPM_BUILD_ROOT%{_mandir}
 %clean
 rm -rf $RPM_BUILD_ROOT
 
-%files
-# These are no files in the root package
+%files -f bin-man-doc-files
+%defattr(-,root,root)
+%{_datadir}/git-core/
+%doc README COPYING Documentation/*.txt
+%{!?_without_docs: %doc Documentation/*.html Documentation/howto}
+%{!?_without_docs: %doc Documentation/technical}
 
 %files svn
 %defattr(-,root,root)
@@ -173,14 +183,13 @@ rm -rf $RPM_BUILD_ROOT
 %files -n perl-Git -f perl-files
 %defattr(-,root,root)
 
-%files core -f bin-man-doc-files
-%defattr(-,root,root)
-%{_datadir}/git-core/
-%doc README COPYING Documentation/*.txt
-%{!?_without_docs: %doc Documentation/*.html Documentation/howto}
-%{!?_without_docs: %doc Documentation/technical}
+%files all
+# No files for you!
 
 %changelog
+* Fri Feb 15 2008 Kristian Høgsberg <krh@redhat.com>
+- Rename git-core to just git and rename meta package from git to git-all.
+
 * Sun Feb 03 2008 James Bowes <jbowes@dangerouslyinc.com>
 - Add a BuildRequires for gettext
 
index 4c8bedf7449266229e8102efac249e68fd9d8b39..2163071047a0f4a7620eebf2f4e18008f592c049 100644 (file)
@@ -233,6 +233,10 @@ You can use the following files in repository:
    Displayed in the project summary page. You can use multiple-valued
    gitweb.url repository configuration variable for that, but the file
    takes precendence.
+ * gitweb.owner
+   You can use the gitweb.owner repository configuration variable to set
+   repository's owner. It is displayed in the project list and summary
+   page. If it's not set, filesystem directory's owner is used.
  * various gitweb.* config variables (in config)
    Read description of %feature hash for detailed list, and some
    descriptions.
index 5e88637b5e0e67143692bac336a57ab6cc1c0c38..fc95e2ca855fed2998b97733f9458d4ed9857cf2 100755 (executable)
@@ -611,6 +611,8 @@ sub href(%) {
        );
        my %mapping = @mapping;
 
+       $params{'project'} = $project unless exists $params{'project'};
+
        if ($params{-replay}) {
                while (my ($name, $symbol) = each %mapping) {
                        if (!exists $params{$name}) {
@@ -620,8 +622,6 @@ sub href(%) {
                }
        }
 
-       $params{'project'} = $project unless exists $params{'project'};
-
        my ($use_pathinfo) = gitweb_check_feature('pathinfo');
        if ($use_pathinfo) {
                # use PATH_INFO for project name
@@ -753,29 +753,40 @@ sub esc_path {
 # Make control characters "printable", using character escape codes (CEC)
 sub quot_cec {
        my $cntrl = shift;
+       my %opts = @_;
        my %es = ( # character escape codes, aka escape sequences
-                  "\t" => '\t',   # tab            (HT)
-                  "\n" => '\n',   # line feed      (LF)
-                  "\r" => '\r',   # carrige return (CR)
-                  "\f" => '\f',   # form feed      (FF)
-                  "\b" => '\b',   # backspace      (BS)
-                  "\a" => '\a',   # alarm (bell)   (BEL)
-                  "\e" => '\e',   # escape         (ESC)
-                  "\013" => '\v', # vertical tab   (VT)
-                  "\000" => '\0', # nul character  (NUL)
-                  );
+               "\t" => '\t',   # tab            (HT)
+               "\n" => '\n',   # line feed      (LF)
+               "\r" => '\r',   # carrige return (CR)
+               "\f" => '\f',   # form feed      (FF)
+               "\b" => '\b',   # backspace      (BS)
+               "\a" => '\a',   # alarm (bell)   (BEL)
+               "\e" => '\e',   # escape         (ESC)
+               "\013" => '\v', # vertical tab   (VT)
+               "\000" => '\0', # nul character  (NUL)
+       );
        my $chr = ( (exists $es{$cntrl})
                    ? $es{$cntrl}
                    : sprintf('\%03o', ord($cntrl)) );
-       return "<span class=\"cntrl\">$chr</span>";
+       if ($opts{-nohtml}) {
+               return $chr;
+       } else {
+               return "<span class=\"cntrl\">$chr</span>";
+       }
 }
 
 # Alternatively use unicode control pictures codepoints,
 # Unicode "printable representation" (PR)
 sub quot_upr {
        my $cntrl = shift;
+       my %opts = @_;
+
        my $chr = sprintf('&#%04d;', 0x2400+ord($cntrl));
-       return "<span class=\"cntrl\">$chr</span>";
+       if ($opts{-nohtml}) {
+               return $chr;
+       } else {
+               return "<span class=\"cntrl\">$chr</span>";
+       }
 }
 
 # git may return quoted and escaped filenames
@@ -800,7 +811,7 @@ sub unquote {
                        return chr(oct($seq));
                } elsif (exists $es{$seq}) {
                        # C escape sequence, aka character escape code
-                       return $es{$seq}
+                       return $es{$seq};
                }
                # quoted ordinary character
                return $seq;
@@ -837,37 +848,78 @@ sub project_in_list {
 ## ----------------------------------------------------------------------
 ## HTML aware string manipulation
 
+# Try to chop given string on a word boundary between position
+# $len and $len+$add_len. If there is no word boundary there,
+# chop at $len+$add_len. Do not chop if chopped part plus ellipsis
+# (marking chopped part) would be longer than given string.
 sub chop_str {
        my $str = shift;
        my $len = shift;
        my $add_len = shift || 10;
+       my $where = shift || 'right'; # 'left' | 'center' | 'right'
 
        # allow only $len chars, but don't cut a word if it would fit in $add_len
        # if it doesn't fit, cut it if it's still longer than the dots we would add
-       $str =~ m/^(.{0,$len}[^ \/\-_:\.@]{0,$add_len})(.*)/;
-       my $body = $1;
-       my $tail = $2;
-       if (length($tail) > 4) {
-               $tail = " ...";
-               $body =~ s/&[^;]*$//; # remove chopped character entities
+       # remove chopped character entities entirely
+
+       # when chopping in the middle, distribute $len into left and right part
+       # return early if chopping wouldn't make string shorter
+       if ($where eq 'center') {
+               return $str if ($len + 5 >= length($str)); # filler is length 5
+               $len = int($len/2);
+       } else {
+               return $str if ($len + 4 >= length($str)); # filler is length 4
+       }
+
+       # regexps: ending and beginning with word part up to $add_len
+       my $endre = qr/.{$len}\w{0,$add_len}/;
+       my $begre = qr/\w{0,$add_len}.{$len}/;
+
+       if ($where eq 'left') {
+               $str =~ m/^(.*?)($begre)$/;
+               my ($lead, $body) = ($1, $2);
+               if (length($lead) > 4) {
+                       $body =~ s/^[^;]*;// if ($lead =~ m/&[^;]*$/);
+                       $lead = " ...";
+               }
+               return "$lead$body";
+
+       } elsif ($where eq 'center') {
+               $str =~ m/^($endre)(.*)$/;
+               my ($left, $str)  = ($1, $2);
+               $str =~ m/^(.*?)($begre)$/;
+               my ($mid, $right) = ($1, $2);
+               if (length($mid) > 5) {
+                       $left  =~ s/&[^;]*$//;
+                       $right =~ s/^[^;]*;// if ($mid =~ m/&[^;]*$/);
+                       $mid = " ... ";
+               }
+               return "$left$mid$right";
+
+       } else {
+               $str =~ m/^($endre)(.*)$/;
+               my $body = $1;
+               my $tail = $2;
+               if (length($tail) > 4) {
+                       $body =~ s/&[^;]*$//;
+                       $tail = "... ";
+               }
+               return "$body$tail";
        }
-       return "$body$tail";
 }
 
 # takes the same arguments as chop_str, but also wraps a <span> around the
 # result with a title attribute if it does get chopped. Additionally, the
 # string is HTML-escaped.
 sub chop_and_escape_str {
-       my $str = shift;
-       my $len = shift;
-       my $add_len = shift || 10;
+       my ($str) = @_;
 
-       my $chopped = chop_str($str, $len, $add_len);
+       my $chopped = chop_str(@_);
        if ($chopped eq $str) {
                return esc_html($chopped);
        } else {
-               return qq{<span title="} . esc_html($str) . qq{">} .
-                       esc_html($chopped) . qq{</span>};
+               $str =~ s/([[:cntrl:]])/?/g;
+               return $cgi->span({-title=>$str}, esc_html($chopped));
        }
 }
 
@@ -1759,6 +1811,7 @@ sub git_get_project_owner {
        my $owner;
 
        return undef unless $project;
+       $git_dir = "$projectroot/$project";
 
        if (!defined $gitweb_project_owner) {
                git_get_project_list_from_file();
@@ -1767,8 +1820,11 @@ sub git_get_project_owner {
        if (exists $gitweb_project_owner->{$project}) {
                $owner = $gitweb_project_owner->{$project};
        }
+       if (!defined $owner){
+               $owner = git_get_project_config('owner');
+       }
        if (!defined $owner) {
-               $owner = get_file_owner("$projectroot/$project");
+               $owner = get_file_owner("$git_dir");
        }
 
        return $owner;
@@ -3769,18 +3825,24 @@ sub git_search_grep_body {
                print "<td title=\"$co{'age_string_age'}\"><i>$co{'age_string_date'}</i></td>\n" .
                      "<td><i>" . $author . "</i></td>\n" .
                      "<td>" .
-                     $cgi->a({-href => href(action=>"commit", hash=>$co{'id'}), -class => "list subject"},
-                              chop_and_escape_str($co{'title'}, 50) . "<br/>");
+                     $cgi->a({-href => href(action=>"commit", hash=>$co{'id'}),
+                              -class => "list subject"},
+                             chop_and_escape_str($co{'title'}, 50) . "<br/>");
                my $comment = $co{'comment'};
                foreach my $line (@$comment) {
                        if ($line =~ m/^(.*)($search_regexp)(.*)$/i) {
-                               my $lead = esc_html($1) || "";
-                               $lead = chop_str($lead, 30, 10);
-                               my $match = esc_html($2) || "";
-                               my $trail = esc_html($3) || "";
-                               $trail = chop_str($trail, 30, 10);
-                               my $text = "$lead<span class=\"match\">$match</span>$trail";
-                               print chop_str($text, 80, 5) . "<br/>\n";
+                               my ($lead, $match, $trail) = ($1, $2, $3);
+                               $match = chop_str($match, 70, 5, 'center');
+                               my $contextlen = int((80 - length($match))/2);
+                               $contextlen = 30 if ($contextlen > 30);
+                               $lead  = chop_str($lead,  $contextlen, 10, 'left');
+                               $trail = chop_str($trail, $contextlen, 10, 'right');
+
+                               $lead  = esc_html($lead);
+                               $match = esc_html($match);
+                               $trail = esc_html($trail);
+
+                               print "$lead<span class=\"match\">$match</span>$trail<br />";
                        }
                }
                print "</td>\n" .
diff --git a/hash.c b/hash.c
index 7b492d4fc039898b975a1122b4e4eb90e3eb8923..d9ec82fa663804210e8ef200f2f300e914662f22 100644 (file)
--- a/hash.c
+++ b/hash.c
@@ -70,7 +70,7 @@ void *lookup_hash(unsigned int hash, struct hash_table *table)
 {
        if (!table->array)
                return NULL;
-       return &lookup_hash_entry(hash, table)->ptr;
+       return lookup_hash_entry(hash, table)->ptr;
 }
 
 void **insert_hash(unsigned int hash, void *ptr, struct hash_table *table)
diff --git a/help.c b/help.c
index 6e28ad9e7129360aa2b3206a606e81134baec85c..8143dcdd38218ef03c47535c7c2e761cf1a868ce 100644 (file)
--- a/help.c
+++ b/help.c
@@ -39,12 +39,8 @@ static void parse_help_format(const char *format)
 
 static int git_help_config(const char *var, const char *value)
 {
-       if (!strcmp(var, "help.format")) {
-               if (!value)
-                       return config_error_nonbool(var);
-               help_default_format = xstrdup(value);
-               return 0;
-       }
+       if (!strcmp(var, "help.format"))
+               return git_config_string(&help_default_format, var, value);
        return git_default_config(var, value);
 }
 
index b2b410df902f2a4f2bca634d82cf103d288c9042..0beb7406c34a19403062a6a2e2aeeee35566a45f 100644 (file)
@@ -1634,12 +1634,19 @@ static struct object_list **process_tree(struct tree *tree,
 
        init_tree_desc(&desc, tree->buffer, tree->size);
 
-       while (tree_entry(&desc, &entry)) {
-               if (S_ISDIR(entry.mode))
+       while (tree_entry(&desc, &entry))
+               switch (object_type(entry.mode)) {
+               case OBJ_TREE:
                        p = process_tree(lookup_tree(entry.sha1), p, &me, name);
-               else
+                       break;
+               case OBJ_BLOB:
                        p = process_blob(lookup_blob(entry.sha1), p, &me, name);
-       }
+                       break;
+               default:
+                       /* Subproject commit - not in this repository */
+                       break;
+               }
+
        free(tree->buffer);
        tree->buffer = NULL;
        return p;
@@ -2383,7 +2390,8 @@ int main(int argc, char **argv)
 
                /* Generate a list of objects that need to be pushed */
                pushing = 0;
-               prepare_revision_walk(&revs);
+               if (prepare_revision_walk(&revs))
+                       die("revision walk setup failed");
                mark_edges_uninteresting(revs.commits);
                objects_to_send = get_delta(&revs, ref_lock);
                finish_all_active_slots();
@@ -2398,15 +2406,17 @@ int main(int argc, char **argv)
                fill_active_slots();
                add_fill_function(NULL, fill_active_slot);
 #endif
-               finish_all_active_slots();
+               do {
+                       finish_all_active_slots();
+#ifdef USE_CURL_MULTI
+                       fill_active_slots();
+#endif
+               } while (request_queue_head && !aborted);
 
                /* Update the remote branch if all went well */
-               if (aborted || !update_remote(ref->new_sha1, ref_lock)) {
+               if (aborted || !update_remote(ref->new_sha1, ref_lock))
                        rc = 1;
-                       goto unlock;
-               }
 
-       unlock:
                if (!rc)
                        fprintf(stderr, "    done\n");
                unlock_remote(ref_lock);
index 4ef58e7ec01ebdfc6f036ccafaf837b2b38ed7a5..c8b8375e4983794e601ba69a1c217a3c711835e9 100644 (file)
@@ -18,6 +18,8 @@ static void process_blob(struct rev_info *revs,
 
        if (!revs->blob_objects)
                return;
+       if (!obj)
+               die("bad blob object");
        if (obj->flags & (UNINTERESTING | SEEN))
                return;
        obj->flags |= SEEN;
@@ -69,6 +71,8 @@ static void process_tree(struct rev_info *revs,
 
        if (!revs->tree_objects)
                return;
+       if (!obj)
+               die("bad tree object");
        if (obj->flags & (UNINTERESTING | SEEN))
                return;
        if (parse_tree(tree) < 0)
index 1f3fcf16ad7a101eb9eab53da84bd2640f97ab00..e9ba6df9d230e8adc12df32b502729c09c8e7d5a 100644 (file)
@@ -149,10 +149,12 @@ void show_log(struct rev_info *opt, const char *sep)
 
        opt->loginfo = NULL;
        if (!opt->verbose_header) {
-               if (opt->left_right) {
-                       if (commit->object.flags & BOUNDARY)
-                               putchar('-');
-                       else if (commit->object.flags & SYMMETRIC_LEFT)
+               if (commit->object.flags & BOUNDARY)
+                       putchar('-');
+               else if (commit->object.flags & UNINTERESTING)
+                       putchar('^');
+               else if (opt->left_right) {
+                       if (commit->object.flags & SYMMETRIC_LEFT)
                                putchar('<');
                        else
                                putchar('>');
@@ -250,6 +252,8 @@ void show_log(struct rev_info *opt, const char *sep)
                        fputs("commit ", stdout);
                if (commit->object.flags & BOUNDARY)
                        putchar('-');
+               else if (commit->object.flags & UNINTERESTING)
+                       putchar('^');
                else if (opt->left_right) {
                        if (commit->object.flags & SYMMETRIC_LEFT)
                                putchar('<');
@@ -278,6 +282,9 @@ void show_log(struct rev_info *opt, const char *sep)
                }
        }
 
+       if (!commit->buffer)
+               return;
+
        /*
         * And then the pretty-printed message itself
         */
index bbb700b54eab2a14f60e090231a196874ff3a9e0..7491c56ad25332fb4aae6a075bf0577a1d800c3b 100644 (file)
@@ -91,7 +91,7 @@ int main(int argc, char **argv)
        signal(SIGCHLD, SIG_DFL);
 
        if (argc < 3)
-               usage("git-merge-index [-o] [-q] <merge-program> (-a | <filename>*)");
+               usage("git-merge-index [-o] [-q] <merge-program> (-a | [--] <filename>*)");
 
        setup_git_directory();
        read_cache();
index dd52342539cd05e59bb13e956d51251417f21e3c..55ef76f5a5f855475f796dfda39fa3417179be8b 100644 (file)
@@ -1673,6 +1673,8 @@ static struct commit *get_ref(const char *ref)
        if (get_sha1(ref, sha1))
                die("Could not resolve ref '%s'", ref);
        object = deref_tag(parse_object(sha1), ref, strlen(ref));
+       if (!object)
+               return NULL;
        if (object->type == OBJ_TREE)
                return make_virtual_commit((struct tree*)object,
                        better_branch_name(ref));
diff --git a/pager.c b/pager.c
index 0376953cb1b8a4095346e0d12ecef6e7db9c48c9..ca002f9f791b6cdb8257836be9e13fe648afa1cc 100644 (file)
--- a/pager.c
+++ b/pager.c
@@ -57,6 +57,7 @@ void setup_pager(void)
        /* return in the child */
        if (!pid) {
                dup2(fd[1], 1);
+               dup2(fd[1], 2);
                close(fd[0]);
                close(fd[1]);
                return;
index b987ff245b310a6693dc69ba8c71ef2915da7864..997f5837d521ded5f158d12abc0c025f74e83341 100644 (file)
--- a/pretty.c
+++ b/pretty.c
@@ -282,59 +282,59 @@ static char *logmsg_reencode(const struct commit *commit,
        return out;
 }
 
-static void format_person_part(struct strbuf *sb, char part,
+static size_t format_person_part(struct strbuf *sb, char part,
                                const char *msg, int len)
 {
+       /* currently all placeholders have same length */
+       const int placeholder_len = 2;
        int start, end, tz = 0;
-       unsigned long date;
+       unsigned long date = 0;
        char *ep;
 
-       /* parse name */
+       /* advance 'end' to point to email start delimiter */
        for (end = 0; end < len && msg[end] != '<'; end++)
                ; /* do nothing */
+
        /*
-        * If it does not even have a '<' and '>', that is
-        * quite a bogus commit author and we discard it;
-        * this is in line with add_user_info() that is used
-        * in the normal codepath.  When end points at the '<'
-        * that we found, it should have matching '>' later,
-        * which means start (beginning of email address) must
-        * be strictly below len.
+        * When end points at the '<' that we found, it should have
+        * matching '>' later, which means 'end' must be strictly
+        * below len - 1.
         */
-       start = end + 1;
-       if (start >= len - 1)
-               return;
-       while (end > 0 && isspace(msg[end - 1]))
-               end--;
+       if (end >= len - 2)
+               goto skip;
+
        if (part == 'n') {      /* name */
+               while (end > 0 && isspace(msg[end - 1]))
+                       end--;
                strbuf_add(sb, msg, end);
-               return;
+               return placeholder_len;
        }
+       start = ++end; /* save email start position */
 
-       /* parse email */
-       for (end = start; end < len && msg[end] != '>'; end++)
+       /* advance 'end' to point to email end delimiter */
+       for ( ; end < len && msg[end] != '>'; end++)
                ; /* do nothing */
 
        if (end >= len)
-               return;
+               goto skip;
 
        if (part == 'e') {      /* email */
                strbuf_add(sb, msg + start, end - start);
-               return;
+               return placeholder_len;
        }
 
-       /* parse date */
+       /* advance 'start' to point to date start delimiter */
        for (start = end + 1; start < len && isspace(msg[start]); start++)
                ; /* do nothing */
        if (start >= len)
-               return;
+               goto skip;
        date = strtoul(msg + start, &ep, 10);
        if (msg + start == ep)
-               return;
+               goto skip;
 
        if (part == 't') {      /* date, UNIX timestamp */
                strbuf_add(sb, msg + start, ep - (msg + start));
-               return;
+               return placeholder_len;
        }
 
        /* parse tz */
@@ -349,17 +349,28 @@ static void format_person_part(struct strbuf *sb, char part,
        switch (part) {
        case 'd':       /* date */
                strbuf_addstr(sb, show_date(date, tz, DATE_NORMAL));
-               return;
+               return placeholder_len;
        case 'D':       /* date, RFC2822 style */
                strbuf_addstr(sb, show_date(date, tz, DATE_RFC2822));
-               return;
+               return placeholder_len;
        case 'r':       /* date, relative */
                strbuf_addstr(sb, show_date(date, tz, DATE_RELATIVE));
-               return;
+               return placeholder_len;
        case 'i':       /* date, ISO 8601 */
                strbuf_addstr(sb, show_date(date, tz, DATE_ISO8601));
-               return;
+               return placeholder_len;
        }
+
+skip:
+       /*
+        * bogus commit, 'sb' cannot be updated, but we still need to
+        * compute a valid return value.
+        */
+       if (part == 'n' || part == 'e' || part == 't' || part == 'd'
+           || part == 'D' || part == 'r' || part == 'i')
+               return placeholder_len;
+
+       return 0; /* unknown placeholder */
 }
 
 struct chunk {
@@ -440,7 +451,7 @@ static void parse_commit_header(struct format_commit_context *context)
        context->commit_header_parsed = 1;
 }
 
-static void format_commit_item(struct strbuf *sb, const char *placeholder,
+static size_t format_commit_item(struct strbuf *sb, const char *placeholder,
                                void *context)
 {
        struct format_commit_context *c = context;
@@ -451,23 +462,23 @@ static void format_commit_item(struct strbuf *sb, const char *placeholder,
        /* these are independent of the commit */
        switch (placeholder[0]) {
        case 'C':
-               switch (placeholder[3]) {
-               case 'd':       /* red */
+               if (!prefixcmp(placeholder + 1, "red")) {
                        strbuf_addstr(sb, "\033[31m");
-                       return;
-               case 'e':       /* green */
+                       return 4;
+               } else if (!prefixcmp(placeholder + 1, "green")) {
                        strbuf_addstr(sb, "\033[32m");
-                       return;
-               case 'u':       /* blue */
+                       return 6;
+               } else if (!prefixcmp(placeholder + 1, "blue")) {
                        strbuf_addstr(sb, "\033[34m");
-                       return;
-               case 's':       /* reset color */
+                       return 5;
+               } else if (!prefixcmp(placeholder + 1, "reset")) {
                        strbuf_addstr(sb, "\033[m");
-                       return;
-               }
+                       return 6;
+               } else
+                       return 0;
        case 'n':               /* newline */
                strbuf_addch(sb, '\n');
-               return;
+               return 1;
        }
 
        /* these depend on the commit */
@@ -477,34 +488,34 @@ static void format_commit_item(struct strbuf *sb, const char *placeholder,
        switch (placeholder[0]) {
        case 'H':               /* commit hash */
                strbuf_addstr(sb, sha1_to_hex(commit->object.sha1));
-               return;
+               return 1;
        case 'h':               /* abbreviated commit hash */
                if (add_again(sb, &c->abbrev_commit_hash))
-                       return;
+                       return 1;
                strbuf_addstr(sb, find_unique_abbrev(commit->object.sha1,
                                                     DEFAULT_ABBREV));
                c->abbrev_commit_hash.len = sb->len - c->abbrev_commit_hash.off;
-               return;
+               return 1;
        case 'T':               /* tree hash */
                strbuf_addstr(sb, sha1_to_hex(commit->tree->object.sha1));
-               return;
+               return 1;
        case 't':               /* abbreviated tree hash */
                if (add_again(sb, &c->abbrev_tree_hash))
-                       return;
+                       return 1;
                strbuf_addstr(sb, find_unique_abbrev(commit->tree->object.sha1,
                                                     DEFAULT_ABBREV));
                c->abbrev_tree_hash.len = sb->len - c->abbrev_tree_hash.off;
-               return;
+               return 1;
        case 'P':               /* parent hashes */
                for (p = commit->parents; p; p = p->next) {
                        if (p != commit->parents)
                                strbuf_addch(sb, ' ');
                        strbuf_addstr(sb, sha1_to_hex(p->item->object.sha1));
                }
-               return;
+               return 1;
        case 'p':               /* abbreviated parent hashes */
                if (add_again(sb, &c->abbrev_parent_hashes))
-                       return;
+                       return 1;
                for (p = commit->parents; p; p = p->next) {
                        if (p != commit->parents)
                                strbuf_addch(sb, ' ');
@@ -513,14 +524,14 @@ static void format_commit_item(struct strbuf *sb, const char *placeholder,
                }
                c->abbrev_parent_hashes.len = sb->len -
                                              c->abbrev_parent_hashes.off;
-               return;
+               return 1;
        case 'm':               /* left/right/bottom */
                strbuf_addch(sb, (commit->object.flags & BOUNDARY)
                                 ? '-'
                                 : (commit->object.flags & SYMMETRIC_LEFT)
                                 ? '<'
                                 : '>');
-               return;
+               return 1;
        }
 
        /* For the rest we have to parse the commit header. */
@@ -528,66 +539,33 @@ static void format_commit_item(struct strbuf *sb, const char *placeholder,
                parse_commit_header(c);
 
        switch (placeholder[0]) {
-       case 's':
+       case 's':       /* subject */
                strbuf_add(sb, msg + c->subject.off, c->subject.len);
-               return;
-       case 'a':
-               format_person_part(sb, placeholder[1],
+               return 1;
+       case 'a':       /* author ... */
+               return format_person_part(sb, placeholder[1],
                                   msg + c->author.off, c->author.len);
-               return;
-       case 'c':
-               format_person_part(sb, placeholder[1],
+       case 'c':       /* committer ... */
+               return format_person_part(sb, placeholder[1],
                                   msg + c->committer.off, c->committer.len);
-               return;
-       case 'e':
+       case 'e':       /* encoding */
                strbuf_add(sb, msg + c->encoding.off, c->encoding.len);
-               return;
-       case 'b':
+               return 1;
+       case 'b':       /* body */
                strbuf_addstr(sb, msg + c->body_off);
-               return;
+               return 1;
        }
+       return 0;       /* unknown placeholder */
 }
 
 void format_commit_message(const struct commit *commit,
                            const void *format, struct strbuf *sb)
 {
-       const char *placeholders[] = {
-               "H",            /* commit hash */
-               "h",            /* abbreviated commit hash */
-               "T",            /* tree hash */
-               "t",            /* abbreviated tree hash */
-               "P",            /* parent hashes */
-               "p",            /* abbreviated parent hashes */
-               "an",           /* author name */
-               "ae",           /* author email */
-               "ad",           /* author date */
-               "aD",           /* author date, RFC2822 style */
-               "ar",           /* author date, relative */
-               "at",           /* author date, UNIX timestamp */
-               "ai",           /* author date, ISO 8601 */
-               "cn",           /* committer name */
-               "ce",           /* committer email */
-               "cd",           /* committer date */
-               "cD",           /* committer date, RFC2822 style */
-               "cr",           /* committer date, relative */
-               "ct",           /* committer date, UNIX timestamp */
-               "ci",           /* committer date, ISO 8601 */
-               "e",            /* encoding */
-               "s",            /* subject */
-               "b",            /* body */
-               "Cred",         /* red */
-               "Cgreen",       /* green */
-               "Cblue",        /* blue */
-               "Creset",       /* reset color */
-               "n",            /* newline */
-               "m",            /* left/right/bottom */
-               NULL
-       };
        struct format_commit_context context;
 
        memset(&context, 0, sizeof(context));
        context.commit = commit;
-       strbuf_expand(sb, format, placeholders, format_commit_item, &context);
+       strbuf_expand(sb, format, format_commit_item, &context);
 }
 
 static void pp_header(enum cmit_fmt fmt,
index 00f289f2f470c0f4b95e0fcac043aa2e054d1ce6..3b1c18ff9b9060d0dd437ce89aedb8871c66c54c 100644 (file)
@@ -15,6 +15,8 @@ static void process_blob(struct blob *blob,
 {
        struct object *obj = &blob->object;
 
+       if (!blob)
+               die("bad blob object");
        if (obj->flags & SEEN)
                return;
        obj->flags |= SEEN;
@@ -39,6 +41,8 @@ static void process_tree(struct tree *tree,
        struct name_entry entry;
        struct name_path me;
 
+       if (!tree)
+               die("bad tree object");
        if (obj->flags & SEEN)
                return;
        obj->flags |= SEEN;
@@ -79,7 +83,8 @@ static void process_tag(struct tag *tag, struct object_array *p, const char *nam
 
        if (parse_tag(tag) < 0)
                die("bad tag object %s", sha1_to_hex(obj->sha1));
-       add_object(tag->tagged, p, NULL, name);
+       if (tag->tagged)
+               add_object(tag->tagged, p, NULL, name);
 }
 
 static void walk_commit_list(struct rev_info *revs)
@@ -150,7 +155,8 @@ static int add_one_reflog(const char *path, const unsigned char *sha1, int flag,
 static void add_one_tree(const unsigned char *sha1, struct rev_info *revs)
 {
        struct tree *tree = lookup_tree(sha1);
-       add_pending_object(revs, &tree->object, "");
+       if (tree)
+               add_pending_object(revs, &tree->object, "");
 }
 
 static void add_cache_tree(struct cache_tree *it, struct rev_info *revs)
@@ -215,6 +221,7 @@ void mark_reachable_objects(struct rev_info *revs, int mark_reflog)
         * Set up the revision walk - this will move all commits
         * from the pending list to the commit walking list.
         */
-       prepare_revision_walk(revs);
+       if (prepare_revision_walk(revs))
+               die("revision walk setup failed");
        walk_commit_list(revs);
 }
index e45f4b3d61c2982ca20c910a7fc11c5bd89204be..fee0c80734db2d5106c4c6fd6bc396af1831c392 100644 (file)
@@ -37,8 +37,13 @@ static unsigned int hash_name(const char *name, int namelen)
 static void hash_index_entry(struct index_state *istate, struct cache_entry *ce)
 {
        void **pos;
-       unsigned int hash = hash_name(ce->name, ce_namelen(ce));
+       unsigned int hash;
 
+       if (ce->ce_flags & CE_HASHED)
+               return;
+       ce->ce_flags |= CE_HASHED;
+       ce->next = NULL;
+       hash = hash_name(ce->name, ce_namelen(ce));
        pos = insert_hash(hash, ce, &istate->name_hash);
        if (pos) {
                ce->next = *pos;
@@ -59,33 +64,18 @@ static void lazy_init_name_hash(struct index_state *istate)
 
 static void set_index_entry(struct index_state *istate, int nr, struct cache_entry *ce)
 {
+       ce->ce_flags &= ~CE_UNHASHED;
        istate->cache[nr] = ce;
        if (istate->name_hash_initialized)
                hash_index_entry(istate, ce);
 }
 
-/*
- * We don't actually *remove* it, we can just mark it invalid so that
- * we won't find it in lookups.
- *
- * Not only would we have to search the lists (simple enough), but
- * we'd also have to rehash other hash buckets in case this makes the
- * hash bucket empty (common). So it's much better to just mark
- * it.
- */
-static void remove_hash_entry(struct index_state *istate, struct cache_entry *ce)
-{
-       ce->ce_flags |= CE_UNHASHED;
-}
-
 static void replace_index_entry(struct index_state *istate, int nr, struct cache_entry *ce)
 {
        struct cache_entry *old = istate->cache[nr];
 
-       if (ce != old) {
-               remove_hash_entry(istate, old);
-               set_index_entry(istate, nr, ce);
-       }
+       remove_index_entry(old);
+       set_index_entry(istate, nr, ce);
        istate->cache_changed = 1;
 }
 
@@ -413,7 +403,7 @@ int remove_index_entry_at(struct index_state *istate, int pos)
 {
        struct cache_entry *ce = istate->cache[pos];
 
-       remove_hash_entry(istate, ce);
+       remove_index_entry(ce);
        istate->cache_changed = 1;
        istate->cache_nr--;
        if (pos >= istate->cache_nr)
diff --git a/refs.c b/refs.c
index 67d2a502afb60050f0ce750c21ae1a42fa5cb803..c979fb1d9507309785909a8d714ab28b1efd2e88 100644 (file)
--- a/refs.c
+++ b/refs.c
@@ -157,6 +157,7 @@ static struct cached_refs {
        struct ref_list *loose;
        struct ref_list *packed;
 } cached_refs;
+static struct ref_list *current_ref;
 
 static void free_ref_list(struct ref_list *list)
 {
@@ -476,6 +477,7 @@ static int do_one_ref(const char *base, each_ref_fn fn, int trim,
                error("%s does not point to a valid object!", entry->name);
                return 0;
        }
+       current_ref = entry;
        return fn(entry->name + trim, entry->sha1, entry->flag, cb_data);
 }
 
@@ -485,6 +487,16 @@ int peel_ref(const char *ref, unsigned char *sha1)
        unsigned char base[20];
        struct object *o;
 
+       if (current_ref && (current_ref->name == ref
+               || !strcmp(current_ref->name, ref))) {
+               if (current_ref->flag & REF_KNOWS_PEELED) {
+                       hashcpy(sha1, current_ref->peeled);
+                       return 0;
+               }
+               hashcpy(base, current_ref->sha1);
+               goto fallback;
+       }
+
        if (!resolve_ref(ref, base, 1, &flag))
                return -1;
 
@@ -504,9 +516,9 @@ int peel_ref(const char *ref, unsigned char *sha1)
                }
        }
 
-       /* fallback - callers should not call this for unpacked refs */
+fallback:
        o = parse_object(base);
-       if (o->type == OBJ_TAG) {
+       if (o && o->type == OBJ_TAG) {
                o = deref_tag(o, ref, 0);
                if (o) {
                        hashcpy(sha1, o->sha1);
@@ -519,7 +531,7 @@ int peel_ref(const char *ref, unsigned char *sha1)
 static int do_for_each_ref(const char *base, each_ref_fn fn, int trim,
                           void *cb_data)
 {
-       int retval;
+       int retval = 0;
        struct ref_list *packed = get_packed_refs();
        struct ref_list *loose = get_loose_refs();
 
@@ -539,15 +551,18 @@ static int do_for_each_ref(const char *base, each_ref_fn fn, int trim,
                }
                retval = do_one_ref(base, fn, trim, cb_data, entry);
                if (retval)
-                       return retval;
+                       goto end_each;
        }
 
        for (packed = packed ? packed : loose; packed; packed = packed->next) {
                retval = do_one_ref(base, fn, trim, cb_data, packed);
                if (retval)
-                       return retval;
+                       goto end_each;
        }
-       return 0;
+
+end_each:
+       current_ref = NULL;
+       return retval;
 }
 
 int head_ref(each_ref_fn fn, void *cb_data)
index 6e85aaa3fb30e98f3b02f094af7f1763577cdb8d..5df7961c501488a5393fd65de5de4bcf2eac1c25 100644 (file)
@@ -46,6 +46,8 @@ void add_object(struct object *obj,
 
 static void mark_blob_uninteresting(struct blob *blob)
 {
+       if (!blob)
+               return;
        if (blob->object.flags & UNINTERESTING)
                return;
        blob->object.flags |= UNINTERESTING;
@@ -57,6 +59,8 @@ void mark_tree_uninteresting(struct tree *tree)
        struct name_entry entry;
        struct object *obj = &tree->object;
 
+       if (!tree)
+               return;
        if (obj->flags & UNINTERESTING)
                return;
        obj->flags |= UNINTERESTING;
@@ -173,6 +177,8 @@ static struct commit *handle_commit(struct rev_info *revs, struct object *object
                struct tag *tag = (struct tag *) object;
                if (revs->tag_objects && !(flags & UNINTERESTING))
                        add_pending_object(revs, object, tag->tag);
+               if (!tag->tagged)
+                       die("bad tag");
                object = parse_object(tag->tagged->sha1);
                if (!object)
                        die("bad object %s", sha1_to_hex(tag->tagged->sha1));
@@ -558,6 +564,12 @@ static void cherry_pick_list(struct commit_list *list, struct rev_info *revs)
        free_patch_ids(&ids);
 }
 
+static void add_to_list(struct commit_list **p, struct commit *commit, struct commit_list *n)
+{
+       p = &commit_list_insert(commit, p)->next;
+       *p = n;
+}
+
 static int limit_list(struct rev_info *revs)
 {
        struct commit_list *list = revs->commits;
@@ -579,9 +591,13 @@ static int limit_list(struct rev_info *revs)
                        return -1;
                if (obj->flags & UNINTERESTING) {
                        mark_parents_uninteresting(commit);
-                       if (everybody_uninteresting(list))
+                       if (everybody_uninteresting(list)) {
+                               if (revs->show_all)
+                                       add_to_list(p, commit, list);
                                break;
-                       continue;
+                       }
+                       if (!revs->show_all)
+                               continue;
                }
                if (revs->min_age != -1 && (commit->date > revs->min_age))
                        continue;
@@ -685,6 +701,8 @@ static int add_parents_only(struct rev_info *revs, const char *arg, int flags)
                it = get_reference(revs, arg, sha1, 0);
                if (it->type != OBJ_TAG)
                        break;
+               if (!((struct tag*)it)->tagged)
+                       return 0;
                hashcpy(sha1, ((struct tag*)it)->tagged->sha1);
        }
        if (it->type != OBJ_COMMIT)
@@ -924,6 +942,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch
        int left = 1;
        int all_match = 0;
        int regflags = 0;
+       int fixed = 0;
 
        /* First, search for "--" */
        seen_dashdash = 0;
@@ -1055,6 +1074,10 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch
                                revs->dense = 0;
                                continue;
                        }
+                       if (!strcmp(arg, "--show-all")) {
+                               revs->show_all = 1;
+                               continue;
+                       }
                        if (!strcmp(arg, "--remove-empty")) {
                                revs->remove_empty_trees = 1;
                                continue;
@@ -1216,6 +1239,11 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch
                                regflags |= REG_ICASE;
                                continue;
                        }
+                       if (!strcmp(arg, "--fixed-strings") ||
+                           !strcmp(arg, "-F")) {
+                               fixed = 1;
+                               continue;
+                       }
                        if (!strcmp(arg, "--all-match")) {
                                all_match = 1;
                                continue;
@@ -1271,8 +1299,10 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch
                }
        }
 
-       if (revs->grep_filter)
+       if (revs->grep_filter) {
                revs->grep_filter->regflags |= regflags;
+               revs->grep_filter->fixed = fixed;
+       }
 
        if (show_merge)
                prepare_show_merge(revs);
@@ -1438,6 +1468,8 @@ enum commit_action simplify_commit(struct rev_info *revs, struct commit *commit)
                return commit_ignore;
        if (revs->unpacked && has_sha1_pack(commit->object.sha1, revs->ignore_packed))
                return commit_ignore;
+       if (revs->show_all)
+               return commit_show;
        if (commit->object.flags & UNINTERESTING)
                return commit_ignore;
        if (revs->min_age != -1 && (commit->date > revs->min_age))
index 8572315954d1fde8c36c426d66c665534c22d1f2..b5f01f8309b6630be7169eb72f613e5deb0ebcab 100644 (file)
@@ -33,6 +33,7 @@ struct rev_info {
                        prune:1,
                        no_merges:1,
                        no_walk:1,
+                       show_all:1,
                        remove_empty_trees:1,
                        simplify_history:1,
                        lifo:1,
diff --git a/setup.c b/setup.c
index 4509598d577baba8b1d7e8782d8e6ff8e74f9556..dc247a84c49709d2bff00440e5ac976df83acd2e 100644 (file)
--- a/setup.c
+++ b/setup.c
 static int inside_git_dir = -1;
 static int inside_work_tree = -1;
 
-const char *prefix_path(const char *prefix, int len, const char *path)
+static int sanitary_path_copy(char *dst, const char *src)
 {
-       const char *orig = path;
+       char *dst0 = dst;
+
+       if (*src == '/') {
+               *dst++ = '/';
+               while (*src == '/')
+                       src++;
+       }
+
        for (;;) {
-               char c;
-               if (*path != '.')
-                       break;
-               c = path[1];
-               /* "." */
-               if (!c) {
-                       path++;
-                       break;
+               char c = *src;
+
+               /*
+                * A path component that begins with . could be
+                * special:
+                * (1) "." and ends   -- ignore and terminate.
+                * (2) "./"           -- ignore them, eat slash and continue.
+                * (3) ".." and ends  -- strip one and terminate.
+                * (4) "../"          -- strip one, eat slash and continue.
+                */
+               if (c == '.') {
+                       switch (src[1]) {
+                       case '\0':
+                               /* (1) */
+                               src++;
+                               break;
+                       case '/':
+                               /* (2) */
+                               src += 2;
+                               while (*src == '/')
+                                       src++;
+                               continue;
+                       case '.':
+                               switch (src[2]) {
+                               case '\0':
+                                       /* (3) */
+                                       src += 2;
+                                       goto up_one;
+                               case '/':
+                                       /* (4) */
+                                       src += 3;
+                                       while (*src == '/')
+                                               src++;
+                                       goto up_one;
+                               }
+                       }
                }
-               /* "./" */
+
+               /* copy up to the next '/', and eat all '/' */
+               while ((c = *src++) != '\0' && c != '/')
+                       *dst++ = c;
                if (c == '/') {
-                       path += 2;
-                       continue;
-               }
-               if (c != '.')
+                       *dst++ = c;
+                       while (c == '/')
+                               c = *src++;
+                       src--;
+               } else if (!c)
                        break;
-               c = path[2];
-               if (!c)
-                       path += 2;
-               else if (c == '/')
-                       path += 3;
-               else
-                       break;
-               /* ".." and "../" */
-               /* Remove last component of the prefix */
-               do {
-                       if (!len)
-                               die("'%s' is outside repository", orig);
-                       len--;
-               } while (len && prefix[len-1] != '/');
                continue;
+
+       up_one:
+               /*
+                * dst0..dst is prefix portion, and dst[-1] is '/';
+                * go up one level.
+                */
+               dst -= 2; /* go past trailing '/' if any */
+               if (dst < dst0)
+                       return -1;
+               while (1) {
+                       if (dst <= dst0)
+                               break;
+                       c = *dst--;
+                       if (c == '/') {
+                               dst += 2;
+                               break;
+                       }
+               }
        }
-       if (len) {
-               int speclen = strlen(path);
-               char *n = xmalloc(speclen + len + 1);
+       *dst = '\0';
+       return 0;
+}
 
-               memcpy(n, prefix, len);
-               memcpy(n + len, path, speclen+1);
-               path = n;
+const char *prefix_path(const char *prefix, int len, const char *path)
+{
+       const char *orig = path;
+       char *sanitized = xmalloc(len + strlen(path) + 1);
+       if (is_absolute_path(orig))
+               strcpy(sanitized, path);
+       else {
+               if (len)
+                       memcpy(sanitized, prefix, len);
+               strcpy(sanitized + len, path);
        }
-       return path;
+       if (sanitary_path_copy(sanitized, sanitized))
+               goto error_out;
+       if (is_absolute_path(orig)) {
+               const char *work_tree = get_git_work_tree();
+               size_t len = strlen(work_tree);
+               size_t total = strlen(sanitized) + 1;
+               if (strncmp(sanitized, work_tree, len) ||
+                   (sanitized[len] != '\0' && sanitized[len] != '/')) {
+               error_out:
+                       error("'%s' is outside repository", orig);
+                       free(sanitized);
+                       return NULL;
+               }
+               if (sanitized[len] == '/')
+                       len++;
+               memmove(sanitized, sanitized + len, total - len);
+       }
+       return sanitized;
 }
 
 /*
@@ -114,7 +181,7 @@ void verify_non_filename(const char *prefix, const char *arg)
 const char **get_pathspec(const char *prefix, const char **pathspec)
 {
        const char *entry = *pathspec;
-       const char **p;
+       const char **src, **dst;
        int prefixlen;
 
        if (!prefix && !entry)
@@ -128,12 +195,19 @@ const char **get_pathspec(const char *prefix, const char **pathspec)
        }
 
        /* Otherwise we have to re-write the entries.. */
-       p = pathspec;
+       src = pathspec;
+       dst = pathspec;
        prefixlen = prefix ? strlen(prefix) : 0;
-       do {
-               *p = prefix_path(prefix, prefixlen, entry);
-       } while ((entry = *++p) != NULL);
-       return (const char **) pathspec;
+       while (*src) {
+               const char *p = prefix_path(prefix, prefixlen, *src);
+               if (p)
+                       *(dst++) = p;
+               src++;
+       }
+       *dst = NULL;
+       if (!*pathspec)
+               return NULL;
+       return pathspec;
 }
 
 /*
index 41799492f909e19d907fe5d954463f9fba177a4e..1ddb96bb82b60f4da8489664d13f398d88bf5a15 100644 (file)
@@ -1845,6 +1845,15 @@ static struct cached_object {
 } *cached_objects;
 static int cached_object_nr, cached_object_alloc;
 
+static struct cached_object empty_tree = {
+       /* empty tree sha1: 4b825dc642cb6eb9a060e54bf8d69288fbee4904 */
+       "\x4b\x82\x5d\xc6\x42\xcb\x6e\xb9\xa0\x60"
+       "\xe5\x4b\xf8\xd6\x92\x88\xfb\xee\x49\x04",
+       OBJ_TREE,
+       "",
+       0
+};
+
 static struct cached_object *find_cached_object(const unsigned char *sha1)
 {
        int i;
@@ -1854,6 +1863,8 @@ static struct cached_object *find_cached_object(const unsigned char *sha1)
                if (!hashcmp(co->sha1, sha1))
                        return co;
        }
+       if (!hashcmp(sha1, empty_tree.sha1))
+               return &empty_tree;
        return NULL;
 }
 
@@ -1943,7 +1954,8 @@ void *read_object_with_reference(const unsigned char *sha1,
                }
                ref_length = strlen(ref_type);
 
-               if (memcmp(buffer, ref_type, ref_length) ||
+               if (ref_length + 40 > isize ||
+                   memcmp(buffer, ref_type, ref_length) ||
                    get_sha1_hex((char *) buffer + ref_length, actual_sha1)) {
                        free(buffer);
                        return NULL;
index be8489e4e5fc98c6e38036a40fb5ca8c0db77ebc..c2805e736b3086a0e33271a4b5c73cea7d2c55cd 100644 (file)
@@ -494,8 +494,11 @@ static int peel_onion(const char *name, int len, unsigned char *sha1)
                                return error("%.*s: expected %s type, but the object dereferences to %s type",
                                             len, name, typename(expected_type),
                                             typename(o->type));
+                       if (!o)
+                               return -1;
                        if (!o->parsed)
-                               parse_object(o->sha1);
+                               if (!parse_object(o->sha1))
+                                       return -1;
                }
        }
        return 0;
@@ -578,8 +581,11 @@ static int handle_one_ref(const char *path,
        struct object *object = parse_object(sha1);
        if (!object)
                return 0;
-       if (object->type == OBJ_TAG)
+       if (object->type == OBJ_TAG) {
                object = deref_tag(object, path, strlen(path));
+               if (!object)
+                       return 0;
+       }
        if (object->type != OBJ_COMMIT)
                return 0;
        insert_by_date((struct commit *)object, list);
@@ -617,7 +623,8 @@ static int get_sha1_oneline(const char *prefix, unsigned char *sha1)
                unsigned long size;
 
                commit = pop_most_recent_commit(&list, ONELINE_SEEN);
-               parse_object(commit->object.sha1);
+               if (!parse_object(commit->object.sha1))
+                       continue;
                if (temp_commit_buffer)
                        free(temp_commit_buffer);
                if (commit->buffer)
index dbd9f5ad0ac21e70fc3a095d8e2938f245c238d3..4d90eda19efe0a80c1cb39e8897ab3ed5e6fcf56 100644 (file)
--- a/shallow.c
+++ b/shallow.c
@@ -56,7 +56,7 @@ struct commit_list *get_shallow_commits(struct object_array *heads, int depth,
                        if (i < heads->nr) {
                                commit = (struct commit *)
                                        deref_tag(heads->objects[i++].item, NULL, 0);
-                               if (commit->object.type != OBJ_COMMIT) {
+                               if (!commit || commit->object.type != OBJ_COMMIT) {
                                        commit = NULL;
                                        continue;
                                }
@@ -70,7 +70,8 @@ struct commit_list *get_shallow_commits(struct object_array *heads, int depth,
                                cur_depth = *(int *)commit->util;
                        }
                }
-               parse_commit(commit);
+               if (parse_commit(commit))
+                       die("invalid commit");
                commit->object.flags |= not_shallow_flag;
                cur_depth++;
                for (p = commit->parents, commit = NULL; p; p = p->next) {
index 5efcfc8860a82766b53a0d579fbdd0844d0f9b62..4aed75265e945d7b8dfafb36913006376768b4d3 100644 (file)
--- a/strbuf.c
+++ b/strbuf.c
@@ -146,11 +146,12 @@ void strbuf_addf(struct strbuf *sb, const char *fmt, ...)
        strbuf_setlen(sb, sb->len + len);
 }
 
-void strbuf_expand(struct strbuf *sb, const char *format,
-                   const char **placeholders, expand_fn_t fn, void *context)
+void strbuf_expand(struct strbuf *sb, const char *format, expand_fn_t fn,
+                  void *context)
 {
        for (;;) {
-               const char *percent, **p;
+               const char *percent;
+               size_t consumed;
 
                percent = strchrnul(format, '%');
                strbuf_add(sb, format, percent - format);
@@ -158,14 +159,10 @@ void strbuf_expand(struct strbuf *sb, const char *format,
                        break;
                format = percent + 1;
 
-               for (p = placeholders; *p; p++) {
-                       if (!prefixcmp(format, *p))
-                               break;
-               }
-               if (*p) {
-                       fn(sb, *p, context);
-                       format += strlen(*p);
-               } else
+               consumed = fn(sb, format, context);
+               if (consumed)
+                       format += consumed;
+               else
                        strbuf_addch(sb, '%');
        }
 }
index 36d61db65728f61188ef3bedbdbe88d0f2d9a0b9..faec2291d9e622c76dcdb3ef13d0876c5e3e6f28 100644 (file)
--- a/strbuf.h
+++ b/strbuf.h
@@ -103,8 +103,8 @@ static inline void strbuf_addbuf(struct strbuf *sb, struct strbuf *sb2) {
 }
 extern void strbuf_adddup(struct strbuf *sb, size_t pos, size_t len);
 
-typedef void (*expand_fn_t) (struct strbuf *sb, const char *placeholder, void *context);
-extern void strbuf_expand(struct strbuf *sb, const char *format, const char **placeholders, expand_fn_t fn, void *context);
+typedef size_t (*expand_fn_t) (struct strbuf *sb, const char *placeholder, void *context);
+extern void strbuf_expand(struct strbuf *sb, const char *format, expand_fn_t fn, void *context);
 
 __attribute__((format(printf,2,3)))
 extern void strbuf_addf(struct strbuf *sb, const char *fmt, ...);
diff --git a/t/t0050-filesystem.sh b/t/t0050-filesystem.sh
new file mode 100755 (executable)
index 0000000..cd088b3
--- /dev/null
@@ -0,0 +1,93 @@
+#!/bin/sh
+
+test_description='Various filesystem issues'
+
+. ./test-lib.sh
+
+auml=`perl -CO -e 'print pack("U",0x00E4)'`
+aumlcdiar=`perl -CO -e 'print pack("U",0x0061).pack("U",0x0308)'`
+
+test_expect_success 'see if we expect ' '
+
+       test_case=test_expect_success
+       test_unicode=test_expect_success
+       mkdir junk &&
+       echo good >junk/CamelCase &&
+       echo bad >junk/camelcase &&
+       if test "$(cat junk/CamelCase)" != good
+       then
+               test_case=test_expect_failure
+               say "will test on a case insensitive filesystem"
+       fi &&
+       rm -fr junk &&
+       mkdir junk &&
+       >junk/"$auml" &&
+       case "$(cd junk && echo *)" in
+       "$aumlcdiar")
+               test_unicode=test_expect_failure
+               say "will test on a unicode corrupting filesystem"
+               ;;
+       *)      ;;
+       esac &&
+       rm -fr junk
+'
+
+test_expect_success "setup case tests" '
+
+       touch camelcase &&
+       git add camelcase &&
+       git commit -m "initial" &&
+       git tag initial &&
+       git checkout -b topic &&
+       git mv camelcase tmp &&
+       git mv tmp CamelCase &&
+       git commit -m "rename" &&
+       git checkout -f master
+
+'
+
+$test_case 'rename (case change)' '
+
+       git mv camelcase CamelCase &&
+       git commit -m "rename"
+
+'
+
+$test_case 'merge (case change)' '
+
+       git reset --hard initial &&
+       git merge topic
+
+'
+
+test_expect_success "setup unicode normalization tests" '
+
+  test_create_repo unicode &&
+  cd unicode &&
+  touch "$aumlcdiar" &&
+  git add "$aumlcdiar" &&
+  git commit -m initial
+  git tag initial &&
+  git checkout -b topic &&
+  git mv $aumlcdiar tmp &&
+  git mv tmp "$auml" &&
+  git commit -m rename &&
+  git checkout -f master
+
+'
+
+$test_unicode 'rename (silent unicode normalization)' '
+
+ git mv "$aumlcdiar" "$auml" &&
+ git commit -m rename
+
+'
+
+$test_unicode 'merge (silent unicode normalization)' '
+
+ git reset --hard initial &&
+ git merge topic
+
+'
+
+test_done
diff --git a/t/t1502-rev-parse-parseopt.sh b/t/t1502-rev-parse-parseopt.sh
new file mode 100755 (executable)
index 0000000..762af5f
--- /dev/null
@@ -0,0 +1,43 @@
+#!/bin/sh
+
+test_description='test git rev-parse --parseopt'
+. ./test-lib.sh
+
+cat > expect.err <<EOF
+usage: some-command [options] <args>...
+    
+    some-command does foo and bar!
+
+    -h, --help            show the help
+    --foo                 some nifty option --foo
+    --bar ...             some cool option --bar with an argument
+
+An option group Header
+    -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 <<EOF
+some-command [options] <args>...
+
+some-command does foo and bar!
+--
+h,help    show the help
+
+foo       some nifty option --foo
+bar=      some cool option --bar with an argument
+
+ An option group Header
+C?        option C with an optional argument
+
+Extras
+extra1    line above used to cause a segfault but no longer does
+EOF
+       git diff expect.err output.err
+'
+
+test_done
index e5ed74545b8a2ac9c2063b2ae40d7c661bda0260..62e65d704b37eb92509a8ad7e844cea8a675ed50 100755 (executable)
@@ -61,8 +61,8 @@ test_expect_success 'setup' '
        git tag I
 '
 
-cat > fake-editor.sh <<\EOF
-#!/bin/sh
+echo "#!$SHELL" >fake-editor
+cat >> fake-editor.sh <<\EOF
 case "$1" in
 */COMMIT_EDITMSG)
        test -z "$FAKE_COMMIT_MESSAGE" || echo "$FAKE_COMMIT_MESSAGE" > "$1"
diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh
new file mode 100755 (executable)
index 0000000..c8dc1ac
--- /dev/null
@@ -0,0 +1,69 @@
+#!/bin/sh
+
+test_description='add -i basic tests'
+. ./test-lib.sh
+
+test_expect_success 'setup (initial)' '
+       echo content >file &&
+       git add file &&
+       echo more >>file &&
+       echo lines >>file
+'
+test_expect_success 'status works (initial)' '
+       git add -i </dev/null >output &&
+       grep "+1/-0 *+2/-0 file" output
+'
+cat >expected <<EOF
+new file mode 100644
+index 0000000..d95f3ad
+--- /dev/null
++++ b/file
+@@ -0,0 +1 @@
++content
+EOF
+test_expect_success 'diff works (initial)' '
+       (echo d; echo 1) | git add -i >output &&
+       sed -ne "/new file/,/content/p" <output >diff &&
+       diff -u expected diff
+'
+test_expect_success 'revert works (initial)' '
+       git add file &&
+       (echo r; echo 1) | git add -i &&
+       git ls-files >output &&
+       ! grep . output
+'
+
+test_expect_success 'setup (commit)' '
+       echo baseline >file &&
+       git add file &&
+       git commit -m commit &&
+       echo content >>file &&
+       git add file &&
+       echo more >>file &&
+       echo lines >>file
+'
+test_expect_success 'status works (commit)' '
+       git add -i </dev/null >output &&
+       grep "+1/-0 *+2/-0 file" output
+'
+cat >expected <<EOF
+index 180b47c..b6f2c08 100644
+--- a/file
++++ b/file
+@@ -1 +1,2 @@
+ baseline
++content
+EOF
+test_expect_success 'diff works (commit)' '
+       (echo d; echo 1) | git add -i >output &&
+       sed -ne "/^index/,/content/p" <output >diff &&
+       diff -u expected diff
+'
+test_expect_success 'revert works (commit)' '
+       git add file &&
+       (echo r; echo 1) | git add -i &&
+       git add -i </dev/null >output &&
+       grep "unchanged *+3/-0 file" output
+'
+
+test_done
index 67e080bdbe5a98a9c446af8aee41acc9fb9129b4..0d9cbb62615c0d94da784f63907989988b0e8151 100755 (executable)
@@ -12,6 +12,7 @@ test_expect_success setup '
        echo "         Eight SP indent" >>F &&
        echo "  HT and SP indent" >>F &&
        echo "With trailing SP " >>F &&
+       echo "Carriage ReturnQ" | tr Q "\015" >>F &&
        echo "No problem" >>F
 
 '
@@ -27,6 +28,7 @@ test_expect_success default '
        grep Eight normal >/dev/null &&
        grep HT error >/dev/null &&
        grep With error >/dev/null &&
+       grep Return error >/dev/null &&
        grep No normal >/dev/null
 
 '
@@ -41,6 +43,7 @@ test_expect_success 'without -trail' '
        grep Eight normal >/dev/null &&
        grep HT error >/dev/null &&
        grep With normal >/dev/null &&
+       grep Return normal >/dev/null &&
        grep No normal >/dev/null
 
 '
@@ -56,6 +59,7 @@ test_expect_success 'without -trail (attribute)' '
        grep Eight normal >/dev/null &&
        grep HT error >/dev/null &&
        grep With normal >/dev/null &&
+       grep Return normal >/dev/null &&
        grep No normal >/dev/null
 
 '
@@ -71,6 +75,7 @@ test_expect_success 'without -space' '
        grep Eight normal >/dev/null &&
        grep HT normal >/dev/null &&
        grep With error >/dev/null &&
+       grep Return error >/dev/null &&
        grep No normal >/dev/null
 
 '
@@ -86,6 +91,7 @@ test_expect_success 'without -space (attribute)' '
        grep Eight normal >/dev/null &&
        grep HT normal >/dev/null &&
        grep With error >/dev/null &&
+       grep Return error >/dev/null &&
        grep No normal >/dev/null
 
 '
@@ -101,6 +107,7 @@ test_expect_success 'with indent-non-tab only' '
        grep Eight error >/dev/null &&
        grep HT normal >/dev/null &&
        grep With normal >/dev/null &&
+       grep Return normal >/dev/null &&
        grep No normal >/dev/null
 
 '
@@ -116,6 +123,39 @@ test_expect_success 'with indent-non-tab only (attribute)' '
        grep Eight error >/dev/null &&
        grep HT normal >/dev/null &&
        grep With normal >/dev/null &&
+       grep Return normal >/dev/null &&
+       grep No normal >/dev/null
+
+'
+
+test_expect_success 'with cr-at-eol' '
+
+       rm -f .gitattributes
+       git config core.whitespace cr-at-eol
+       git diff --color >output
+       grep "$blue_grep" output >error
+       grep -v "$blue_grep" output >normal
+
+       grep Eight normal >/dev/null &&
+       grep HT error >/dev/null &&
+       grep With error >/dev/null &&
+       grep Return normal >/dev/null &&
+       grep No normal >/dev/null
+
+'
+
+test_expect_success 'with cr-at-eol (attribute)' '
+
+       git config --unset core.whitespace
+       echo "F whitespace=trailing,cr-at-eol" >.gitattributes
+       git diff --color >output
+       grep "$blue_grep" output >error
+       grep -v "$blue_grep" output >normal
+
+       grep Eight normal >/dev/null &&
+       grep HT error >/dev/null &&
+       grep With error >/dev/null &&
+       grep Return normal >/dev/null &&
        grep No normal >/dev/null
 
 '
diff --git a/t/t4105-apply-fuzz.sh b/t/t4105-apply-fuzz.sh
new file mode 100755 (executable)
index 0000000..0e8d25f
--- /dev/null
@@ -0,0 +1,57 @@
+#!/bin/sh
+
+test_description='apply with fuzz and offset'
+
+. ./test-lib.sh
+
+dotest () {
+       name="$1" && shift &&
+       test_expect_success "$name" "
+               git checkout-index -f -q -u file &&
+               git apply $* &&
+               diff -u expect file
+       "
+}
+
+test_expect_success setup '
+
+       for i in 1 2 3 4 5 6 7 8 9 10 11 12
+       do
+               echo $i
+       done >file &&
+       git update-index --add file &&
+       for i in 1 2 3 4 5 6 7 a b c d e 8 9 10 11 12
+       do
+               echo $i
+       done >file &&
+       cat file >expect &&
+       git diff >O0.diff &&
+
+       sed -e "s/@@ -5,6 +5,11 @@/@@ -2,6 +2,11 @@/" >O1.diff O0.diff &&
+       sed -e "s/@@ -5,6 +5,11 @@/@@ -7,6 +7,11 @@/" >O2.diff O0.diff &&
+       sed -e "s/@@ -5,6 +5,11 @@/@@ -19,6 +19,11 @@/" >O3.diff O0.diff &&
+
+       sed -e "s/^ 5/ S/" >F0.diff O0.diff &&
+       sed -e "s/^ 5/ S/" >F1.diff O1.diff &&
+       sed -e "s/^ 5/ S/" >F2.diff O2.diff &&
+       sed -e "s/^ 5/ S/" >F3.diff O3.diff
+
+'
+
+dotest 'unmodified patch' O0.diff
+
+dotest 'minus offset' O1.diff
+
+dotest 'plus offset' O2.diff
+
+dotest 'big offset' O3.diff
+
+dotest 'fuzz with no offset' -C2 F0.diff
+
+dotest 'fuzz with minus offset' -C2 F1.diff
+
+dotest 'fuzz with plus offset' -C2 F2.diff
+
+dotest 'fuzz with big offset' -C2 F3.diff
+
+test_done
diff --git a/t/t4125-apply-ws-fuzz.sh b/t/t4125-apply-ws-fuzz.sh
new file mode 100755 (executable)
index 0000000..d6f15be
--- /dev/null
@@ -0,0 +1,103 @@
+#!/bin/sh
+
+test_description='applying patch that has broken whitespaces in context'
+
+. ./test-lib.sh
+
+test_expect_success setup '
+
+       >file &&
+       git add file &&
+
+       # file-0 is full of whitespace breakages
+       for l in a bb c d eeee f ggg h
+       do
+               echo "$l "
+       done >file-0 &&
+
+       # patch-0 creates a whitespace broken file
+       cat file-0 >file &&
+       git diff >patch-0 &&
+       git add file &&
+
+       # file-1 is still full of whitespace breakages,
+       # but has one line updated, without fixing any
+       # whitespaces.
+       # patch-1 records that change.
+       sed -e "s/d/D/" file-0 >file-1 &&
+       cat file-1 >file &&
+       git diff >patch-1 &&
+
+       # patch-all is the effect of both patch-0 and patch-1
+       >file &&
+       git add file &&
+       cat file-1 >file &&
+       git diff >patch-all &&
+
+       # patch-2 is the same as patch-1 but is based
+       # on a version that already has whitespace fixed,
+       # and does not introduce whitespace breakages.
+       sed -e "s/ $//" patch-1 >patch-2 &&
+
+       # If all whitespace breakages are fixed the contents
+       # should look like file-fixed
+       sed -e "s/ $//" file-1 >file-fixed
+
+'
+
+test_expect_success nofix '
+
+       >file &&
+       git add file &&
+
+       # Baseline.  Applying without fixing any whitespace
+       # breakages.
+       git apply --whitespace=nowarn patch-0 &&
+       git apply --whitespace=nowarn patch-1 &&
+
+       # The result should obviously match.
+       diff -u file-1 file
+'
+
+test_expect_success 'withfix (forward)' '
+
+       >file &&
+       git add file &&
+
+       # The first application will munge the context lines
+       # the second patch depends on.  We should be able to
+       # adjust and still apply.
+       git apply --whitespace=fix patch-0 &&
+       git apply --whitespace=fix patch-1 &&
+
+       diff -u file-fixed file
+'
+
+test_expect_success 'withfix (backward)' '
+
+       >file &&
+       git add file &&
+
+       # Now we have a whitespace breakages on our side.
+       git apply --whitespace=nowarn patch-0 &&
+
+       # And somebody sends in a patch based on image
+       # with whitespace already fixed.
+       git apply --whitespace=fix patch-2 &&
+
+       # The result should accept the whitespace fixed
+       # postimage.  But the line with "h" is beyond context
+       # horizon and left unfixed.
+
+       sed -e /h/d file-fixed >fixed-head &&
+       sed -e /h/d file >file-head &&
+       diff -u fixed-head file-head &&
+
+       sed -n -e /h/p file-fixed >fixed-tail &&
+       sed -n -e /h/p file >file-tail &&
+
+       ! diff -u fixed-tail file-tail
+
+'
+
+test_done
index 822ac8c28e112dc1da61cb7fecdab1b4f25717ec..59a165a6d44190a1ce9ef9575dc6c8a2ce9f4efb 100755 (executable)
@@ -63,4 +63,12 @@ test_expect_success 'Even without -l, local will make a hardlink' '
        test 0 = $copied
 '
 
+test_expect_success 'local clone of repo with nonexistent ref in HEAD' '
+       cd "$D" &&
+       echo "ref: refs/heads/nonexistent" > a.git/HEAD &&
+       git clone a d &&
+       cd d &&
+       git fetch &&
+       test ! -e .git/refs/remotes/origin/HEAD'
+
 test_done
index b1243b4163d231bb0f29fd91fe7fa15c34463c82..fa382c58da08a6eeca1aa51d4af47215e3e1c107 100755 (executable)
@@ -118,4 +118,42 @@ test_expect_success "Sergey Vlasov's test case" '
        git mv ab a
 '
 
+test_expect_success 'absolute pathname' '(
+
+       rm -fr mine &&
+       mkdir mine &&
+       cd mine &&
+       test_create_repo one &&
+       cd one &&
+       mkdir sub &&
+       >sub/file &&
+       git add sub/file &&
+
+       git mv sub "$(pwd)/in" &&
+       ! test -d sub &&
+       test -d in &&
+       git ls-files --error-unmatch in/file
+
+
+)'
+
+test_expect_success 'absolute pathname outside should fail' '(
+
+       rm -fr mine &&
+       mkdir mine &&
+       cd mine &&
+       out=$(pwd) &&
+       test_create_repo one &&
+       cd one &&
+       mkdir sub &&
+       >sub/file &&
+       git add sub/file &&
+
+       ! git mv sub "$out/out" &&
+       test -d sub &&
+       ! test -d ../in &&
+       git ls-files --error-unmatch sub/file
+
+)'
+
 test_done
diff --git a/t/t7010-setup.sh b/t/t7010-setup.sh
new file mode 100755 (executable)
index 0000000..e809e0e
--- /dev/null
@@ -0,0 +1,164 @@
+#!/bin/sh
+
+test_description='setup taking and sanitizing funny paths'
+
+. ./test-lib.sh
+
+test_expect_success setup '
+
+       mkdir -p a/b/c a/e &&
+       D=$(pwd) &&
+       >a/b/c/d &&
+       >a/e/f
+
+'
+
+test_expect_success 'git add (absolute)' '
+
+       git add "$D/a/b/c/d" &&
+       git ls-files >current &&
+       echo a/b/c/d >expect &&
+       diff -u expect current
+
+'
+
+
+test_expect_success 'git add (funny relative)' '
+
+       rm -f .git/index &&
+       (
+               cd a/b &&
+               git add "../e/./f"
+       ) &&
+       git ls-files >current &&
+       echo a/e/f >expect &&
+       diff -u expect current
+
+'
+
+test_expect_success 'git rm (absolute)' '
+
+       rm -f .git/index &&
+       git add a &&
+       git rm -f --cached "$D/a/b/c/d" &&
+       git ls-files >current &&
+       echo a/e/f >expect &&
+       diff -u expect current
+
+'
+
+test_expect_success 'git rm (funny relative)' '
+
+       rm -f .git/index &&
+       git add a &&
+       (
+               cd a/b &&
+               git rm -f --cached "../e/./f"
+       ) &&
+       git ls-files >current &&
+       echo a/b/c/d >expect &&
+       diff -u expect current
+
+'
+
+test_expect_success 'git ls-files (absolute)' '
+
+       rm -f .git/index &&
+       git add a &&
+       git ls-files "$D/a/e/../b" >current &&
+       echo a/b/c/d >expect &&
+       diff -u expect current
+
+'
+
+test_expect_success 'git ls-files (relative #1)' '
+
+       rm -f .git/index &&
+       git add a &&
+       (
+               cd a/b &&
+               git ls-files "../b/c"
+       )  >current &&
+       echo c/d >expect &&
+       diff -u expect current
+
+'
+
+test_expect_success 'git ls-files (relative #2)' '
+
+       rm -f .git/index &&
+       git add a &&
+       (
+               cd a/b &&
+               git ls-files --full-name "../e/f"
+       )  >current &&
+       echo a/e/f >expect &&
+       diff -u expect current
+
+'
+
+test_expect_success 'git ls-files (relative #3)' '
+
+       rm -f .git/index &&
+       git add a &&
+       (
+               cd a/b &&
+               if git ls-files "../e/f"
+               then
+                       echo Gaah, should have failed
+                       exit 1
+               else
+                       : happy
+               fi
+       )
+
+'
+
+test_expect_success 'commit using absolute path names' '
+       git commit -m "foo" &&
+       echo aa >>a/b/c/d &&
+       git commit -m "aa" "$(pwd)/a/b/c/d"
+'
+
+test_expect_success 'log using absolute path names' '
+       echo bb >>a/b/c/d &&
+       git commit -m "bb" $(pwd)/a/b/c/d &&
+
+       git log a/b/c/d >f1.txt &&
+       git log "$(pwd)/a/b/c/d" >f2.txt &&
+       diff -u f1.txt f2.txt
+'
+
+test_expect_success 'blame using absolute path names' '
+       git blame a/b/c/d >f1.txt &&
+       git blame "$(pwd)/a/b/c/d" >f2.txt &&
+       diff -u f1.txt f2.txt
+'
+
+test_expect_success 'setup deeper work tree' '
+       test_create_repo tester
+'
+
+test_expect_success 'add a directory outside the work tree' '(
+       cd tester &&
+       d1="$(cd .. ; pwd)" &&
+       git add "$d1"
+)'
+
+test_expect_success 'add a file outside the work tree, nasty case 1' '(
+       cd tester &&
+       f="$(pwd)x" &&
+       echo "$f" &&
+       touch "$f" &&
+       git add "$f"
+)'
+
+test_expect_success 'add a file outside the work tree, nasty case 2' '(
+       cd tester &&
+       f="$(pwd | sed "s/.$//")x" &&
+       echo "$f" &&
+       touch "$f" &&
+       git add "$f"
+)'
+
+test_done
diff --git a/t/t7104-reset.sh b/t/t7104-reset.sh
new file mode 100755 (executable)
index 0000000..f136ee7
--- /dev/null
@@ -0,0 +1,46 @@
+#!/bin/sh
+
+test_description='reset --hard unmerged'
+
+. ./test-lib.sh
+
+test_expect_success setup '
+
+       mkdir before later &&
+       >before/1 &&
+       >before/2 &&
+       >hello &&
+       >later/3 &&
+       git add before hello later &&
+       git commit -m world &&
+
+       H=$(git rev-parse :hello) &&
+       git rm --cached hello &&
+       echo "100644 $H 2       hello" | git update-index --index-info &&
+
+       rm -f hello &&
+       mkdir -p hello &&
+       >hello/world &&
+       test "$(git ls-files -o)" = hello/world
+
+'
+
+test_expect_success 'reset --hard should restore unmerged ones' '
+
+       git reset --hard &&
+       git ls-files --error-unmatch before/1 before/2 hello later/3 &&
+       test -f hello
+
+'
+
+test_expect_success 'reset --hard did not corrupt index nor cached-tree' '
+
+       T=$(git write-tree) &&
+       rm -f .git/index &&
+       git add before hello later &&
+       U=$(git write-tree) &&
+       test "$T" = "$U"
+
+'
+
+test_done
index dfd118878fd37c096ccd426aa01fa2ac36581367..38403643a6271ae4e6bb5a9c7d768ae4b50df34d 100755 (executable)
@@ -316,4 +316,14 @@ test_expect_success 'core.excludesfile' '
 
 '
 
+test_expect_success 'removal failure' '
+
+       mkdir foo &&
+       touch foo/bar &&
+       chmod 0 foo &&
+       ! git clean -f -d
+
+'
+chmod 755 foo
+
 test_done
index 08f7c3d8d7666aeb7a116f475127c9c183e64d5a..cbbfa9cb4986403cb214bba6c2216c85471469c9 100755 (executable)
@@ -15,16 +15,22 @@ test_expect_success \
     'Setup helper tool' \
     '(echo "#!/bin/sh"
       echo shift
+      echo output=1
+      echo "while test -f commandline\$output; do output=\$((\$output+1)); done"
       echo for a
       echo do
       echo "  echo \"!\$a!\""
-      echo "done >commandline"
-      echo "cat > msgtxt"
+      echo "done >commandline\$output"
+      echo "cat > msgtxt\$output"
       ) >fake.sendmail &&
      chmod +x ./fake.sendmail &&
      git add fake.sendmail &&
      GIT_AUTHOR_NAME="A" git commit -a -m "Second."'
 
+clean_fake_sendmail() {
+       rm -f commandline* msgtxt*
+}
+
 test_expect_success 'Extract patches' '
     patches=`git format-patch -n HEAD^1`
 '
@@ -39,7 +45,7 @@ cat >expected <<\EOF
 EOF
 test_expect_success \
     'Verify commandline' \
-    'diff commandline expected'
+    'diff commandline1 expected'
 
 cat >expected-show-all-headers <<\EOF
 0001-Second.patch
@@ -82,7 +88,7 @@ z8=zzzzzzzz
 z64=$z8$z8$z8$z8$z8$z8$z8$z8
 z512=$z64$z64$z64$z64$z64$z64$z64$z64
 test_expect_success 'reject long lines' '
-       rm -f commandline &&
+       clean_fake_sendmail &&
        cp $patches longline.patch &&
        echo $z512$z512 >>longline.patch &&
        ! git send-email \
@@ -95,7 +101,7 @@ test_expect_success 'reject long lines' '
 '
 
 test_expect_success 'no patch was sent' '
-       ! test -e commandline
+       ! test -e commandline1
 '
 
 test_expect_success 'allow long lines with --no-validate' '
@@ -108,4 +114,56 @@ test_expect_success 'allow long lines with --no-validate' '
                2>errors
 '
 
+test_expect_success 'Invalid In-Reply-To' '
+       clean_fake_sendmail &&
+       git send-email \
+               --from="Example <nobody@example.com>" \
+               --to=nobody@example.com \
+               --in-reply-to=" " \
+               --smtp-server="$(pwd)/fake.sendmail" \
+               $patches
+               2>errors
+       ! grep "^In-Reply-To: < *>" msgtxt1
+'
+
+test_expect_success 'Valid In-Reply-To when prompting' '
+       clean_fake_sendmail &&
+       (echo "From Example <from@example.com>"
+        echo "To Example <to@example.com>"
+        echo ""
+       ) | env GIT_SEND_EMAIL_NOTTY=1 git send-email \
+               --smtp-server="$(pwd)/fake.sendmail" \
+               $patches 2>errors &&
+       ! grep "^In-Reply-To: < *>" msgtxt1
+'
+
+test_expect_success 'setup fake editor' '
+       (echo "#!/bin/sh" &&
+        echo "echo fake edit >>\$1"
+       ) >fake-editor &&
+       chmod +x fake-editor
+'
+
+test_expect_success '--compose works' '
+       clean_fake_sendmail &&
+       echo y | \
+               GIT_EDITOR=$(pwd)/fake-editor \
+               GIT_SEND_EMAIL_NOTTY=1 \
+               git send-email \
+               --compose --subject foo \
+               --from="Example <nobody@example.com>" \
+               --to=nobody@example.com \
+               --smtp-server="$(pwd)/fake.sendmail" \
+               $patches \
+               2>errors
+'
+
+test_expect_success 'first message is compose text' '
+       grep "^fake edit" msgtxt1
+'
+
+test_expect_success 'second message is patch' '
+       grep "Subject:.*Second" msgtxt2
+'
+
 test_done
index 49d57a81ec1cc55f83fb63436631dfdc7d647e0b..58c59ed5ae0159810b4c8258f9182991bad33636 100755 (executable)
@@ -262,4 +262,39 @@ test_expect_success '-w option should work with relative GIT_DIR' '
       )
 '
 
+test_expect_success 'check files before directories' '
+
+       echo Notes > release-notes &&
+       git add release-notes &&
+       git commit -m "Add release notes" release-notes &&
+       id=$(git rev-parse HEAD) &&
+       git cvsexportcommit -w "$CVSWORK" -c $id &&
+
+       echo new > DS &&
+       echo new > E/DS &&
+       echo modified > release-notes &&
+       git add DS E/DS release-notes &&
+       git commit -m "Add two files with the same basename" &&
+       id=$(git rev-parse HEAD) &&
+       git cvsexportcommit -w "$CVSWORK" -c $id &&
+       check_entries "$CVSWORK/E" "DS/1.1/|newfile5.txt/1.1/" &&
+       check_entries "$CVSWORK" "DS/1.1/|release-notes/1.2/" &&
+       diff -u "$CVSWORK/DS" DS &&
+       diff -u "$CVSWORK/E/DS" E/DS &&
+       diff -u "$CVSWORK/release-notes" release-notes
+
+'
+
+test_expect_success 'commit a file with leading spaces in the name' '
+
+       echo space > " space" &&
+       git add " space" &&
+       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/" &&
+       diff -u "$CVSWORK/ space" " space"
+
+'
+
 test_done
diff --git a/tag.c b/tag.c
index 38bf9134f97c18973fe189c8703438f5e1135e49..990134fe7ab14043d40b97230571ffea109b9129 100644 (file)
--- a/tag.c
+++ b/tag.c
@@ -9,7 +9,10 @@ const char *tag_type = "tag";
 struct object *deref_tag(struct object *o, const char *warn, int warnlen)
 {
        while (o && o->type == OBJ_TAG)
-               o = parse_object(((struct tag *)o)->tagged->sha1);
+               if (((struct tag *)o)->tagged)
+                       o = parse_object(((struct tag *)o)->tagged->sha1);
+               else
+                       o = NULL;
        if (!o && warn) {
                if (!warnlen)
                        warnlen = strlen(warn);
diff --git a/thread-utils.c b/thread-utils.c
new file mode 100644 (file)
index 0000000..55e7e29
--- /dev/null
@@ -0,0 +1,48 @@
+#include "cache.h"
+
+#ifdef _WIN32
+#  define WIN32_LEAN_AND_MEAN
+#  include <windows.h>
+#elif defined(hpux) || defined(__hpux) || defined(_hpux)
+#  include <sys/pstat.h>
+#endif
+
+/*
+ * By doing this in two steps we can at least get
+ * the function to be somewhat coherent, even
+ * with this disgusting nest of #ifdefs.
+ */
+#ifndef _SC_NPROCESSORS_ONLN
+#  ifdef _SC_NPROC_ONLN
+#    define _SC_NPROCESSORS_ONLN _SC_NPROC_ONLN
+#  elif defined _SC_CRAY_NCPU
+#    define _SC_NPROCESSORS_ONLN _SC_CRAY_NCPU
+#  endif
+#endif
+
+int online_cpus(void)
+{
+#ifdef _SC_NPROCESSORS_ONLN
+       long ncpus;
+#endif
+
+#ifdef _WIN32
+       SYSTEM_INFO info;
+       GetSystemInfo(&info);
+
+       if ((int)info.dwNumberOfProcessors > 0)
+               return (int)info.dwNumberOfProcessors;
+#elif defined(hpux) || defined(__hpux) || defined(_hpux)
+       struct pst_dynamic psd;
+
+       if (!pstat_getdynamic(&psd, sizeof(psd), (size_t)1, 0))
+               return (int)psd.psd_proc_cnt;
+#endif
+
+#ifdef _SC_NPROCESSORS_ONLN
+       if ((ncpus = (long)sysconf(_SC_NPROCESSORS_ONLN)) > 0)
+               return (int)ncpus;
+#endif
+
+       return 1;
+}
diff --git a/thread-utils.h b/thread-utils.h
new file mode 100644 (file)
index 0000000..cce4b77
--- /dev/null
@@ -0,0 +1,6 @@
+#ifndef THREAD_COMPAT_H
+#define THREAD_COMPAT_H
+
+extern int online_cpus(void);
+
+#endif /* THREAD_COMPAT_H */
index ec558f9005fab372f9bf62d8c3df9ea34f5222bb..56c1ffbc199c534a53da9615aa16b4357656e320 100644 (file)
@@ -301,7 +301,7 @@ static void check_updates(struct cache_entry **src, int nr,
                }
 
                progress = start_progress_delay("Checking out files",
-                                               total, 50, 2);
+                                               total, 50, 1);
                cnt = 0;
        }
 
@@ -590,7 +590,7 @@ static int merged_entry(struct cache_entry *merge, struct cache_entry *old,
                 * a match.
                 */
                if (same(old, merge)) {
-                       memcpy(merge, old, offsetof(struct cache_entry, name));
+                       copy_cache_entry(merge, old);
                } else {
                        verify_uptodate(old, o);
                        invalidate_ce_path(old);
index 51e3ec49d120f2e5a095cde45eb0a22bb7e624da..b26d05331d7eeab4efea01594ecf196bc5fb50ed 100644 (file)
@@ -129,7 +129,8 @@ static int do_rev_list(int fd, void *create_full_pack)
                }
                setup_revisions(0, NULL, &revs, NULL);
        }
-       prepare_revision_walk(&revs);
+       if (prepare_revision_walk(&revs))
+               die("revision walk setup failed");
        mark_edges_uninteresting(revs.commits, &revs, show_edge);
        traverse_commit_list(&revs, show_commit, show_object);
        return 0;
@@ -533,7 +534,8 @@ static void receive_needs(void)
                                /* make sure the real parents are parsed */
                                unregister_shallow(object->sha1);
                                object->parsed = 0;
-                               parse_commit((struct commit *)object);
+                               if (parse_commit((struct commit *)object))
+                                       die("invalid commit");
                                parents = ((struct commit *)object)->parents;
                                while (parents) {
                                        add_object_array(&parents->item->object,
@@ -575,7 +577,8 @@ static int send_ref(const char *refname, const unsigned char *sha1, int flag, vo
        }
        if (o->type == OBJ_TAG) {
                o = deref_tag(o, refname, 0);
-               packet_write(1, "%s %s^{}\n", sha1_to_hex(o->sha1), refname);
+               if (o)
+                       packet_write(1, "%s %s^{}\n", sha1_to_hex(o->sha1), refname);
        }
        return 0;
 }
diff --git a/ws.c b/ws.c
index d09b9df89a7e19367640d4c6ad64ff828d01d26f..ba7e834ca819b1d2ccce6cf125aa9f34efea8d5c 100644 (file)
--- a/ws.c
+++ b/ws.c
@@ -14,6 +14,7 @@ static struct whitespace_rule {
        { "trailing-space", WS_TRAILING_SPACE },
        { "space-before-tab", WS_SPACE_BEFORE_TAB },
        { "indent-with-non-tab", WS_INDENT_WITH_NON_TAB },
+       { "cr-at-eol", WS_CR_AT_EOL },
 };
 
 unsigned parse_whitespace_rule(const char *string)
@@ -124,6 +125,7 @@ unsigned check_and_emit_line(const char *line, int len, unsigned ws_rule,
        int written = 0;
        int trailing_whitespace = -1;
        int trailing_newline = 0;
+       int trailing_carriage_return = 0;
        int i;
 
        /* Logic is simpler if we temporarily ignore the trailing newline. */
@@ -131,6 +133,11 @@ unsigned check_and_emit_line(const char *line, int len, unsigned ws_rule,
                trailing_newline = 1;
                len--;
        }
+       if ((ws_rule & WS_CR_AT_EOL) &&
+           len > 0 && line[len - 1] == '\r') {
+               trailing_carriage_return = 1;
+               len--;
+       }
 
        /* Check for trailing whitespace. */
        if (ws_rule & WS_TRAILING_SPACE) {
@@ -176,8 +183,10 @@ unsigned check_and_emit_line(const char *line, int len, unsigned ws_rule,
        }
 
        if (stream) {
-               /* Now the rest of the line starts at written.
-                * The non-highlighted part ends at trailing_whitespace. */
+               /*
+                * Now the rest of the line starts at "written".
+                * The non-highlighted part ends at "trailing_whitespace".
+                */
                if (trailing_whitespace == -1)
                        trailing_whitespace = len;
 
@@ -196,8 +205,114 @@ unsigned check_and_emit_line(const char *line, int len, unsigned ws_rule,
                            len - trailing_whitespace, 1, stream);
                        fputs(reset, stream);
                }
+               if (trailing_carriage_return)
+                       fputc('\r', stream);
                if (trailing_newline)
                        fputc('\n', stream);
        }
        return result;
 }
+
+/* Copy the line to the buffer while fixing whitespaces */
+int ws_fix_copy(char *dst, const char *src, int len, unsigned ws_rule, int *error_count)
+{
+       /*
+        * len is number of bytes to be copied from src, starting
+        * at src.  Typically src[len-1] is '\n', unless this is
+        * the incomplete last line.
+        */
+       int i;
+       int add_nl_to_tail = 0;
+       int add_cr_to_tail = 0;
+       int fixed = 0;
+       int last_tab_in_indent = -1;
+       int last_space_in_indent = -1;
+       int need_fix_leading_space = 0;
+       char *buf;
+
+       /*
+        * Strip trailing whitespace
+        */
+       if ((ws_rule & WS_TRAILING_SPACE) &&
+           (2 <= len && isspace(src[len-2]))) {
+               if (src[len - 1] == '\n') {
+                       add_nl_to_tail = 1;
+                       len--;
+                       if (1 < len && src[len - 1] == '\r') {
+                               add_cr_to_tail = !!(ws_rule & WS_CR_AT_EOL);
+                               len--;
+                       }
+               }
+               if (0 < len && isspace(src[len - 1])) {
+                       while (0 < len && isspace(src[len-1]))
+                               len--;
+                       fixed = 1;
+               }
+       }
+
+       /*
+        * Check leading whitespaces (indent)
+        */
+       for (i = 0; i < len; i++) {
+               char ch = src[i];
+               if (ch == '\t') {
+                       last_tab_in_indent = i;
+                       if ((ws_rule & WS_SPACE_BEFORE_TAB) &&
+                           0 <= last_space_in_indent)
+                           need_fix_leading_space = 1;
+               } else if (ch == ' ') {
+                       last_space_in_indent = i;
+                       if ((ws_rule & WS_INDENT_WITH_NON_TAB) &&
+                           8 <= i - last_tab_in_indent)
+                               need_fix_leading_space = 1;
+               } else
+                       break;
+       }
+
+       buf = dst;
+       if (need_fix_leading_space) {
+               /* Process indent ourselves */
+               int consecutive_spaces = 0;
+               int last = last_tab_in_indent + 1;
+
+               if (ws_rule & WS_INDENT_WITH_NON_TAB) {
+                       /* have "last" point at one past the indent */
+                       if (last_tab_in_indent < last_space_in_indent)
+                               last = last_space_in_indent + 1;
+                       else
+                               last = last_tab_in_indent + 1;
+               }
+
+               /*
+                * between src[0..last-1], strip the funny spaces,
+                * updating them to tab as needed.
+                */
+               for (i = 0; i < last; i++) {
+                       char ch = src[i];
+                       if (ch != ' ') {
+                               consecutive_spaces = 0;
+                               *dst++ = ch;
+                       } else {
+                               consecutive_spaces++;
+                               if (consecutive_spaces == 8) {
+                                       *dst++ = '\t';
+                                       consecutive_spaces = 0;
+                               }
+                       }
+               }
+               while (0 < consecutive_spaces--)
+                       *dst++ = ' ';
+               len -= last;
+               src += last;
+               fixed = 1;
+       }
+
+       memcpy(dst, src, len);
+       if (add_cr_to_tail)
+               dst[len++] = '\r';
+       if (add_nl_to_tail)
+               dst[len++] = '\n';
+       if (fixed && error_count)
+               (*error_count)++;
+       return dst + len - buf;
+}
index 0b060934e218f1d6fb95777ea7dd7faef1c2dd93..32d780af1e4f6e701f75d9759dfd4ebec56e6425 100644 (file)
@@ -9,7 +9,7 @@
 #include "diffcore.h"
 
 int wt_status_relative_paths = 1;
-int wt_status_use_color = 0;
+int wt_status_use_color = -1;
 static char wt_status_colors[][COLOR_MAXLEN] = {
        "",         /* WT_STATUS_HEADER: normal */
        "\033[32m", /* WT_STATUS_UPDATED: green */
@@ -40,7 +40,7 @@ static int parse_status_slot(const char *var, int offset)
 
 static const char* color(int slot)
 {
-       return wt_status_use_color ? wt_status_colors[slot] : "";
+       return wt_status_use_color > 0 ? wt_status_colors[slot] : "";
 }
 
 void wt_status_prepare(struct wt_status *s)
@@ -401,5 +401,5 @@ int git_status_config(const char *k, const char *v)
                wt_status_relative_paths = git_config_bool(k, v);
                return 0;
        }
-       return git_default_config(k, v);
+       return git_color_default_config(k, v);
 }