From cfb6b75c4633e576675dd8eab84dc45831b3c8d7 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Sun, 8 Feb 2009 06:00:42 -0500 Subject: [PATCH] Handle blaming beyond the creation of file more gracefully Currently when you ask to re-blame from the parent of a commit that created the file, blame_read_file will complain that it cannot get the file contents ("No blame exist"). At the time we try to read the file, it is too late to abort the operation, as we have already changed to the new blame view. However, we can detect this situation early by limiting the selection of the parent revision to the particular path of interest: if it returns a parent even with path-limiting, then we know the path exists; if not, then we know it doesn't. Signed-off-by: Jeff King Signed-off-by: Jonas Fonseca --- tig.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tig.c b/tig.c index 04a44db..13c167d 100644 --- a/tig.c +++ b/tig.c @@ -3384,11 +3384,11 @@ select_commit_parent_handler(void *data, char *buf, int c) } static bool -select_commit_parent(const char *id, char rev[SIZEOF_REV]) +select_commit_parent(const char *id, char rev[SIZEOF_REV], const char *path) { char buf[SIZEOF_STR * 4]; const char *revlist_argv[] = { - "git", "rev-list", "-1", "--parents", id, NULL + "git", "rev-list", "-1", "--parents", id, "--", path, NULL }; int parents; @@ -3399,7 +3399,10 @@ select_commit_parent(const char *id, char rev[SIZEOF_REV]) return FALSE; } else if (parents == 0) { - report("The selected commit has no parents"); + if (path) + report("Path '%s' does not exist in the parent", path); + else + report("The selected commit has no parents"); return FALSE; } @@ -4468,7 +4471,8 @@ blame_request(struct view *view, enum request request, struct line *line) case REQ_PARENT: if (check_blame_commit(blame) && - select_commit_parent(blame->commit->id, opt_ref)) { + select_commit_parent(blame->commit->id, opt_ref, + blame->commit->filename)) { string_copy(opt_file, blame->commit->filename); setup_blame_parent_line(view, blame); open_view(view, REQ_VIEW_BLAME, OPEN_REFRESH); -- 2.32.0.93.g670b81a890