@matheusbsbs / matheus-bagliano / commits / e11fc02066
Fork 0

mailsplit: -d<prec>

Instead of the default 4 digits with leading zeros, different precision can be specified for the generated filenames. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Oct 6, 2005 at 14:25 UTC e11fc02066435b0f370d639e665ec70680e876a6
2 files changed +12 -4
git-applymbox.sh
+2 -1
@@ -42,7 +42,8 @@ case "$continue" in
42 '')
43 rm -rf .dotest
44 mkdir .dotest
45 - git-mailsplit "$1" .dotest || exit 1
45 + num_msgs=$(git-mailsplit "$1" .dotest) || exit 1
46 + echo "$num_msgs patch(es) to process."
47 shift
48 esac
49
mailsplit.c
+10 -3
@@ -17,7 +17,7 @@
17
18 static int usage(void)
19 {
20 - fprintf(stderr, "mailsplit <mbox> <directory>\n");
20 + fprintf(stderr, "git-mailsplit [-d<prec>] <mbox> <directory>\n");
21 exit(1);
22 }
23
@@ -96,11 +96,17 @@ corrupt:
96
97 int main(int argc, char **argv)
98 {
99 - int fd, nr;
99 + int fd, nr, nr_prec = 4;
100 struct stat st;
101 unsigned long size;
102 void *map;
103
104 + if (argc == 4 && !strncmp(argv[1], "-d", 2)) {
105 + nr_prec = strtol(argv[1] + 2, NULL, 10);
106 + if (nr_prec < 3 || 10 <= nr_prec)
107 + usage();
108 + argc--; argv++;
109 + }
110 if (argc != 3)
111 usage();
112 fd = open(argv[1], O_RDONLY);
@@ -127,7 +133,7 @@ int main(int argc, char **argv)
133 char name[10];
134 unsigned long len = parse_email(map, size);
135 assert(len <= size);
130 - sprintf(name, "%04d", ++nr);
136 + sprintf(name, "%0*d", nr_prec, ++nr);
137 fd = open(name, O_WRONLY | O_CREAT | O_EXCL, 0666);
138 if (fd < 0) {
139 perror(name);
@@ -141,5 +147,6 @@ int main(int argc, char **argv)
147 map += len;
148 size -= len;
149 } while (size > 0);
150 + printf("%d\n", nr);
151 return 0;
152 }