Skip to content

Commit

Permalink
ls-tree: further cleanup to parallel ls-files.
Browse files Browse the repository at this point in the history
To get more a "git-ls-files" approach, this trivial patch (on top of my
previous one) enables recursion, and doesn't show partial trees.

[jc: after further discussion, this version enables recursion by default,
 and you can disable it with "-d" flag.

	git-ls-tree -d HEAD Documentation/no/such/directory

 shows Documentation tree (without -d it shows nothing).

	git-ls-tree HEAD

 shows everything from the tree.  Only to get the single level from the top

	git-ls-tree -d HEAD

 is needed.  But there is no way to get the single level with pathspec.
 You need to extract the object name of Documentation tree from the parent
 tree and run

	git-ls-tree -d $tree_id_of_Documentation_tree

 to get something similar to what you can get from the current

	git-ls-tree HEAD Documentation
 ]
  • Loading branch information
Linus Torvalds authored and Junio C Hamano committed Nov 29, 2005
1 parent 3c5e846 commit b45c569
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions ls-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,23 @@
static int line_termination = '\n';
#define LS_RECURSIVE 1
#define LS_TREE_ONLY 2
static int ls_options = 0;
static int ls_options = LS_RECURSIVE;

static const char ls_tree_usage[] =
"git-ls-tree [-d] [-r] [-z] <tree-ish> [path...]";

static int show_tree(unsigned char *sha1, const char *base, int baselen, const char *pathname, unsigned mode, int stage)
{
const char *type = "blob";
int retval = 0;

if (S_ISDIR(mode)) {
type = "tree";
if (ls_options & LS_RECURSIVE)
retval = READ_TREE_RECURSIVE;
return READ_TREE_RECURSIVE;
type = "tree";
}

printf("%06o %s %s\t%.*s%s%c", mode, type, sha1_to_hex(sha1), baselen, base, pathname, line_termination);
return retval;
return 0;
}

int main(int argc, const char **argv)
Expand Down

0 comments on commit b45c569

Please sign in to comment.