git-notify 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675
  1. #!/usr/bin/perl -w
  2. #
  3. # Tool to send git commit notifications
  4. #
  5. # Copyright 2005 Alexandre Julliard
  6. # Copyright 2009 Nagios Plugins Development Team
  7. #
  8. # This program is free software; you can redistribute it and/or
  9. # modify it under the terms of the GNU General Public License as
  10. # published by the Free Software Foundation; either version 2 of
  11. # the License, or (at your option) any later version.
  12. #
  13. #
  14. # This script is meant to be called from .git/hooks/post-receive.
  15. #
  16. # Usage: git-notify [options] [--] old-sha1 new-sha1 refname
  17. #
  18. # -A Omit the author name from the mail subject
  19. # -C Show committer in the body if different from the author
  20. # -c name Send CIA notifications under specified project name
  21. # -m addr Send mail notifications to specified address
  22. # -n max Set max number of individual mails to send
  23. # -r name Set the git repository name
  24. # -S Enable compatibility with SourceForge's gitweb URLs
  25. # -s bytes Set the maximum diff size in bytes (-1 for no limit)
  26. # -T Prefix the mail subject with a [repository name] tag
  27. # -t file Prevent duplicate notifications by saving state to this file
  28. # -U mask Set the umask for creating the state file
  29. # -u url Set the URL to the gitweb browser
  30. # -i branch If at least one -i is given, report only for specified branches
  31. # -x branch Exclude changes to the specified branch from reports
  32. # -X Exclude merge commits
  33. # -z Try to abbreviate the SHA1 name within gitweb URLs (unsafe)
  34. #
  35. use strict;
  36. use Fcntl ':flock';
  37. use Encode qw(encode decode);
  38. use Cwd 'realpath';
  39. sub git_config($);
  40. sub get_repos_name();
  41. # some parameters you may want to change
  42. # sendmail's pathname
  43. my $sendmail = "/usr/sbin/sendmail";
  44. # CIA notification address
  45. my $cia_address = "cia\@cia.vc";
  46. # debug mode
  47. my $debug = 0;
  48. # configuration parameters
  49. # omit the author from the mail subject (can be set with the -A option)
  50. my $omit_author = git_config( "notify.omitauthor" );
  51. # prefix the mail subject with a [repository name] tag (can be set with the -T option)
  52. my $emit_repo = git_config( "notify.emitrepository" );
  53. # show the committer if different from the author (can be set with the -C option)
  54. my $show_committer = git_config( "notify.showcommitter" );
  55. # base URL of the gitweb repository browser (can be set with the -u option)
  56. my $gitweb_url = git_config( "notify.baseurl" );
  57. # abbreviate the SHA1 name within gitweb URLs (can be set with the -z option)
  58. my $abbreviate_url = git_config( "notify.shorturls" );
  59. # enable compatibility with SourceForge's gitweb (can be set with the -S option)
  60. my $sourceforge = git_config( "notify.sourceforge" );
  61. # default repository name (can be changed with the -r option)
  62. my $repos_name = git_config( "notify.repository" ) || get_repos_name();
  63. # max size of diffs in bytes (can be changed with the -s option)
  64. my $max_diff_size = git_config( "notify.maxdiff" ) || 10000;
  65. # address for mail notices (can be set with -m option)
  66. my $commitlist_address = git_config( "notify.mail" );
  67. # project name for CIA notices (can be set with -c option)
  68. my $cia_project_name = git_config( "notify.cia" );
  69. # max number of individual notices before falling back to a single global notice (can be set with -n option)
  70. my $max_individual_notices = git_config( "notify.maxnotices" ) || 100;
  71. # branches to include
  72. my @include_list = split /\s+/, git_config( "notify.include" ) || "";
  73. # branches to exclude
  74. my @exclude_list = split /\s+/, git_config( "notify.exclude" ) || "";
  75. # the state file we use (can be set with the -t option)
  76. my $state_file = git_config( "notify.statefile" );
  77. # umask for creating the state file (can be set with -U option)
  78. my $mode_mask = git_config( "notify.umask" ) || 002;
  79. # Extra options to git rev-list
  80. my @revlist_options;
  81. sub usage()
  82. {
  83. print "Usage: $0 [options] [--] old-sha1 new-sha1 refname\n";
  84. print " -A Omit the author name from the mail subject\n";
  85. print " -C Show committer in the body if different from the author\n";
  86. print " -c name Send CIA notifications under specified project name\n";
  87. print " -m addr Send mail notifications to specified address\n";
  88. print " -n max Set max number of individual mails to send\n";
  89. print " -r name Set the git repository name\n";
  90. print " -S Enable compatibility with SourceForge's gitweb URLs\n";
  91. print " -s bytes Set the maximum diff size in bytes (-1 for no limit)\n";
  92. print " -T Prefix the mail subject with a [repository name] tag\n";
  93. print " -t file Prevent duplicate notifications by saving state to this file\n";
  94. print " -U mask Set the umask for creating the state file\n";
  95. print " -u url Set the URL to the gitweb browser\n";
  96. print " -i branch If at least one -i is given, report only for specified branches\n";
  97. print " -x branch Exclude changes to the specified branch from reports\n";
  98. print " -X Exclude merge commits\n";
  99. print " -z Try to abbreviate the SHA1 name within gitweb URLs (unsafe)\n";
  100. exit 1;
  101. }
  102. sub xml_escape($)
  103. {
  104. my $str = shift;
  105. $str =~ s/&/&/g;
  106. $str =~ s/</&lt;/g;
  107. $str =~ s/>/&gt;/g;
  108. my @chars = unpack "U*", $str;
  109. $str = join "", map { ($_ > 127) ? sprintf "&#%u;", $_ : chr($_); } @chars;
  110. return $str;
  111. }
  112. # execute git-rev-list(1) with the given parameters and return the output
  113. sub git_rev_list(@)
  114. {
  115. my @args = @_;
  116. my $revlist = [];
  117. my $pid = open REVLIST, "-|";
  118. die "Cannot open pipe: $!" if not defined $pid;
  119. if (!$pid)
  120. {
  121. exec "git", "rev-list", "--reverse", @revlist_options, @args or die "Cannot execute rev-list: $!";
  122. }
  123. while (<REVLIST>)
  124. {
  125. chomp;
  126. unless (grep {$_ eq "--pretty"} @args)
  127. {
  128. die "Invalid commit: $_" if not /^[0-9a-f]{40}$/;
  129. }
  130. push @$revlist, $_;
  131. }
  132. close REVLIST or die $! ? "Cannot execute rev-list: $!" : "rev-list exited with status: $?";
  133. return $revlist;
  134. }
  135. # append the given commit hashes to the state file
  136. sub save_commits($)
  137. {
  138. my $commits = shift;
  139. open STATE, ">>", $state_file or die "Cannot open $state_file: $!";
  140. flock STATE, LOCK_EX or die "Cannot lock $state_file";
  141. print STATE "$_\n" for @$commits;
  142. flock STATE, LOCK_UN or die "Cannot unlock $state_file";
  143. close STATE or die "Cannot close $state_file: $!";
  144. }
  145. # for the given range, return the new hashes (and append them to the state file)
  146. sub get_new_commits($$)
  147. {
  148. my ($old_sha1, $new_sha1) = @_;
  149. my ($seen, @args);
  150. my $newrevs = [];
  151. @args = ( "^$old_sha1" ) unless $old_sha1 eq '0' x 40;
  152. push @args, $new_sha1, @exclude_list;
  153. my $revlist = git_rev_list(@args);
  154. if (not defined $state_file or not -e $state_file)
  155. {
  156. save_commits(git_rev_list("--all", "--full-history")) if defined $state_file;
  157. return $revlist;
  158. }
  159. open STATE, $state_file or die "Cannot open $state_file: $!";
  160. flock STATE, LOCK_SH or die "Cannot lock $state_file";
  161. while (<STATE>)
  162. {
  163. chomp;
  164. die "Invalid commit: $_" if not /^[0-9a-f]{40}$/;
  165. $seen->{$_} = 1;
  166. }
  167. flock STATE, LOCK_UN or die "Cannot unlock $state_file";
  168. close STATE or die "Cannot close $state_file: $!";
  169. # FIXME: if another git-notify process reads the $state_file at *this*
  170. # point, that process might generate duplicates of our notifications.
  171. save_commits($revlist);
  172. foreach my $commit (@$revlist)
  173. {
  174. push @$newrevs, $commit unless $seen->{$commit};
  175. }
  176. return $newrevs;
  177. }
  178. # truncate the given string if it exceeds the specified number of characters
  179. sub truncate_str($$)
  180. {
  181. my ($str, $max) = @_;
  182. if (length($str) > $max)
  183. {
  184. $str = substr($str, 0, $max);
  185. $str =~ s/\s+\S+$//;
  186. $str .= " ...";
  187. }
  188. return $str;
  189. }
  190. # right-justify the left column of "left: right" elements, omit undefined elements
  191. sub format_table(@)
  192. {
  193. my @lines = @_;
  194. my @table;
  195. my $max = 0;
  196. foreach my $line (@lines)
  197. {
  198. next if not defined $line;
  199. my $pos = index($line, ":");
  200. $max = $pos if $pos > $max;
  201. }
  202. foreach my $line (@lines)
  203. {
  204. next if not defined $line;
  205. my ($left, $right) = split(/: */, $line, 2);
  206. push @table, (defined $left and defined $right)
  207. ? sprintf("%*s: %s", $max + 1, $left, $right)
  208. : $line;
  209. }
  210. return @table;
  211. }
  212. # format an integer date + timezone as string
  213. # algorithm taken from git's date.c
  214. sub format_date($$)
  215. {
  216. my ($time,$tz) = @_;
  217. if ($tz < 0)
  218. {
  219. my $minutes = (-$tz / 100) * 60 + (-$tz % 100);
  220. $time -= $minutes * 60;
  221. }
  222. else
  223. {
  224. my $minutes = ($tz / 100) * 60 + ($tz % 100);
  225. $time += $minutes * 60;
  226. }
  227. return gmtime($time) . sprintf " %+05d", $tz;
  228. }
  229. # fetch a parameter from the git config file
  230. sub git_config($)
  231. {
  232. my ($param) = @_;
  233. open CONFIG, "-|" or exec "git", "config", $param;
  234. my $ret = <CONFIG>;
  235. chomp $ret if $ret;
  236. close CONFIG or $ret = undef;
  237. return $ret;
  238. }
  239. # parse command line options
  240. sub parse_options()
  241. {
  242. while (@ARGV && $ARGV[0] =~ /^-/)
  243. {
  244. my $arg = shift @ARGV;
  245. if ($arg eq '--') { last; }
  246. elsif ($arg eq '-A') { $omit_author = 1; }
  247. elsif ($arg eq '-C') { $show_committer = 1; }
  248. elsif ($arg eq '-c') { $cia_project_name = shift @ARGV; }
  249. elsif ($arg eq '-m') { $commitlist_address = shift @ARGV; }
  250. elsif ($arg eq '-n') { $max_individual_notices = shift @ARGV; }
  251. elsif ($arg eq '-r') { $repos_name = shift @ARGV; }
  252. elsif ($arg eq '-S') { $sourceforge = 1; }
  253. elsif ($arg eq '-s') { $max_diff_size = shift @ARGV; }
  254. elsif ($arg eq '-T') { $emit_repo = 1; }
  255. elsif ($arg eq '-t') { $state_file = shift @ARGV; }
  256. elsif ($arg eq '-U') { $mode_mask = shift @ARGV; }
  257. elsif ($arg eq '-u') { $gitweb_url = shift @ARGV; }
  258. elsif ($arg eq '-i') { push @include_list, shift @ARGV; }
  259. elsif ($arg eq '-x') { push @exclude_list, shift @ARGV; }
  260. elsif ($arg eq '-X') { push @revlist_options, "--no-merges"; }
  261. elsif ($arg eq '-z') { $abbreviate_url = 1; }
  262. elsif ($arg eq '-d') { $debug++; }
  263. else { usage(); }
  264. }
  265. if (@ARGV && $#ARGV != 2) { usage(); }
  266. @exclude_list = map { "^$_"; } @exclude_list;
  267. }
  268. # send an email notification
  269. sub mail_notification($$$@)
  270. {
  271. my ($name, $subject, $content_type, @text) = @_;
  272. $subject = "[$repos_name] $subject" if ($emit_repo and $name ne $cia_address);
  273. $subject = encode("MIME-Q",$subject);
  274. my @header = ("To: $name", "Subject: $subject", "Content-Type: $content_type");
  275. if ($debug)
  276. {
  277. binmode STDOUT, ":utf8";
  278. print "---------------------\n";
  279. print join("\n", @header), "\n\n", join("\n", @text), "\n";
  280. }
  281. else
  282. {
  283. my $pid = open MAIL, "|-";
  284. return unless defined $pid;
  285. if (!$pid)
  286. {
  287. exec $sendmail, "-t", "-oi", "-oem" or die "Cannot exec $sendmail";
  288. }
  289. binmode MAIL, ":utf8";
  290. print MAIL join("\n", @header), "\n\n", join("\n", @text), "\n";
  291. close MAIL or warn $! ? "Cannot execute $sendmail: $!" : "$sendmail exited with status: $?";
  292. }
  293. }
  294. # get the default repository name
  295. sub get_repos_name()
  296. {
  297. my $dir = `git rev-parse --git-dir`;
  298. chomp $dir;
  299. my $repos = realpath($dir);
  300. $repos =~ s/(.*?)((\.git\/)?\.git)$/$1/;
  301. $repos =~ s/(.*)\/([^\/]+)\/?$/$2/;
  302. return $repos;
  303. }
  304. # return the type of the given object
  305. sub get_object_type($)
  306. {
  307. my $obj = shift;
  308. open TYPE, "-|" or exec "git", "cat-file", "-t", $obj or die "cannot run git-cat-file";
  309. my $type = <TYPE>;
  310. chomp $type;
  311. close TYPE or die $! ? "Cannot execute cat-file: $!" : "cat-file exited with status: $?";
  312. return $type;
  313. }
  314. # extract the information from a commit or tag object and return a hash containing the various fields
  315. sub get_object_info($)
  316. {
  317. my $obj = shift;
  318. my %info = ();
  319. my @log = ();
  320. my $do_log = 0;
  321. $info{"encoding"} = "utf-8";
  322. my $type = get_object_type($obj);
  323. open OBJ, "-|" or exec "git", "cat-file", $type, $obj or die "cannot run git-cat-file";
  324. while (<OBJ>)
  325. {
  326. chomp;
  327. if ($do_log)
  328. {
  329. last if /^-----BEGIN PGP SIGNATURE-----/;
  330. push @log, $_;
  331. }
  332. elsif (/^(author|committer|tagger) ((.*) (<.*>)) (\d+) ([+-]\d+)$/)
  333. {
  334. $info{$1} = $2;
  335. $info{$1 . "_name"} = $3;
  336. $info{$1 . "_email"} = $4;
  337. $info{$1 . "_date"} = $5;
  338. $info{$1 . "_tz"} = $6;
  339. }
  340. elsif (/^tag (.+)/)
  341. {
  342. $info{"tag"} = $1;
  343. }
  344. elsif (/^encoding (.+)/)
  345. {
  346. $info{"encoding"} = $1;
  347. }
  348. elsif (/^$/) { $do_log = 1; }
  349. }
  350. close OBJ or die $! ? "Cannot execute cat-file: $!" : "cat-file exited with status: $?";
  351. $info{"type"} = $type;
  352. $info{"log"} = \@log;
  353. return %info;
  354. }
  355. # send a ref change notice to a mailing list
  356. sub send_ref_notice($$@)
  357. {
  358. my ($ref, $action, @notice) = @_;
  359. my ($reftype, $refname) = ($ref =~ /^refs\/(head|tag)s\/(.+)/);
  360. $reftype =~ s/^head$/branch/;
  361. @notice = (format_table(
  362. "Module: $repos_name",
  363. ($reftype eq "tag" ? "Tag:" : "Branch:") . $refname,
  364. @notice,
  365. ($action ne "removed" and $gitweb_url)
  366. ? "URL: ${gitweb_url}a=shortlog;h=$ref" : undef),
  367. "",
  368. "The $refname $reftype has been $action.");
  369. mail_notification($commitlist_address, "$refname $reftype $action",
  370. "text/plain; charset=us-ascii", @notice);
  371. }
  372. # send a commit notice to a mailing list
  373. sub send_commit_notice($$)
  374. {
  375. my ($ref,$obj) = @_;
  376. my %info = get_object_info($obj);
  377. my @notice = ();
  378. my ($url,$subject,$obj_string);
  379. if ($gitweb_url)
  380. {
  381. if ($abbreviate_url)
  382. {
  383. open REVPARSE, "-|" or exec "git", "rev-parse", "--short", $obj or die "cannot exec git-rev-parse";
  384. $obj_string = <REVPARSE>;
  385. chomp $obj_string if defined $obj_string;
  386. close REVPARSE or die $! ? "Cannot execute rev-parse: $!" : "rev-parse exited with status: $?";
  387. }
  388. $obj_string = $obj if not defined $obj_string;
  389. $url = "${gitweb_url}a=$info{type};h=$obj_string";
  390. }
  391. if ($info{"type"} eq "tag")
  392. {
  393. push @notice, format_table(
  394. "Module: $repos_name",
  395. "Tag: $ref",
  396. "SHA1: $obj",
  397. "Tagger:" . $info{"tagger"},
  398. "Date:" . format_date($info{"tagger_date"},$info{"tagger_tz"}),
  399. $url ? "URL: $url" : undef),
  400. "",
  401. join "\n", @{$info{"log"}};
  402. $subject = "Tag " . $info{"tag"} . ": ";
  403. $subject .= $info{"tagger_name"} . ": " unless $omit_author;
  404. }
  405. else
  406. {
  407. push @notice, format_table(
  408. "Module: $repos_name",
  409. "Branch: $ref",
  410. "Commit: $obj",
  411. "Author:" . $info{"author"},
  412. $show_committer && $info{"committer"} ne $info{"author"} ? "Committer:" . $info{"committer"} : undef,
  413. "Date:" . format_date($info{"author_date"},$info{"author_tz"}),
  414. $url ? "URL: $url" : undef),
  415. "",
  416. @{$info{"log"}},
  417. "",
  418. "---",
  419. "";
  420. open STAT, "-|" or exec "git", "diff-tree", "--stat", "-M", "--no-commit-id", $obj or die "cannot exec git-diff-tree";
  421. push @notice, join("", <STAT>);
  422. close STAT or die $! ? "Cannot execute diff-tree: $!" : "diff-tree exited with status: $?";
  423. open DIFF, "-|" or exec "git", "diff-tree", "-p", "-M", "--no-commit-id", $obj or die "cannot exec git-diff-tree";
  424. my $diff = join("", <DIFF>);
  425. close DIFF or die $! ? "Cannot execute diff-tree: $!" : "diff-tree exited with status: $?";
  426. if (($max_diff_size == -1) || (length($diff) < $max_diff_size))
  427. {
  428. push @notice, $diff;
  429. }
  430. else
  431. {
  432. push @notice, "Diff: ${gitweb_url}a=commitdiff;h=$obj_string" if $gitweb_url;
  433. }
  434. $subject = $info{"author_name"} . ": " unless $omit_author;
  435. }
  436. $subject .= truncate_str(${$info{"log"}}[0],50);
  437. $_ = decode($info{"encoding"}, $_) for @notice;
  438. mail_notification($commitlist_address, $subject, "text/plain; charset=UTF-8", @notice);
  439. }
  440. # send a commit notice to the CIA server
  441. sub send_cia_notice($$)
  442. {
  443. my ($ref,$commit) = @_;
  444. my %info = get_object_info($commit);
  445. my @cia_text = ();
  446. return if $info{"type"} ne "commit";
  447. push @cia_text,
  448. "<message>",
  449. " <generator>",
  450. " <name>git-notify script for CIA</name>",
  451. " </generator>",
  452. " <source>",
  453. " <project>" . xml_escape($cia_project_name) . "</project>",
  454. " <module>" . xml_escape($repos_name) . "</module>",
  455. " <branch>" . xml_escape($ref). "</branch>",
  456. " </source>",
  457. " <body>",
  458. " <commit>",
  459. " <revision>" . substr($commit,0,10) . "</revision>",
  460. " <author>" . xml_escape($info{"author"}) . "</author>",
  461. " <log>" . xml_escape(join "\n", @{$info{"log"}}) . "</log>",
  462. " <files>";
  463. open COMMIT, "-|" or exec "git", "diff-tree", "--name-status", "-r", "-M", $commit or die "cannot run git-diff-tree";
  464. while (<COMMIT>)
  465. {
  466. chomp;
  467. if (/^([AMD])\t(.*)$/)
  468. {
  469. my ($action, $file) = ($1, $2);
  470. my %actions = ( "A" => "add", "M" => "modify", "D" => "remove" );
  471. next unless defined $actions{$action};
  472. push @cia_text, " <file action=\"$actions{$action}\">" . xml_escape($file) . "</file>";
  473. }
  474. elsif (/^R\d+\t(.*)\t(.*)$/)
  475. {
  476. my ($old, $new) = ($1, $2);
  477. push @cia_text, " <file action=\"rename\" to=\"" . xml_escape($new) . "\">" . xml_escape($old) . "</file>";
  478. }
  479. }
  480. close COMMIT or die $! ? "Cannot execute diff-tree: $!" : "diff-tree exited with status: $?";
  481. push @cia_text,
  482. " </files>",
  483. $gitweb_url ? " <url>" . xml_escape("${gitweb_url}a=commit;h=$commit") . "</url>" : "",
  484. " </commit>",
  485. " </body>",
  486. " <timestamp>" . $info{"author_date"} . "</timestamp>",
  487. "</message>";
  488. mail_notification($cia_address, "DeliverXML", "text/xml", @cia_text);
  489. }
  490. # send a global commit notice when there are too many commits for individual mails
  491. sub send_global_notice($$$)
  492. {
  493. my ($ref, $old_sha1, $new_sha1) = @_;
  494. my $notice = git_rev_list("--pretty", "^$old_sha1", "$new_sha1", @exclude_list);
  495. foreach my $rev (@$notice)
  496. {
  497. $rev =~ s/^commit /URL: ${gitweb_url}a=commit;h=/ if $gitweb_url;
  498. }
  499. mail_notification($commitlist_address, "New commits on branch $ref", "text/plain; charset=UTF-8", @$notice);
  500. }
  501. # send all the notices
  502. sub send_all_notices($$$)
  503. {
  504. my ($old_sha1, $new_sha1, $ref) = @_;
  505. my ($reftype, $refname, $tagtype, $action, @notice);
  506. return if ($ref =~ /^refs\/remotes\//
  507. or (@include_list && !grep {$_ eq $ref} @include_list));
  508. die "The name \"$ref\" doesn't sound like a local branch or tag"
  509. if not (($reftype, $refname) = ($ref =~ /^refs\/(head|tag)s\/(.+)/));
  510. if ($reftype eq "tag")
  511. {
  512. $tagtype = get_object_type($ref) eq "tag" ? "annotated" : "lightweight";
  513. }
  514. if ($new_sha1 eq '0' x 40)
  515. {
  516. $action = "removed";
  517. @notice = ( "Old SHA1: $old_sha1" );
  518. }
  519. elsif ($old_sha1 eq '0' x 40)
  520. {
  521. if ($reftype eq "tag" and $tagtype eq "annotated")
  522. {
  523. send_commit_notice( $refname, $new_sha1 ) if $commitlist_address;
  524. return;
  525. }
  526. $action = "created";
  527. @notice = ( "SHA1: $new_sha1" );
  528. }
  529. elsif ($reftype eq "tag")
  530. {
  531. $action = "updated";
  532. @notice = ( "Old SHA1: $old_sha1", "New SHA1: $new_sha1" );
  533. }
  534. elsif (not grep( $_ eq $old_sha1, @{ git_rev_list( $new_sha1, "--full-history" ) } ))
  535. {
  536. $action = "rewritten";
  537. @notice = ( "Old SHA1: $old_sha1", "New SHA1: $new_sha1" );
  538. }
  539. send_ref_notice( $ref, $action, @notice ) if ($commitlist_address and $action);
  540. unless ($reftype eq "tag" or $new_sha1 eq '0' x 40)
  541. {
  542. my $commits = get_new_commits ( $old_sha1, $new_sha1 );
  543. if (@$commits > $max_individual_notices)
  544. {
  545. send_global_notice( $refname, $old_sha1, $new_sha1 ) if $commitlist_address;
  546. }
  547. elsif (@$commits > 0)
  548. {
  549. foreach my $commit (@$commits)
  550. {
  551. send_commit_notice( $refname, $commit ) if $commitlist_address;
  552. send_cia_notice( $refname, $commit ) if $cia_project_name;
  553. }
  554. }
  555. elsif ($commitlist_address)
  556. {
  557. @notice = ( "Old SHA1: $old_sha1", "New SHA1: $new_sha1" );
  558. send_ref_notice( $ref, "modified", @notice );
  559. }
  560. }
  561. }
  562. parse_options();
  563. umask( $mode_mask );
  564. # append repository path to URL
  565. if ($gitweb_url) {
  566. $gitweb_url .= $sourceforge ? "/$repos_name;" : "/$repos_name.git/?";
  567. }
  568. if (@ARGV)
  569. {
  570. send_all_notices( $ARGV[0], $ARGV[1], $ARGV[2] );
  571. }
  572. else # read them from stdin
  573. {
  574. while (<>)
  575. {
  576. chomp;
  577. if (/^([0-9a-f]{40}) ([0-9a-f]{40}) (.*)$/) { send_all_notices( $1, $2, $3 ); }
  578. }
  579. }
  580. exit 0;