Merge branch 'jc/http'

* jc/http:
  Add WEBDAV timeout to http-fetch.
diff --git a/Documentation/git-http-push.txt b/Documentation/git-http-push.txt
index 7e1f894..c2485c6 100644
--- a/Documentation/git-http-push.txt
+++ b/Documentation/git-http-push.txt
@@ -34,7 +34,7 @@
 	Report the list of objects being walked locally and the
 	list of objects successfully sent to the remote repository.
 
-<ref>...:
+<ref>...::
 	The remote refs to update.
 
 
diff --git a/Documentation/git-send-pack.txt b/Documentation/git-send-pack.txt
index 9e67f17..5376f68 100644
--- a/Documentation/git-send-pack.txt
+++ b/Documentation/git-send-pack.txt
@@ -43,7 +43,7 @@
 <directory>::
 	The repository to update.
 
-<ref>...:
+<ref>...::
 	The remote refs to update.
 
 
diff --git a/Documentation/git-shortlog.txt b/Documentation/git-shortlog.txt
index 7486ebe..d54fc3e 100644
--- a/Documentation/git-shortlog.txt
+++ b/Documentation/git-shortlog.txt
@@ -7,16 +7,29 @@
 
 SYNOPSIS
 --------
-git-log --pretty=short | 'git-shortlog'
+git-log --pretty=short | 'git-shortlog' [-h] [-n] [-s]
 
 DESCRIPTION
 -----------
 Summarizes 'git log' output in a format suitable for inclusion
-in release announcements. Each commit will be grouped by author
+in release announcements. Each commit will be grouped by author and
 the first line of the commit message will be shown.
 
 Additionally, "[PATCH]" will be stripped from the commit description.
 
+OPTIONS
+-------
+
+-h::
+	Print a short usage message and exit.
+
+-n::
+	Sort output according to the number of commits per author instead
+	of author alphabetic order.
+
+-s::
+	Supress commit description and provide a commit count summary only.
+
 FILES
 -----
 '.mailmap'::
diff --git a/Documentation/git-svn.txt b/Documentation/git-svn.txt
index 1cfa3e3..450ff1f 100644
--- a/Documentation/git-svn.txt
+++ b/Documentation/git-svn.txt
@@ -37,7 +37,9 @@
 'init'::
 	Creates an empty git repository with additional metadata
 	directories for git-svn.  The Subversion URL must be specified
-	as a command-line argument.
+	as a command-line argument.  Optionally, the target directory
+	to operate on can be specified as a second argument.  Normally
+	this command initializes the current directory.
 
 'fetch'::
 
@@ -63,7 +65,30 @@
 	This is advantageous over 'commit' (below) because it produces
 	cleaner, more linear history.
 
+'log'::
+	This should make it easy to look up svn log messages when svn
+	users refer to -r/--revision numbers.
+
+	The following features from `svn log' are supported:
+
+	--revision=<n>[:<n>] - is supported, non-numeric args are not:
+	                       HEAD, NEXT, BASE, PREV, etc ...
+	-v/--verbose         - it's not completely compatible with
+	                       the --verbose output in svn log, but
+			       reasonably close.
+	--limit=<n>          - is NOT the same as --max-count,
+	                       doesn't count merged/excluded commits
+	--incremental        - supported
+
+	New features:
+
+	--show-commit        - shows the git commit sha1, as well
+	--oneline            - our version of --pretty=oneline
+
+	Any other arguments are passed directly to `git log'
+
 'commit'::
+	You should consider using 'dcommit' instead of this command.
 	Commit specified commit or tree objects to SVN.  This relies on
 	your imported fetch data being up-to-date.  This makes
 	absolutely no attempts to do patching when committing to SVN, it
@@ -86,12 +111,49 @@
 	directories.  The output is suitable for appending to
 	the $GIT_DIR/info/exclude file.
 
+'commit-diff'::
+	Commits the diff of two tree-ish arguments from the
+	command-line.  This command is intended for interopability with
+	git-svnimport and does not rely on being inside an git-svn
+	init-ed repository.  This command takes three arguments, (a) the
+	original tree to diff against, (b) the new tree result, (c) the
+	URL of the target Subversion repository.  The final argument
+	(URL) may be omitted if you are working from a git-svn-aware
+	repository (that has been init-ed with git-svn).
+
+'graft-branches'::
+	This command attempts to detect merges/branches from already
+	imported history.  Techniques used currently include regexes,
+	file copies, and tree-matches).  This command generates (or
+	modifies) the $GIT_DIR/info/grafts file.  This command is
+	considered experimental, and inherently flawed because
+	merge-tracking in SVN is inherently flawed and inconsistent
+	across different repositories.
+
+'multi-init'::
+	This command supports git-svnimport-like command-line syntax for
+	importing repositories that are layed out as recommended by the
+	SVN folks.  This is a bit more tolerant than the git-svnimport
+	command-line syntax and doesn't require the user to figure out
+	where the repository URL ends and where the repository path
+	begins.
+
+'multi-fetch'::
+	This runs fetch on all known SVN branches we're tracking.  This
+	will NOT discover new branches (unlike git-svnimport), so
+	multi-init will need to be re-run (it's idempotent).
+
 --
 
 OPTIONS
 -------
 --
 
+--shared::
+--template=<template_directory>::
+	Only used with the 'init' command.
+	These are passed directly to gitlink:git-init-db[1].
+
 -r <ARG>::
 --revision <ARG>::
 
@@ -115,7 +177,7 @@
 
 --rmdir::
 
-Only used with the 'commit' command.
+Only used with the 'dcommit', 'commit' and 'commit-diff' commands.
 
 Remove directories from the SVN tree if there are no files left
 behind.  SVN can version empty directories, and they are not
@@ -128,7 +190,7 @@
 -e::
 --edit::
 
-Only used with the 'commit' command.
+Only used with the 'dcommit', 'commit' and 'commit-diff' commands.
 
 Edit the commit message before committing to SVN.  This is off by
 default for objects that are commits, and forced on when committing
@@ -139,7 +201,7 @@
 -l<num>::
 --find-copies-harder::
 
-Both of these are only used with the 'commit' command.
+Only used with the 'dcommit', 'commit' and 'commit-diff' commands.
 
 They are both passed directly to git-diff-tree see
 gitlink:git-diff-tree[1] for more information.
@@ -164,7 +226,26 @@
 appropriate entry.  Re-running the previous git-svn command
 after the authors-file is modified should continue operation.
 
-repo-config key: svn.authors-file
+repo-config key: svn.authorsfile
+
+-q::
+--quiet::
+	Make git-svn less verbose.  This only affects git-svn if you
+	have the SVN::* libraries installed and are using them.
+
+--repack[=<n>]::
+--repack-flags=<flags>
+	These should help keep disk usage sane for large fetches
+	with many revisions.
+
+	--repack takes an optional argument for the number of revisions
+	to fetch before repacking.  This defaults to repacking every
+	1000 commits fetched if no argument is specified.
+
+	--repack-flags are passed directly to gitlink:git-repack[1].
+
+repo-config key: svn.repack
+repo-config key: svn.repackflags
 
 -m::
 --merge::
@@ -215,6 +296,28 @@
 '<<tracking-multiple-repos,Tracking Multiple Repositories or Branches>>'
 for more information on using GIT_SVN_ID.
 
+--follow-parent::
+	This is especially helpful when we're tracking a directory
+	that has been moved around within the repository, or if we
+	started tracking a branch and never tracked the trunk it was
+	descended from.
+
+	This relies on the SVN::* libraries to work.
+
+repo-config key: svn.followparent
+
+--no-metadata::
+	This gets rid of the git-svn-id: lines at the end of every commit.
+
+	With this, you lose the ability to use the rebuild command.  If
+	you ever lose your .git/svn/git-svn/.rev_db file, you won't be
+	able to fetch again, either.  This is fine for one-shot imports.
+
+	The 'git-svn log' command will not work on repositories using this,
+	either.
+
+repo-config key: svn.nometadata
+
 --
 
 COMPATIBILITY OPTIONS
@@ -231,6 +334,9 @@
 --no-ignore-externals::
 Only used with the 'fetch' and 'rebuild' command.
 
+This command has no effect when you are using the SVN::*
+libraries with git, svn:externals are always avoided.
+
 By default, git-svn passes --ignore-externals to svn to avoid
 fetching svn:external trees into git.  Pass this flag to enable
 externals tracking directly via git.
@@ -264,7 +370,7 @@
 Tracking and contributing to an Subversion managed-project:
 
 ------------------------------------------------------------------------
-# Initialize a tree (like git init-db):
+# Initialize a repo (like git init-db):
 	git-svn init http://svn.foo.org/project/trunk
 # Fetch remote revisions:
 	git-svn fetch
@@ -312,8 +418,8 @@
 hack to allow it to track an arbitrary number of related _or_ unrelated
 SVN repositories via one git repository.  Simply set the GIT_SVN_ID
 environment variable to a name other other than "git-svn" (the default)
-and git-svn will ignore the contents of the $GIT_DIR/git-svn directory
-and instead do all of its work in $GIT_DIR/$GIT_SVN_ID for that
+and git-svn will ignore the contents of the $GIT_DIR/svn/git-svn directory
+and instead do all of its work in $GIT_DIR/svn/$GIT_SVN_ID for that
 invocation.  The interface branch will be remotes/$GIT_SVN_ID, instead of
 remotes/git-svn.  Any remotes/$GIT_SVN_ID branch should never be modified
 by the user outside of git-svn commands.
@@ -341,6 +447,9 @@
 
 Advanced Example: Tracking a Reorganized Repository
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+Note: this example is now obsolete if you have SVN::* libraries
+installed.  Simply use --follow-parent when fetching.
+
 If you're tracking a directory that has moved, or otherwise been
 branched or tagged off of another directory in the repository and you
 care about the full history of the project, then you can read this
@@ -371,20 +480,18 @@
 
 BUGS
 ----
-If somebody commits a conflicting changeset to SVN at a bad moment
-(right before you commit) causing a conflict and your commit to fail,
-your svn working tree ($GIT_DIR/git-svn/tree) may be dirtied.  The
-easiest thing to do is probably just to rm -rf $GIT_DIR/git-svn/tree and
-run 'rebuild'.
+
+If you are not using the SVN::* Perl libraries and somebody commits a
+conflicting changeset to SVN at a bad moment (right before you commit)
+causing a conflict and your commit to fail, your svn working tree
+($GIT_DIR/git-svn/tree) may be dirtied.  The easiest thing to do is
+probably just to rm -rf $GIT_DIR/git-svn/tree and run 'rebuild'.
 
 We ignore all SVN properties except svn:executable.  Too difficult to
 map them since we rely heavily on git write-tree being _exactly_ the
 same on both the SVN and git working trees and I prefer not to clutter
 working trees with metadata files.
 
-svn:keywords can't be ignored in Subversion (at least I don't know of
-a way to ignore them).
-
 Renamed and copied directories are not detected by git and hence not
 tracked when committing to SVN.  I do not plan on adding support for
 this as it's quite difficult and time-consuming to get working for all
diff --git a/Documentation/glossary.txt b/Documentation/glossary.txt
index 14449ca..7e560b0 100644
--- a/Documentation/glossary.txt
+++ b/Documentation/glossary.txt
@@ -179,7 +179,7 @@
 	character hexadecimal encoding of the hash of the object (possibly
 	followed by a white space).
 
-object type:
+object type::
 	One of the identifiers "commit","tree","tag" and "blob" describing
 	the type of an object.
 
@@ -324,7 +324,7 @@
 	A tag is most typically used to mark a particular point in the
 	commit ancestry chain.
 
-unmerged index:
+unmerged index::
 	An index which contains unmerged index entries.
 
 working tree::
diff --git a/builtin-apply.c b/builtin-apply.c
index de5f855..cbe5977 100644
--- a/builtin-apply.c
+++ b/builtin-apply.c
@@ -1783,8 +1783,6 @@
 {
 	const char *name = patch->old_name ? patch->old_name : patch->new_name;
 	unsigned char sha1[20];
-	unsigned char hdr[50];
-	int hdrlen;
 
 	/* For safety, we require patch index line to contain
 	 * full 40-byte textual SHA1 for old and new, at least for now.
@@ -1800,8 +1798,7 @@
 		/* See if the old one matches what the patch
 		 * applies to.
 		 */
-		write_sha1_file_prepare(desc->buffer, desc->size,
-					blob_type, sha1, hdr, &hdrlen);
+		hash_sha1_file(desc->buffer, desc->size, 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 "
@@ -1846,8 +1843,7 @@
 				     name);
 
 		/* verify that the result matches */
-		write_sha1_file_prepare(desc->buffer, desc->size, blob_type,
-					sha1, hdr, &hdrlen);
+		hash_sha1_file(desc->buffer, desc->size, 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));
 	}
@@ -2112,7 +2108,7 @@
 			quote_c_style(name, NULL, stdout, 0);
 		else
 			fputs(name, stdout);
-		putchar('\n');
+		putchar(line_termination);
 	}
 }
 
diff --git a/builtin-archive.c b/builtin-archive.c
index 6dabdee..9177379 100644
--- a/builtin-archive.c
+++ b/builtin-archive.c
@@ -75,7 +75,7 @@
 		die("git-archive: expected a flush");
 
 	/* Now, start reading from fd[0] and spit it out to stdout */
-	rv = recv_sideband("archive", fd[0], 1, 2, buf, sizeof(buf));
+	rv = recv_sideband("archive", fd[0], 1, 2);
 	close(fd[0]);
 	rv |= finish_connect(pid);
 
diff --git a/cache-tree.c b/cache-tree.c
index 323c68a..d388848 100644
--- a/cache-tree.c
+++ b/cache-tree.c
@@ -344,12 +344,8 @@
 #endif
 	}
 
-	if (dryrun) {
-		unsigned char hdr[200];
-		int hdrlen;
-		write_sha1_file_prepare(buffer, offset, tree_type, it->sha1,
-					hdr, &hdrlen);
-	}
+	if (dryrun)
+		hash_sha1_file(buffer, offset, tree_type, it->sha1);
 	else
 		write_sha1_file(buffer, offset, tree_type, it->sha1);
 	free(buffer);
diff --git a/cache.h b/cache.h
index 97debd0..c354701 100644
--- a/cache.h
+++ b/cache.h
@@ -245,13 +245,8 @@
 extern int sha1_object_info(const unsigned char *, char *, unsigned long *);
 extern void * unpack_sha1_file(void *map, unsigned long mapsize, char *type, unsigned long *size);
 extern void * read_sha1_file(const unsigned char *sha1, char *type, unsigned long *size);
+extern int hash_sha1_file(void *buf, unsigned long len, const char *type, unsigned char *sha1);
 extern int write_sha1_file(void *buf, unsigned long len, const char *type, unsigned char *return_sha1);
-extern char *write_sha1_file_prepare(void *buf,
-				     unsigned long len,
-				     const char *type,
-				     unsigned char *sha1,
-				     unsigned char *hdr,
-				     int *hdrlen);
 
 extern int check_sha1_signature(const unsigned char *sha1, void *buf, unsigned long size, const char *type);
 
diff --git a/commit.c b/commit.c
index 5b6e082..a6d543e 100644
--- a/commit.c
+++ b/commit.c
@@ -548,10 +548,13 @@
 
 	while (parent) {
 		struct commit *p = parent->item;
-		const char *hex = abbrev
-			? find_unique_abbrev(p->object.sha1, abbrev)
-			: sha1_to_hex(p->object.sha1);
-		const char *dots = (abbrev && strlen(hex) != 40) ? "..." : "";
+		const char *hex = NULL;
+		const char *dots;
+		if (abbrev)
+			hex = find_unique_abbrev(p->object.sha1, abbrev);
+		if (!hex)
+			hex = sha1_to_hex(p->object.sha1);
+		dots = (abbrev && strlen(hex) != 40) ?  "..." : "";
 		parent = parent->next;
 
 		offset += sprintf(buf + offset, " %s%s", hex, dots);
diff --git a/fetch-clone.c b/fetch-clone.c
index b632ca0..76b99af 100644
--- a/fetch-clone.c
+++ b/fetch-clone.c
@@ -115,12 +115,10 @@
 		die("%s: unable to fork off sideband demultiplexer", me);
 	if (!side_pid) {
 		/* subprocess */
-		char buf[LARGE_PACKET_MAX];
-
 		close(fd[0]);
 		if (xd[0] != xd[1])
 			close(xd[1]);
-		if (recv_sideband(me, xd[0], fd[1], 2, buf, sizeof(buf)))
+		if (recv_sideband(me, xd[0], fd[1], 2))
 			exit(1);
 		exit(0);
 	}
diff --git a/git-clone.sh b/git-clone.sh
index 3998c55..bf54a11 100755
--- a/git-clone.sh
+++ b/git-clone.sh
@@ -312,7 +312,7 @@
 		fi
 		;;
 	*)
-		cd "$D" && case "$upload_pack" in
+		case "$upload_pack" in
 		'') git-fetch-pack --all -k $quiet "$repo" ;;
 		*) git-fetch-pack --all -k $quiet "$upload_pack" "$repo" ;;
 		esac >"$GIT_DIR/CLONE_HEAD" || {
diff --git a/git-cvsserver.perl b/git-cvsserver.perl
index 2130d57..08ad831 100755
--- a/git-cvsserver.perl
+++ b/git-cvsserver.perl
@@ -275,7 +275,7 @@
     $state->{directory} = "" if ( $state->{directory} eq "." );
     $state->{directory} .= "/" if ( $state->{directory} =~ /\S/ );
 
-    if ( not defined($state->{prependdir}) and $state->{localdir} eq "." and $state->{path} =~ /\S/ )
+    if ( (not defined($state->{prependdir}) or $state->{prependdir} eq '') and $state->{localdir} eq "." and $state->{path} =~ /\S/ )
     {
         $log->info("Setting prepend to '$state->{path}'");
         $state->{prependdir} = $state->{path};
@@ -805,7 +805,14 @@
             $meta = $updater->getmeta($filename);
         }
 
-        next unless ( $meta->{revision} );
+	if ( ! defined $meta )
+	{
+	    $meta = {
+	        name => $filename,
+	        revision => 0,
+	        filehash => 'added'
+	    };
+	}
 
         my $oldmeta = $meta;
 
@@ -835,7 +842,7 @@
              and not exists ( $state->{opt}{C} ) )
         {
             $log->info("Tell the client the file is modified");
-            print "MT text U\n";
+            print "MT text M \n";
             print "MT fname $filename\n";
             print "MT newline\n";
             next;
@@ -855,15 +862,36 @@
 	    }
         }
         elsif ( not defined ( $state->{entries}{$filename}{modified_hash} )
-		or $state->{entries}{$filename}{modified_hash} eq $oldmeta->{filehash} )
+		or $state->{entries}{$filename}{modified_hash} eq $oldmeta->{filehash}
+		or $meta->{filehash} eq 'added' )
         {
-            $log->info("Updating '$filename'");
-            # normal update, just send the new revision (either U=Update, or A=Add, or R=Remove)
-            print "MT +updated\n";
-            print "MT text U\n";
-            print "MT fname $filename\n";
-            print "MT newline\n";
-            print "MT -updated\n";
+            # normal update, just send the new revision (either U=Update,
+            # or A=Add, or R=Remove)
+	    if ( defined($wrev) && $wrev < 0 )
+	    {
+	        $log->info("Tell the client the file is scheduled for removal");
+		print "MT text R \n";
+                print "MT fname $filename\n";
+                print "MT newline\n";
+		next;
+	    }
+	    elsif ( !defined($wrev) || $wrev == 0 )
+	    {
+	        $log->info("Tell the client the file will be added");
+		print "MT text A \n";
+                print "MT fname $filename\n";
+                print "MT newline\n";
+		next;
+
+	    }
+	    else {
+                $log->info("Updating '$filename' $wrev");
+                print "MT +updated\n";
+                print "MT text U \n";
+                print "MT fname $filename\n";
+                print "MT newline\n";
+		print "MT -updated\n";
+	    }
 
             my ( $filepart, $dirpart ) = filenamesplit($filename,1);
 
@@ -1709,6 +1737,17 @@
 
     return if ( scalar ( @{$state->{args}} ) > 1 );
 
+    my @gethead = @{$updater->gethead};
+
+    # push added files
+    foreach my $file (keys %{$state->{entries}}) {
+	if ( exists $state->{entries}{$file}{revision} &&
+		$state->{entries}{$file}{revision} == 0 )
+	{
+	    push @gethead, { name => $file, filehash => 'added' };
+	}
+    }
+
     if ( scalar(@{$state->{args}}) == 1 )
     {
         my $arg = $state->{args}[0];
@@ -1716,7 +1755,7 @@
 
         $log->info("Only one arg specified, checking for directory expansion on '$arg'");
 
-        foreach my $file ( @{$updater->gethead} )
+        foreach my $file ( @gethead )
         {
             next if ( $file->{filehash} eq "deleted" and not defined ( $state->{entries}{$file->{name}} ) );
             next unless ( $file->{name} =~ /^$arg\// or $file->{name} eq $arg  );
@@ -1729,7 +1768,7 @@
 
         $state->{args} = [];
 
-        foreach my $file ( @{$updater->gethead} )
+        foreach my $file ( @gethead )
         {
             next if ( $file->{filehash} eq "deleted" and not defined ( $state->{entries}{$file->{name}} ) );
             next unless ( $file->{name} =~ s/^$state->{prependdir}// );
diff --git a/git-fetch.sh b/git-fetch.sh
index f1522bd..79222fb 100755
--- a/git-fetch.sh
+++ b/git-fetch.sh
@@ -436,10 +436,10 @@
 
 # If the original head was empty (i.e. no "master" yet), or
 # if we were told not to worry, we do not have to check.
-case ",$update_head_ok,$orig_head," in
-*,, | t,* )
+case "$orig_head" in
+'')
 	;;
-*)
+?*)
 	curr_head=$(git-rev-parse --verify HEAD 2>/dev/null)
 	if test "$curr_head" != "$orig_head"
 	then
diff --git a/git-pull.sh b/git-pull.sh
index f380437..ed04e7d 100755
--- a/git-pull.sh
+++ b/git-pull.sh
@@ -58,7 +58,7 @@
 
 	echo >&2 "Warning: fetch updated the current branch head."
 	echo >&2 "Warning: fast forwarding your working tree from"
-	echo >&2 "Warning: $orig_head commit."
+	echo >&2 "Warning: commit $orig_head."
 	git-update-index --refresh 2>/dev/null
 	git-read-tree -u -m "$orig_head" "$curr_head" ||
 		die 'Cannot fast-forward your working tree.
diff --git a/git-revert.sh b/git-revert.sh
index 0784f74..4fd81b6 100755
--- a/git-revert.sh
+++ b/git-revert.sh
@@ -7,9 +7,11 @@
 case "$0" in
 *-revert* )
 	test -t 0 && edit=-e
+	replay=
 	me=revert
 	USAGE='[--edit | --no-edit] [-n] <commit-ish>' ;;
 *-cherry-pick* )
+	replay=t
 	edit=
 	me=cherry-pick
 	USAGE='[--edit] [-n] [-r] [-x] <commit-ish>'  ;;
@@ -18,7 +20,7 @@
 esac
 . git-sh-setup
 
-no_commit= replay=t
+no_commit=
 while case "$#" in 0) break ;; esac
 do
 	case "$1" in
diff --git a/git-shortlog.perl b/git-shortlog.perl
index 0b14f83..334fec7 100755
--- a/git-shortlog.perl
+++ b/git-shortlog.perl
@@ -1,6 +1,18 @@
 #!/usr/bin/perl -w
 
 use strict;
+use Getopt::Std;
+use File::Basename qw(basename dirname);
+
+our ($opt_h, $opt_n, $opt_s);
+getopts('hns');
+
+$opt_h && usage();
+
+sub usage {
+	print STDERR "Usage: ${\basename $0} [-h] [-n] [-s] < <log_data>\n";
+        exit(1);
+}
 
 my (%mailmap);
 my (%email);
@@ -38,16 +50,38 @@
 
 	uc($a) cmp uc($b);
 }
+sub by_nbentries($$) {
+	my ($a, $b) = @_;
+	my $a_entries = $map{$a};
+	my $b_entries = $map{$b};
+
+	@$b_entries - @$a_entries || by_name $a, $b;
+}
+
+my $sort_method = $opt_n ? \&by_nbentries : \&by_name;
+
+sub summary_output {
+	my ($obj, $num, $key);
+
+	foreach $key (sort $sort_method keys %map) {
+		$obj = $map{$key};
+		$num = @$obj;
+		printf "%s: %u\n", $key, $num;
+		$n_output += $num;
+	}
+}
 
 sub shortlog_output {
-	my ($obj, $key, $desc);
+	my ($obj, $num, $key, $desc);
 
-	foreach $key (sort by_name keys %map) {
+	foreach $key (sort $sort_method keys %map) {
+		$obj = $map{$key};
+		$num = @$obj;
+
 		# output author
-		printf "%s:\n", $key;
+		printf "%s (%u):\n", $key, $num;
 
 		# output author's 1-line summaries
-		$obj = $map{$key};
 		foreach $desc (reverse @$obj) {
 			print "  $desc\n";
 			$n_output++;
@@ -152,7 +186,7 @@
 
 &setup_mailmap;
 &changelog_input;
-&shortlog_output;
+$opt_s ? &summary_output : &shortlog_output;
 &finalize;
 exit(0);
 
diff --git a/git-svn.perl b/git-svn.perl
index f5c7d46..54d2356 100755
--- a/git-svn.perl
+++ b/git-svn.perl
@@ -40,8 +40,22 @@
 memoize('get_commit_time');
 
 my ($SVN_PATH, $SVN, $SVN_LOG, $_use_lib);
+
+sub nag_lib {
+	print STDERR <<EOF;
+! Please consider installing the SVN Perl libraries (version 1.1.0 or
+! newer).  You will generally get better performance and fewer bugs,
+! especially if you:
+! 1) have a case-insensitive filesystem
+! 2) replace symlinks with files (and vice-versa) in commits
+
+EOF
+}
+
 $_use_lib = 1 unless $ENV{GIT_SVN_NO_LIB};
 libsvn_load();
+nag_lib() unless $_use_lib;
+
 my $_optimize_commits = 1 unless $ENV{GIT_SVN_NO_OPTIMIZE_COMMITS};
 my $sha1 = qr/[a-f\d]{40}/;
 my $sha1_short = qr/[a-f\d]{4,40}/;
@@ -52,7 +66,7 @@
 	$_template, $_shared, $_no_default_regex, $_no_graft_copy,
 	$_limit, $_verbose, $_incremental, $_oneline, $_l_fmt, $_show_commit,
 	$_version, $_upgrade, $_authors, $_branch_all_refs, @_opt_m,
-	$_merge, $_strategy, $_dry_run, $_ignore_nodate);
+	$_merge, $_strategy, $_dry_run, $_ignore_nodate, $_non_recursive);
 my (@_branch_from, %tree_map, %users, %rusers, %equiv);
 my ($_svn_co_url_revs, $_svn_pg_peg_revs);
 my @repo_path_split_cache;
@@ -114,6 +128,7 @@
 			  'incremental' => \$_incremental,
 			  'oneline' => \$_oneline,
 			  'show-commit' => \$_show_commit,
+			  'non-recursive' => \$_non_recursive,
 			  'authors-file|A=s' => \$_authors,
 			} ],
 	'commit-diff' => [ \&commit_diff, 'Commit a diff between two trees',
@@ -168,11 +183,11 @@
 
 	foreach (sort keys %cmd) {
 		next if $cmd && $cmd ne $_;
-		print $fd '  ',pack('A13',$_),$cmd{$_}->[1],"\n";
+		print $fd '  ',pack('A17',$_),$cmd{$_}->[1],"\n";
 		foreach (keys %{$cmd{$_}->[2]}) {
 			# prints out arguments as they should be passed:
 			my $x = s#[:=]s$## ? '<arg>' : s#[:=]i$## ? '<num>' : '';
-			print $fd ' ' x 17, join(', ', map { length $_ > 1 ?
+			print $fd ' ' x 21, join(', ', map { length $_ > 1 ?
 							"--$_" : "-$_" }
 						split /\|/,$_)," $x\n";
 		}
@@ -521,7 +536,7 @@
 			$SVN = libsvn_connect($repo);
 			my $ed = SVN::Git::Editor->new(
 					{	r => $r_last,
-						ra => $SVN,
+						ra => $SVN_LOG,
 						c => $c,
 						svn_path => $SVN_PATH
 					},
@@ -682,12 +697,17 @@
 		}
 		$_trunk = $url . $_trunk;
 	}
+	my $ch_id;
 	if ($GIT_SVN eq 'git-svn') {
-		print "GIT_SVN_ID set to 'trunk' for $_trunk\n";
+		$ch_id = 1;
 		$GIT_SVN = $ENV{GIT_SVN_ID} = 'trunk';
 	}
 	init_vars();
-	init($_trunk);
+	unless (-d $GIT_SVN_DIR) {
+		print "GIT_SVN_ID set to 'trunk' for $_trunk\n" if $ch_id;
+		init($_trunk);
+		sys('git-repo-config', 'svn.trunk', $_trunk);
+	}
 	complete_url_ls_init($url, $_branches, '--branches/-b', '');
 	complete_url_ls_init($url, $_tags, '--tags/-t', 'tags/');
 }
@@ -747,13 +767,18 @@
 			# ignore
 		} elsif (/^:\d{6} \d{6} $sha1_short/o) {
 			push @{$c->{raw}}, $_;
+		} elsif (/^[ACRMDT]\t/) {
+			# we could add $SVN_PATH here, but that requires
+			# remote access at the moment (repo_path_split)...
+			s#^([ACRMDT])\t#   $1 #;
+			push @{$c->{changed}}, $_;
 		} elsif (/^diff /) {
 			$d = 1;
 			push @{$c->{diff}}, $_;
 		} elsif ($d) {
 			push @{$c->{diff}}, $_;
 		} elsif (/^    (git-svn-id:.+)$/) {
-			(undef, $c->{r}, undef) = extract_metadata($1);
+			($c->{url}, $c->{r}, undef) = extract_metadata($1);
 		} elsif (s/^    //) {
 			push @{$c->{l}}, $_;
 		}
@@ -807,7 +832,7 @@
 	$SVN ||= libsvn_connect($repo);
 	my @lock = $SVN::Core::VERSION ge '1.2.0' ? (undef, 0) : ();
 	my $ed = SVN::Git::Editor->new({	r => $SVN->get_latest_revnum,
-						ra => $SVN, c => $tb,
+						ra => $SVN_LOG, c => $tb,
 						svn_path => $SVN_PATH
 					},
 				$SVN->get_commit_editor($_message,
@@ -845,7 +870,8 @@
 	my ($r_min, $r_max) = @_;
 	my @cmd = (qw/git-log --abbrev-commit --pretty=raw
 			--default/, "refs/remotes/$GIT_SVN");
-	push @cmd, '--summary' if $_verbose;
+	push @cmd, '-r' unless $_non_recursive;
+	push @cmd, qw/--raw --name-status/ if $_verbose;
 	return @cmd unless defined $r_max;
 	if ($r_max == $r_min) {
 		push @cmd, '--max-count=1';
@@ -856,7 +882,7 @@
 		my ($c_min, $c_max);
 		$c_max = revdb_get($REVDB, $r_max);
 		$c_min = revdb_get($REVDB, $r_min);
-		if ($c_min && $c_max) {
+		if (defined $c_min && defined $c_max) {
 			if ($r_max > $r_max) {
 				push @cmd, "$c_min..$c_max";
 			} else {
@@ -937,16 +963,21 @@
 				print STDERR "W: Unrecognized URL: $u\n";
 				die "This should never happen\n";
 			}
+			# don't try to init already existing refs
 			my $id = $pfx.$1;
-			print "init $u => $id\n";
 			$GIT_SVN = $ENV{GIT_SVN_ID} = $id;
 			init_vars();
-			init($u);
+			unless (-d $GIT_SVN_DIR) {
+				print "init $u => $id\n";
+				init($u);
+			}
 		}
 		exit 0;
 	}
 	waitpid $pid, 0;
 	croak $? if $?;
+	my ($n) = ($switch =~ /^--(\w+)/);
+	sys('git-repo-config', "svn.$n", $var);
 }
 
 sub common_prefix {
@@ -2551,6 +2582,12 @@
 	}
 }
 
+sub show_commit_changed_paths {
+	my ($c) = @_;
+	return unless $c->{changed};
+	print "Changed paths:\n", @{$c->{changed}};
+}
+
 sub show_commit_normal {
 	my ($c) = @_;
 	print '-' x72, "\nr$c->{r} | ";
@@ -2560,7 +2597,8 @@
 	my $nr_line = 0;
 
 	if (my $l = $c->{l}) {
-		while ($l->[$#$l] eq "\n" && $l->[($#$l - 1)] eq "\n") {
+		while ($l->[$#$l] eq "\n" && $#$l > 0
+		                          && $l->[($#$l - 1)] eq "\n") {
 			pop @$l;
 		}
 		$nr_line = scalar @$l;
@@ -2572,11 +2610,15 @@
 			} else {
 				$nr_line .= ' lines';
 			}
-			print $nr_line, "\n\n";
+			print $nr_line, "\n";
+			show_commit_changed_paths($c);
+			print "\n";
 			print $_ foreach @$l;
 		}
 	} else {
-		print "1 line\n\n";
+		print "1 line\n";
+		show_commit_changed_paths($c);
+		print "\n";
 
 	}
 	foreach my $x (qw/raw diff/) {
@@ -3312,9 +3354,11 @@
 	seek $fh, 0, 0 or croak $!;
 
 	my $exp = $md5->hexdigest;
-	my $atd = $self->apply_textdelta($fbat, undef, $self->{pool});
-	my $got = SVN::TxDelta::send_stream($fh, @$atd, $self->{pool});
+	my $pool = SVN::Pool->new;
+	my $atd = $self->apply_textdelta($fbat, undef, $pool);
+	my $got = SVN::TxDelta::send_stream($fh, @$atd, $pool);
 	die "Checksum mismatch\nexpected: $exp\ngot: $got\n" if ($got ne $exp);
+	$pool->clear;
 
 	close $fh or croak $!;
 }
diff --git a/git.c b/git.c
index d7103a4..e089b53 100644
--- a/git.c
+++ b/git.c
@@ -226,7 +226,7 @@
 		{ "check-ref-format", cmd_check_ref_format },
 		{ "commit-tree", cmd_commit_tree, RUN_SETUP },
 		{ "count-objects", cmd_count_objects, RUN_SETUP },
-		{ "diff", cmd_diff, RUN_SETUP },
+		{ "diff", cmd_diff, RUN_SETUP | USE_PAGER },
 		{ "diff-files", cmd_diff_files, RUN_SETUP },
 		{ "diff-index", cmd_diff_index, RUN_SETUP },
 		{ "diff-stages", cmd_diff_stages, RUN_SETUP },
diff --git a/git.spec.in b/git.spec.in
index 6d90034..9b1217a 100644
--- a/git.spec.in
+++ b/git.spec.in
@@ -97,7 +97,7 @@
 find $RPM_BUILD_ROOT -type f -name perllocal.pod -exec rm -f {} ';'
 
 (find $RPM_BUILD_ROOT%{_bindir} -type f | grep -vE "arch|svn|cvs|email|gitk" | sed -e s@^$RPM_BUILD_ROOT@@)               > bin-man-doc-files
-(find $RPM_BUILD_ROOT%{perl_vendorarch} -type f | sed -e s@^$RPM_BUILD_ROOT@@) >> perl-files
+(find $RPM_BUILD_ROOT%{perl_vendorlib} -type f | sed -e s@^$RPM_BUILD_ROOT@@) >> perl-files
 %if %{!?_without_docs:1}0
 (find $RPM_BUILD_ROOT%{_mandir} $RPM_BUILD_ROOT/Documentation -type f | grep -vE "arch|svn|git-cvs|email|gitk" | sed -e s@^$RPM_BUILD_ROOT@@ -e 's/$/*/' ) >> bin-man-doc-files
 %else
diff --git a/merge-recursive.c b/merge-recursive.c
index 611cd95..2ba43ae 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -1235,13 +1235,10 @@
 	if (merged_common_ancestors == NULL) {
 		/* if there is no common ancestor, make an empty tree */
 		struct tree *tree = xcalloc(1, sizeof(struct tree));
-		unsigned char hdr[40];
-		int hdrlen;
 
 		tree->object.parsed = 1;
 		tree->object.type = OBJ_TREE;
-		write_sha1_file_prepare(NULL, 0, tree_type, tree->object.sha1,
-					hdr, &hdrlen);
+		hash_sha1_file(NULL, 0, tree_type, tree->object.sha1);
 		merged_common_ancestors = make_virtual_commit(tree, "ancestor");
 	}
 
diff --git a/sha1_file.c b/sha1_file.c
index 27b1ebb..d111be7 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -1347,12 +1347,9 @@
 	}
 }
 
-char *write_sha1_file_prepare(void *buf,
-			      unsigned long len,
-			      const char *type,
-			      unsigned char *sha1,
-			      unsigned char *hdr,
-			      int *hdrlen)
+static char *write_sha1_file_prepare(void *buf, unsigned long len,
+                                     const char *type, unsigned char *sha1,
+                                     unsigned char *hdr, int *hdrlen)
 {
 	SHA_CTX c;
 
@@ -1501,6 +1498,15 @@
 	stream->avail_out -= hdr;
 }
 
+int hash_sha1_file(void *buf, unsigned long len, const char *type,
+                   unsigned char *sha1)
+{
+	unsigned char hdr[50];
+	int hdrlen;
+	write_sha1_file_prepare(buf, len, type, sha1, hdr, &hdrlen);
+	return 0;
+}
+
 int write_sha1_file(void *buf, unsigned long len, const char *type, unsigned char *returnsha1)
 {
 	int size;
@@ -1784,8 +1790,6 @@
 	unsigned long size = 4096;
 	char *buf = xmalloc(size);
 	int ret;
-	unsigned char hdr[50];
-	int hdrlen;
 
 	if (read_pipe(fd, &buf, &size)) {
 		free(buf);
@@ -1796,10 +1800,8 @@
 		type = blob_type;
 	if (write_object)
 		ret = write_sha1_file(buf, size, type, sha1);
-	else {
-		write_sha1_file_prepare(buf, size, type, sha1, hdr, &hdrlen);
-		ret = 0;
-	}
+	else
+		ret = hash_sha1_file(buf, size, type, sha1);
 	free(buf);
 	return ret;
 }
@@ -1809,8 +1811,6 @@
 	unsigned long size = st->st_size;
 	void *buf;
 	int ret;
-	unsigned char hdr[50];
-	int hdrlen;
 
 	buf = "";
 	if (size)
@@ -1823,10 +1823,8 @@
 		type = blob_type;
 	if (write_object)
 		ret = write_sha1_file(buf, size, type, sha1);
-	else {
-		write_sha1_file_prepare(buf, size, type, sha1, hdr, &hdrlen);
-		ret = 0;
-	}
+	else
+		ret = hash_sha1_file(buf, size, type, sha1);
 	if (size)
 		munmap(buf, size);
 	return ret;
@@ -1855,12 +1853,9 @@
 			return error("readlink(\"%s\"): %s", path,
 			             errstr);
 		}
-		if (!write_object) {
-			unsigned char hdr[50];
-			int hdrlen;
-			write_sha1_file_prepare(target, st->st_size, blob_type,
-						sha1, hdr, &hdrlen);
-		} else if (write_sha1_file(target, st->st_size, blob_type, sha1))
+		if (!write_object)
+			hash_sha1_file(target, st->st_size, blob_type, sha1);
+		else if (write_sha1_file(target, st->st_size, blob_type, sha1))
 			return error("%s: failed to insert into database",
 				     path);
 		free(target);
diff --git a/sideband.c b/sideband.c
index 1b14ff8..277fa3c 100644
--- a/sideband.c
+++ b/sideband.c
@@ -11,10 +11,13 @@
  * stream, aka "verbose").  A message over band #3 is a signal that
  * the remote died unexpectedly.  A flush() concludes the stream.
  */
-int recv_sideband(const char *me, int in_stream, int out, int err, char *buf, int bufsz)
+int recv_sideband(const char *me, int in_stream, int out, int err)
 {
+	char buf[7 + LARGE_PACKET_MAX + 1];
+	strcpy(buf, "remote:");
 	while (1) {
-		int len = packet_read_line(in_stream, buf, bufsz);
+		int band, len;
+		len	= packet_read_line(in_stream, buf+7, LARGE_PACKET_MAX);
 		if (len == 0)
 			break;
 		if (len < 1) {
@@ -22,25 +25,26 @@
 			safe_write(err, buf, len);
 			return SIDEBAND_PROTOCOL_ERROR;
 		}
+		band = buf[7] & 0xff;
 		len--;
-		switch (buf[0] & 0xFF) {
+		switch (band) {
 		case 3:
-			safe_write(err, "remote: ", 8);
-			safe_write(err, buf+1, len);
-			safe_write(err, "\n", 1);
+			buf[7] = ' ';
+			buf[8+len] = '\n';
+			safe_write(err, buf, 8+len+1);
 			return SIDEBAND_REMOTE_ERROR;
 		case 2:
-			safe_write(err, "remote: ", 8);
-			safe_write(err, buf+1, len);
+			buf[7] = ' ';
+			safe_write(err, buf, 8+len);
 			continue;
 		case 1:
-			safe_write(out, buf+1, len);
+			safe_write(out, buf+8, len);
 			continue;
 		default:
-			len = sprintf(buf + 1,
+			len = sprintf(buf,
 				      "%s: protocol error: bad band #%d\n",
-				      me, buf[0] & 0xFF);
-			safe_write(err, buf+1, len);
+				      me, band);
+			safe_write(err, buf, len);
 			return SIDEBAND_PROTOCOL_ERROR;
 		}
 	}
diff --git a/sideband.h b/sideband.h
index 4872106..a84b691 100644
--- a/sideband.h
+++ b/sideband.h
@@ -7,7 +7,7 @@
 #define DEFAULT_PACKET_MAX 1000
 #define LARGE_PACKET_MAX 65520
 
-int recv_sideband(const char *me, int in_stream, int out, int err, char *, int);
+int recv_sideband(const char *me, int in_stream, int out, int err);
 ssize_t send_sideband(int fd, int band, const char *data, ssize_t sz, int packet_max);
 
 #endif
diff --git a/t/t4015-diff-whitespace.sh b/t/t4015-diff-whitespace.sh
new file mode 100755
index 0000000..1bc5b7a
--- /dev/null
+++ b/t/t4015-diff-whitespace.sh
@@ -0,0 +1,122 @@
+#!/bin/sh
+#
+# Copyright (c) 2006 Johannes E. Schindelin
+#
+
+test_description='Test special whitespace in diff engine.
+
+'
+. ./test-lib.sh
+. ../diff-lib.sh
+
+# Ray Lehtiniemi's example
+
+cat << EOF > x
+do {
+   nothing;
+} while (0);
+EOF
+
+git-update-index --add x
+
+cat << EOF > x
+do
+{
+   nothing;
+}
+while (0);
+EOF
+
+cat << EOF > expect
+diff --git a/x b/x
+index adf3937..6edc172 100644
+--- a/x
++++ b/x
+@@ -1,3 +1,5 @@
+-do {
++do
++{
+    nothing;
+-} while (0);
++}
++while (0);
+EOF
+
+git-diff > out
+test_expect_success "Ray's example without options" 'diff -u expect out'
+
+git-diff -w > out
+test_expect_success "Ray's example with -w" 'diff -u expect out'
+
+git-diff -b > out
+test_expect_success "Ray's example with -b" 'diff -u expect out'
+
+tr 'Q' '\015' << EOF > x
+whitespace at beginning
+whitespace change
+whitespace in the middle
+whitespace at end
+unchanged line
+CR at endQ
+EOF
+
+git-update-index x
+
+cat << EOF > x
+	whitespace at beginning
+whitespace 	 change
+white space in the middle
+whitespace at end  
+unchanged line
+CR at end
+EOF
+
+tr 'Q' '\015' << EOF > expect
+diff --git a/x b/x
+index d99af23..8b32fb5 100644
+--- a/x
++++ b/x
+@@ -1,6 +1,6 @@
+-whitespace at beginning
+-whitespace change
+-whitespace in the middle
+-whitespace at end
++	whitespace at beginning
++whitespace 	 change
++white space in the middle
++whitespace at end  
+ unchanged line
+-CR at endQ
++CR at end
+EOF
+git-diff > out
+test_expect_success 'another test, without options' 'diff -u expect out'
+
+cat << EOF > expect
+diff --git a/x b/x
+index d99af23..8b32fb5 100644
+EOF
+git-diff -w > out
+test_expect_success 'another test, with -w' 'diff -u expect out'
+
+tr 'Q' '\015' << EOF > expect
+diff --git a/x b/x
+index d99af23..8b32fb5 100644
+--- a/x
++++ b/x
+@@ -1,6 +1,6 @@
+-whitespace at beginning
++	whitespace at beginning
+ whitespace change
+-whitespace in the middle
+-whitespace at end
++white space in the middle
++whitespace at end  
+ unchanged line
+-CR at endQ
++CR at end
+EOF
+git-diff -b > out
+test_expect_success 'another test, with -b' 'diff -u expect out'
+
+test_done
diff --git a/t/t5600-clone-fail-cleanup.sh b/t/t5600-clone-fail-cleanup.sh
index 0c6a363..041be04 100755
--- a/t/t5600-clone-fail-cleanup.sh
+++ b/t/t5600-clone-fail-cleanup.sh
@@ -25,6 +25,12 @@
 # clone doesn't like it if there is no HEAD. Is that a bug?
 (cd foo && touch file && git add file && git commit -m 'add file' >/dev/null 2>&1)
 
+# source repository given to git-clone should be relative to the
+# current path not to the target dir
+test_expect_failure \
+    'clone of non-existent (relative to $PWD) source should fail' \
+    'git-clone ../foo baz'
+
 test_expect_success \
     'clone should work now that source exists' \
     'git-clone foo bar'
diff --git a/trace.c b/trace.c
index f9efc91..495e5ed 100644
--- a/trace.c
+++ b/trace.c
@@ -55,7 +55,8 @@
 {
 	char *trace = getenv("GIT_TRACE");
 
-	if (!trace || !strcmp(trace, "0") || !strcasecmp(trace, "false"))
+	if (!trace || !strcmp(trace, "") ||
+	    !strcmp(trace, "0") || !strcasecmp(trace, "false"))
 		return 0;
 	if (!strcmp(trace, "1") || !strcasecmp(trace, "true"))
 		return STDERR_FILENO;
diff --git a/xdiff/xutils.c b/xdiff/xutils.c
index f7bdd39..9e4bb47 100644
--- a/xdiff/xutils.c
+++ b/xdiff/xutils.c
@@ -191,36 +191,30 @@
 	int i1, i2;
 
 	if (flags & XDF_IGNORE_WHITESPACE) {
-		for (i1 = i2 = 0; i1 < s1 && i2 < s2; i1++, i2++) {
+		for (i1 = i2 = 0; i1 < s1 && i2 < s2; ) {
 			if (isspace(l1[i1]))
 				while (isspace(l1[i1]) && i1 < s1)
 					i1++;
-			else if (isspace(l2[i2]))
+			if (isspace(l2[i2]))
 				while (isspace(l2[i2]) && i2 < s2)
 					i2++;
-			else if (l1[i1] != l2[i2])
-				return l2[i2] - l1[i1];
+			if (i1 < s1 && i2 < s2 && l1[i1++] != l2[i2++])
+				return 0;
 		}
-		if (i1 >= s1)
-			return 1;
-		else if (i2 >= s2)
-			return -1;
+		return (i1 >= s1 && i2 >= s2);
 	} else if (flags & XDF_IGNORE_WHITESPACE_CHANGE) {
-		for (i1 = i2 = 0; i1 < s1 && i2 < s2; i1++, i2++) {
+		for (i1 = i2 = 0; i1 < s1 && i2 < s2; ) {
 			if (isspace(l1[i1])) {
 				if (!isspace(l2[i2]))
-					return -1;
+					return 0;
 				while (isspace(l1[i1]) && i1 < s1)
 					i1++;
 				while (isspace(l2[i2]) && i2 < s2)
 					i2++;
-			} else if (l1[i1] != l2[i2])
-				return l2[i2] - l1[i1];
+			} else if (l1[i1++] != l2[i2++])
+				return 0;
 		}
-		if (i1 >= s1)
-			return 1;
-		else if (i2 >= s2)
-			return -1;
+		return (i1 >= s1 && i2 >= s2);
 	} else
 		return s1 == s2 && !memcmp(l1, l2, s1);
 
@@ -233,7 +227,8 @@
 
 	for (; ptr < top && *ptr != '\n'; ptr++) {
 		if (isspace(*ptr) && (flags & XDF_WHITESPACE_FLAGS)) {
-			while (ptr < top && isspace(*ptr) && ptr[1] != '\n')
+			while (ptr + 1 < top && isspace(ptr[1])
+					&& ptr[1] != '\n')
 				ptr++;
 			if (flags & XDF_IGNORE_WHITESPACE_CHANGE) {
 				ha += (ha << 5);