summaryrefslogtreecommitdiffstats
path: root/gitmirror
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2009-07-19 17:41:21 -0700
committerH. Peter Anvin <hpa@zytor.com>2009-07-19 17:41:21 -0700
commit974bc06f4d5fca571f4d8bc38cf05814d8f6d65d (patch)
treedb62743747ad803ddbf5016fb5c149867731b513 /gitmirror
parent37e873dc1cb2847f63abcd545eedfb9d513abc66 (diff)
downloadnasmbuild-974bc06f4d5fca571f4d8bc38cf05814d8f6d65d.tar.gz
nasmbuild-974bc06f4d5fca571f4d8bc38cf05814d8f6d65d.tar.xz
nasmbuild-974bc06f4d5fca571f4d8bc38cf05814d8f6d65d.zip
Updated git email robot from the tip project
Diffstat (limited to 'gitmirror')
-rw-r--r--gitmirror/.gitignore6
-rwxr-xr-xgitmirror/filter-branches.pl18
-rwxr-xr-xgitmirror/robot-wrapper.sh3
-rwxr-xr-xgitmirror/robot.sh67
-rwxr-xr-xgitmirror/robotfmt.pl149
5 files changed, 202 insertions, 41 deletions
diff --git a/gitmirror/.gitignore b/gitmirror/.gitignore
index f76371a..852a673 100644
--- a/gitmirror/.gitignore
+++ b/gitmirror/.gitignore
@@ -1,3 +1,9 @@
/LAST_EMAIL
/git
/nasm.git
+/nasm-mail.git
+/tip
+.#*
+#*
+*~
+/old
diff --git a/gitmirror/filter-branches.pl b/gitmirror/filter-branches.pl
new file mode 100755
index 0000000..002c923
--- /dev/null
+++ b/gitmirror/filter-branches.pl
@@ -0,0 +1,18 @@
+#!/usr/bin/perl
+open(GIT, "-|", "git branch -r") or die;
+%branches = ();
+while (<GIT>) {
+ chomp;
+ s/^[ \*] //;
+ next if (/ \-\> /);
+ next if (/^\s*(\#.*|)$/);
+ next if (/^build$/);
+ next if (/^auto-/);
+ next if (/^tmp-/);
+ next if (/^[^\/]+\/base-/);
+ $branches{"refs/remotes/".$_}++;
+}
+close(GIT);
+foreach $b (sort(keys(%branches))) {
+ print $b, "\n";
+}
diff --git a/gitmirror/robot-wrapper.sh b/gitmirror/robot-wrapper.sh
new file mode 100755
index 0000000..8cca014
--- /dev/null
+++ b/gitmirror/robot-wrapper.sh
@@ -0,0 +1,3 @@
+#!/bin/sh
+cd /home/nasmbuild/gitmirror
+exec ./robot.sh > log/`date +%Y%m%d.%H%M.log` 2>&1
diff --git a/gitmirror/robot.sh b/gitmirror/robot.sh
index a289f4b..2c23482 100755
--- a/gitmirror/robot.sh
+++ b/gitmirror/robot.sh
@@ -1,37 +1,60 @@
#!/bin/bash -xe
-MAILTO='NASM commits list <nasm-cvs@lists.sourceforge.net>'
-#MAILTO='NASM commits list <hpa+nasm/cvs@zytor.com>'
-SENDER='nasmbuild@zytor.com'
+#MAILTO='tip commits list <linux-tip-commits@vger.kernel.org>'
+MAILTO='nasm-cvs@lists.sourceforge.net'
+SENDER='nasmbuild@nasm.us'
+MASTER="$HOME/gitmirror/nasm.git"
# /usr/sbin needed for sendmail
export PATH=/bin:/usr/bin:/usr/local/bin:/usr/sbin:$HOME/bin
-cd $HOME/gitmirror
-export GIT_DIR=$HOME/gitmirror/nasm.git
+topdir="$HOME/gitmirror"
+
+tmpdir="/tmp/$USER/tipmail"
+slave="$HOME/gitmirror/nasm-mail.git"
+date=$(date -uR)
(
flock -nx 8 || exit 0
- mkdir -m 0700 -p /tmp/$USER
-
+ cd "$MASTER"
git fetch -f
git push -f --mirror zytor
-
- HEAD=$(git rev-parse HEAD)
- OLD_HEAD=$(cat LAST_EMAIL)
-
- if [ x"$HEAD" != x"$OLD_HEAD" ]; then
- mkdir -m 0700 /tmp/$USER/gitpatches.$$
-
- # -k = no [PATCH], since we're sending to a mailing list.
- git format-patch -M -C -C -k -o /tmp/$USER/gitpatches.$$ $OLD_HEAD..$HEAD
-
- for f in /tmp/$USER/gitpatches.$$/*; do
- ./robotfmt.pl "$MAILTO" < "$f" | sendmail -f "$SENDER" -t
- done
- echo "$HEAD" > LAST_EMAIL
- rm -rf /tmp/$USER/gitpatches.$$
+ cd "$topdir"
+
+ if [ -f kill/kill ]; then
+ exit 0
+ fi
+
+ mkdir -m 0700 -p $tmpdir
+
+ GIT_DIR="$slave" "$topdir"/filter-branches.pl > branches
+ (
+ while read branch; do
+ GIT_DIR="$MASTER" git rev-parse "$branch"'^{}'
+ done
+ ) < branches > branches.heads
+ sha1sum branches.heads > branches.id.new
+
+ if [ "$(cat branches.id)" != "$(cat branches.id.new)" ]; then
+ cd "$slave"
+ git checkout mail-merge
+ OLD_HEAD=$(git rev-parse HEAD)
+ git fetch -f
+ git fetch -f linus
+ git merge -s ours -m "Mail run on $date" $(sed -e 's:^:refs/remotes/origin/:' < "$topdir"/branches)
+ NEW_HEAD=$(git rev-parse HEAD)
+
+ if [ x"$NEW_HEAD" != x"$OLD_HEAD" ]; then
+ git rev-list --reverse --no-merges ^$OLD_HEAD $NEW_HEAD | (
+ while read rev; do
+ "$topdir"/robotfmt.pl $rev "$topdir"/branches
+ done
+ )
+ fi
+ cd "$topdir"
+
+ mv -f branches.id.new branches.id
fi
) 8< "$0"
diff --git a/gitmirror/robotfmt.pl b/gitmirror/robotfmt.pl
index 0eeefed..af99572 100755
--- a/gitmirror/robotfmt.pl
+++ b/gitmirror/robotfmt.pl
@@ -1,27 +1,138 @@
#!/usr/bin/perl
+#
+# Take a commit and generate an email from it
+#
-($mailto) = @ARGV;
+use Email::Valid;
-$hdr = 1;
-while (defined($line = <STDIN>)) {
- chomp $line;
- if ($hdr) {
- next if ($line =~ /^From /); # Skip line
- if ($line =~ /^Date:/) {
- $date = $line;
- next;
+($rev, $branches) = @ARGV;
+
+sub count_commits($$) {
+ my($f, $t) = @_;
+ my($rl, $l);
+ my $count = 0;
+
+ open($rl, "-|", "git rev-list \Q${f}\E..\Q${t}\E") or die;
+ while (defined($l = <$rl>)) {
+ $count++;
+ }
+ close($rl);
+ return $count;
+}
+
+sub best_branch($$) {
+ my($rev, $branches) = @_;
+ my($r, $best, $best_metric);
+ my($branch_fd, $present_fd);
+
+ my %branches = ();
+ open($branch_fd, '<', $branches) or die;
+ while (defined($r = <$branch_fd>)) {
+ chomp $r;
+ $branches{$r}++;
+ }
+ close($branch_fd);
+
+ $best = 'branch?';
+ undef $best_metric;
+ open($present_fd, '-|', "git branch -a --contains \"\Q${rev}\E\"") or die;
+ while (defined($l = <$present_fd>)) {
+ chomp $l;
+ if ($l =~ m:^[ \*] (remotes/|)origin/(.*)$:) {
+ $l = $2;
+ if ($branches{$l}) {
+ $metric = count_commits("refs/remotes/origin/$l", $rev);
+ if (!defined($best_metric) || $metric < $best_metric) {
+ $best = $l;
+ $best_metric = $metric;
+ }
+ }
}
- if ($line eq '') {
- $hdr = 0;
- print "To: $mailto\n";
- print "X-Mailer: NASM-git-log-daemon\n";
- print "\n";
- print $date, "\n";
- print "\n";
- next;
+ }
+ close($present_fd);
+
+ return $best;
+}
+
+$branch = best_branch($rev, $branches);
+
+$format = <<EOF;
+From: \"nasm-bot for %an\" <%ae>
+To: nasm-cvs@lists.sourceforge.net
+Subject: [${branch}] %s
+Message-ID: <nasm-%H\@git.nasm.us>
+Git-Commit-ID: %H
+X-Mailer: NASM-git-log-daemon
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Disposition: inline
+Precedence: bulk
+
+Commit-ID: %H
+Gitweb: http://repo.or.cz/w/nasm.git?a=commitdiff;h=%H
+Author: %an <%ae>
+AuthorDate: %aD
+Committer: %cn <%ce>
+CommitDate: %cD
+
+%s
+
+%b
+
+EOF
+$format =~ s/\n/%n/g;
+
+@message = ();
+@references = ();
+%cclist = ();
+$lkml = 'nasm-devel@lists.sourceforge.net';
+open(LOG, "-|", "git log -M -C -C --pretty=format:\Q${format}\E -p --stat \Q${rev}^..${rev}\E") or die;
+$header = 1;
+while (defined($l = <LOG>)) {
+ chomp $l;
+ $header = 0 if ($l eq '');
+ if ($header) {
+ if ($l =~ /^From: \"([a-zA-Z0-9_\-\. ]*)\" (\<[^\<\>]*\>)$/i) {
+ # Strip quotes in From: if author string seems safe
+ $l = "From: $1 $2";
+ }
+ } else {
+ if ($l =~ /^([a-z-]+-by|Cc|Author):\s.*<([^\>]+)>\s*$/i) {
+ $e = $2;
+ if (Email::Valid->address($e)) {
+ $cclist{$e}++;
+ }
+ } elsif ($l =~ /^NASM-Devel-Reference:\s*(\<.+\>)\s*$/i) {
+ # We have a thread in which to autopost to LKML...
+ # Let's be very careful with this...
+ $cclist{$lkml}++;
+ push(@references, $1);
}
}
- print $line, "\n";
+ push(@message, $l."\n");
+}
+close(LOG);
+
+# We don't actually want to send this to anyone else...
+%cclist = ();
+
+# WARNING: make sure all the moreheaders are newline-terminated!!!!
+%replylist = %cclist;
+%replylist = ();
+$replylist{$lkml}++; # Always include LKML in Reply-To:
+
+@moreheaders =
+(
+ "Cc: ".join(",\n\t", keys(%cclist))."\n",
+ "Reply-To: ".join(",\n\t", keys(%replylist))."\n"
+);
+if (scalar(@references)) {
+ push(@moreheaders,
+ ("In-Reply-To: ".$references[scalar(@references)-1]."\n",
+ "References: ".join(",\n\t", @references)."\n"));
}
-exit 0;
+splice(@message, 2, 0, @moreheaders);
+open(SENDMAIL, "|-", "sendmail -i -t -O DeliveryMode=b") or die;
+print SENDMAIL @message;
+close(SENDMAIL);