commit - d8f38dc4399d778c7e8df3c3a0d7e5e427146257
commit + 4e97c21c3a2f1e5e9c13a45f7735591bcaa7e48f
blob - 3bd8203a3a857bacf24911b98bfbf1756ca256b1
blob + 7c2c3668d66487cfb8b0e14d90d5e39d59115c9d
--- tog/tog.c
+++ tog/tog.c
int ndisplayed, selected, show_ids;
struct tog_parent_trees parents;
struct got_object_id *commit_id;
+ const char *head_ref_name;
struct got_repository *repo;
struct got_tree_entry *matched_entry;
struct tog_colors colors;
static const struct got_error *search_next_blame_view(struct tog_view *);
static const struct got_error *open_tree_view(struct tog_view *,
- struct got_tree_object *, struct got_object_id *, struct got_repository *);
+ struct got_tree_object *, struct got_object_id *, const char *,
+ struct got_repository *);
static const struct got_error *show_tree_view(struct tog_view *);
static const struct got_error *input_tree_view(struct tog_view **,
struct tog_view *, int);
static const struct got_error *
browse_commit_tree(struct tog_view **new_view, int begin_x,
struct commit_queue_entry *entry, const char *path,
- struct got_repository *repo)
+ const char *head_ref_name, struct got_repository *repo)
{
const struct got_error *err = NULL;
struct got_tree_object *tree;
if (tree_view == NULL)
return got_error_from_errno("view_open");
- err = open_tree_view(tree_view, tree, entry->id, repo);
+ err = open_tree_view(tree_view, tree, entry->id, head_ref_name, repo);
if (err) {
got_object_tree_close(tree);
return err;
if (view_is_parent_view(view))
begin_x = view_split_begin_x(view->begin_x);
err = browse_commit_tree(&tree_view, begin_x,
- s->selected_entry, s->in_repo_path, s->repo);
+ s->selected_entry, s->in_repo_path, s->head_ref_name,
+ s->repo);
if (err)
break;
view->focussed = 0;
}
static const struct got_error *
-log_tree_entry(struct tog_view **new_view, int begin_x,
- struct got_tree_entry *te, struct tog_parent_trees *parents,
- struct got_object_id *commit_id, struct got_repository *repo)
+log_selected_tree_entry(struct tog_view **new_view, int begin_x,
+ struct tog_tree_view_state *s)
{
struct tog_view *log_view;
const struct got_error *err = NULL;
if (log_view == NULL)
return got_error_from_errno("view_open");
- err = tree_entry_path(&path, parents, te);
+ err = tree_entry_path(&path, &s->parents, s->selected_entry);
if (err)
return err;
- err = open_log_view(log_view, commit_id, repo, NULL, path, 0);
+ err = open_log_view(log_view, s->commit_id, s->repo, s->head_ref_name,
+ path, 0);
if (err)
view_close(log_view);
else
static const struct got_error *
open_tree_view(struct tog_view *view, struct got_tree_object *root,
- struct got_object_id *commit_id, struct got_repository *repo)
+ struct got_object_id *commit_id, const char *head_ref_name,
+ struct got_repository *repo)
{
const struct got_error *err = NULL;
char *commit_id_str = NULL;
err = got_error_from_errno("got_object_id_dup");
goto done;
}
+ s->head_ref_name = head_ref_name;
s->repo = repo;
SIMPLEQ_INIT(&s->colors);
break;
if (view_is_parent_view(view))
begin_x = view_split_begin_x(view->begin_x);
- err = log_tree_entry(&log_view, begin_x, s->selected_entry,
- &s->parents, s->commit_id, s->repo);
+ err = log_selected_tree_entry(&log_view, begin_x, s);
view->focussed = 0;
log_view->focussed = 1;
if (view_is_parent_view(view)) {
struct got_worktree *worktree = NULL;
char *cwd = NULL, *repo_path = NULL, *in_repo_path = NULL;
struct got_object_id *commit_id = NULL;
- char *commit_id_arg = NULL;
+ const char *commit_id_arg = NULL;
+ char *label = NULL;
struct got_commit_object *commit = NULL;
struct got_tree_object *tree = NULL;
+ struct got_reference *ref = NULL;
+ const char *head_ref_name = NULL;
int ch;
struct tog_view *view;
if (error)
goto done;
- error = got_repo_match_object_id(&commit_id, NULL,
- commit_id_arg ? commit_id_arg : GOT_REF_HEAD,
- GOT_OBJ_TYPE_COMMIT, 1, repo);
- if (error)
- goto done;
+ if (commit_id_arg == NULL) {
+ error = got_repo_match_object_id(&commit_id, &label,
+ worktree ? got_worktree_get_head_ref_name(worktree) :
+ GOT_REF_HEAD, GOT_OBJ_TYPE_COMMIT, 1, repo);
+ if (error)
+ goto done;
+ head_ref_name = label;
+ } else {
+ error = got_ref_open(&ref, repo, commit_id_arg, 0);
+ if (error == NULL)
+ head_ref_name = got_ref_get_name(ref);
+ else if (error->code != GOT_ERR_NOT_REF)
+ goto done;
+ error = got_repo_match_object_id(&commit_id, NULL,
+ commit_id_arg, GOT_OBJ_TYPE_COMMIT, 1, repo);
+ if (error)
+ goto done;
+ }
error = got_object_open_as_commit(&commit, repo, commit_id);
if (error)
error = got_error_from_errno("view_open");
goto done;
}
- error = open_tree_view(view, tree, commit_id, repo);
+ error = open_tree_view(view, tree, commit_id, head_ref_name, repo);
if (error)
goto done;
if (!got_path_is_root_dir(in_repo_path)) {
free(repo_path);
free(cwd);
free(commit_id);
+ free(label);
if (commit)
got_object_commit_close(commit);
if (tree)
goto done;
}
- err = open_tree_view(tree_view, tree, commit_id, repo);
+ err = open_tree_view(tree_view, tree, commit_id,
+ got_ref_get_name(re->ref), repo);
if (err)
goto done;