Skip to content

Commit

Permalink
Improve on branch information in the status view
Browse files Browse the repository at this point in the history
The file checks was inspired by the prompt code from the git bash
completion script.
  • Loading branch information
jonas committed Feb 5, 2009
1 parent 19115b2 commit d06137e
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 15 deletions.
8 changes: 8 additions & 0 deletions NEWS
@@ -1,6 +1,14 @@
Release notes
=============

tig master
----------

Improvements:

- Status view: improve "on branch" information inspired by the prompt
code in git's bash completion script.

tig-0.14
--------

Expand Down
78 changes: 63 additions & 15 deletions tig.c
Expand Up @@ -676,20 +676,24 @@ io_write(struct io *io, const void *buf, size_t bufsize)
}

static bool
run_io_buf(const char **argv, char buf[], size_t bufsize)
io_read_buf(struct io *io, char buf[], size_t bufsize)
{
struct io io = {};
bool error;

if (!run_io_rd(&io, argv, FORMAT_NONE))
return FALSE;
io->buf = io->bufpos = buf;
io->bufalloc = bufsize;
error = !io_get(io, '\n', TRUE) && io_error(io);
io->buf = NULL;

return done_io(io) || error;
}

io.buf = io.bufpos = buf;
io.bufalloc = bufsize;
error = !io_get(&io, '\n', TRUE) && io_error(&io);
io.buf = NULL;
static bool
run_io_buf(const char **argv, char buf[], size_t bufsize)
{
struct io io = {};

return done_io(&io) || error;
return run_io_rd(&io, argv, FORMAT_NONE) && io_read_buf(&io, buf, bufsize);
}

static int
Expand Down Expand Up @@ -4702,6 +4706,55 @@ status_restore(struct view *view)
view->p_restore = FALSE;
}

static void
status_update_onbranch(void)
{
static const char *paths[][2] = {
{ "rebase-apply/rebasing", "Rebasing" },
{ "rebase-apply/applying", "Applying mailbox" },
{ "rebase-apply/", "Rebasing mailbox" },
{ "rebase-merge/interactive", "Interactive rebase" },
{ "rebase-merge/", "Rebase merge" },
{ "MERGE_HEAD", "Merging" },
{ "BISECT_LOG", "Bisecting" },
{ "HEAD", "On branch" },
};
char buf[SIZEOF_STR];
struct stat stat;
int i;

if (is_initial_commit()) {
string_copy(status_onbranch, "Initial commit");
return;
}

for (i = 0; i < ARRAY_SIZE(paths); i++) {
char *head = opt_head;

if (!string_format(buf, "%s/%s", opt_git_dir, paths[i][0]) ||
lstat(buf, &stat) < 0)
continue;

if (!*opt_head) {
struct io io = {};

if (string_format(buf, "%s/rebase-merge/head-name", opt_git_dir) &&
io_open(&io, buf) &&
io_read_buf(&io, buf, sizeof(buf))) {
head = chomp_string(buf);
if (!prefixcmp(head, "refs/heads/"))
head += STRING_SIZE("refs/heads/");
}
}

if (!string_format(status_onbranch, "%s %s", paths[i][1], head))
string_copy(status_onbranch, opt_head);
return;
}

string_copy(status_onbranch, "Not currently on any branch");
}

/* First parse staged info using git-diff-index(1), then parse unstaged
* info using git-diff-files(1), and finally untracked files using
* git-ls-files(1). */
Expand All @@ -4711,12 +4764,7 @@ status_open(struct view *view)
reset_view(view);

add_line_data(view, NULL, LINE_STAT_HEAD);
if (is_initial_commit())
string_copy(status_onbranch, "Initial commit");
else if (!*opt_head)
string_copy(status_onbranch, "Not currently on any branch");
else if (!string_format(status_onbranch, "On branch %s", opt_head))
return FALSE;
status_update_onbranch();

run_io_bg(update_index_argv);

Expand Down

0 comments on commit d06137e

Please sign in to comment.