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

Function stgit_patch_to_mail

builtin/am.c:796–827  ·  view source on GitHub ↗

* A split_mail_conv() callback that converts an StGit patch to an RFC2822 * message suitable for parsing with git-mailinfo. */

Source from the content-addressed store, hash-verified

794 * message suitable for parsing with git-mailinfo.
795 */
796static int stgit_patch_to_mail(FILE *out, FILE *in, int keep_cr UNUSED)
797{
798 struct strbuf sb = STRBUF_INIT;
799 int subject_printed = 0;
800
801 while (!strbuf_getline_lf(&sb, in)) {
802 const char *str;
803
804 if (str_isspace(sb.buf))
805 continue;
806 else if (skip_prefix(sb.buf, "Author:", &str))
807 fprintf(out, "From:%s\n", str);
808 else if (starts_with(sb.buf, "From") || starts_with(sb.buf, "Date"))
809 fprintf(out, "%s\n", sb.buf);
810 else if (!subject_printed) {
811 fprintf(out, "Subject: %s\n", sb.buf);
812 subject_printed = 1;
813 } else {
814 fprintf(out, "\n%s\n", sb.buf);
815 break;
816 }
817 }
818
819 strbuf_reset(&sb);
820 while (strbuf_fread(&sb, 8192, in) > 0) {
821 fwrite(sb.buf, 1, sb.len, out);
822 strbuf_reset(&sb);
823 }
824
825 strbuf_release(&sb);
826 return 0;
827}
828
829/**
830 * This function only supports a single StGit series file in `paths`.

Callers

nothing calls this directly

Calls 5

strbuf_getline_lfFunction · 0.85
str_isspaceFunction · 0.85
starts_withFunction · 0.85
strbuf_freadFunction · 0.85
strbuf_releaseFunction · 0.85

Tested by

no test coverage detected