git-notify 20 KB

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