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 import os
35
36 from mercurial.i18n import gettext as _
37 from mercurial.node import bin, hex, nullid
38 from mercurial.context import workingctx
39
40
41
42
43 try:
44 from mercurial import demandimport
45 demandimport.disable()
46 except ImportError:
47 pass
48
49 from buildbot.clients import sendchange
50 from twisted.internet import defer, reactor
51
52
53 -def hook(ui, repo, hooktype, node=None, source=None, **kwargs):
54
55 master = ui.config('hgbuildbot', 'master')
56 if master:
57 branchtype = ui.config('hgbuildbot', 'branchtype')
58 branch = ui.config('hgbuildbot', 'branch')
59 else:
60 ui.write("* You must add a [hgbuildbot] section to .hg/hgrc in "
61 "order to use buildbot hook\n")
62 return
63
64 if branch is None:
65 if branchtype is not None:
66 if branchtype == 'dirname':
67 branch = os.path.basename(os.getcwd())
68 if branchtype == 'inrepo':
69 branch = workingctx(repo).branch()
70
71 if hooktype == 'changegroup':
72 s = sendchange.Sender(master, None)
73 d = defer.Deferred()
74 reactor.callLater(0, d.callback, None)
75
76 def _send(res, c):
77 ui.status("rev %s sent\n" % c['revision'])
78 return s.send(c['branch'], c['revision'], c['comments'],
79 c['files'], c['username'])
80
81 try:
82 start = repo[node].rev()
83 end = len(repo)
84 except TypeError:
85 start = repo.changelog.rev(bin(node))
86 end = repo.changelog.count()
87
88 for rev in xrange(start, end):
89
90 node = repo.changelog.node(rev)
91 manifest, user, (time, timezone), files, desc, extra = repo.changelog.read(node)
92 parents = filter(lambda p: not p == nullid, repo.changelog.parents(node))
93 if branchtype == 'inrepo':
94 branch = extra['branch']
95
96 if len(parents) > 1 and not files:
97 files = ["merge"]
98 change = {
99 'master': master,
100 'username': user,
101 'revision': hex(node),
102 'comments': desc,
103 'files': files,
104 'branch': branch
105 }
106 d.addCallback(_send, change)
107
108 d.addCallbacks(s.printSuccess, s.printFailure)
109 d.addBoth(s.stop)
110 s.run()
111 else:
112 ui.status(_('hgbuildbot: hook %s not supported\n') % hooktype)
113 return
114