blame: treat HEAD as the parent of not-committed-yet

When blaming a file with uncommitted changes, it is annoying that it is
not possible to jump to the HEAD version from an uncommitted line.  It
turns out that the commit already has HEAD as its parent, so we simply
need to relax the check in check_blame_commit() to allow the parent
request to make it to blame_go_forward().

Signed-off-by: John Keeping <john@keeping.me.uk>
Merge pull request #295 from johnkeeping/blame-head-parent-of-not-committed

blame: treat HEAD as the parent of not-committed-yet
Use string_ncopy when copying ref names

Change code that updates the internal env/state variables to use
string_ncopy instead of string_copy_rev, since the latter copies atmost
40 characters. Test that both branches and tags with long names can be
succesfully checked out.

Fixes #290
Clearify that Tig always uses author date

This changes two 'commit date' to 'author date'.

References #294
Fix spurious failure in main/default-test

Calling `:set vertical-split = no` will cause a reload so move the
setting from the steps to the tigrc.
Fix readline support

The watch code introduced a bug where stdin was marked with nodelay()
when reading multibyte key input. This changed get_input() to use
wtimeout() instead of nodelay(). Unfortunately, as a defensive measure
an extra nodelay() was added before the loop that reads the remaining
multibyte stream, which in turn broke readline support.
Allow scripts to go through the readline backend

As a stop gap measure, the readline backend was by-passed during script
execution. This changes the prompt code to allow scripts to interact
with the readline code by decoding the symbolic keys and serving them to
readline as bytes.

Since the script executing is mainly targeting towards the test suite
this will make it possible to test the readline backend. However, it
does cause script behavior to act differently based on whether readline
is supported or not.
Fix '/' to redo previous search when readline support is enabled

The readline version of read_prompt() did not act the same way as the
non-readline version. Add check to ensure that NULL is returned instead
of the empty string.

Fixes #302
Fix readline prompt to correctly handle UTF-8 characters
Make blame ID colors predictable across reloads

Change draw_id() to use a hash function to generate a color index based
on the ID characters so that the same commit ID is always assigned the
same color across reloads. Previously the memory location of the commit
struct's ID member was used to derive the color index.

To further improve the ID coloring, increase the palette to 14 colors by
adding "boldified" versions of the base ASCII colors.
Add test for displayment of index changes in the main view
prompt: fix memleak of empty strings

The readline-enabled version of read_prompt() was memleaking 1-byte when
readline() returned an empty string. Free it first to fix it.

Refs #302
Signed-off-by: Vivien Didelot <vivien.didelot@savoirfairelinux.com>
Fix test result summary to only count succeeded and failed assertions

The .test-result files also contains the diff and for failures all diff
lines were counted. Now only lines containing "[OK]" or "[FAIL]" are
counted.
Add test option to start tig inside a debugger
Move repo setup method from main/show-changes-test to libgit
Reorder test directory setup and TEST_OPTS parsing
Add test option to show tig trace information
Partly restore old refresh behavior

This ensures that the current view is refreshed after returning from an
external command when `refresh-mode` is set to `after-command`. That was
what Tig used to do before the option was introduced. It special cases
the 'after-command' event to force a refresh in the current view.

The fix is tested to work in both the main and status view.

Fixes #289
Unify the color palette used for graph and ID drawing

Graph rendering will now use up to 14 colors if the terminal supports
boldified (highlighted) colors.

References #305
Add workaround for system dependent date comparison

The date injection used in the tests for the main view's "show-changes"
feature fails on some systems either because the TZ environment variable
does not work as expected or because the time to execute the test causes
the generated timestamp to be off (Cygwin). Fix both issues by simply
replacing the dates with a dummy string.

As reported by Ramsay Jones, the recent commit bac9dcef ("Add test for
displayment of index changes in the main view", 15-06-2014) adds a test
that fails on Linux (Mint 17).

The failures (5 failed assertions in the test/main/show-changes-test
test), are all due to the test expecting the timestamp on Un/staged
changes to be in UTC but they are actually in BST (DST for my timezone).

If I change the test, like so:

    $ git diff
    diff --git a/test/main/show-changes-test b/test/main/show-changes-test
    index df3c318..c337def 100755
    --- a/test/main/show-changes-test
    +++ b/test/main/show-changes-test
    @@ -59,7 +59,7 @@ in_work_dir prepare_git_repo

     test_tig

    -YYY_MM_DD_HH_MM="$(date +"%Y-%m-%d %H:%M")"
    +YYY_MM_DD_HH_MM="$(unset TZ; date +"%Y-%m-%d %H:%M")"

     assert_equals 'main-with-unstaged.screen' <<EOF
     $YYY_MM_DD_HH_MM Unknown    o Unstaged changes
    $

... then the test passes. This is not the fix, of course, it just helps
diagnose the problem. Note that if I run tig thus:

    $ TZ=UTC ./src/tig

... with an unstaged change, then the timestamp still shows as BST.
So, the handling of the tz data in main_add_changes_commit() seems
to be off somehow. (Isn't use of the tz parameter in gettimeofday()
discouraged because it's not portable/reliable?).

I should note that (on a different laptop) on 64-bit cygwin, the test
runs just fine - most of the time! :-P  Occasionally, it will fail with
the timestamp differing by one minute ...