On Sun, Jan 25, 2015 at 7:37 AM, Nguyễn Thái Ngọc Duy <pclouds@xxxxxxxxx> wrote: > The index does not store directories explicitly (except submodules) so > we have to figure them out from file list when output lis depth-limited. > > The function show_as_directory() deliberately generates duplicate > directories and expects the previous patch to remove duplicates. > > Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@xxxxxxxxx> > --- > diff --git a/builtin/ls-files.c b/builtin/ls-files.c > index 1a1c9c8..29b5c2e 100644 > --- a/builtin/ls-files.c > +++ b/builtin/ls-files.c > @@ -179,6 +181,35 @@ static void show_killed_files(struct dir_struct *dir) > } > } > > +static int show_as_directory(const struct cache_entry *ce) > +{ > + struct strbuf sb = STRBUF_INIT; > + const char *p; > + > + strbuf_add(&sb, ce->name, ce_namelen(ce)); > + while (sb.len && (p = strrchr(sb.buf, '/')) != NULL) { > + struct strbuf sb2 = STRBUF_INIT; > + strbuf_setlen(&sb, p - sb.buf); > + if (!match_pathspec(&pathspec, sb.buf, sb.len, > + max_prefix_len, NULL, 1)) > + continue; > + write_name(&sb2, sb.buf); > + if (want_color(use_color)) { > + struct strbuf sb3 = STRBUF_INIT; > + color_filename(&sb3, ce->name, sb2.buf, S_IFDIR, 1); > + strbuf_release(&sb2); > + sb2 = sb3; Although more expensive, would it be a bit more idiomatic and obvious to phrase this as strbuf_swap(&sb2, &sb3); strbuf_release(&sb3); or is it not worth it? > + } > + if (show_tag) > + strbuf_insert(&sb2, 0, tag_cached, strlen(tag_cached)); > + strbuf_fputs(&sb2, strbuf_detach(&sb, NULL), NULL); The detached strbuf content gets assigned to the 'util' field of the 'struct string_list output' item and is eventually leaked, however, the program exits soon after. Okay. > + strbuf_release(&sb2); > + return 1; > + } > + strbuf_release(&sb); > + return 0; > +} > + > static void write_ce_name(struct strbuf *sb, const struct cache_entry *ce) > { > struct strbuf quoted = STRBUF_INIT; -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html