MCPcopy Create free account
hub / github.com/git/git / gather_stats

Function gather_stats

convert.c:45–88  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

43};
44
45static void gather_stats(const char *buf, unsigned long size, struct text_stat *stats)
46{
47 unsigned long i;
48
49 memset(stats, 0, sizeof(*stats));
50
51 for (i = 0; i < size; i++) {
52 unsigned char c = buf[i];
53 if (c == '\r') {
54 if (i+1 < size && buf[i+1] == '\n') {
55 stats->crlf++;
56 i++;
57 } else
58 stats->lonecr++;
59 continue;
60 }
61 if (c == '\n') {
62 stats->lonelf++;
63 continue;
64 }
65 if (c == 127)
66 /* DEL */
67 stats->nonprintable++;
68 else if (c < 32) {
69 switch (c) {
70 /* BS, HT, ESC and FF */
71 case '\b': case '\t': case '\033': case '\014':
72 stats->printable++;
73 break;
74 case 0:
75 stats->nul++;
76 /* fall through */
77 default:
78 stats->nonprintable++;
79 }
80 }
81 else
82 stats->printable++;
83 }
84
85 /* If file ends with EOF then don't count this EOF as non-printable. */
86 if (size >= 1 && buf[size-1] == '\032')
87 stats->nonprintable--;
88}
89
90/*
91 * The same heuristics as diff.c::mmfile_is_binary()

Callers 3

gather_convert_statsFunction · 0.85
crlf_to_gitFunction · 0.85
crlf_to_worktreeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected