MCPcopy Index your code
hub / github.com/git/git / format_commit_item

Function format_commit_item

pretty.c:1906–1964  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1904}
1905
1906static size_t format_commit_item(struct strbuf *sb, /* in UTF-8 */
1907 const char *placeholder,
1908 struct format_commit_context *context)
1909{
1910 size_t consumed, orig_len;
1911 enum {
1912 NO_MAGIC,
1913 ADD_LF_BEFORE_NON_EMPTY,
1914 DEL_LF_BEFORE_EMPTY,
1915 ADD_SP_BEFORE_NON_EMPTY
1916 } magic = NO_MAGIC;
1917
1918 switch (placeholder[0]) {
1919 case '-':
1920 magic = DEL_LF_BEFORE_EMPTY;
1921 break;
1922 case '+':
1923 magic = ADD_LF_BEFORE_NON_EMPTY;
1924 break;
1925 case ' ':
1926 magic = ADD_SP_BEFORE_NON_EMPTY;
1927 break;
1928 default:
1929 break;
1930 }
1931 if (magic != NO_MAGIC) {
1932 placeholder++;
1933
1934 switch (placeholder[0]) {
1935 case 'w':
1936 /*
1937 * `%+w()` cannot ever expand to a non-empty string,
1938 * and it potentially changes the layout of preceding
1939 * contents. We're thus not able to handle the magic in
1940 * this combination and refuse the pattern.
1941 */
1942 return 0;
1943 };
1944 }
1945
1946 orig_len = sb->len;
1947 if (context->flush_type == no_flush)
1948 consumed = format_commit_one(sb, placeholder, context);
1949 else
1950 consumed = format_and_pad_commit(sb, placeholder, context);
1951 if (magic == NO_MAGIC)
1952 return consumed;
1953
1954 if ((orig_len == sb->len) && magic == DEL_LF_BEFORE_EMPTY) {
1955 while (sb->len && sb->buf[sb->len - 1] == '\n')
1956 strbuf_setlen(sb, sb->len - 1);
1957 } else if (orig_len != sb->len) {
1958 if (magic == ADD_LF_BEFORE_NON_EMPTY)
1959 strbuf_insertstr(sb, orig_len, "\n");
1960 else if (magic == ADD_SP_BEFORE_NON_EMPTY)
1961 strbuf_insertstr(sb, orig_len, " ");
1962 }
1963 return consumed + 1;

Callers 1

Calls 4

format_commit_oneFunction · 0.85
format_and_pad_commitFunction · 0.85
strbuf_setlenFunction · 0.85
strbuf_insertstrFunction · 0.85

Tested by

no test coverage detected