[Pkg-bazaar-commits] ./bzr/unstable r62: - new find_branch_root function; based on suggestion from aaron
mbp at sourcefrog.net
mbp at sourcefrog.net
Fri Apr 10 07:27:10 UTC 2009
------------------------------------------------------------
revno: 62
committer: mbp at sourcefrog.net
timestamp: Tue 2005-03-22 17:55:17 +1100
message:
- new find_branch_root function; based on suggestion from aaron
but cleaned up a bit and should work on non-unix systems
- new find-branch-root command to exercise it
- Branch constructor does this by default
modified:
bzrlib/branch.py
bzrlib/commands.py
-------------- next part --------------
=== modified file 'bzrlib/branch.py'
--- a/bzrlib/branch.py 2005-03-13 05:22:51 +0000
+++ b/bzrlib/branch.py 2005-03-22 06:55:17 +0000
@@ -1,6 +1,3 @@
-#! /usr/bin/env python
-# -*- coding: UTF-8 -*-
-
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
@@ -41,6 +38,32 @@
+def find_branch_root(f=None):
+ """Find the branch root enclosing f, or pwd.
+
+ It is not necessary that f exists.
+
+ Basically we keep looking up until we find the control directory or
+ run into the root."""
+ if f is None:
+ f = os.getcwd()
+ elif hasattr(os.path, 'realpath'):
+ f = os.path.realpath(f)
+ else:
+ f = os.path.abspath(f)
+
+ orig_f = f
+
+ last_f = f
+ while True:
+ if os.path.exists(os.path.join(f, bzrlib.BZRDIR)):
+ return f
+ head, tail = os.path.split(f)
+ if head == f:
+ # reached the root, whatever that may be
+ bailout('%r is not in a branch' % orig_f)
+ f = head
+
######################################################################
@@ -62,27 +85,32 @@
:todo: mkdir() method.
"""
- def __init__(self, base, init=False):
+ def __init__(self, base, init=False, find_root=True):
"""Create new branch object at a particular location.
:param base: Base directory for the branch.
-
+
:param init: If True, create new control files in a previously
unversioned directory. If False, the branch must already
be versioned.
+ :param find_root: If true and init is false, find the root of the
+ existing branch containing base.
+
In the test suite, creation of new trees is tested using the
`ScratchBranch` class.
"""
- self.base = os.path.realpath(base)
if init:
self._make_control()
+ elif find_root:
+ self.base = find_branch_root(base)
else:
+ self.base = os.path.realpath(base)
if not isdir(self.controlfilename('.')):
bailout("not a bzr branch: %s" % quotefn(base),
['use "bzr init" to initialize a new working tree',
'current bzr can only operate from top-of-tree'])
- self._check_format()
+ self._check_format()
self.text_store = ImmutableStore(self.controlfilename('text-store'))
self.revision_store = ImmutableStore(self.controlfilename('revision-store'))
=== modified file 'bzrlib/commands.py'
--- a/bzrlib/commands.py 2005-03-22 00:37:17 +0000
+++ b/bzrlib/commands.py 2005-03-22 06:55:17 +0000
@@ -368,6 +368,10 @@
+def cmd_find_branch_root(filename=None):
+ print bzrlib.branch.find_branch_root(filename)
+
+
def cmd_log(timezone='original'):
"""Show log of this branch.
@@ -587,6 +591,7 @@
'commit': [],
'diff': [],
'file-id': ['filename'],
+ 'find-branch-root': ['filename?'],
'get-file-text': ['text_id'],
'get-inventory': ['inventory_id'],
'get-revision': ['revision_id'],
@@ -681,10 +686,12 @@
# TODO: Need a way to express 'cp SRC... DEST', where it matches
# all but one.
+ # step through args and argform, allowing appropriate 0-many matches
for ap in argform:
argname = ap[:-1]
if ap[-1] == '?':
- assert 0
+ if args:
+ argdict[argname] = args.pop(0)
elif ap[-1] == '*':
assert 0
elif ap[-1] == '+':
More information about the Pkg-bazaar-commits
mailing list