def test_get_commit_builder(self): branch = self.make_branch(".") branch.lock_write() builder = branch.get_commit_builder([]) self.assertIsInstance(builder, repository.CommitBuilder) branch.repository.commit_write_group() branch.unlock()
def apply(self, bzrdir): branch = bzrdir.open_branch() branch.lock_write() try: branch.set_stacked_on_url(None) if not trace.is_quiet(): ui.ui_factory.note(gettext( "%s is now not stacked\n") % (branch.base,)) finally: branch.unlock()
def test_set_revision_history_when_locked(self): """When the branch is locked, calling set_revision_history should cache the revision history so that a later call to revision_history will not need to call _gen_revision_history. """ branch, calls = self.get_instrumented_branch() # Lock the branch, set the revision history, then repeatedly call # revision_history. branch.lock_write() branch.set_revision_history([]) try: branch.revision_history() self.assertEqual([], calls) finally: branch.unlock()
def apply(self, bzrdir, stacked_on_url): branch = bzrdir.open_branch() # it may be a path relative to the cwd or a url; the branch wants # a path relative to itself... on_url = urlutils.relative_url(branch.base, urlutils.normalize_url(stacked_on_url)) branch.lock_write() try: branch.set_stacked_on_url(on_url) if not trace.is_quiet(): ui.ui_factory.note(gettext( "{0} is now stacked on {1}\n").format( branch.base, branch.get_stacked_on_url())) finally: branch.unlock()
def test_store_signature(self): wt = self.make_branch_and_tree('.') branch = wt.branch branch.lock_write() try: branch.repository.start_write_group() try: branch.repository.store_revision_signature( gpg.LoopbackGPGStrategy(None), 'FOO', 'A') except: branch.repository.abort_write_group() raise else: branch.repository.commit_write_group() finally: branch.unlock() # A signature without a revision should not be accessible. self.assertRaises(errors.NoSuchRevision, branch.repository.has_signature_for_revision_id, 'A') wt.commit("base", allow_pointless=True, rev_id='A') self.assertEqual('-----BEGIN PSEUDO-SIGNED CONTENT-----\n' 'FOO-----END PSEUDO-SIGNED CONTENT-----\n', branch.repository.get_signature_text('A'))
def test_store_signature(self): wt = self.make_branch_and_tree('.') branch = wt.branch branch.lock_write() try: branch.repository.start_write_group() try: branch.repository.store_revision_signature( gpg.LoopbackGPGStrategy(None), 'FOO', 'A') except: branch.repository.abort_write_group() raise else: branch.repository.commit_write_group() finally: branch.unlock() # A signature without a revision should not be accessible. self.assertRaises(errors.NoSuchRevision, branch.repository.has_signature_for_revision_id, 'A') wt.commit("base", allow_pointless=True, rev_id='A') self.assertEqual( '-----BEGIN PSEUDO-SIGNED CONTENT-----\n' 'FOO-----END PSEUDO-SIGNED CONTENT-----\n', branch.repository.get_signature_text('A'))
def parse_commit(parser): parents = [] ref = parser[1] parser.next() if ref.startswith('refs/heads/'): name = ref[len('refs/heads/'):] branch = get_remote_branch(name) else: die('unknown ref') commit_mark = parser.get_mark() parser.next() author = parser.get_author() parser.next() committer = parser.get_author() parser.next() data = parser.get_data() parser.next() if parser.check('from'): parents.append(parser.get_mark()) parser.next() while parser.check('merge'): parents.append(parser.get_mark()) parser.next() # fast-export adds an extra newline if data[-1] == '\n': data = data[:-1] files = {} for line in parser: if parser.check('M'): t, m, mark_ref, path = line.split(' ', 3) mark = int(mark_ref[1:]) f = {'mode': m, 'mark': mark} elif parser.check('D'): t, path = line.split(' ', 1) f = {'deleted': True} else: die('Unknown file command: %s' % line) path = c_style_unescape(path).decode('utf-8') files[path] = f committer, date, tz = committer author, _, _ = author parents = [mark_to_rev(p) for p in parents] revid = bzrlib.generate_ids.gen_revision_id(committer, date) props = {} props['branch-nick'] = branch.nick props['authors'] = author mtree = CustomTree(branch, revid, parents, files) changes = mtree.iter_changes() branch.lock_write() try: builder = branch.get_commit_builder(parents, None, date, tz, committer, props, revid) try: list( builder.record_iter_changes(mtree, mtree.last_revision(), changes)) builder.finish_inventory() builder.commit(data.decode('utf-8', 'replace')) except Exception, e: builder.abort() raise finally: branch.unlock() parsed_refs[ref] = revid marks.new_mark(revid, commit_mark)
def parse_commit(parser): parents = [] ref = parser[1] parser.next() if ref.startswith('refs/heads/'): name = ref[len('refs/heads/'):] branch = get_remote_branch(name) else: die('unknown ref') commit_mark = parser.get_mark() parser.next() author = parser.get_author() parser.next() committer = parser.get_author() parser.next() data = parser.get_data() parser.next() if parser.check('from'): parents.append(parser.get_mark()) parser.next() while parser.check('merge'): parents.append(parser.get_mark()) parser.next() # fast-export adds an extra newline if data[-1] == '\n': data = data[:-1] files = {} for line in parser: if parser.check('M'): t, m, mark_ref, path = line.split(' ', 3) mark = int(mark_ref[1:]) f = { 'mode' : m, 'mark' : mark } elif parser.check('D'): t, path = line.split(' ', 1) f = { 'deleted' : True } else: die('Unknown file command: %s' % line) path = c_style_unescape(path).decode('utf-8') files[path] = f committer, date, tz = committer author, _, _ = author parents = [mark_to_rev(p) for p in parents] revid = bzrlib.generate_ids.gen_revision_id(committer, date) props = {} props['branch-nick'] = branch.nick props['authors'] = author mtree = CustomTree(branch, revid, parents, files) changes = mtree.iter_changes() branch.lock_write() try: builder = branch.get_commit_builder(parents, None, date, tz, committer, props, revid) try: list(builder.record_iter_changes(mtree, mtree.last_revision(), changes)) builder.finish_inventory() builder.commit(data.decode('utf-8', 'replace')) except Exception, e: builder.abort() raise finally: branch.unlock() parsed_refs[ref] = revid marks.new_mark(revid, commit_mark)