##// END OF EJS Templates
localrepository.addchangegroup: add more source infos to hooks
Vadim Gelfer -
r2230:33295034 default
parent child Browse files
Show More
@@ -40,6 +40,8 b''
40 # changegroup = ... # template when run as changegroup hook
40 # changegroup = ... # template when run as changegroup hook
41 # maxdiff = 300 # max lines of diffs to include (0=none, -1=all)
41 # maxdiff = 300 # max lines of diffs to include (0=none, -1=all)
42 # maxsubject = 67 # truncate subject line longer than this
42 # maxsubject = 67 # truncate subject line longer than this
43 # sources = serve # notify if source of incoming changes in this list
44 # # (serve == ssh or http, push, pull, bundle)
43 # [email]
45 # [email]
44 # from = user@host.com # email address to send as if none given
46 # from = user@host.com # email address to send as if none given
45 # [web]
47 # [web]
@@ -167,6 +169,11 b' class notifier(object):'
167 root=self.repo.root,
169 root=self.repo.root,
168 webroot=self.root)
170 webroot=self.root)
169
171
172 def skipsource(self, source):
173 '''true if incoming changes from this source should be skipped.'''
174 ok_sources = self.ui.config('notify', 'sources', 'serve').split()
175 return source not in ok_sources
176
170 def send(self, node, count):
177 def send(self, node, count):
171 '''send message.'''
178 '''send message.'''
172
179
@@ -210,7 +217,7 b' class notifier(object):'
210 msg['Message-Id'] = ('<hg.%s.%s.%s@%s>' %
217 msg['Message-Id'] = ('<hg.%s.%s.%s@%s>' %
211 (short(node), int(time.time()),
218 (short(node), int(time.time()),
212 hash(self.repo.root), socket.getfqdn()))
219 hash(self.repo.root), socket.getfqdn()))
213 msg['To'] = self.subs
220 msg['To'] = ', '.join(self.subs)
214
221
215 msgtext = msg.as_string(0)
222 msgtext = msg.as_string(0)
216 if self.ui.configbool('notify', 'test', True):
223 if self.ui.configbool('notify', 'test', True):
@@ -238,13 +245,14 b' class notifier(object):'
238 self.sio.write(_('\ndiffs (%d lines):\n\n') % len(difflines))
245 self.sio.write(_('\ndiffs (%d lines):\n\n') % len(difflines))
239 self.sio.write(*difflines)
246 self.sio.write(*difflines)
240
247
241 def hook(ui, repo, hooktype, node=None, **kwargs):
248 def hook(ui, repo, hooktype, node=None, source=None, **kwargs):
242 '''send email notifications to interested subscribers.
249 '''send email notifications to interested subscribers.
243
250
244 if used as changegroup hook, send one email for all changesets in
251 if used as changegroup hook, send one email for all changesets in
245 changegroup. else send one email per changeset.'''
252 changegroup. else send one email per changeset.'''
246 n = notifier(ui, repo, hooktype)
253 n = notifier(ui, repo, hooktype)
247 if not n.subs: return True
254 if not n.subs or n.skipsource(source):
255 return
248 node = bin(node)
256 node = bin(node)
249 if hooktype == 'changegroup':
257 if hooktype == 'changegroup':
250 start = repo.changelog.rev(node)
258 start = repo.changelog.rev(node)
@@ -2477,7 +2477,7 b' def serve(ui, repo, **opts):'
2477 continue
2477 continue
2478 respond("")
2478 respond("")
2479
2479
2480 r = repo.addchangegroup(fin)
2480 r = repo.addchangegroup(fin, 'serve')
2481 respond(str(r))
2481 respond(str(r))
2482
2482
2483 optlist = ("name templates style address port ipv6"
2483 optlist = ("name templates style address port ipv6"
@@ -2701,7 +2701,7 b' def unbundle(ui, repo, fname, **opts):'
2701 raise util.Abort(_("%s: unknown bundle compression type")
2701 raise util.Abort(_("%s: unknown bundle compression type")
2702 % fname)
2702 % fname)
2703 gen = generator(util.filechunkiter(f, 4096))
2703 gen = generator(util.filechunkiter(f, 4096))
2704 modheads = repo.addchangegroup(util.chunkbuffer(gen))
2704 modheads = repo.addchangegroup(util.chunkbuffer(gen), 'unbundle')
2705 return postincoming(ui, repo, modheads, opts['update'])
2705 return postincoming(ui, repo, modheads, opts['update'])
2706
2706
2707 def undo(ui, repo):
2707 def undo(ui, repo):
@@ -1079,7 +1079,7 b' class localrepository(object):'
1079 cg = remote.changegroup(fetch, 'pull')
1079 cg = remote.changegroup(fetch, 'pull')
1080 else:
1080 else:
1081 cg = remote.changegroupsubset(fetch, heads, 'pull')
1081 cg = remote.changegroupsubset(fetch, heads, 'pull')
1082 return self.addchangegroup(cg)
1082 return self.addchangegroup(cg, 'pull')
1083
1083
1084 def push(self, remote, force=False, revs=None):
1084 def push(self, remote, force=False, revs=None):
1085 lock = remote.lock()
1085 lock = remote.lock()
@@ -1116,7 +1116,7 b' class localrepository(object):'
1116 cg = self.changegroup(update, 'push')
1116 cg = self.changegroup(update, 'push')
1117 else:
1117 else:
1118 cg = self.changegroupsubset(update, revs, 'push')
1118 cg = self.changegroupsubset(update, revs, 'push')
1119 return remote.addchangegroup(cg)
1119 return remote.addchangegroup(cg, 'push')
1120
1120
1121 def changegroupsubset(self, bases, heads, source):
1121 def changegroupsubset(self, bases, heads, source):
1122 """This function generates a changegroup consisting of all the nodes
1122 """This function generates a changegroup consisting of all the nodes
@@ -1455,7 +1455,7 b' class localrepository(object):'
1455
1455
1456 return util.chunkbuffer(gengroup())
1456 return util.chunkbuffer(gengroup())
1457
1457
1458 def addchangegroup(self, source):
1458 def addchangegroup(self, source, srctype):
1459 """add changegroup to repo.
1459 """add changegroup to repo.
1460 returns number of heads modified or added + 1."""
1460 returns number of heads modified or added + 1."""
1461
1461
@@ -1469,7 +1469,7 b' class localrepository(object):'
1469 if not source:
1469 if not source:
1470 return 0
1470 return 0
1471
1471
1472 self.hook('prechangegroup', throw=True, source=source)
1472 self.hook('prechangegroup', throw=True, source=srctype)
1473
1473
1474 changesets = files = revisions = 0
1474 changesets = files = revisions = 0
1475
1475
@@ -1534,17 +1534,17 b' class localrepository(object):'
1534 % (changesets, revisions, files, heads))
1534 % (changesets, revisions, files, heads))
1535
1535
1536 self.hook('pretxnchangegroup', throw=True,
1536 self.hook('pretxnchangegroup', throw=True,
1537 node=hex(self.changelog.node(cor+1)), source=source)
1537 node=hex(self.changelog.node(cor+1)), source=srctype)
1538
1538
1539 tr.close()
1539 tr.close()
1540
1540
1541 if changesets > 0:
1541 if changesets > 0:
1542 self.hook("changegroup", node=hex(self.changelog.node(cor+1)),
1542 self.hook("changegroup", node=hex(self.changelog.node(cor+1)),
1543 source=source)
1543 source=srctype)
1544
1544
1545 for i in range(cor + 1, cnr + 1):
1545 for i in range(cor + 1, cnr + 1):
1546 self.hook("incoming", node=hex(self.changelog.node(i)),
1546 self.hook("incoming", node=hex(self.changelog.node(i)),
1547 source=source)
1547 source=srctype)
1548
1548
1549 return newheads - oldheads + 1
1549 return newheads - oldheads + 1
1550
1550
@@ -134,7 +134,7 b' class sshrepository(remoterepository):'
134 f = self.do_cmd("changegroup", roots=n)
134 f = self.do_cmd("changegroup", roots=n)
135 return self.pipei
135 return self.pipei
136
136
137 def addchangegroup(self, cg):
137 def addchangegroup(self, cg, source):
138 d = self.call("addchangegroup")
138 d = self.call("addchangegroup")
139 if d:
139 if d:
140 raise hg.RepoError(_("push refused: %s"), d)
140 raise hg.RepoError(_("push refused: %s"), d)
General Comments 0
You need to be logged in to leave comments. Login now