Skip to content

Commit

Permalink
Reimplemented "Added support for move to parent in main view.", with …
Browse files Browse the repository at this point in the history
…logic now in main.c

We also handle unstaged changes correctly now.
  • Loading branch information
rdnetto4 committed Jun 17, 2016
1 parent 0164f51 commit f9e732e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/tig/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ enum request main_request(struct view *view, enum request request, struct line *
void main_select(struct view *view, struct line *line);
void main_done(struct view *view);
bool main_status_exists(struct view *view, enum line_type type);
enum status_code read_hash(char *id, size_t idlen, char *s2, size_t n2, void *data);

extern struct view main_view;

Expand Down
38 changes: 38 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,12 @@ main_request(struct view *view, enum request request, struct line *line)
{
enum open_flags flags = (view_is_displayed(view) && request != REQ_VIEW_DIFF)
? OPEN_SPLIT : OPEN_DEFAULT;
struct commit *commit = view->line[view->pos.lineno].data;

char current_hash[SIZEOF_REV + 1] = "";
char parent_hash[SIZEOF_REV] = "";
static const char *rev_list_parents_argv[] = { "git", "rev-list", "-n1", NULL, NULL };
rev_list_parents_argv[3] = current_hash;

switch (request) {
case REQ_NEXT:
Expand Down Expand Up @@ -532,6 +538,38 @@ main_request(struct view *view, enum request request, struct line *line)
refresh_view(view);
break;

case REQ_PARENT:
string_copy_rev(current_hash, commit->id);

if(!strcasecmp(commit->id, NULL_ID)) {
// Unstaged changes - parent is HEAD
strcpy(current_hash, "HEAD");
} else {
// Can't assume the hash takes the full 41 bytes
size_t n = strlen(commit->id);
current_hash[n] = '~';
current_hash[n + 1] = 0;
}


if(io_run_load(rev_list_parents_argv, " ", read_hash, parent_hash) != SUCCESS || !strlen(parent_hash)) {
report("Unable to locate parent.");
break;
}

int i;
for (i = 0; i < view->lines; i++) {
struct commit *commit = view->line[i].data;

if (!strncasecmp(commit->id, parent_hash, strlen(parent_hash))) {
select_view_line(view, i);
report_clear();
break;
}
}

break;

default:
return request;
}
Expand Down

0 comments on commit f9e732e

Please sign in to comment.