This simplifies our code a bit, and hopefully in public-inbox, too.
There is little practical danger of a Message-ID not having '<>',
and having '<>' in all URLs is annoying.
This breaks compatibility. Fortunately, this project is not
publically announced, yet.
A Message-ID may be extremely long and also contain slashes, so using
them as a path name is challenging. Instead we use the SHA-1 hexdigest
-of the Message-ID (including the "<" and ">") to generate a path name.
-Leading and trailing white space in the Message-ID header is ignored
-for hashing.
+of the Message-ID (excluding the leading "<" and trailing ">") to
+generate a path name. Leading and trailing white space in the
+Message-ID header is ignored for hashing.
A message with Message-ID of: <20131106023245.GA20224@dcvr.yhbt.net>
-Would be stored as: 21/4527ce3741f50bb9afa65e7c5003c8a8ddc4b1
+Would be stored as: f2/8c6cfd2b0a65f994c3e1be266105413b3d3f63
Thus it is easy to look up the contents of a message matching a given
a Message-ID.
sub midextract {
my ($self, $message_id, $mbox) = @_;
$self->{git}->tmp_git_do(sub {
- # leaving <> out of Message-IDs on the command-line is
- # common and practical since it frees the user from
- # quoting/escaping in most cases, so do not require
- # Message-IDs have <> around them
- if ($message_id =~ /\A<.+>\z/) { # rare
- $self->_midextract($message_id, $mbox);
- } else { # common
- eval { # try with additional <> first
- my $tmpid = "<$message_id>";
- $self->_midextract($tmpid, $mbox);
- };
- $self->_midextract($message_id, $mbox) if $@;
- }
+ $self->_midextract($message_id, $mbox);
});
}
sub mid2path {
my ($self, $message_id) = @_;
stripws($message_id);
+ $message_id =~ s/\A<//;
+ $message_id =~ s/>\z//;
my $hex = sha1_hex($message_id);
$hex =~ /\A([a-f0-9]{2})([a-f0-9]{38})\z/i or
die "BUG: not a SHA-1 hex: $hex";
local $ENV{GIT_DIR} = "$tmpdir/gittest";
-my $blob_id = sha1_hex("<666\@example.com>");
+my $blob_id = sha1_hex("666\@example.com");
my ($dir, $base) = ($blob_id =~ m!\A([a-f0-9]{2})([a-f0-9]{38})\z!);
ok(defined $dir && defined $base, "bad sha1: $blob_id");
my $mid = $simple->header("message-id");
my $path_sha1 = $path;
$path_sha1 =~ tr!/!!d;
+ $mid =~ tr/<>//d;
is($path_sha1, sha1_hex($mid), "path mapping works $mid");
}