/// <summary> /// Parse the footer lines (e.g. "Signed-off-by") for machine processing. /// <para /> /// This method splits all of the footer lines out of the last paragraph of /// the commit message, providing each line as a key-value pair, ordered by /// the order of the line's appearance in the commit message itself. /// <para /> /// A footer line's key must match the pattern {@code ^[A-Za-z0-9-]+:}, while /// the value is free-form, but must not contain an LF. Very common keys seen /// in the wild are: /// <ul> /// <li>{@code Signed-off-by} (agrees to Developer Certificate of Origin)</li> /// <li>{@code Acked-by} (thinks change looks sane in context)</li> /// <li>{@code Reported-by} (originally found the issue this change fixes)</li> /// <li>{@code Tested-by} (validated change fixes the issue for them)</li> /// <li>{@code CC}, {@code Cc} (copy on all email related to this change)</li> /// <li>{@code Bug} (link to project's bug tracking system)</li> /// </ul> /// </summary> /// <returns> /// Ordered list of footer lines; empty list if no footers found. /// </returns> public IList <FooterLine> GetFooterLines() { byte[] raw = _buffer; int ptr = raw.Length - 1; while (raw[ptr] == '\n') // trim any trailing LFs, not interesting { ptr--; } int msgB = RawParseUtils.commitMessage(raw, 0); var r = new List <FooterLine>(4); Encoding enc = Encoding; while (true) { ptr = RawParseUtils.prevLF(raw, ptr); if (ptr <= msgB) { break; // Don't parse commit headers as footer lines. } int keyStart = ptr + 2; if (raw[keyStart] == '\n') { break; // Stop at first paragraph break, no footers above it. } int keyEnd = RawParseUtils.endOfFooterLineKey(raw, keyStart); if (keyEnd < 0) { continue; // Not a well formed footer line, skip it. } // Skip over the ': *' at the end of the key before the value. // int valStart = keyEnd + 1; while (valStart < raw.Length && raw[valStart] == ' ') { valStart++; } // Value ends at the LF, and does not include it. // int valEnd = RawParseUtils.nextLF(raw, valStart); if (raw[valEnd - 1] == '\n') { valEnd--; } r.Add(new FooterLine(raw, enc, keyStart, keyEnd, valStart, valEnd)); } r.Reverse(); return(r); }