##// END OF EJS Templates
add preoutgoing and outgoing hooks....
Vadim Gelfer -
r1736:50de0887 default
parent child Browse files
Show More
@@ -160,6 +160,10 b' hooks::'
160 160 Run after a changeset has been pulled, pushed, or unbundled into
161 161 the local repository. The ID of the newly arrived changeset is in
162 162 $HG_NODE.
163 outgoing;;
164 Run after sending changes from local repository to another. ID of
165 first changeset sent is in $HG_NODE. Source of operation is in
166 $HG_SOURCE; see "preoutgoing" hook for description.
163 167 prechangegroup;;
164 168 Run before a changegroup is added via push, pull or unbundle.
165 169 Exit status 0 allows the changegroup to proceed. Non-zero status
@@ -168,6 +172,15 b' hooks::'
168 172 Run before starting a local commit. Exit status 0 allows the
169 173 commit to proceed. Non-zero status will cause the commit to fail.
170 174 Parent changeset IDs are in $HG_PARENT1 and $HG_PARENT2.
175 preoutgoing;;
176 Run before computing changes to send from the local repository to
177 another. Non-zero status will cause failure. This lets you
178 prevent pull over http or ssh. Also prevents against local pull,
179 push (outbound) or bundle commands, but not effective, since you
180 can just copy files instead then. Source of operation is in
181 $HG_SOURCE. If "serve", operation is happening on behalf of
182 remote ssh or http repository. If "push", "pull" or "bundle",
183 operation is happening on behalf of repository on same system.
171 184 pretag;;
172 185 Run before creating a tag. Exit status 0 allows the tag to be
173 186 created. Non-zero status will cause the tag to fail. ID of
@@ -622,7 +622,7 b' def bundle(ui, repo, fname, dest="defaul'
622 622 dest = ui.expandpath(dest, repo.root)
623 623 other = hg.repository(ui, dest)
624 624 o = repo.findoutgoing(other)
625 cg = repo.changegroup(o)
625 cg = repo.changegroup(o, 'bundle')
626 626
627 627 try:
628 628 f.write("HG10")
@@ -1999,7 +1999,7 b' def serve(ui, repo, **opts):'
1999 1999 arg, roots = getarg()
2000 2000 nodes = map(bin, roots.split(" "))
2001 2001
2002 cg = repo.changegroup(nodes)
2002 cg = repo.changegroup(nodes, 'serve')
2003 2003 while 1:
2004 2004 d = cg.read(4096)
2005 2005 if not d:
@@ -962,7 +962,7 b' class hgweb(object):'
962 962 nodes = map(bin, req.form['roots'][0].split(" "))
963 963
964 964 z = zlib.compressobj()
965 f = self.repo.changegroup(nodes)
965 f = self.repo.changegroup(nodes, 'serve')
966 966 while 1:
967 967 chunk = f.read(4096)
968 968 if not chunk:
@@ -119,7 +119,7 b' class httprepository(remoterepository):'
119 119 self.ui.warn(_("unexpected response:\n") + d[:400] + "\n...\n")
120 120 raise
121 121
122 def changegroup(self, nodes):
122 def changegroup(self, nodes, kind):
123 123 n = " ".join(map(hex, nodes))
124 124 f = self.do_cmd("changegroup", roots=n)
125 125 bytes = 0
@@ -957,9 +957,9 b' class localrepository(object):'
957 957 return 1
958 958
959 959 if heads is None:
960 cg = remote.changegroup(fetch)
960 cg = remote.changegroup(fetch, 'pull')
961 961 else:
962 cg = remote.changegroupsubset(fetch, heads)
962 cg = remote.changegroupsubset(fetch, heads, 'pull')
963 963 return self.addchangegroup(cg)
964 964
965 965 def push(self, remote, force=False):
@@ -984,10 +984,10 b' class localrepository(object):'
984 984 " use push -f to force)\n"))
985 985 return 1
986 986
987 cg = self.changegroup(update)
987 cg = self.changegroup(update, 'push')
988 988 return remote.addchangegroup(cg)
989 989
990 def changegroupsubset(self, bases, heads):
990 def changegroupsubset(self, bases, heads, source):
991 991 """This function generates a changegroup consisting of all the nodes
992 992 that are descendents of any of the bases, and ancestors of any of
993 993 the heads.
@@ -999,6 +999,8 b' class localrepository(object):'
999 999 Another wrinkle is doing the reverse, figuring out which changeset in
1000 1000 the changegroup a particular filenode or manifestnode belongs to."""
1001 1001
1002 self.hook('preoutgoing', throw=True, source=source)
1003
1002 1004 # Set up some initial variables
1003 1005 # Make it easy to refer to self.changelog
1004 1006 cl = self.changelog
@@ -1251,14 +1253,19 b' class localrepository(object):'
1251 1253 # Signal that no more groups are left.
1252 1254 yield struct.pack(">l", 0)
1253 1255
1256 self.hook('outgoing', node=hex(msng_cl_lst[0]), source=source)
1257
1254 1258 return util.chunkbuffer(gengroup())
1255 1259
1256 def changegroup(self, basenodes):
1260 def changegroup(self, basenodes, source):
1257 1261 """Generate a changegroup of all nodes that we have that a recipient
1258 1262 doesn't.
1259 1263
1260 1264 This is much easier than the previous function as we can assume that
1261 1265 the recipient has any changenode we aren't sending them."""
1266
1267 self.hook('preoutgoing', throw=True, source=source)
1268
1262 1269 cl = self.changelog
1263 1270 nodes = cl.nodesbetween(basenodes, None)[0]
1264 1271 revset = dict.fromkeys([cl.rev(n) for n in nodes])
@@ -1310,6 +1317,7 b' class localrepository(object):'
1310 1317 yield chnk
1311 1318
1312 1319 yield struct.pack(">l", 0)
1320 self.hook('outgoing', node=hex(nodes[0]), source=source)
1313 1321
1314 1322 return util.chunkbuffer(gengroup())
1315 1323
@@ -110,7 +110,7 b' class sshrepository(remoterepository):'
110 110 except:
111 111 raise hg.RepoError(_("unexpected response '%s'") % (d[:400] + "..."))
112 112
113 def changegroup(self, nodes):
113 def changegroup(self, nodes, kind):
114 114 n = " ".join(map(hex, nodes))
115 115 f = self.do_cmd("changegroup", roots=n)
116 116 return self.pipei
@@ -74,3 +74,17 b" echo '[hooks]' > .hg/hgrc"
74 74 echo 'pretxnchangegroup.forbid = echo pretxnchangegroup.forbid hook: tip=`hg -q tip`; exit 1' >> .hg/hgrc
75 75 hg pull ../a
76 76 hg -q tip
77
78 # outgoing hooks can see env vars
79 rm .hg/hgrc
80 echo '[hooks]' > ../a/.hg/hgrc
81 echo 'preoutgoing = echo preoutgoing hook: s=$HG_SOURCE' >> ../a/.hg/hgrc
82 echo 'outgoing = echo outgoing hook: n=$HG_NODE s=$HG_SOURCE' >> ../a/.hg/hgrc
83 hg pull ../a
84 hg undo
85
86 # preoutgoing hook can prevent outgoing changes
87 echo 'preoutgoing.forbid = echo preoutgoing.forbid hook; exit 1' >> ../a/.hg/hgrc
88 hg pull ../a
89
90 exit 0
@@ -71,3 +71,18 b' abort: pretxnchangegroup.forbid hook exi'
71 71 transaction abort!
72 72 rollback completed
73 73 3:07f3376c1e65
74 preoutgoing hook: s=pull
75 outgoing hook: n=3cd2c6a5a36c5908aad3bc0d717c29873a05dfc2 s=pull
76 pulling from ../a
77 searching for changes
78 adding changesets
79 adding manifests
80 adding file changes
81 added 1 changesets with 1 changes to 1 files
82 (run 'hg update' to get a working copy)
83 rolling back last transaction
84 preoutgoing hook: s=pull
85 preoutgoing.forbid hook
86 pulling from ../a
87 searching for changes
88 abort: preoutgoing.forbid hook exited with status 1
General Comments 0
You need to be logged in to leave comments. Login now