def run(self, merge_type=None, directory="."): from bzrlib.plugins.rewrite.rebase import RebaseState1, WorkingTreeRevisionRewriter from bzrlib.workingtree import WorkingTree wt = WorkingTree.open_containing(directory)[0] wt.lock_write() try: state = RebaseState1(wt) replayer = WorkingTreeRevisionRewriter(wt, state, merge_type=merge_type) # Abort if there are any conflicts if len(wt.conflicts()) != 0: raise BzrCommandError( gettext( "There are still conflicts present. " "Resolve the conflicts and then run " "'bzr resolve' and try again." ) ) # Read plan file try: replace_map = state.read_plan()[1] except NoSuchFile: raise BzrCommandError(gettext("No rebase to continue")) oldrevid = state.read_active_revid() if oldrevid is not None: oldrev = wt.branch.repository.get_revision(oldrevid) replayer.commit_rebase(oldrev, replace_map[oldrevid][0]) finish_rebase(state, wt, replace_map, replayer) finally: wt.unlock()
def run(self, file_list, all=False): if file_list is None: if not all: raise BzrCommandError( "command 'extmerge' needs one or more FILE, or --all") tree = WorkingTree.open_containing(u'.')[0] file_list = list(tree.abspath(f.path) for f in tree.conflicts()) else: if all: raise BzrCommandError( "If --all is specified, no FILE may be provided") for filename in file_list: if not os.path.exists(filename): print "%s does not exists" % filename else: failures = 0 for suffix in CONFLICT_SUFFIXES: if not os.path.exists(filename + suffix) and not failures: print "%s is not conflicted" % filename failures = 1 if not failures: run_extmerge(filename) if len(file_list) == 0: print "no conflicting files" else: # TODO: ask if the file(s) should get resolved, per file. print "remember to bzr resolve your files"
def run(self, location=None, remember=False, directory=None, no_rebase=False, strict=None): from bzrlib import urlutils from bzrlib.controldir import ControlDir from bzrlib.errors import BzrCommandError, NoWorkingTree from bzrlib.workingtree import WorkingTree if directory is None: directory = "." try: source_wt = WorkingTree.open_containing(directory)[0] source_branch = source_wt.branch except NoWorkingTree: source_branch = Branch.open(directory) source_wt = None if source_wt is not None: source_wt.check_changed_or_out_of_date( strict, 'dpush_strict', more_error='Use --no-strict to force the push.', more_warning='Uncommitted changes will not be pushed.') stored_loc = source_branch.get_push_location() if location is None: if stored_loc is None: raise BzrCommandError(gettext("No push location known or specified.")) else: display_url = urlutils.unescape_for_display(stored_loc, self.outf.encoding) self.outf.write( gettext("Using saved location: %s\n") % display_url) location = stored_loc controldir = ControlDir.open(location) target_branch = controldir.open_branch() target_branch.lock_write() try: try: push_result = source_branch.push(target_branch, lossy=True) except errors.LossyPushToSameVCS: raise BzrCommandError(gettext("{0!r} and {1!r} are in the same VCS, lossy " "push not necessary. Please use regular push.").format( source_branch, target_branch)) # We successfully created the target, remember it if source_branch.get_push_location() is None or remember: # FIXME: Should be done only if we succeed ? -- vila 2012-01-18 source_branch.set_push_location(target_branch.base) if not no_rebase: old_last_revid = source_branch.last_revision() source_branch.pull(target_branch, overwrite=True) new_last_revid = source_branch.last_revision() if source_wt is not None and old_last_revid != new_last_revid: source_wt.lock_write() try: target = source_wt.branch.repository.revision_tree( new_last_revid) update_workingtree_fileids(source_wt, target) finally: source_wt.unlock() push_result.report(self.outf) finally: target_branch.unlock()
def run(self, file_list): wt = WorkingTree.open_containing('.') # Create the files if they don't exist. for filename in file_list: filepath = os.path.join(os.getcwd(), filename) fd = os.open(filepath, FLAGS, 0666) os.close(fd) wt[0].smart_add(file_list, recurse=False)
def run(self, location=None, remember=False, directory=None, no_rebase=False): from bzrlib import urlutils from bzrlib.bzrdir import BzrDir from bzrlib.errors import BzrCommandError, NoWorkingTree from bzrlib.trace import info from bzrlib.workingtree import WorkingTree from upgrade import update_workingtree_fileids if directory is None: directory = "." try: source_wt = WorkingTree.open_containing(directory)[0] source_branch = source_wt.branch except NoWorkingTree: source_branch = Branch.open_containing(directory)[0] source_wt = None stored_loc = source_branch.get_push_location() if location is None: if stored_loc is None: raise BzrCommandError("No push location known or specified.") else: display_url = urlutils.unescape_for_display(stored_loc, self.outf.encoding) self.outf.write("Using saved location: %s\n" % display_url) location = stored_loc bzrdir = BzrDir.open(location) target_branch = bzrdir.open_branch() target_branch.lock_write() try: if not isinstance(target_branch, ForeignBranch): info("target branch is not a foreign branch, using regular push.") target_branch.pull(source_branch) no_rebase = True else: revid_map = target_branch.dpull(source_branch) # We successfully created the target, remember it if source_branch.get_push_location() is None or remember: source_branch.set_push_location(target_branch.base) if not no_rebase: _, old_last_revid = source_branch.last_revision_info() new_last_revid = revid_map[old_last_revid] if source_wt is not None: source_wt.pull(target_branch, overwrite=True, stop_revision=new_last_revid) source_wt.lock_write() try: update_workingtree_fileids(source_wt, source_wt.branch.repository.revision_tree(old_last_revid), source_wt.branch.repository.revision_tree(new_last_revid)) finally: source_wt.unlock() else: source_branch.pull(target_branch, overwrite=True, stop_revision=new_last_revid) finally: target_branch.unlock()
def test_open_containing(self): branch = self.make_branch_and_tree('.').branch local_base = urlutils.local_path_from_url(branch.base) # Empty opens '.' wt, relpath = WorkingTree.open_containing() self.assertEqual('', relpath) self.assertEqual(wt.basedir + '/', local_base) # '.' opens this dir wt, relpath = WorkingTree.open_containing(u'.') self.assertEqual('', relpath) self.assertEqual(wt.basedir + '/', local_base) # './foo' finds '.' and a relpath of 'foo' wt, relpath = WorkingTree.open_containing('./foo') self.assertEqual('foo', relpath) self.assertEqual(wt.basedir + '/', local_base) # abspath(foo) finds '.' and relpath of 'foo' wt, relpath = WorkingTree.open_containing('./foo') wt, relpath = WorkingTree.open_containing(getcwd() + '/foo') self.assertEqual('foo', relpath) self.assertEqual(wt.basedir + '/', local_base) # can even be a url: finds '.' and relpath of 'foo' wt, relpath = WorkingTree.open_containing('./foo') wt, relpath = WorkingTree.open_containing( urlutils.local_path_to_url(getcwd() + '/foo')) self.assertEqual('foo', relpath) self.assertEqual(wt.basedir + '/', local_base)
def test_open_containing(self): branch = self.make_branch_and_tree('.').branch local_base = urlutils.local_path_from_url(branch.base) # Empty opens '.' wt, relpath = WorkingTree.open_containing() self.assertEqual('', relpath) self.assertEqual(wt.basedir + '/', local_base) # '.' opens this dir wt, relpath = WorkingTree.open_containing(u'.') self.assertEqual('', relpath) self.assertEqual(wt.basedir + '/', local_base) # './foo' finds '.' and a relpath of 'foo' wt, relpath = WorkingTree.open_containing('./foo') self.assertEqual('foo', relpath) self.assertEqual(wt.basedir + '/', local_base) # abspath(foo) finds '.' and relpath of 'foo' wt, relpath = WorkingTree.open_containing('./foo') wt, relpath = WorkingTree.open_containing(getcwd() + '/foo') self.assertEqual('foo', relpath) self.assertEqual(wt.basedir + '/', local_base) # can even be a url: finds '.' and relpath of 'foo' wt, relpath = WorkingTree.open_containing('./foo') wt, relpath = WorkingTree.open_containing( urlutils.local_path_to_url(getcwd() + '/foo')) self.assertEqual('foo', relpath) self.assertEqual(wt.basedir + '/', local_base)
def vimdiff_to_file(vimdiff_args, file_to_diff, revision=None): from bzrlib.workingtree import WorkingTree work_tree, rel_path = WorkingTree.open_containing(file_to_diff) work_tree.lock_read() try: _vimdiff_to_file(work_tree, rel_path, vimdiff_args, file_to_diff, revision=revision) finally: work_tree.unlock()
def run(self, threshold=55, dry_run=False): from bzrlib.workingtree import WorkingTree tree = WorkingTree.open_containing('.')[0] tree.lock_write() try: self.tree = tree self.basis_tree = tree.basis_tree() self._detect_moves(threshold / 100.0, dry_run) finally: tree.unlock()
def run(self, text=False): from bzrlib.workingtree import WorkingTree wt = WorkingTree.open_containing(u'.')[0] for conflict in wt.conflicts(): if text: if conflict.typestring != 'text conflict': continue self.outf.write(conflict.path + '\n') else: self.outf.write(str(conflict) + '\n')
def update_file_info(self, file): if file.get_uri_scheme() != 'file': return try: tree, path = WorkingTree.open_containing(file.get_uri()) except NotBranchError: return except NoWorkingTree: return disabled_flag = self.check_branch_enabled(tree.branch) if disabled_flag == 'False': return emblem = None status = None id = tree.path2id(path) if id == None: if tree.is_ignored(path): status = 'ignored' emblem = 'bzr-ignored' else: status = 'unversioned' elif tree.has_filename(path): emblem = 'bzr-controlled' status = 'unchanged' delta = tree.changes_from(tree.branch.basis_tree()) if delta.touches_file_id(id): emblem = 'bzr-modified' status = 'modified' for f, _, _ in delta.added: if f == path: emblem = 'bzr-added' status = 'added' for of, f, _, _, _, _ in delta.renamed: if f == path: status = 'renamed from %s' % f elif tree.branch.basis_tree().has_filename(path): emblem = 'bzr-removed' status = 'removed' else: # FIXME: Check for ignored files status = 'unversioned' if emblem is not None: file.add_emblem(emblem) file.add_string_attribute('bzr_status', status)
def vimdiff_to_file(vimdiff_args, file_to_diff, revision=None): from bzrlib.workingtree import WorkingTree work_tree, rel_path = WorkingTree.open_containing(file_to_diff) work_tree.lock_read() try: _vimdiff_to_file(work_tree, rel_path, vimdiff_args, file_to_diff, revision=revision) finally: work_tree.unlock()
def remove_cb(self, menu, vfs_file): # We can only cope with local files if vfs_file.get_uri_scheme() != 'file': return file = vfs_file.get_uri() try: tree, path = WorkingTree.open_containing(file) except NotBranchError: return tree.remove(path)
def newtree_cb(self, menu, vfs_file): # We can only cope with local files if vfs_file.get_uri_scheme() != 'file': return file = vfs_file.get_uri() # We only want to continue here if we get a NotBranchError try: tree, path = WorkingTree.open_containing(file) except NotBranchError: BzrDir.create_standalone_workingtree(file)
def update(self, update_file=False): self.tree = None self.root = self.path try: self.tree = WorkingTree.open_containing(self.path)[0] self.root = self.tree.basedir except NoWorkingTree: pass if update_file: self.update_file()
def commit_cb(self, menu, vfs_file=None): # We can only cope with local files if vfs_file.get_uri_scheme() != 'file': return file = vfs_file.get_uri() tree = None branch = None try: tree, path = WorkingTree.open_containing(file) branch = tree.branch except NotBranchError, e: path = e.path
def toggle_integration(self, menu, action, vfs_file=None): try: tree, path = WorkingTree.open_containing(vfs_file.get_uri()) except NotBranchError: return except NoWorkingTree: return branch = tree.branch if branch is None: config = GlobalConfig() else: config = branch.get_config() config.set_user_option('nautilus_integration', action)
def test_resolve_in_subdir(self): """resolve when run from subdirectory should handle relative paths""" orig_dir = os.getcwdu() try: os.mkdir("subdir") os.chdir("subdir") self.run_bzr("resolve ../myfile") os.chdir("../../b") self.run_bzr("resolve ../a/myfile") wt = WorkingTree.open_containing('.')[0] conflicts = wt.conflicts() if not conflicts.is_empty(): self.fail("tree still contains conflicts: %r" % conflicts) finally: os.chdir(orig_dir)
def test_resolve_in_subdir(self): """resolve when run from subdirectory should handle relative paths""" orig_dir = os.getcwdu() try: os.mkdir("subdir") os.chdir("subdir") self.run_bzr("resolve ../myfile") os.chdir("../../b") self.run_bzr("resolve ../a/myfile") wt = WorkingTree.open_containing('.')[0] conflicts = wt.conflicts() if not conflicts.is_empty(): self.fail("tree still contains conflicts: %r" % conflicts) finally: os.chdir(orig_dir)
def pull_cb(self, menu, vfs_file): # We can only cope with local files if vfs_file.get_uri_scheme() != 'file': return file = vfs_file.get_uri() # We only want to continue here if we get a NotBranchError try: tree, path = WorkingTree.open_containing(file) except NotBranchError: return from bzrlib.plugins.gtk.pull import PullDialog dialog = PullDialog(tree, path) dialog.display() gtk.main()
def __init__(self): cmd.Cmd.__init__(self) self.prompt = "bzr> " try: self.tree = WorkingTree.open_containing('.')[0] except: self.tree = None self.set_title() self.set_prompt() self.identchars += '-' ensure_config_dir_exists() self.history_file = osutils.pathjoin(config_dir(), 'shell-history') readline.set_completer_delims(string.whitespace) if os.access(self.history_file, os.R_OK) and \ os.path.isfile(self.history_file): readline.read_history_file(self.history_file) self.cwd = os.getcwd()
def merge_cb(self, menu, vfs_file): # We can only cope with local files if vfs_file.get_uri_scheme() != 'file': return file = vfs_file.get_uri() # We only want to continue here if we get a NotBranchError try: tree, path = WorkingTree.open_containing(file) except NotBranchError: return from bzrlib.plugins.gtk.merge import MergeDialog dialog = MergeDialog(tree, path) dialog.run() dialog.destroy()
def run(self, directory="."): from bzrlib.plugins.rewrite.rebase import RebaseState1, complete_revert from bzrlib.workingtree import WorkingTree wt = WorkingTree.open_containing(directory)[0] wt.lock_write() try: state = RebaseState1(wt) # Read plan file and set last revision try: last_rev_info = state.read_plan()[0] except NoSuchFile: raise BzrCommandError("No rebase to abort") complete_revert(wt, [last_rev_info[1]]) state.remove_plan() finally: wt.unlock()
def __init__(self): cmd.Cmd.__init__(self) self.prompt = "bzr> " try: self.tree = WorkingTree.open_containing('.')[0] except: self.tree = None self.set_title() self.set_prompt() self.identchars += '-' ensure_config_dir_exists() self.history_file = osutils.pathjoin(config_dir(), 'shell-history') readline.set_completer_delims(string.whitespace) if os.access(self.history_file, os.R_OK) and \ os.path.isfile(self.history_file): readline.read_history_file(self.history_file) self.cwd = os.getcwd()
def get_rootdir(): """Work out what the rootdir should be""" # strange things can happen when you mess up your ROOTDIR, so it pays # to be careful rootdir = None if 'ROOTDIR' in os.environ: rootdir = os.environ['ROOTDIR'] if _bad_rootdir(rootdir): warn('Environment variable ROOTDIR is bad, falling back to bzr') rootdir = None elif not abspath(__file__).startswith(abspath(rootdir)): warn('Environment variable ROOTDIR is pointing somewhere else') if rootdir is None: rootdir = WorkingTree.open_containing(__file__)[0].basedir if _bad_rootdir(rootdir): raise RuntimeError("Bad ROOTDIR %r (bzr trouble?)" % (rootdir,)) return rootdir
def diff_cb(self, menu, vfs_file): # We can only cope with local files if vfs_file.get_uri_scheme() != 'file': return file = vfs_file.get_uri() try: tree, path = WorkingTree.open_containing(file) except NotBranchError: return from bzrlib.plugins.gtk.diff import DiffWindow window = DiffWindow() window.set_diff(tree.branch._get_nick(local=True), tree, tree.branch.basis_tree()) window.show() return
def run(self, directory="."): from bzrlib.plugins.rewrite.rebase import RebaseState1, rebase_todo from bzrlib.workingtree import WorkingTree wt = WorkingTree.open_containing(directory)[0] wt.lock_read() try: state = RebaseState1(wt) try: replace_map = state.read_plan()[1] except NoSuchFile: raise BzrCommandError(gettext("No rebase in progress")) currentrevid = state.read_active_revid() if currentrevid is not None: note(gettext("Currently replaying: %s") % currentrevid) for revid in rebase_todo(wt.branch.repository, replace_map): note(gettext("{0} -> {1}").format(revid, replace_map[revid][0])) finally: wt.unlock()
def load(self): self.wt = wt = WorkingTree.open_containing(self.wt_dir)[0] self.set_title([gettext("Conflicts"), wt.basedir]) conflicts = self.wt.conflicts() items = [] for conflict in conflicts: item = QtGui.QTreeWidgetItem() item.setText(0, conflict.path) item.setText(1, gettext(conflict.typestring)) item.setData( 0, QtCore.Qt.UserRole, QtCore.QVariant(conflict.file_id or '') ) # file_id is None for non-versioned items, so we force it to be empty string to avoid Qt error item.setData(1, QtCore.Qt.UserRole, QtCore.QVariant(conflict.typestring)) items.append(item) if len(items) == 0 and self.conflicts_list.topLevelItemCount() > 0: self.emit(QtCore.SIGNAL("allResolved(bool)"), True) self.conflicts_list.clear() self.conflicts_list.addTopLevelItems(items)
def clean_tree(directory, unknown=False, ignored=False, detritus=False, dry_run=False, no_prompt=False): """Remove files in the specified classes from the tree""" tree = WorkingTree.open_containing(directory)[0] tree.lock_read() try: deletables = list(iter_deletables(tree, unknown=unknown, ignored=ignored, detritus=detritus)) deletables = _filter_out_nested_bzrdirs(deletables) if len(deletables) == 0: note(gettext('Nothing to delete.')) return 0 if not no_prompt: for path, subp in deletables: ui.ui_factory.note(subp) prompt = gettext('Are you sure you wish to delete these') if not ui.ui_factory.get_boolean(prompt): ui.ui_factory.note(gettext('Canceled')) return 0 delete_items(deletables, dry_run=dry_run) finally: tree.unlock()
def run(self, file_list=None, all=False): from bzrlib.workingtree import WorkingTree if all: if file_list: raise errors.BzrCommandError("If --all is specified," " no FILE may be provided") tree = WorkingTree.open_containing('.')[0] resolve(tree) else: tree, file_list = builtins.tree_files(file_list) if file_list is None: un_resolved, resolved = tree.auto_resolve() if len(un_resolved) > 0: trace.note('%d conflict(s) auto-resolved.', len(resolved)) trace.note('Remaining conflicts:') for conflict in un_resolved: trace.note(conflict) return 1 else: trace.note('All conflicts resolved.') return 0 else: resolve(tree, file_list)
def run(self, merge_type=None, directory="."): from bzrlib.plugins.rewrite.rebase import ( RebaseState1, rebase, WorkingTreeRevisionRewriter, ) from bzrlib.workingtree import WorkingTree wt = WorkingTree.open_containing(directory)[0] wt.lock_write() try: state = RebaseState1(wt) replayer = WorkingTreeRevisionRewriter(wt, state, merge_type=merge_type) # Abort if there are any conflicts if len(wt.conflicts()) != 0: raise BzrCommandError("There are still conflicts present. " "Resolve the conflicts and then run " "'bzr resolve' and try again.") # Read plan file try: replace_map = state.read_plan()[1] except NoSuchFile: raise BzrCommandError("No rebase to continue") oldrevid = state.read_active_revid() if oldrevid is not None: oldrev = wt.branch.repository.get_revision(oldrevid) replayer.commit_rebase(oldrev, replace_map[oldrevid][0]) try: # Start executing plan from current Branch.last_revision() rebase(wt.branch.repository, replace_map, replayer) except ConflictsInTree: raise BzrCommandError("A conflict occurred replaying a commit." " Resolve the conflict and run 'bzr rebase-continue' or " "run 'bzr rebase-abort'.") # Remove plan file state.remove_plan() finally: wt.unlock()
def run(self): from bzrlib.branch import Branch from bzrlib.errors import NoWorkingTree from bzrlib.workingtree import WorkingTree from bzrlib import urlutils import os from PyQt4 import QtCore, QtGui from qctlib.gui_logic import CommitTool from qctlib.vcs.bzr import qctVcsBzr def local_path(path): if path.startswith("file://"): return urlutils.local_path_from_url(path) else: return urlutils.unescape(path) try: branch = WorkingTree.open_containing(u'.')[0].branch except NoWorkingTree: branch = Branch.open_containing(u'.')[0] branch_root = branch.bzrdir.root_transport.base # print "Branch root at " + branch_root os.chdir(local_path(branch_root)) vcs = qctVcsBzr() if vcs.initRepo(None) != 0: return try: app = QtGui.QApplication([]) dialog = CommitTool(vcs) dialog.show() app.exec_() except SystemExit: pass
def run( self, upstream_location=None, onto=None, revision=None, merge_type=None, verbose=False, dry_run=False, always_rebase_merges=False, pending_merges=False, directory=".", ): from bzrlib.branch import Branch from bzrlib.revisionspec import RevisionSpec from bzrlib.workingtree import WorkingTree from bzrlib.plugins.rewrite.rebase import ( generate_simple_plan, rebase, RebaseState1, WorkingTreeRevisionRewriter, regenerate_default_revid, rebase_todo, ) if revision is not None and pending_merges: raise BzrCommandError(gettext("--revision and --pending-merges are mutually exclusive")) wt = WorkingTree.open_containing(directory)[0] wt.lock_write() try: state = RebaseState1(wt) if upstream_location is None: if pending_merges: upstream_location = directory else: upstream_location = wt.branch.get_parent() if upstream_location is None: raise BzrCommandError(gettext("No upstream branch specified.")) note(gettext("Rebasing on %s"), upstream_location) upstream = Branch.open_containing(upstream_location)[0] upstream_repository = upstream.repository upstream_revision = upstream.last_revision() # Abort if there already is a plan file if state.has_plan(): raise BzrCommandError( gettext( "A rebase operation was interrupted. " "Continue using 'bzr rebase-continue' or abort using 'bzr " "rebase-abort'" ) ) start_revid = None stop_revid = None if revision is not None: if len(revision) == 1: if revision[0] is not None: stop_revid = revision[0].as_revision_id(wt.branch) elif len(revision) == 2: if revision[0] is not None: start_revid = revision[0].as_revision_id(wt.branch) if revision[1] is not None: stop_revid = revision[1].as_revision_id(wt.branch) else: raise BzrCommandError(gettext("--revision takes only one or two arguments")) if pending_merges: wt_parents = wt.get_parent_ids() if len(wt_parents) in (0, 1): raise BzrCommandError(gettext("No pending merges present.")) elif len(wt_parents) > 2: raise BzrCommandError(gettext("Rebasing more than one pending merge not supported")) stop_revid = wt_parents[1] assert stop_revid is not None, "stop revid invalid" # Check for changes in the working tree. if not pending_merges and wt.basis_tree().changes_from(wt).has_changed(): raise UncommittedChanges(wt) # Pull required revisions wt.branch.repository.fetch(upstream_repository, upstream_revision) if onto is None: onto = upstream.last_revision() else: rev_spec = RevisionSpec.from_string(onto) onto = rev_spec.as_revision_id(upstream) wt.branch.repository.fetch(upstream_repository, onto) if stop_revid is None: stop_revid = wt.branch.last_revision() repo_graph = wt.branch.repository.get_graph() our_new, onto_unique = repo_graph.find_difference(stop_revid, onto) if start_revid is None: if not onto_unique: self.outf.write(gettext("No revisions to rebase.\n")) return if not our_new: self.outf.write(gettext("Base branch is descendant of current " "branch. Pulling instead.\n")) if not dry_run: wt.pull(upstream, onto) return # else: include extra revisions needed to make start_revid mean # something. # Create plan replace_map = generate_simple_plan( our_new, start_revid, stop_revid, onto, repo_graph, lambda revid, ps: regenerate_default_revid(wt.branch.repository, revid), not always_rebase_merges, ) if verbose or dry_run: todo = list(rebase_todo(wt.branch.repository, replace_map)) note(gettext("%d revisions will be rebased:") % len(todo)) for revid in todo: note("%s" % revid) if not dry_run: # Write plan file state.write_plan(replace_map) replayer = WorkingTreeRevisionRewriter(wt, state, merge_type=merge_type) finish_rebase(state, wt, replace_map, replayer) finally: wt.unlock()
class PromptCmd(cmd.Cmd): def __init__(self): cmd.Cmd.__init__(self) self.prompt = "bzr> " try: self.tree = WorkingTree.open_containing('.')[0] except: self.tree = None self.set_title() self.set_prompt() self.identchars += '-' ensure_config_dir_exists() self.history_file = osutils.pathjoin(config_dir(), 'shell-history') readline.set_completer_delims(string.whitespace) if os.access(self.history_file, os.R_OK) and \ os.path.isfile(self.history_file): readline.read_history_file(self.history_file) self.cwd = os.getcwd() def write_history(self): readline.write_history_file(self.history_file) def do_quit(self, args): self.write_history() raise StopIteration def do_exit(self, args): self.do_quit(args) def do_EOF(self, args): print self.do_quit(args) def postcmd(self, line, bar): self.set_title() self.set_prompt() def set_prompt(self): if self.tree is not None: try: prompt_data = (self.tree.branch.nick, self.tree.branch.revno(), self.tree.relpath('.')) prompt = " %s:%d/%s" % prompt_data except: prompt = "" else: prompt = "" self.prompt = "bzr%s> " % prompt def set_title(self, command=None): try: b = Branch.open_containing('.')[0] version = "%s:%d" % (b.nick, b.revno()) except: version = "[no version]" if command is None: command = "" sys.stdout.write(terminal.term_title("bzr %s %s" % (command, version))) def do_cd(self, line): if line == "": line = "~" line = os.path.expanduser(line) if os.path.isabs(line): newcwd = line else: newcwd = self.cwd + '/' + line newcwd = os.path.normpath(newcwd) try: os.chdir(newcwd) self.cwd = newcwd except Exception, e: print e try: self.tree = WorkingTree.open_containing(".")[0] except: self.tree = None
def run(self, location=None, remember=False, directory=None, no_rebase=False, strict=None): from bzrlib import urlutils from bzrlib.controldir import ControlDir from bzrlib.errors import BzrCommandError, NoWorkingTree from bzrlib.workingtree import WorkingTree if directory is None: directory = "." try: source_wt = WorkingTree.open_containing(directory)[0] source_branch = source_wt.branch except NoWorkingTree: source_branch = Branch.open(directory) source_wt = None if source_wt is not None: source_wt.check_changed_or_out_of_date( strict, 'dpush_strict', more_error='Use --no-strict to force the push.', more_warning='Uncommitted changes will not be pushed.') stored_loc = source_branch.get_push_location() if location is None: if stored_loc is None: raise BzrCommandError( gettext("No push location known or specified.")) else: display_url = urlutils.unescape_for_display( stored_loc, self.outf.encoding) self.outf.write( gettext("Using saved location: %s\n") % display_url) location = stored_loc controldir = ControlDir.open(location) target_branch = controldir.open_branch() target_branch.lock_write() try: try: push_result = source_branch.push(target_branch, lossy=True) except errors.LossyPushToSameVCS: raise BzrCommandError( gettext( "{0!r} and {1!r} are in the same VCS, lossy " "push not necessary. Please use regular push.").format( source_branch, target_branch)) # We successfully created the target, remember it if source_branch.get_push_location() is None or remember: # FIXME: Should be done only if we succeed ? -- vila 2012-01-18 source_branch.set_push_location(target_branch.base) if not no_rebase: old_last_revid = source_branch.last_revision() source_branch.pull(target_branch, overwrite=True) new_last_revid = source_branch.last_revision() if source_wt is not None and old_last_revid != new_last_revid: source_wt.lock_write() try: target = source_wt.branch.repository.revision_tree( new_last_revid) update_workingtree_fileids(source_wt, target) finally: source_wt.unlock() push_result.report(self.outf) finally: target_branch.unlock()
def get_file_items(self, window, files): items = [] wtfiles = {} for vfs_file in files: # We can only cope with local files if vfs_file.get_uri_scheme() != 'file': continue file = vfs_file.get_uri() try: tree, path = WorkingTree.open_containing(file) disabled_flag = self.check_branch_enabled(tree.branch) except NotBranchError: disabled_flag = self.check_branch_enabled() if not vfs_file.is_directory(): continue if disabled_flag == 'False': return item = nautilus.MenuItem('BzrNautilus::newtree', 'Make directory versioned', 'Create new Bazaar tree in %s' % vfs_file.get_name()) item.connect('activate', self.newtree_cb, vfs_file) return item, except NoWorkingTree: continue # Refresh the list of filestatuses in the working tree if path not in wtfiles.keys(): tree.lock_read() for rpath, file_class, kind, id, entry in tree.list_files(): wtfiles[rpath] = file_class tree.unlock() wtfiles[u''] = 'V' if wtfiles[path] == '?': item = nautilus.MenuItem('BzrNautilus::add', 'Add', 'Add as versioned file') item.connect('activate', self.add_cb, vfs_file) items.append(item) item = nautilus.MenuItem('BzrNautilus::ignore', 'Ignore', 'Ignore file for versioning') item.connect('activate', self.ignore_cb, vfs_file) items.append(item) elif wtfiles[path] == 'I': item = nautilus.MenuItem('BzrNautilus::unignore', 'Unignore', 'Unignore file for versioning') item.connect('activate', self.unignore_cb, vfs_file) items.append(item) elif wtfiles[path] == 'V': item = nautilus.MenuItem('BzrNautilus::log', 'History ...', 'List changes') item.connect('activate', self.log_cb, vfs_file) items.append(item) item = nautilus.MenuItem('BzrNautilus::diff', 'View Changes ...', 'Show differences') item.connect('activate', self.diff_cb, vfs_file) items.append(item) item = nautilus.MenuItem('BzrNautilus::remove', 'Remove', 'Remove this file from versioning') item.connect('activate', self.remove_cb, vfs_file) items.append(item) item = nautilus.MenuItem('BzrNautilus::annotate', 'Annotate ...', 'Annotate File Data') item.connect('activate', self.annotate_cb, vfs_file) items.append(item) item = nautilus.MenuItem('BzrNautilus::commit', 'Commit ...', 'Commit Changes') item.connect('activate', self.commit_cb, vfs_file) items.append(item) return items
def get_background_items(self, window, vfs_file): items = [] file = vfs_file.get_uri() try: tree, path = WorkingTree.open_containing(file) disabled_flag = self.check_branch_enabled(tree.branch) except UnsupportedProtocol: return except NotBranchError: disabled_flag = self.check_branch_enabled() item = nautilus.MenuItem('BzrNautilus::newtree', 'Make directory versioned', 'Create new Bazaar tree in this folder') item.connect('activate', self.newtree_cb, vfs_file) items.append(item) item = nautilus.MenuItem('BzrNautilus::clone', 'Checkout Bazaar branch ...', 'Checkout Existing Bazaar Branch') item.connect('activate', self.clone_cb, vfs_file) items.append(item) return items except NoWorkingTree: return if disabled_flag == 'False': item = nautilus.MenuItem('BzrNautilus::enable', 'Enable Bazaar Plugin for this Branch', 'Enable Bazaar plugin for nautilus') item.connect('activate', self.toggle_integration, 'True', vfs_file) return item, else: item = nautilus.MenuItem('BzrNautilus::disable', 'Disable Bazaar Plugin this Branch', 'Disable Bazaar plugin for nautilus') item.connect('activate', self.toggle_integration, 'False', vfs_file) items.append(item) item = nautilus.MenuItem('BzrNautilus::log', 'History ...', 'Show Bazaar history') item.connect('activate', self.log_cb, vfs_file) items.append(item) item = nautilus.MenuItem('BzrNautilus::pull', 'Pull ...', 'Pull from another branch') item.connect('activate', self.pull_cb, vfs_file) items.append(item) item = nautilus.MenuItem('BzrNautilus::merge', 'Merge ...', 'Merge from another branch') item.connect('activate', self.merge_cb, vfs_file) items.append(item) item = nautilus.MenuItem('BzrNautilus::commit', 'Commit ...', 'Commit Changes') item.connect('activate', self.commit_cb, vfs_file) items.append(item) return items
def run(self, location=None, remember=False, directory=None, no_rebase=False): from bzrlib import urlutils from bzrlib.bzrdir import BzrDir from bzrlib.errors import BzrCommandError, NoWorkingTree from bzrlib.trace import info from bzrlib.workingtree import WorkingTree from upgrade import update_workingtree_fileids if directory is None: directory = "." try: source_wt = WorkingTree.open_containing(directory)[0] source_branch = source_wt.branch except NoWorkingTree: source_branch = Branch.open_containing(directory)[0] source_wt = None stored_loc = source_branch.get_push_location() if location is None: if stored_loc is None: raise BzrCommandError("No push location known or specified.") else: display_url = urlutils.unescape_for_display( stored_loc, self.outf.encoding) self.outf.write("Using saved location: %s\n" % display_url) location = stored_loc bzrdir = BzrDir.open(location) target_branch = bzrdir.open_branch() target_branch.lock_write() try: if not isinstance(target_branch, ForeignBranch): info( "target branch is not a foreign branch, using regular push." ) target_branch.pull(source_branch) no_rebase = True else: revid_map = target_branch.dpull(source_branch) # We successfully created the target, remember it if source_branch.get_push_location() is None or remember: source_branch.set_push_location(target_branch.base) if not no_rebase: _, old_last_revid = source_branch.last_revision_info() new_last_revid = revid_map[old_last_revid] if source_wt is not None: source_wt.pull(target_branch, overwrite=True, stop_revision=new_last_revid) source_wt.lock_write() try: update_workingtree_fileids( source_wt, source_wt.branch.repository.revision_tree( old_last_revid), source_wt.branch.repository.revision_tree( new_last_revid)) finally: source_wt.unlock() else: source_branch.pull(target_branch, overwrite=True, stop_revision=new_last_revid) finally: target_branch.unlock()