builtin-blame: set up the work_tree before the first file access
We check in cmd_blame() if the specified path is there, but we failed to set up the working tree before that. While at it, make setup_work_tree() just return if it was run before. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Johannes Schindelin committed
Nov 9, 2007 at 11:34 UTC
354e6534c1569d0d23937add8e7b55bf87bbaf20
2 files changed
+9
-2
builtin-blame.c
+1
@@ -2295,6 +2295,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
2295
else if (i != argc - 1)
2296
usage(blame_usage); /* garbage at end */
2297
2298
+ setup_work_tree();
2299
if (!has_path_in_work_tree(path))
2300
die("cannot stat path %s: %s",
2301
path, strerror(errno));
setup.c
+8
-2
@@ -208,12 +208,18 @@ static const char *set_work_tree(const char *dir)
208
209
void setup_work_tree(void)
210
{
211
- const char *work_tree = get_git_work_tree();
212
- const char *git_dir = get_git_dir();
211
+ const char *work_tree, *git_dir;
212
+ static int initialized = 0;
213
+
214
+ if (initialized)
215
+ return;
216
+ work_tree = get_git_work_tree();
217
+ git_dir = get_git_dir();
218
if (!is_absolute_path(git_dir))
219
set_git_dir(make_absolute_path(git_dir));
220
if (!work_tree || chdir(work_tree))
221
die("This operation must be run in a work tree");
222
+ initialized = 1;
223
}
224
225
/*