summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 751e27c)
raw | patch | inline | side by side (parent: 751e27c)
author | Jonas Fonseca <fonseca@diku.dk> | |
Sat, 2 Jun 2007 08:55:29 +0000 (10:55 +0200) | ||
committer | Jonas Fonseca <fonseca@diku.dk> | |
Sat, 2 Jun 2007 16:24:16 +0000 (18:24 +0200) |
tig.c | patch | blob | history |
index ba1ad3d6b002c0c2116651162209793e75590226..d6e54b180ef98e51ffd09ed6b299669a33e558b3 100644 (file)
--- a/tig.c
+++ b/tig.c
#define string_copy_rev(dst, src) \
string_ncopy_do(dst, SIZEOF_REV, src, SIZEOF_REV - 1)
+#define string_add(dst, from, src) \
+ string_ncopy_do(dst + (from), sizeof(dst) - (from), src, sizeof(src))
+
static char *
chomp_string(char *name)
{
static char opt_codeset[20] = "UTF-8";
static iconv_t opt_iconv = ICONV_NONE;
static char opt_search[SIZEOF_STR] = "";
+static char opt_cdup[SIZEOF_STR] = "";
enum option_type {
OPT_NONE,
status_enter(struct view *view, struct line *line)
{
struct status *status = line->data;
- const char *cmd;
+ char cmd[SIZEOF_STR];
char buf[SIZEOF_STR];
+ size_t cmdsize = 0;
size_t bufsize = 0;
size_t written = 0;
FILE *pipe;
if (!status)
return TRUE;
+ if (opt_cdup[0] &&
+ line->type != LINE_STAT_UNTRACKED &&
+ !string_format_from(cmd, &cmdsize, "cd %s;", opt_cdup))
+ return FALSE;
+
switch (line->type) {
case LINE_STAT_STAGED:
if (!string_format_from(buf, &bufsize, "%06o %s\t%s%c",
status->old.rev,
status->name, 0))
return FALSE;
- cmd = "git update-index -z --index-info";
+
+ string_add(cmd, cmdsize, "git update-index -z --index-info");
break;
case LINE_STAT_UNSTAGED:
case LINE_STAT_UNTRACKED:
if (!string_format_from(buf, &bufsize, "%s%c", status->name, 0))
return FALSE;
- cmd = "git update-index -z --add --remove --stdin";
+
+ string_add(cmd, cmdsize, "git update-index -z --add --remove --stdin");
break;
default:
"=", read_repo_config_option);
}
+static int
+read_repo_info(char *name, int namelen, char *value, int valuelen)
+{
+ if (!opt_cdup[0])
+ string_copy(opt_cdup, name);
+ return OK;
+}
+
+static int
+load_repo_info(void)
+{
+ return read_properties(popen("git rev-parse --show-cdup", "r"),
+ "=", read_repo_info);
+}
+
static int
read_properties(FILE *pipe, const char *separators,
int (*read_property)(char *, int, char *, int))
if (load_repo_config() == ERR)
die("Failed to load repo config.");
+ if (load_repo_info() == ERR)
+ die("Failed to load repo info.");
+
if (!parse_options(argc, argv))
return 0;