Introduce the stash view

This patch adds a new "stash" view, bound to the 'y' key.
This view displays the list of stashes. Pressing Enter on one of them
displays the corresponding change in a split view.

Running 'tig stash' opens directly the stash view.

A new %(stash) variable is added for bindings and commands.

A built-in command to pop the current stash is bound to 'P' in this
view. Other bindings may be added in the ~/.tigrc file, for instance:

    bind stash D !?git stash drop %(stash)
    bind stash A !?git stash apply %(stash)
    bind status S !?git stash save --keep-index %(prompt)

Fixes #169
Closes #174

Signed-off-by: Vivien Didelot <vivien.didelot@savoirfairelinux.com>
Signed-off-by: Jonas Fonseca <fonseca@diku.dk>
Prepend the path to the repository root when editing a diff file

Fixes #165
Scroll diff with arrow keys in log view

This commit introduces the VIEW_NO_PARENT_NAV flag and adds it to the
log view. This allows the scrolling commands to fall through from the
pager to the diff when the diff is viewed in the log mode.

Signed-Off-By: Kumar Appaiah <a.kumar@alumni.iitm.ac.in>
Signed-off-by: Jonas Fonseca <fonseca@diku.dk>
Crop text when title-overflow is enabled

Limit the length of the title text if less columns are available when
drawing the title. This fixes a glitch introduced with the original
title-overflow patch, where the title text would wrap to the next line
when rendered.

Improve the rendering when only part of the "non-overflowing" title text
is displayed by showing the '~' character to indicate that the text was
cropped.

Fixes #166
Only set LINES and COLUMNS environment variables for external commands

Setting the LINES/COLUMNS environment variables to a constant number
breaks ncurses' getmaxyx() logic, so dynamic resizing doesn't work as
pointed out by Marcel Partap in a comment to the fix for issue #151
(https://github.com/jonas/tig/commit/f0ad1f74#commitcomment-3528715).

As a work-around, only set LINES/COLUMNS when forking Git processes. This
way diff stats will still use the whole terminal width and resizing works
as intended.

Fixes #109
iconv: Ignore unrepresentable characters when transliterating

Certain characters where causing iconv() to fail, which resulted in
buggy rendering. By adding "//IGNORE" to the already existing
"//TRANSLIT" flag unrepresentable characters are automatically removed
from the resulting output.

    > echo "Nguyễn Thái Ngọc Duy" | iconv -f UTF-8 -t ASCII//TRANSLIT
    Nguy
    iconv: (stdin):1:4: cannot convert
    > echo "Nguyễn Thái Ngọc Duy" | iconv -f UTF-8 -t ASCII//TRANSLIT//IGNORE
    Nguyn Th'ai Ngc Duy
iconv: Move draw_chars encoding code to IO module
iconv: Convert characters before trimming text before rendering

By first trimming and then transliterating, characters which need two
characters to represent would cause the rendered text to get out of
alignment. An example can be seen by running:

	$ LANG=C ./tig 2324d6120c5de58f63b32b876bd33e99d7375dbb

Fix the misalignment by reversing the operations so that text is trimmed
after it has been transliterated.

Fixes #86
iconv: Remove unnecessary length argument to encoding_iconv
iconv: Consolidate convert methods into one single backend
stash: Use main view infrastructure for the stash view

Change the output to use "--pretty=raw", which is compatible with the
main view. This simplifies the parsing of the 'stash{X}' ID by using the
emitted 'Reflog' line and displays the stash date for free.

The reference to the stash is stored as the commit->id for easy access
when updating the status line (view->ref).

Fixes #169
stash: Refactor ID drawing method

Simpify the main method (draw_id) and add custom method for more
advanced requirements.
stash: Ensure that the whole stash@{_} text is shown

Fixes #169
stash: Highlight the diffstat of combined diffs

Fixes #169
Add utility method to help copy commit ID to revision buffer
Fix %(commit) assignment in the diff view

Since commit 0c278556e52b9b78fde9f089cab755a6366d9ce6, the %(commit)
variable is badly overwritten with part of the commit title when we
highlight this line. For instance, browsing a commit message like this:

    linux: add support for [...]

    This text explains the patch
    [...]

will result in the %(commit) variable to be "ux:".
(the offset corresponds to strlen("commit ") which is LINE_COMMIT).

This patch reworks commit 0c278556e52b9b78fde9f089cab755a6366d9ce6:
"Fix regression causing incorect coloring of the commit title", to
set the line type to LINE_DEFAULT instead of LINE_COMMIT.

Closes #179

Signed-off-by: Vivien Didelot <vivien.didelot@savoirfairelinux.com>
Signed-off-by: Jonas Fonseca <fonseca@diku.dk>
Add example showing how to show display submodule log in diffs

Proposed by Ingo Oeser.
Fixes #171
Provide mkstemps() work-around for platforms lacking it

The function mkstemps() isn't available in all libc implementations. In
glibc it first became available in 2.11. This is likely true of many
non-LINUX platforms as well.

The work-around is based on mkstemps() implementation from libiberty and
is kept inside its own source file under a new compat/ subdirectory. The
work-around can be enabled via configure (and config.make.in), via the
config.make file by adding the line 'NO_MKSTEMPS=y' or when calling make
by adding 'NO_MKSTEMPS=y' to its parameter list.

This fixes breakage that was introduced with a0fdac29 "Create temporary
file with name as suffix."

Fixes #152
Closes #175

Signed-off-by: Drew Northup <n1xim.email@gmail.com>

Original patch by Drew reworked to make it easier to enable the
work-around when not using configure. Also, switched mkstemps()
implementation to that of libiberty instead of the adapted version from
Git.

Signed-off-by: Jonas Fonseca <fonseca@diku.dk>
Provide proper work-around for missing setenv()

This patch removes the set_environment_variable() function that was
introduced by 46ef80d for compatibility reason, for platforms lacking
the setenv() function.

It borrows the setenv.c code from the libiberty. The work-around can be
enabled via configure (and config.make.in), via the config.make file by
adding the line 'NO_SETENV=y' or when calling make by adding
'NO_SETENV=y' to its parameter list.

Based on Drew's work for compat and mkstemps.c.

References: GH #156 #152
Closes #180

Signed-off-by: Vivien Didelot <vivien.didelot@savoirfairelinux.com>
Signed-off-by: Jonas Fonseca <fonseca@diku.dk>
Add log_select function to find commit from context in log view

This commit introduces and uses the log_select function to find the
correct commit in the unsplit log view. In the log view, if one
scrolls down across a commit line, the current commit (as displayed in
the status bar) gets updated, but not so when scrolling upward across
a commit. The log_select function handles this scenario to do the
``right thing''. In addition, it introduces the log_state structure as
the private entry of the log view to hold a flag that decides whether
to re-evaluate the current commit based on scrolling.

Signed-off-by: Kumar Appaiah <a.kumar@alumni.iitm.ac.in>