aboutsummaryrefslogtreecommitdiff
path: root/Carpet/CarpetWeb/scripts/darcs0
blob: 82ee739d43329b9b97f3f0fee3ae0d52897b23e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/usr/bin/perl -w

# (C) 2004-12-10 Thomas Radke <tradke@aei.mpg.de>
# Some changes by Erik Schnetter <schnetter@aei.mpg.de>
# GPL licenced

use strict;

### some constants
# list of email addresses to send notifications to
my $email_list_standard = 'carpet-darcs@lists.carpetcode.org';
my $email_list_experimental = 'carpet-experimental-darcs@lists.carpetcode.org';
# where to find the real darcs executable
my $darcs = '/home/darcs/bin/darcs1';


# patch database
my %submitters = ();
my %timestamps = ();
my %comments   = ();


# sanity check
die "Couldn't find executable '$darcs'!\n\n" if (! -x $darcs);

open (LOG, ">> /home/darcs/LOG");
print LOG "\n";
print LOG "darcs called:\n";
print LOG "date: ", `date`, "\n";
print LOG "arguments: ", join (' ', @ARGV), "\n";

# short cut for darcs commands other than 'apply --all'
my $repodir = '';
exec ($darcs, @ARGV)
  if (! ($#ARGV == 1 && ($ARGV[0] eq 'apply' && $ARGV[1] eq '--all')) &&
      ! ($#ARGV == 3 && ($ARGV[0] eq 'apply' && $ARGV[1] eq '--all' &&
                         $ARGV[2] eq '--repodir' && ($repodir = $ARGV[3]))));

print LOG "calling darcs:\n";

# open a pipe for running darcs on the other end
open (DARCS, "| $darcs @ARGV") || die "Couldn't open pipe to darcs !\n";

# skip everything before the 'New patches:' section
while (<STDIN>)
{
  print DARCS;
  print LOG;
  last if (/^New patches:$/);
}

# separator for a patch's header and its contents
my $endmarker = '] {';

# now parse individual patches
while (<STDIN>)
{
  print DARCS;
  print LOG;

  # each patch starts with a line '[<patch name>'
  next if (! /^\[(.+)$/);
  my $patch = $1;

  # on the next line follow the submitter's email address
  # and the timestamp of the patch
  $_ = <STDIN>;
  print DARCS;
  print LOG;
  next if (! /^(.+)\*\*(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})($endmarker)??$/o);

  # add this patch to the database
  $submitters{$patch} = $1;
  # convert the timestamp into some readable form 'YYYY-MM-DD HH:MM:SS'
  $timestamps{$patch} = "$2-$3-$4 $5:$6:$7";

  # everything until an end-marker string belongs to
  # a long comment for this patch
  if (! $8)
  {
    while (<STDIN>)
    {
      print DARCS;
      print LOG;
      last if (/^$endmarker$/);
      $comments{$patch} .= $_;
    }
    delete $submitters{$patch} if (! ($_ && /^$endmarker$/));
  }

  # skip everything that makes out the patch's contents
  # (i.e., read away until a single line '}' matches)
  while (<STDIN>)
  {
    print DARCS;
    print LOG;
    last if (/^}$/);
  }
}

close (DARCS) || die "Failed to run darcs command '$darcs @ARGV'\n";

print LOG "(that was the patch set)\n";
print LOG "submitters: ", join (' ', %submitters), "\n";
print LOG "done.\n";

if ($repodir eq '') {
  $repodir = `pwd`;
  chomp $repodir;
}
$repodir =~ s+^.*/home/+~+;

my $email_list = $email_list_standard;
if ($repodir eq '~darcs/carpet-experimental') {
  $email_list = $email_list_experimental;
}

# now send out notification email(s)
foreach my $patch (keys %submitters)
{
  # Not safe, because the shell expands meta-characters:
  #open (NOTIFY, "| mail -s '$patch' $email_list");
  # More elegant, but only in Perl 5.8 and later:
  #open (NOTIFY, '|-', 'mail', '-s', $patch, $email_list);
  # Safe, I think:
  open (NOTIFY, '|-') || exec 'mail', '-s', $patch, $email_list;

  #print NOTIFY "A new patch has been pushed into the Carpet repository:\n\n";
  print NOTIFY "The Carpet repository at $repodir received a new patch:\n\n";
  print NOTIFY "   $patch\n\n";
  print NOTIFY "This patch was recorded by " .
               "${submitters{$patch}} at ${timestamps{$patch}}.";
  if ($comments{$patch})
  {
    print NOTIFY "\n\nThe long comment for this patch reads:\n\n";
    print NOTIFY $comments{$patch};
  }

  close (NOTIFY);
}