summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 655c747)
raw | patch | inline | side by side (parent: 655c747)
author | Junio C Hamano <junkio@cox.net> | |
Thu, 6 Oct 2005 21:25:52 +0000 (14:25 -0700) | ||
committer | Junio C Hamano <junkio@cox.net> | |
Thu, 6 Oct 2005 21:25:52 +0000 (14:25 -0700) |
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>
can be specified for the generated filenames.
Signed-off-by: Junio C Hamano <junkio@cox.net>
git-applymbox.sh | patch | blob | history | |
mailsplit.c | patch | blob | history |
diff --git a/git-applymbox.sh b/git-applymbox.sh
index 79abce2a258cd3c4f701f58328bba9b87a029efc..4e77132ab5f73839241c430d6354d5abb8294d85 100755 (executable)
--- a/git-applymbox.sh
+++ b/git-applymbox.sh
'')
rm -rf .dotest
mkdir .dotest
- git-mailsplit "$1" .dotest || exit 1
+ num_msgs=$(git-mailsplit "$1" .dotest) || exit 1
+ echo "$num_msgs patch(es) to process."
shift
esac
diff --git a/mailsplit.c b/mailsplit.c
index 7afea1aaca6af966b6532ba66f7411d897a2874f..bd7c611bb9902281a002f907b6bcf0aa41f58285 100644 (file)
--- a/mailsplit.c
+++ b/mailsplit.c
static int usage(void)
{
- fprintf(stderr, "mailsplit <mbox> <directory>\n");
+ fprintf(stderr, "git-mailsplit [-d<prec>] <mbox> <directory>\n");
exit(1);
}
int main(int argc, char **argv)
{
- int fd, nr;
+ int fd, nr, nr_prec = 4;
struct stat st;
unsigned long size;
void *map;
+ if (argc == 4 && !strncmp(argv[1], "-d", 2)) {
+ nr_prec = strtol(argv[1] + 2, NULL, 10);
+ if (nr_prec < 3 || 10 <= nr_prec)
+ usage();
+ argc--; argv++;
+ }
if (argc != 3)
usage();
fd = open(argv[1], O_RDONLY);
char name[10];
unsigned long len = parse_email(map, size);
assert(len <= size);
- sprintf(name, "%04d", ++nr);
+ sprintf(name, "%0*d", nr_prec, ++nr);
fd = open(name, O_WRONLY | O_CREAT | O_EXCL, 0666);
if (fd < 0) {
perror(name);
map += len;
size -= len;
} while (size > 0);
+ printf("%d\n", nr);
return 0;
}