[Pkg-bazaar-commits] ./bzr/unstable r68: - new relpath command and function
mbp at sourcefrog.net
mbp at sourcefrog.net
Fri Apr 10 07:27:26 UTC 2009
------------------------------------------------------------
revno: 68
committer: mbp at sourcefrog.net
timestamp: Tue 2005-03-22 19:00:50 +1100
message:
- new relpath command and function
modified:
bzrlib/branch.py
bzrlib/commands.py
-------------- next part --------------
=== modified file 'bzrlib/branch.py'
--- a/bzrlib/branch.py 2005-03-22 07:28:45 +0000
+++ b/bzrlib/branch.py 2005-03-22 08:00:50 +0000
@@ -130,6 +130,19 @@
return os.path.join(self.base, name)
+ def relpath(self, path):
+ """Return path relative to this branch of something inside it.
+
+ Raises an error if path is not in this branch."""
+ rp = os.path.realpath(path)
+ # FIXME: windows
+ if not rp.startswith(self.base):
+ bailout("path %r is not within branch %r" % (rp, self.base))
+ rp = rp[len(self.base):]
+ rp = rp.lstrip(os.sep)
+ return rp
+
+
def controlfilename(self, file_or_path):
"""Return location relative to branch."""
if isinstance(file_or_path, types.StringTypes):
=== modified file 'bzrlib/commands.py'
--- a/bzrlib/commands.py 2005-03-22 07:25:50 +0000
+++ b/bzrlib/commands.py 2005-03-22 08:00:50 +0000
@@ -175,6 +175,10 @@
b.add(file_list, verbose=verbose)
+def cmd_relpath(filename):
+ print Branch(filename).relpath(filename)
+
+
def cmd_inventory(revision=None):
"""Show inventory of the current working copy."""
## TODO: Also optionally show a previous inventory
@@ -595,6 +599,7 @@
'diff': [],
'file-id': ['filename'],
'root': ['filename?'],
+ 'relpath': ['filename'],
'get-file-text': ['text_id'],
'get-inventory': ['inventory_id'],
'get-revision': ['revision_id'],
More information about the Pkg-bazaar-commits
mailing list