mirror of
https://github.com/git/git.git
synced 2024-05-06 11:06:10 +02:00
Merge branch 'zh/ls-files-format-atoms' into next
Some atoms that can be used in "--format=<format>" for "git ls-tree" were not supported by "git ls-files", even though they were relevant in the context of the latter. * zh/ls-files-format-atoms: ls-files: align format atoms with ls-tree
This commit is contained in:
commit
116b11effb
|
@ -270,8 +270,14 @@ interpolated. The following "fieldname" are understood:
|
||||||
|
|
||||||
objectmode::
|
objectmode::
|
||||||
The mode of the file which is recorded in the index.
|
The mode of the file which is recorded in the index.
|
||||||
|
objecttype::
|
||||||
|
The object type of the file which is recorded in the index.
|
||||||
objectname::
|
objectname::
|
||||||
The name of the file which is recorded in the index.
|
The name of the file which is recorded in the index.
|
||||||
|
objectsize[:padded]::
|
||||||
|
The object size of the file which is recorded in the index
|
||||||
|
("-" if the object is a `commit` or `tree`).
|
||||||
|
It also supports a padded format of size with "%(objectsize:padded)".
|
||||||
stage::
|
stage::
|
||||||
The stage of the file which is recorded in the index.
|
The stage of the file which is recorded in the index.
|
||||||
eolinfo:index::
|
eolinfo:index::
|
||||||
|
|
|
@ -25,6 +25,9 @@
|
||||||
#include "setup.h"
|
#include "setup.h"
|
||||||
#include "submodule.h"
|
#include "submodule.h"
|
||||||
#include "submodule-config.h"
|
#include "submodule-config.h"
|
||||||
|
#include "object-store.h"
|
||||||
|
#include "hex.h"
|
||||||
|
|
||||||
|
|
||||||
static int abbrev;
|
static int abbrev;
|
||||||
static int show_deleted;
|
static int show_deleted;
|
||||||
|
@ -241,6 +244,24 @@ static void show_submodule(struct repository *superproject,
|
||||||
repo_clear(&subrepo);
|
repo_clear(&subrepo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void expand_objectsize(struct strbuf *line, const struct object_id *oid,
|
||||||
|
const enum object_type type, unsigned int padded)
|
||||||
|
{
|
||||||
|
if (type == OBJ_BLOB) {
|
||||||
|
unsigned long size;
|
||||||
|
if (oid_object_info(the_repository, oid, &size) < 0)
|
||||||
|
die(_("could not get object info about '%s'"),
|
||||||
|
oid_to_hex(oid));
|
||||||
|
if (padded)
|
||||||
|
strbuf_addf(line, "%7"PRIuMAX, (uintmax_t)size);
|
||||||
|
else
|
||||||
|
strbuf_addf(line, "%"PRIuMAX, (uintmax_t)size);
|
||||||
|
} else if (padded) {
|
||||||
|
strbuf_addf(line, "%7s", "-");
|
||||||
|
} else {
|
||||||
|
strbuf_addstr(line, "-");
|
||||||
|
}
|
||||||
|
}
|
||||||
struct show_index_data {
|
struct show_index_data {
|
||||||
const char *pathname;
|
const char *pathname;
|
||||||
struct index_state *istate;
|
struct index_state *istate;
|
||||||
|
@ -272,6 +293,12 @@ static size_t expand_show_index(struct strbuf *sb, const char *start,
|
||||||
strbuf_addf(sb, "%06o", data->ce->ce_mode);
|
strbuf_addf(sb, "%06o", data->ce->ce_mode);
|
||||||
else if (skip_prefix(start, "(objectname)", &p))
|
else if (skip_prefix(start, "(objectname)", &p))
|
||||||
strbuf_add_unique_abbrev(sb, &data->ce->oid, abbrev);
|
strbuf_add_unique_abbrev(sb, &data->ce->oid, abbrev);
|
||||||
|
else if (skip_prefix(start, "(objecttype)", &p))
|
||||||
|
strbuf_addstr(sb, type_name(object_type(data->ce->ce_mode)));
|
||||||
|
else if (skip_prefix(start, "(objectsize:padded)", &p))
|
||||||
|
expand_objectsize(sb, &data->ce->oid, object_type(data->ce->ce_mode), 1);
|
||||||
|
else if (skip_prefix(start, "(objectsize)", &p))
|
||||||
|
expand_objectsize(sb, &data->ce->oid, object_type(data->ce->ce_mode), 0);
|
||||||
else if (skip_prefix(start, "(stage)", &p))
|
else if (skip_prefix(start, "(stage)", &p))
|
||||||
strbuf_addf(sb, "%d", ce_stage(data->ce));
|
strbuf_addf(sb, "%d", ce_stage(data->ce));
|
||||||
else if (skip_prefix(start, "(eolinfo:index)", &p))
|
else if (skip_prefix(start, "(eolinfo:index)", &p))
|
||||||
|
|
|
@ -38,6 +38,41 @@ test_expect_success 'git ls-files --format objectname v.s. -s' '
|
||||||
test_cmp expect actual
|
test_cmp expect actual
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'git ls-files --format objecttype' '
|
||||||
|
git ls-files --format="%(objectname)" o1.txt o4.txt o6.txt >objectname &&
|
||||||
|
git cat-file --batch-check="%(objecttype)" >expect <objectname &&
|
||||||
|
git ls-files --format="%(objecttype)" o1.txt o4.txt o6.txt >actual &&
|
||||||
|
test_cmp expect actual
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'git ls-files --format objectsize' '
|
||||||
|
cat>expect <<-\EOF &&
|
||||||
|
26
|
||||||
|
29
|
||||||
|
27
|
||||||
|
26
|
||||||
|
-
|
||||||
|
26
|
||||||
|
EOF
|
||||||
|
git ls-files --format="%(objectsize)" >actual &&
|
||||||
|
|
||||||
|
test_cmp expect actual
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'git ls-files --format objectsize:padded' '
|
||||||
|
cat>expect <<-\EOF &&
|
||||||
|
26
|
||||||
|
29
|
||||||
|
27
|
||||||
|
26
|
||||||
|
-
|
||||||
|
26
|
||||||
|
EOF
|
||||||
|
git ls-files --format="%(objectsize:padded)" >actual &&
|
||||||
|
|
||||||
|
test_cmp expect actual
|
||||||
|
'
|
||||||
|
|
||||||
test_expect_success 'git ls-files --format v.s. --eol' '
|
test_expect_success 'git ls-files --format v.s. --eol' '
|
||||||
git ls-files --eol >tmp &&
|
git ls-files --eol >tmp &&
|
||||||
sed -e "s/ / /g" -e "s/ */ /g" tmp >expect 2>err &&
|
sed -e "s/ / /g" -e "s/ */ /g" tmp >expect 2>err &&
|
||||||
|
|
Loading…
Reference in New Issue