comparison mercurial/exchange.py @ 42811:3332bde53714 stable

exchange: abort on pushing bookmarks pointing to secret changesets (issue6159) Until now, if there is a bookmark points to a changeset which is in secret phase, hg will push the bookmark, but not the changeset referenced by that bookmark. This leaves the server bookmarks in a bad state, because that bookmark now points to a revision that does not exist on the server. This patch makes hg to abort on such cases. Differential Revision: https://phab.mercurial-scm.org/D6731
author Navaneeth Suresh <navaneeths1998@gmail.com>
date Sat, 17 Aug 2019 01:49:28 +0530
parents 5d4ec64a6fcb
children 10841b9a80c3
comparison
equal deleted inserted replaced
42810:cf9dbc7377de 42811:3332bde53714
1032 return 'export' 1032 return 'export'
1033 elif not new: 1033 elif not new:
1034 return 'delete' 1034 return 'delete'
1035 return 'update' 1035 return 'update'
1036 1036
1037 def _abortonsecretctx(pushop, node, b):
1038 """abort if a given bookmark points to a secret changeset"""
1039 if node and pushop.repo[node].phase() == phases.secret:
1040 raise error.Abort(_('cannot push bookmark %s as it points to a secret'
1041 ' changeset') % b)
1042
1037 def _pushb2bookmarkspart(pushop, bundler): 1043 def _pushb2bookmarkspart(pushop, bundler):
1038 pushop.stepsdone.add('bookmarks') 1044 pushop.stepsdone.add('bookmarks')
1039 if not pushop.outbookmarks: 1045 if not pushop.outbookmarks:
1040 return 1046 return
1041 1047
1042 allactions = [] 1048 allactions = []
1043 data = [] 1049 data = []
1044 for book, old, new in pushop.outbookmarks: 1050 for book, old, new in pushop.outbookmarks:
1051 _abortonsecretctx(pushop, new, book)
1045 new = bin(new) 1052 new = bin(new)
1046 data.append((book, new)) 1053 data.append((book, new))
1047 allactions.append((book, _bmaction(old, new))) 1054 allactions.append((book, _bmaction(old, new)))
1048 checkdata = bookmod.binaryencode(data) 1055 checkdata = bookmod.binaryencode(data)
1049 bundler.newpart('bookmarks', data=checkdata) 1056 bundler.newpart('bookmarks', data=checkdata)
1068 raise error.Abort(bookmsgmap[action][1].rstrip() % book) 1075 raise error.Abort(bookmsgmap[action][1].rstrip() % book)
1069 # we should not be called for part we did not generated 1076 # we should not be called for part we did not generated
1070 assert False 1077 assert False
1071 1078
1072 for book, old, new in pushop.outbookmarks: 1079 for book, old, new in pushop.outbookmarks:
1080 _abortonsecretctx(pushop, new, book)
1073 part = bundler.newpart('pushkey') 1081 part = bundler.newpart('pushkey')
1074 part.addparam('namespace', enc('bookmarks')) 1082 part.addparam('namespace', enc('bookmarks'))
1075 part.addparam('key', enc(book)) 1083 part.addparam('key', enc(book))
1076 part.addparam('old', enc(old)) 1084 part.addparam('old', enc(old))
1077 part.addparam('new', enc(new)) 1085 part.addparam('new', enc(new))