summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: de46362)
raw | patch | inline | side by side (parent: de46362)
author | Jonas Fonseca <fonseca@diku.dk> | |
Wed, 26 Mar 2008 10:26:00 +0000 (11:26 +0100) | ||
committer | Jonas Fonseca <fonseca@diku.dk> | |
Wed, 26 Mar 2008 10:26:00 +0000 (11:26 +0100) |
tig.c | patch | blob | history |
index b0134107099ab672f3abee7eb081cff9f7bc0a75..668255543b18e06659c1badb396a0eb364d735e7 100644 (file)
--- a/tig.c
+++ b/tig.c
@@ -103,6 +103,8 @@ static size_t utf8_length(const char *string, size_t max_width, int *trimmed, bo
#define SCALE_SPLIT_VIEW(height) ((height) * 2 / 3)
+#define NULL_ID "0000000000000000000000000000000000000000"
+
#ifndef GIT_CONFIG
#define GIT_CONFIG "git config"
#endif
static char opt_file[SIZEOF_STR] = "";
static char opt_ref[SIZEOF_REF] = "";
static char opt_head[SIZEOF_REF] = "";
+static bool opt_no_head = TRUE;
static FILE *opt_pipe = NULL;
static char opt_encoding[20] = "UTF-8";
static bool opt_utf8 = TRUE;
break;
}
- if (!strcmp(blame->commit->id, "0000000000000000000000000000000000000000")) {
+ if (!strcmp(blame->commit->id, NULL_ID)) {
char path[SIZEOF_STR];
if (sq_quote(path, 0, view->vid) >= sizeof(path))
if (!commit)
return;
- if (!strcmp(commit->id, "0000000000000000000000000000000000000000"))
+ if (!strcmp(commit->id, NULL_ID))
string_ncopy(ref_commit, "HEAD", 4);
else
string_copy_rev(ref_commit, commit->id);
}
static bool
-status_run(struct view *view, const char cmd[], bool diff, enum line_type type)
+status_run(struct view *view, const char cmd[], char status, enum line_type type)
{
struct status *file = NULL;
struct status *unmerged = NULL;
@@ -3803,8 +3806,10 @@ status_run(struct view *view, const char cmd[], bool diff, enum line_type type)
}
/* Parse diff info part. */
- if (!diff) {
- file->status = '?';
+ if (status) {
+ file->status = status;
+ if (status == 'A')
+ string_copy(file->old.rev, NULL_ID);
} else if (!file->status) {
if (!status_get_diff(file, buf, sepsize))
#define STATUS_DIFF_FILES_CMD "git diff-files -z"
#define STATUS_LIST_OTHER_CMD \
"git ls-files -z --others --exclude-per-directory=.gitignore"
+#define STATUS_LIST_NO_HEAD_CMD \
+ "git ls-files -z --cached --exclude-per-directory=.gitignore"
#define STATUS_DIFF_INDEX_SHOW_CMD \
"git diff-index --root --patch-with-stat -C -M --cached HEAD -- %s %s 2>/dev/null"
#define STATUS_DIFF_FILES_SHOW_CMD \
"git diff-files --root --patch-with-stat -C -M -- %s %s 2>/dev/null"
+#define STATUS_DIFF_NO_HEAD_SHOW_CMD \
+ "git diff --no-color --patch-with-stat /dev/null %s 2>/dev/null"
+
/* First parse staged info using git-diff-index(1), then parse unstaged
* info using git-diff-files(1), and finally untracked files using
* git-ls-files(1). */
{
struct stat statbuf;
char exclude[SIZEOF_STR];
- char cmd[SIZEOF_STR];
+ char indexcmd[SIZEOF_STR] = STATUS_DIFF_INDEX_CMD;
+ char othercmd[SIZEOF_STR] = STATUS_LIST_OTHER_CMD;
unsigned long prev_lineno = view->lineno;
+ char indexstatus = 0;
size_t i;
for (i = 0; i < view->lines; i++)
return FALSE;
add_line_data(view, NULL, LINE_STAT_HEAD);
- if (!*opt_head)
+ if (opt_no_head)
+ string_copy(status_onbranch, "Initial commit");
+ else if (!*opt_head)
string_copy(status_onbranch, "Not currently on any branch");
else if (!string_format(status_onbranch, "On branch %s", opt_head))
return FALSE;
+ if (opt_no_head) {
+ string_copy(indexcmd, STATUS_LIST_NO_HEAD_CMD);
+ indexstatus = 'A';
+ }
+
if (!string_format(exclude, "%s/info/exclude", opt_git_dir))
return FALSE;
- string_copy(cmd, STATUS_LIST_OTHER_CMD);
-
if (stat(exclude, &statbuf) >= 0) {
- size_t cmdsize = strlen(cmd);
+ size_t cmdsize = strlen(othercmd);
+
+ if (!string_format_from(othercmd, &cmdsize, " %s", "--exclude-from=") ||
+ sq_quote(othercmd, cmdsize, exclude) >= sizeof(othercmd))
+ return FALSE;
- if (!string_format_from(cmd, &cmdsize, " %s", "--exclude-from=") ||
- sq_quote(cmd, cmdsize, exclude) >= sizeof(cmd))
+ cmdsize = strlen(indexcmd);
+ if (opt_no_head &&
+ (!string_format_from(indexcmd, &cmdsize, " %s", "--exclude-from=") ||
+ sq_quote(indexcmd, cmdsize, exclude) >= sizeof(indexcmd)))
return FALSE;
}
system("git update-index -q --refresh");
- if (!status_run(view, STATUS_DIFF_INDEX_CMD, TRUE, LINE_STAT_STAGED) ||
- !status_run(view, STATUS_DIFF_FILES_CMD, TRUE, LINE_STAT_UNSTAGED) ||
- !status_run(view, cmd, FALSE, LINE_STAT_UNTRACKED))
+ if (!status_run(view, indexcmd, indexstatus, LINE_STAT_STAGED) ||
+ !status_run(view, STATUS_DIFF_FILES_CMD, 0, LINE_STAT_UNSTAGED) ||
+ !status_run(view, othercmd, '?', LINE_STAT_UNTRACKED))
return FALSE;
/* If all went well restore the previous line number to stay in
switch (line->type) {
case LINE_STAT_STAGED:
- if (!string_format_from(opt_cmd, &cmdsize,
- STATUS_DIFF_INDEX_SHOW_CMD, oldpath, newpath))
- return REQ_QUIT;
+ if (opt_no_head) {
+ if (!string_format_from(opt_cmd, &cmdsize,
+ STATUS_DIFF_NO_HEAD_SHOW_CMD,
+ newpath))
+ return REQ_QUIT;
+ } else {
+ if (!string_format_from(opt_cmd, &cmdsize,
+ STATUS_DIFF_INDEX_SHOW_CMD,
+ oldpath, newpath))
+ return REQ_QUIT;
+ }
+
if (status)
info = "Staged changes to %s";
else
if (opt_pipe)
return REQ_QUIT;
-
if (!status) {
report("No file to show");
return REQ_NONE;
static void
stage_update(struct view *view, struct line *line)
{
- if (stage_line_type != LINE_STAT_UNTRACKED &&
+ if (!opt_no_head && stage_line_type != LINE_STAT_UNTRACKED &&
(line->type == LINE_DIFF_CHUNK || !stage_status.status)) {
if (!stage_update_chunk(view, line)) {
report("Failed to apply chunk");
head = !strncmp(opt_head, name, namelen);
} else if (!strcmp(name, "HEAD")) {
+ opt_no_head = FALSE;
return OK;
}