Commit c1f3e90a authored by Robert Ricci's avatar Robert Ricci
Browse files

Add clone URLs to commit messages

... seems useful enough that we ought to just do it by default.

Works fine on our server because the hostname is set right and the
path works out fine. Might work less well on servers configured
differently.
parent f4f1cb04
......@@ -264,6 +264,12 @@ my $max_patches = get_config("maxpatches",20);
#
my $gitweb_url = get_config("gitweburl",undef);
#
# If true, include clone URLs in the mail. These will be guessed from
# the local hostname and the path
#
my $include_urls = get_config("includeurls",1);
######################################################################
# Constants
######################################################################
......@@ -299,6 +305,12 @@ my $CT_DELETE = "delete";
my $CT_REWIND = "rewind";
my $CT_REBASE = "rebase";
#
# Types of clone URLs
#
my $CLONE_SSH = "ssh";
my $CLONE_PUBLIC = "public";
#
# Tired of typing this and getting it wrong
#
......@@ -328,6 +340,7 @@ sub filter_out_objects_in_repo($@);
sub generate_messageid();
sub get_hostname();
sub get_pathname();
sub get_clone_url($);
######################################################################
# Main Body
......@@ -846,6 +859,23 @@ sub commit_mail($$$\@$@) {
$actionstring .= "\n\n";
#
# Show clone URLs
#
my $cloneurls = "";
if ($include_urls) {
my $ssh_url = get_clone_url($CLONE_SSH);
my $public_url = get_clone_url($CLONE_PUBLIC);
$cloneurls .= "Clone via ssh: $ssh_url\n";
if ($public_url) {
# This one might not be set, since the repo may only be
# accessable through ssh
$cloneurls .= "Clone read-only: $public_url\n";
}
$cloneurls .= "\n";
}
#
# Make a pretty summary of commits if there are enough of them
#
......@@ -955,6 +985,7 @@ sub commit_mail($$$\@$@) {
if (!$separate_mail && @commitmessages) {
send_mail($subject,
$actionstring .
$cloneurls .
$summary .
join($SEP, map { join "",@$_} @commitmessages) .
(scalar(@patches) ? "$BODYSEP" : "") .
......@@ -1336,3 +1367,32 @@ sub get_pathname() {
chomp $pwd;
return $pwd;
}
#
# Returns a URL for cloning the repo, or undef if it can't figure it out
#
sub get_clone_url($) {
my ($type) = @_;
my $hostname = get_hostname();
my $path = get_pathname();
if ($type eq $CLONE_SSH) {
return "$hostname:$path";
}
if ($type eq $CLONE_PUBLIC) {
# Check to see if this repo is exported publicly - only method
# supported at the moment is anonymous git URLs; would be good to
# support http/https in the future
if (-e "$path/git-daemon-export-ok") {
my $reponame = `basename $path`;
chomp $reponame;
return "git://$hostname/$reponame";
} else {
return undef;
}
}
return undef;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment