Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>2022-03-23 12:13:10 +0300
committerJunio C Hamano <gitster@pobox.com>2022-03-23 21:38:40 +0300
commite81517155e0370ae5433d256046ab287bb10d04d (patch)
treeeafe640056d5294b2166a8cfc87cd5c9b483483e /builtin/ls-tree.c
parent315f22c853c08b1f3473fc50985d76618f31ebd0 (diff)
ls-tree: introduce struct "show_tree_data"
"show_tree_data" is a struct that packages the necessary fields for "show_tree()". This commit is a pre-prepared commit for supporting "--format" option and it does not affect any existing functionality. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Teng Long <dyroneteng@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/ls-tree.c')
-rw-r--r--builtin/ls-tree.c42
1 files changed, 27 insertions, 15 deletions
diff --git a/builtin/ls-tree.c b/builtin/ls-tree.c
index 173a534e92..edc8bf53a6 100644
--- a/builtin/ls-tree.c
+++ b/builtin/ls-tree.c
@@ -23,6 +23,13 @@ static int ls_options;
static struct pathspec pathspec;
static int chomp_prefix;
static const char *ls_tree_prefix;
+struct show_tree_data {
+ unsigned mode;
+ enum object_type type;
+ const struct object_id *oid;
+ const char *pathname;
+ struct strbuf *base;
+};
static const char * const ls_tree_usage[] = {
N_("git ls-tree [<options>] <tree-ish> [<path>...]"),
@@ -64,17 +71,15 @@ static int show_recursive(const char *base, size_t baselen, const char *pathname
return 0;
}
-static int show_default(const struct object_id *oid, enum object_type type,
- const char *pathname, unsigned mode,
- struct strbuf *base)
+static int show_default(struct show_tree_data *data)
{
- size_t baselen = base->len;
+ size_t baselen = data->base->len;
if (cmdmode == MODE_LONG) {
char size_text[24];
- if (type == OBJ_BLOB) {
+ if (data->type == OBJ_BLOB) {
unsigned long size;
- if (oid_object_info(the_repository, oid, &size) == OBJ_BAD)
+ if (oid_object_info(the_repository, data->oid, &size) == OBJ_BAD)
xsnprintf(size_text, sizeof(size_text), "BAD");
else
xsnprintf(size_text, sizeof(size_text),
@@ -82,18 +87,18 @@ static int show_default(const struct object_id *oid, enum object_type type,
} else {
xsnprintf(size_text, sizeof(size_text), "-");
}
- printf("%06o %s %s %7s\t", mode, type_name(type),
- find_unique_abbrev(oid, abbrev), size_text);
+ printf("%06o %s %s %7s\t", data->mode, type_name(data->type),
+ find_unique_abbrev(data->oid, abbrev), size_text);
} else {
- printf("%06o %s %s\t", mode, type_name(type),
- find_unique_abbrev(oid, abbrev));
+ printf("%06o %s %s\t", data->mode, type_name(data->type),
+ find_unique_abbrev(data->oid, abbrev));
}
- baselen = base->len;
- strbuf_addstr(base, pathname);
- write_name_quoted_relative(base->buf,
+ baselen = data->base->len;
+ strbuf_addstr(data->base, data->pathname);
+ write_name_quoted_relative(data->base->buf,
chomp_prefix ? ls_tree_prefix : NULL, stdout,
line_termination);
- strbuf_setlen(base, baselen);
+ strbuf_setlen(data->base, baselen);
return 1;
}
@@ -103,6 +108,13 @@ static int show_tree(const struct object_id *oid, struct strbuf *base,
int recurse = 0;
size_t baselen;
enum object_type type = object_type(mode);
+ struct show_tree_data data = {
+ .mode = mode,
+ .type = type,
+ .oid = oid,
+ .pathname = pathname,
+ .base = base,
+ };
if (type == OBJ_BLOB) {
if (ls_options & LS_TREE_ONLY)
@@ -128,7 +140,7 @@ static int show_tree(const struct object_id *oid, struct strbuf *base,
(!ls_options || (ls_options & LS_RECURSIVE)
|| (ls_options & LS_SHOW_TREES)
|| (ls_options & LS_TREE_ONLY)))
- show_default(oid, type, pathname, mode, base);
+ show_default(&data);
return recurse;
}