summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrandon Williams <bmwill@google.com>2017-06-12 15:14:08 -0700
committerJunio C Hamano <gitster@pobox.com>2017-06-13 11:40:52 -0700
commita84f3e59ebde9e891275ef8325c432db6bdf950c (patch)
tree2c0feb7e43526d8bbc495cff58c759bc7aa74d3e
parent5306ccf9e9ec7204eef409e90b57ddf23b8f5ca6 (diff)
downloadgit-bw/ls-files-sans-the-index.tar.gz
ls-files: factor out tag calculationbw/ls-files-sans-the-index
Signed-off-by: Brandon Williams <bmwill@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--builtin/ls-files.c41
1 files changed, 25 insertions, 16 deletions
diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index c9307f9ef4..cdc1cfdd26 100644
--- a/builtin/ls-files.c
+++ b/builtin/ls-files.c
@@ -93,6 +93,30 @@ static void write_name(const char *name)
strbuf_release(&full_name);
}
+static const char *get_tag(const struct cache_entry *ce, const char *tag)
+{
+ static char alttag[4];
+
+ if (tag && *tag && show_valid_bit && (ce->ce_flags & CE_VALID)) {
+ memcpy(alttag, tag, 3);
+
+ if (isalpha(tag[0])) {
+ alttag[0] = tolower(tag[0]);
+ } else if (tag[0] == '?') {
+ alttag[0] = '!';
+ } else {
+ alttag[0] = 'v';
+ alttag[1] = tag[0];
+ alttag[2] = ' ';
+ alttag[3] = 0;
+ }
+
+ tag = alttag;
+ }
+
+ return tag;
+}
+
static void print_debug(const struct cache_entry *ce)
{
if (debug_mode) {
@@ -264,22 +288,7 @@ static void show_ce_entry(const struct index_state *istate,
len, ps_matched,
S_ISDIR(ce->ce_mode) ||
S_ISGITLINK(ce->ce_mode))) {
- if (tag && *tag && show_valid_bit &&
- (ce->ce_flags & CE_VALID)) {
- static char alttag[4];
- memcpy(alttag, tag, 3);
- if (isalpha(tag[0]))
- alttag[0] = tolower(tag[0]);
- else if (tag[0] == '?')
- alttag[0] = '!';
- else {
- alttag[0] = 'v';
- alttag[1] = tag[0];
- alttag[2] = ' ';
- alttag[3] = 0;
- }
- tag = alttag;
- }
+ tag = get_tag(ce, tag);
if (!show_stage) {
fputs(tag, stdout);