static int line_termination = '\n';
#define LS_RECURSIVE 1
-#define LS_TREE_ONLY 2
-#define LS_SHOW_TREES 4
-#define LS_NAME_ONLY 8
-#define LS_SHOW_SIZE 16
+#define LS_TREE_ONLY (1 << 1)
+#define LS_SHOW_TREES (1 << 2)
static int abbrev;
static int ls_options;
static struct pathspec pathspec;
NULL
};
+static enum ls_tree_cmdmode {
+ MODE_LONG = 1,
+ MODE_NAME_ONLY,
+} cmdmode;
+
static int show_recursive(const char *base, size_t baselen, const char *pathname)
{
int i;
return 0;
}
+static int show_default(const struct object_id *oid, enum object_type type,
+ const char *pathname, unsigned mode,
+ struct strbuf *base)
+{
+ size_t baselen = base->len;
+
+ if (cmdmode == MODE_LONG) {
+ char size_text[24];
+ if (type == OBJ_BLOB) {
+ unsigned long size;
+ if (oid_object_info(the_repository, oid, &size) == OBJ_BAD)
+ xsnprintf(size_text, sizeof(size_text), "BAD");
+ else
+ xsnprintf(size_text, sizeof(size_text),
+ "%" PRIuMAX, (uintmax_t)size);
+ } else {
+ xsnprintf(size_text, sizeof(size_text), "-");
+ }
+ printf("%06o %s %s %7s\t", mode, type_name(type),
+ find_unique_abbrev(oid, abbrev), size_text);
+ } else {
+ printf("%06o %s %s\t", mode, type_name(type),
+ find_unique_abbrev(oid, abbrev));
+ }
+ baselen = base->len;
+ strbuf_addstr(base, pathname);
+ write_name_quoted_relative(base->buf,
+ chomp_prefix ? ls_tree_prefix : NULL, stdout,
+ line_termination);
+ strbuf_setlen(base, baselen);
+ return 1;
+}
+
static int show_tree(const struct object_id *oid, struct strbuf *base,
const char *pathname, unsigned mode, void *context)
{
return recurse;
}
- if (!(ls_options & LS_NAME_ONLY)) {
- if (ls_options & LS_SHOW_SIZE) {
- char size_text[24];
- if (type == OBJ_BLOB) {
- unsigned long size;
- if (oid_object_info(the_repository, oid, &size) == OBJ_BAD)
- xsnprintf(size_text, sizeof(size_text),
- "BAD");
- else
- xsnprintf(size_text, sizeof(size_text),
- "%"PRIuMAX, (uintmax_t)size);
- } else {
- xsnprintf(size_text, sizeof(size_text), "-");
- }
- printf("%06o %s %s %7s\t", mode, type_name(type),
- find_unique_abbrev(oid, abbrev),
- size_text);
- } else {
- printf("%06o %s %s\t", mode, type_name(type),
- find_unique_abbrev(oid, abbrev));
- }
+ if (cmdmode == MODE_NAME_ONLY) {
+ baselen = base->len;
+ strbuf_addstr(base, pathname);
+ write_name_quoted_relative(base->buf,
+ chomp_prefix ? ls_tree_prefix : NULL,
+ stdout, line_termination);
+ strbuf_setlen(base, baselen);
+ return recurse;
}
- baselen = base->len;
- strbuf_addstr(base, pathname);
- write_name_quoted_relative(base->buf,
- chomp_prefix ? ls_tree_prefix : NULL,
- stdout, line_termination);
- strbuf_setlen(base, baselen);
+
+ if (cmdmode == MODE_LONG ||
+ (!ls_options || (ls_options & LS_RECURSIVE)
+ || (ls_options & LS_SHOW_TREES)
+ || (ls_options & LS_TREE_ONLY)))
+ show_default(oid, type, pathname, mode, base);
+
return recurse;
}
LS_SHOW_TREES),
OPT_SET_INT('z', NULL, &line_termination,
N_("terminate entries with NUL byte"), 0),
- OPT_CMDMODE('l', "long", &ls_options, N_("include object size"),
- LS_SHOW_SIZE),
- OPT_CMDMODE(0, "name-only", &ls_options, N_("list only filenames"),
- LS_NAME_ONLY),
- OPT_CMDMODE(0, "name-status", &ls_options, N_("list only filenames"),
- LS_NAME_ONLY),
+ OPT_CMDMODE('l', "long", &cmdmode, N_("include object size"),
+ MODE_LONG),
+ OPT_CMDMODE(0, "name-only", &cmdmode, N_("list only filenames"),
+ MODE_NAME_ONLY),
+ OPT_CMDMODE(0, "name-status", &cmdmode, N_("list only filenames"),
+ MODE_NAME_ONLY),
OPT_SET_INT(0, "full-name", &chomp_prefix,
N_("use full path names"), 0),
OPT_BOOL(0, "full-tree", &full_tree,