summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 8a68098)
raw | patch | inline | side by side (parent: 8a68098)
author | Jonas Fonseca <fonseca@diku.dk> | |
Sun, 23 Mar 2008 02:00:03 +0000 (03:00 +0100) | ||
committer | Jonas Fonseca <fonseca@diku.dk> | |
Sun, 23 Mar 2008 03:44:50 +0000 (04:44 +0100) |
- Fix entering from status and stage views by making opt_ref setting
optional.
- Use separate opt_file variable, since the tree view also uses
opt_path.
optional.
- Use separate opt_file variable, since the tree view also uses
opt_path.
tig.c | patch | blob | history |
index 8db304e872cc47f6a2051aff619b9cca0c76bcd1..493c4281c8132be64434f8419c50184a758e5984 100644 (file)
--- a/tig.c
+++ b/tig.c
static enum request opt_request = REQ_VIEW_MAIN;
static char opt_cmd[SIZEOF_STR] = "";
static char opt_path[SIZEOF_STR] = "";
+static char opt_file[SIZEOF_STR] = "";
static char opt_ref[SIZEOF_REF] = "";
static FILE *opt_pipe = NULL;
static char opt_encoding[20] = "UTF-8";
i++;
}
- string_ncopy(opt_path, argv[i], strlen(argv[i]));
+ string_ncopy(opt_file, argv[i], strlen(argv[i]));
return TRUE;
} else if (!strcmp(subcommand, "show")) {
break;
case REQ_VIEW_BLAME:
- if (!opt_path[0]) {
+ if (!opt_file[0]) {
report("No file chosen, press %s to open tree view",
get_key(REQ_VIEW_TREE));
break;
}
- if (opt_path[strlen(opt_path) - 1] == '/') {
- report("Cannot show blame for directory %s", opt_path);
- break;
- }
- string_copy(opt_ref, ref_commit);
open_view(view, request, OPEN_DEFAULT);
break;
return strcmp(name1, name2);
}
+static char *
+tree_path(struct line *line)
+{
+ char *path = line->data;
+
+ return path + SIZEOF_TREE_ATTR;
+}
+
static bool
tree_read(struct view *view, char *text)
{
/* Skip "Directory ..." and ".." line. */
for (pos = 1 + !!*opt_path; pos < view->lines; pos++) {
struct line *line = &view->line[pos];
- char *path1 = ((char *) line->data) + SIZEOF_TREE_ATTR;
+ char *path1 = tree_path(line);
char *path2 = text + SIZEOF_TREE_ATTR;
int cmp = tree_compare_entry(line->type, path1, type, path2);
{
enum open_flags flags;
+ if (request == REQ_VIEW_BLAME) {
+ char *filename = tree_path(line);
+
+ if (line->type == LINE_TREE_DIR) {
+ report("Cannot show blame for directory %s", opt_path);
+ return REQ_NONE;
+ }
+
+ string_copy(opt_ref, ref_commit);
+ string_ncopy(opt_file, filename, strlen(filename));
+ return request;
+ }
if (request == REQ_TREE_PARENT) {
if (*opt_path) {
/* fake 'cd ..' */
pop_tree_stack_entry();
} else {
- char *data = line->data;
- char *basename = data + SIZEOF_TREE_ATTR;
+ char *basename = tree_path(line);
push_tree_stack_entry(basename, view->lineno);
}
static bool
blob_read(struct view *view, char *line)
{
+ if (!line)
+ return TRUE;
return add_line_text(view, line, LINE_DEFAULT) != NULL;
}
*
* Loading the blame view is a two phase job:
*
- * 1. File content is read either using opt_path from the
+ * 1. File content is read either using opt_file from the
* filesystem or using git-cat-file.
* 2. Then blame information is incrementally added by
* reading output from git-blame.
char path[SIZEOF_STR];
char ref[SIZEOF_STR] = "";
- if (sq_quote(path, 0, opt_path) >= sizeof(path))
+ if (sq_quote(path, 0, opt_file) >= sizeof(path))
return FALSE;
if (*opt_ref && sq_quote(ref, 0, opt_ref) >= sizeof(ref))
if (!string_format(view->cmd, BLAME_CAT_FILE_CMD, ref, path))
return FALSE;
} else {
- view->pipe = fopen(opt_path, "r");
+ view->pipe = fopen(opt_file, "r");
if (!view->pipe &&
!string_format(view->cmd, BLAME_CAT_FILE_CMD, "HEAD", path))
return FALSE;
if (!string_format(view->cmd, BLAME_INCREMENTAL_CMD, ref, path))
return FALSE;
- string_format(view->ref, "%s ...", opt_path);
- string_copy_rev(view->vid, opt_path);
+ string_format(view->ref, "%s ...", opt_file);
+ string_copy_rev(view->vid, opt_file);
set_nonblocking_input(TRUE);
if (view->line) {
case REQ_VIEW_BLAME:
if (status) {
- string_copy(opt_path, status->new.name);
+ string_copy(opt_file, status->new.name);
opt_ref[0] = 0;
}
return request;
case REQ_VIEW_BLAME:
if (stage_status.new.name[0]) {
- string_copy(opt_path, stage_status.new.name);
+ string_copy(opt_file, stage_status.new.name);
opt_ref[0] = 0;
}
return request;