Fix assertion failure if timeline switch happened at page boundary.

If the master and standby diverged at a page boundary, we would start the
scan for the last checkpoint record at the page boundary. XLogReadRecord
is not cool with that; it expects there to be a valid WAL record at the
start point. To fix, skip over the page header.
Refactor test suite.

This makes it easier to write separate test cases, instead of doing
everything as one test case.

The pg_rewind.sh script has been split into several parts. Initialization
happens in config_test.sh, and actually running the test in run_test.sh.
The test case -specific logic is in "basictest.sql", which defines four
functions describing the things to do in various steps in the test, and
calls config_test.sh and run_test.sh

Create the log files with predictable names. I don't think there's much
value in keeping old logs - we don't keep the regression.diffs file either,
for example.
Handle creation/removal of directory trees correctly.

If there is a directory with files or subdirectories in it in the source
that are not present in the destination, we will remove them all. But we
must be careful to remove the contents of the directory before the directory
itself, otherwise rmdir() failes with ENOTEMPTY.

Also add a test case for that.

I believe this fixes issue #34 reported by Thom Brown, where a subdir in
pg_replslot was present in source but not destination.
Plug memory leak.

pg_rewind only runs once so minor leaks don't generally matter. But this
runs once for file, so it's probably worth plugging.
Flush output after printing the filemap.

Makes the log nicer to read when stdout and stderr outputs are not mixed
up so badly.
Fix rewinding over DROP DATABSE.

The PG_VERSION file was ignored in source and destination, and hence not
deleted. Removing the directory then failed, because the PG_VERSION file
was still in it.

Also add a regression test.
Use REGRESS_OPTS instead of EXTRA_REGRESS_OPTS.

The latter doesn't seem to work on REL9_3_STABLE. I'm not sure what the
distinction is, but REGRESS_OPTS seems to work so let's use that.
Fix removal of subdirectories.

The previous commit to fix directory tree removal didn't take into account
the case of nested subdirs, ie. "dir/subdir/file", where the whole tree
is removed.

Pointed out by Samrat Revagade.
Fix parsing of XLOG record caused by B-tree race condition fix

Commit efada2b of PostgreSQL is causing errors in compilation due to
XLOG record modifications that became necessary to fix a race condition
for a B-tree page deletion.

This patch simply takes into account the record modifications and parses
them accordingly.
Add support for tablespaces.

The gist of this is to create/remove symbolic links. In libpq-mode,
use pg_tablespace_location() to query the target of a tablespace symlink.

Based on patch by Samrat Revagade
Fix handling of tables larger than 1GB.

The regular expression to detect relation data files only caught the first
1GB segment of a file. Other segments were always copied as is.

Also add an assertion that a block-level change is not applied to a file
that we earlier decided to not be a relation data file.
Fix WAL-parsing for recent upstream changes in WAL record formats.
Fix some typos in regress test suite configuration
Remove dependency of pg_rewind binary to local folder in tests

Instead we rely on bindir that can be set by PGXS properly. This makes
the code more simple and more portable in environments that may run the
tests without directly the source code present.