File: svn-mailer-integration.patch

package info (click to toggle)
viewcvs 0.9.2%2Bcvs.1.0.dev.2004.07.28-4.1etch1
  • links: PTS
  • area: main
  • in suites: etch
  • size: 1,452 kB
  • ctags: 1,355
  • sloc: python: 10,100; cpp: 840; ansic: 763; yacc: 526; sh: 163; makefile: 115
file content (195 lines) | stat: -rw-r--r-- 7,202 bytes parent folder | download | duplicates (3)
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#
# Copyright (C) 1999-2004 The ViewCVS Group. All Rights Reserved.
#
# By using this file, you agree to the terms and conditions set forth in
# the LICENSE.html file which can be found at the top level of the ViewCVS
# distribution or at http://viewcvs.sourceforge.net/license-1.html.
#
# Contact information:
#   Greg Stein, PO Box 760, Palo Alto, CA, 94302
#   gstein@lyra.org, http://viewcvs.sourceforge.net/
#
# This patch composed by C. Michael Pilato <cmpilato@red-bean.com>.
# -----------------------------------------------------------------------
#

Teach Subversion's mailer.py how to send ViewCVS diffs.  This adds a
new configuration option to the mailer.conf configuration file called
'viewcvs_base_url'.  If that variable is set for the repository group
to which the commit applies, URLs will be transmitted.

NOTE: This doesn't work if you use ViewCVS in a way that requires your
root to be specified as a CGI query variable, such as:

   http://server.com/viewcvs/path/to/file?root=reposname

You must either be viewing the default root, or have the
root_as_url_component option enabled so that URLs look like:

   http://server.com/viewcvs/reposname/path/to/file

Index: tools/hook-scripts/mailer/mailer.py
===================================================================
--- tools/hook-scripts/mailer/mailer.py	(revision 9928)
+++ tools/hook-scripts/mailer/mailer.py	(working copy)
@@ -23,6 +23,7 @@
 import cStringIO
 import smtplib
 import re
+import urllib
 
 import svn.fs
 import svn.delta
@@ -420,6 +421,7 @@
     return
 
   gen_diffs = cfg.get('generate_diffs', group, params)
+  viewcvs_base_url = cfg.get('viewcvs_base_url', group, params)
 
   ### Do a little dance for deprecated options.  Note that even if you
   ### don't have an option anywhere in your configuration file, it
@@ -452,37 +454,73 @@
     if suppress == 'yes':
       diff_add = False
 
+  # Figure out if we're supposed to show ViewCVS URLs
+  if len(viewcvs_base_url):
+    show_urls = True
+  else:
+    show_urls = False
+    
+  diff = None
+  diff_url = None
+  header = None
+  
   if not change.path:
     ### params is a bit silly here
-    if diff_delete == False:
-      # a record of the deletion is in the summary. no need to write
-      # anything further here.
-      return
 
-    output.write('\nDeleted: %s\n' % change.base_path)
-    diff = svn.fs.FileDiff(repos.get_root(change.base_rev),
-                           change.base_path, None, None, pool)
+    header = 'Deleted: %s' % change.base_path
+    if show_urls:
+      diff_url = '%s/%s?view=auto&rev=%d' \
+                 % (viewcvs_base_url,
+                    urllib.quote(change.base_path[1:]), change.base_rev)
+    if diff_delete:
+      diff = svn.fs.FileDiff(repos.get_root(change.base_rev),
+                             change.base_path, None, None, pool)
+      label1 = '%s\t%s' % (change.base_path, date)
+      label2 = '(empty file)'
+      singular = True
 
-    label1 = '%s\t%s' % (change.base_path, date)
-    label2 = '(empty file)'
-    singular = True
   elif change.added:
-    if change.base_path and (change.base_rev != -1):
-      # this file was copied.
-
-      if not change.text_changed:
-        # copies with no changes are reported in the header, so we can just
-        # skip them here.
-        return
-
-      if diff_copy == False:
-        # a record of the copy is in the summary, no need to write
-        # anything further here.
-	return
-
+    if change.base_path and (change.base_rev != -1): # this file was copied.
       # note that we strip the leading slash from the base (copyfrom) path
-      output.write('\nCopied: %s (from r%d, %s)\n'
-                   % (change.path, change.base_rev, change.base_path[1:]))
+      header = 'Copied: %s (from r%d, %s)' \
+               % (change.path, change.base_rev, change.base_path[1:])
+      if show_urls:
+        diff_url = '%s/%s?view=diff&rev=%d&p1=%s&r1=%d&p2=%s&r2=%d' \
+                   % (viewcvs_base_url,
+                      urllib.quote(change.path), repos.rev,
+                      urllib.quote(change.base_path[1:]), change.base_rev,
+                      urllib.quote(change.path), repos.rev)
+      if change.text_changed and diff_copy:
+        diff = svn.fs.FileDiff(repos.get_root(change.base_rev),
+                               change.base_path[1:],
+                               repos.root_this, change.path,
+                               pool)
+        label1 = change.base_path[1:] + '\t(original)'
+        label2 = '%s\t%s' % (change.path, date)
+        singular = False
+    else:
+      header = 'Added: %s' % change.path
+      if show_urls:
+        diff_url = '%s/%s?view=auto&rev=%d' \
+                   % (viewcvs_base_url,
+                      urllib.quote(change.path), repos.rev)
+      if diff_add:
+        diff = svn.fs.FileDiff(None, None, repos.root_this, change.path, pool)
+        label1 = '(empty file)'
+        label2 = '%s\t%s' % (change.path, date)
+        singular = True
+  elif not change.text_changed:
+    # don't bother to show an empty diff. prolly just a prop change.
+    return
+  else:
+    header = 'Modified: %s' % change.path
+    if show_urls:
+      diff_url = '%s/%s?view=diff&rev=%d&p1=%s&r1=%d&p2=%s&r2=%d' \
+                 % (viewcvs_base_url,
+                    urllib.quote(change.path), repos.rev,
+                    urllib.quote(change.base_path[1:]), change.base_rev,
+                    urllib.quote(change.path), repos.rev)
+    if diff_modify:
       diff = svn.fs.FileDiff(repos.get_root(change.base_rev),
                              change.base_path[1:],
                              repos.root_this, change.path,
@@ -490,37 +528,17 @@
       label1 = change.base_path[1:] + '\t(original)'
       label2 = '%s\t%s' % (change.path, date)
       singular = False
-    else:
-      if diff_add == False:
-        # a record of the addition is in the summary. no need to write
-        # anything further here.
-        return
 
-      output.write('\nAdded: %s\n' % change.path)
-      diff = svn.fs.FileDiff(None, None, repos.root_this, change.path, pool)
-      label1 = '(empty file)'
-      label2 = '%s\t%s' % (change.path, date)
-      singular = True
-  elif not change.text_changed:
-    # don't bother to show an empty diff. prolly just a prop change.
+  if not (show_urls or diff):
     return
-  else:
-    if diff_modify == False:
-      # a record of the modification is in the summary, no need to write
-      # anything further here.
-      return
-
-    output.write('\nModified: %s\n' % change.path)
-    diff = svn.fs.FileDiff(repos.get_root(change.base_rev),
-                           change.base_path[1:],
-                           repos.root_this, change.path,
-                           pool)
-    label1 = change.base_path[1:] + '\t(original)'
-    label2 = '%s\t%s' % (change.path, date)
-    singular = False
-
+  
+  output.write('\n' + header + '\n')
+  if diff_url:
+    output.write('Url: ' + diff_url + '\n')
   output.write(SEPARATOR + '\n')
-
+  if not diff:
+    return
+  
   if diff.either_binary():
     if singular:
       output.write('Binary file. No diff available.\n')