summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 3cb8caf)
raw | patch | inline | side by side (parent: 3cb8caf)
author | Petr Baudis <pasky@suse.cz> | |
Mon, 3 Jul 2006 20:48:01 +0000 (22:48 +0200) | ||
committer | Junio C Hamano <junkio@cox.net> | |
Tue, 4 Jul 2006 01:35:23 +0000 (18:35 -0700) |
These methods can retrieve/parse the author/committer ident.
Signed-off-by: Petr Baudis <pasky@suse.cz>
Signed-off-by: Junio C Hamano <junkio@cox.net>
Signed-off-by: Petr Baudis <pasky@suse.cz>
Signed-off-by: Junio C Hamano <junkio@cox.net>
git-send-email.perl | patch | blob | history | |
perl/Git.pm | patch | blob | history |
diff --git a/git-send-email.perl b/git-send-email.perl
index e794e4492551fe5eaad60950ee74fa94ef01eca6..79e82f5a8069362ccf41723df7db017228cd97bf 100755 (executable)
--- a/git-send-email.perl
+++ b/git-send-email.perl
# Now, let's fill any that aren't set in with defaults:
-sub gitvar_ident {
- my ($name) = @_;
- my $val = $repo->command('var', $name);
- my @field = split(/\s+/, $val);
- return join(' ', @field[0...(@field-3)]);
-}
-
-my ($author) = gitvar_ident('GIT_AUTHOR_IDENT');
-my ($committer) = gitvar_ident('GIT_COMMITTER_IDENT');
+my ($author) = $repo->ident_person('author');
+my ($committer) = $repo->ident_person('committer');
my %aliases;
my @alias_files = $repo->config('sendemail.aliasesfile');
diff --git a/perl/Git.pm b/perl/Git.pm
index 24fd7ce25c20f85cea10fb8ffec1cebf9c38a6af..9ce9fcdd3ec95f08a7bf6c00bdd6da2931c01cde 100644 (file)
--- a/perl/Git.pm
+++ b/perl/Git.pm
}
+=item ident ( TYPE | IDENTSTR )
+
+=item ident_person ( TYPE | IDENTSTR | IDENTARRAY )
+
+This suite of functions retrieves and parses ident information, as stored
+in the commit and tag objects or produced by C<var GIT_type_IDENT> (thus
+C<TYPE> can be either I<author> or I<committer>; case is insignificant).
+
+The C<ident> method retrieves the ident information from C<git-var>
+and either returns it as a scalar string or as an array with the fields parsed.
+Alternatively, it can take a prepared ident string (e.g. from the commit
+object) and just parse it.
+
+C<ident_person> returns the person part of the ident - name and email;
+it can take the same arguments as C<ident> or the array returned by C<ident>.
+
+The synopsis is like:
+
+ my ($name, $email, $time_tz) = ident('author');
+ "$name <$email>" eq ident_person('author');
+ "$name <$email>" eq ident_person($name);
+ $time_tz =~ /^\d+ [+-]\d{4}$/;
+
+Both methods must be called on a repository instance.
+
+=cut
+
+sub ident {
+ my ($self, $type) = @_;
+ my $identstr;
+ if (lc $type eq lc 'committer' or lc $type eq lc 'author') {
+ $identstr = $self->command_oneline('var', 'GIT_'.uc($type).'_IDENT');
+ } else {
+ $identstr = $type;
+ }
+ if (wantarray) {
+ return $identstr =~ /^(.*) <(.*)> (\d+ [+-]\d{4})$/;
+ } else {
+ return $identstr;
+ }
+}
+
+sub ident_person {
+ my ($self, @ident) = @_;
+ $#ident == 0 and @ident = $self->ident($ident[0]);
+ return "$ident[0] <$ident[1]>";
+}
+
+
=item hash_object ( TYPE, FILENAME )
=item hash_object ( TYPE, FILEHANDLE )