diff options
author | Junio C Hamano <gitster@pobox.com> | 2013-03-26 12:44:11 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2013-03-26 12:44:11 -0700 |
commit | ece12fd84480fc2bf9d43fc8c6be3aed4ada8ccc (patch) | |
tree | ff07e9c41f8f20c327f63cf8bd4f74a7ef67f502 /builtin | |
parent | 7d2726c3933538e5f256846a2bb38e1065c868b5 (diff) | |
parent | 18505c34237d3544729c3deed3e4f851fb672086 (diff) | |
download | git-ece12fd84480fc2bf9d43fc8c6be3aed4ada8ccc.tar.gz git-ece12fd84480fc2bf9d43fc8c6be3aed4ada8ccc.tar.xz |
Merge branch 'jk/mailsplit-maildir-muttsort' into maint
Sort filenames read from the maildir/ in a way that is more likely
to sort messages in the order the writing MUA meant to, by sorting
numeric segment in numeric order and non-numeric segment in
alphabetical order.
* jk/mailsplit-maildir-muttsort:
mailsplit: sort maildir filenames more cleverly
Diffstat (limited to 'builtin')
-rw-r--r-- | builtin/mailsplit.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/builtin/mailsplit.c b/builtin/mailsplit.c index 2d4327801..06296d4bd 100644 --- a/builtin/mailsplit.c +++ b/builtin/mailsplit.c @@ -130,6 +130,27 @@ static int populate_maildir_list(struct string_list *list, const char *path) return 0; } +static int maildir_filename_cmp(const char *a, const char *b) +{ + while (*a && *b) { + if (isdigit(*a) && isdigit(*b)) { + long int na, nb; + na = strtol(a, (char **)&a, 10); + nb = strtol(b, (char **)&b, 10); + if (na != nb) + return na - nb; + /* strtol advanced our pointers */ + } + else { + if (*a != *b) + return (unsigned char)*a - (unsigned char)*b; + a++; + b++; + } + } + return (unsigned char)*a - (unsigned char)*b; +} + static int split_maildir(const char *maildir, const char *dir, int nr_prec, int skip) { @@ -139,6 +160,8 @@ static int split_maildir(const char *maildir, const char *dir, int i; struct string_list list = STRING_LIST_INIT_DUP; + list.cmp = maildir_filename_cmp; + if (populate_maildir_list(&list, maildir) < 0) goto out; |