ls-tree: work from subdirectory.
This makes ls-tree to work from subdirectory. It defaults to show the paths under the current subdirectory, and interprets user-supplied paths as relative to the current subdirectory. Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Nov 26, 2005 at 00:40 UTC
b191fa72ea501c0789fb1bd7a80fcec9da38804d
1 file changed
+14
-5
ls-tree.c
+14
-5
@@ -206,7 +206,7 @@ static int list_one(const char *path)
206
return err;
207
}
208
209
-static int list(char **path)
209
+static int list(const char **path)
210
{
211
int i;
212
int err = 0;
@@ -218,11 +218,16 @@ static int list(char **path)
218
static const char ls_tree_usage[] =
219
"git-ls-tree [-d] [-r] [-z] <tree-ish> [path...]";
220
221
-int main(int argc, char **argv)
221
+int main(int argc, const char **argv)
222
{
223
- static char *path0[] = { "", NULL };
224
- char **path;
223
+ static const char *path0[] = { "", NULL };
224
+ const char **path;
225
unsigned char sha1[20];
226
+ int nongit = 0;
227
+ const char *prefix = setup_git_directory_gently(&nongit);
228
+
229
+ if (prefix)
230
+ path0[0] = prefix;
231
232
while (1 < argc && argv[1][0] == '-') {
233
switch (argv[1][1]) {
@@ -246,7 +251,11 @@ int main(int argc, char **argv)
251
if (get_sha1(argv[1], sha1) < 0)
252
usage(ls_tree_usage);
253
249
- path = (argc == 2) ? path0 : (argv + 2);
254
+ if (argc == 2)
255
+ path = path0;
256
+ else
257
+ path = get_pathspec(prefix, argv + 2);
258
+
259
prepare_root(sha1);
260
if (list(path) < 0)
261
die("list failed");