Merge refs/heads/portable from http://www.cs.berkeley.edu/~ejr/gits/git.git
[gitweb.git] / tools / mailinfo.c
index 5a857f711a0de4e9d098d3c1a7ca23ead0030384..a36123a1f5bc27e90debcf19d5348937c738d2f2 100644 (file)
@@ -9,6 +9,7 @@
 
 static FILE *cmitmsg, *patchfile;
 
+static int keep_subject = 0;
 static char line[1000];
 static char date[1000];
 static char name[1000];
@@ -101,6 +102,8 @@ static void check_line(char *line, int len)
 
 static char * cleanup_subject(char *subject)
 {
+       if (keep_subject)
+               return subject;
        for (;;) {
                char *p;
                int len, remove;
@@ -152,13 +155,13 @@ static void cleanup_space(char *buf)
 
 static void handle_rest(void)
 {
+       FILE *out = cmitmsg;
        char *sub = cleanup_subject(subject);
        cleanup_space(name);
        cleanup_space(date);
        cleanup_space(email);
        cleanup_space(sub);
        printf("Author: %s\nEmail: %s\nSubject: %s\nDate: %s\n\n", name, email, sub, date);
-       FILE *out = cmitmsg;
 
        do {
                if (!memcmp("diff -", line, 6) ||
@@ -242,8 +245,20 @@ static void usage(void)
        exit(1);
 }
 
+static const char mailinfo_usage[] =
+"git-mailinfo [-k] msg patch <mail >info";
 int main(int argc, char ** argv)
 {
+       while (1 < argc && argv[1][0] == '-') {
+               if (!strcmp(argv[1], "-k"))
+                       keep_subject = 1;
+               else {
+                       fprintf(stderr, "usage: %s\n", mailinfo_usage);
+                       exit(1);
+               }
+               argc--; argv++;
+       }
+
        if (argc != 3)
                usage();
        cmitmsg = fopen(argv[1], "w");