Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for move to parent in main view. #506

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
48 changes: 48 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 Expand Up @@ -575,6 +613,16 @@ static struct view_ops main_ops = {
main_get_column_data,
};

enum status_code read_hash(char *id, size_t idlen, char *s2, size_t s2len, void *data) {
char *result = data;

if (! result[0] && idlen > 0) {
string_copy_rev(result, id);
}

return SUCCESS;
}

DEFINE_VIEW(main);

/* vim: set ts=8 sw=8 noexpandtab: */