builtins: print setup info if repo is found
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Nguyễn Thái Ngọc Duy committed
Nov 26, 2010 at 22:31 UTC
a9ca8a85ef493aac947f9da44a4fbb5724768897
3 files changed
+47
cache.h
+1
@@ -1062,6 +1062,7 @@ __attribute__((format (printf, 1, 2)))
1062
extern void trace_printf(const char *format, ...);
1063
__attribute__((format (printf, 2, 3)))
1064
extern void trace_argv_printf(const char **argv, const char *format, ...);
1065
+extern void trace_repo_setup(const char *prefix);
1066
1067
/* convert.c */
1068
/* returns 1 if *dst was used */
git.c
+4
@@ -264,6 +264,10 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
264
use_pager = check_pager_config(p->cmd);
265
if (use_pager == -1 && p->option & USE_PAGER)
266
use_pager = 1;
267
+
268
+ if ((p->option & (RUN_SETUP | RUN_SETUP_GENTLY)) &&
269
+ startup_info->have_repository) /* get_git_dir() may set up repo, avoid that */
270
+ trace_repo_setup(prefix);
271
}
272
commit_pager_choice();
273
trace.c
+42
@@ -131,3 +131,45 @@ void trace_argv_printf(const char **argv, const char *fmt, ...)
131
if (need_close)
132
close(fd);
133
}
134
+
135
+static const char *quote_crnl(const char *path)
136
+{
137
+ static char new_path[PATH_MAX];
138
+ const char *p2 = path;
139
+ char *p1 = new_path;
140
+
141
+ if (!path)
142
+ return NULL;
143
+
144
+ while (*p2) {
145
+ switch (*p2) {
146
+ case '\\': *p1++ = '\\'; *p1++ = '\\'; break;
147
+ case '\n': *p1++ = '\\'; *p1++ = 'n'; break;
148
+ case '\r': *p1++ = '\\'; *p1++ = 'r'; break;
149
+ default:
150
+ *p1++ = *p2;
151
+ }
152
+ p2++;
153
+ }
154
+ *p1 = '\0';
155
+ return new_path;
156
+}
157
+
158
+/* FIXME: move prefix to startup_info struct and get rid of this arg */
159
+void trace_repo_setup(const char *prefix)
160
+{
161
+ char cwd[PATH_MAX];
162
+ char *trace = getenv("GIT_TRACE");
163
+
164
+ if (!trace || !strcmp(trace, "") ||
165
+ !strcmp(trace, "0") || !strcasecmp(trace, "false"))
166
+ return;
167
+
168
+ if (!getcwd(cwd, PATH_MAX))
169
+ die("Unable to get current working directory");
170
+
171
+ trace_printf("setup: git_dir: %s\n", quote_crnl(get_git_dir()));
172
+ trace_printf("setup: worktree: %s\n", quote_crnl(get_git_work_tree()));
173
+ trace_printf("setup: cwd: %s\n", quote_crnl(cwd));
174
+ trace_printf("setup: prefix: %s\n", quote_crnl(prefix));
175
+}