[PATCH] export with top directory for tar format

William Dodé wilk-ml at flibuste.net
Thu Jul 7 10:35:39 BST 2005


On 06-07-2005, John A Meinel wrote:
> This is an OpenPGP/MIME signed message (RFC 2440 and 3156)
> --------------enigFCE5D33BDC20CE8586C24352
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
> Content-Transfer-Encoding: quoted-printable
>
> Lalo Martins wrote:
>
>>And so says William Dod=E9 on 06/07/05 21:45...
>> =20
>>
>>>When we export in tar format we cannot give a top directory like=20
>>>bzr-0.0.5/... It's very annoying when we extract it.
>>>
>>>If there is no better idea, i did a patch to can give the root=20
>>>directory as an option like : bzr export --format=3Dtgz
>>>--root=3Dbzr-0.0.5 bzr-0.0.5.tgz (maybe --top instead of root to don't
>>>make confusion with bzr root ?)
>>>   =20
>>>
>>
>>Sorry, not adding this feature to begin with, was a serious oversight on=
>
>>my part.  So I'm +1 on your patch.
>>
>>best,
>>Lalo Martins
>> =20
>>
> Well, I think in general having the exported tarbal use '/' is probably=20
> bad form. Pretty much nobody expects to untar and get files in the=20
> current directory. I would actually say we should default to using the=20
> name of the tarball, which can be overridden with something like a=20
> '--root' flag.

In the same time, should we remove the need of --format=tgz if the dest
file ends with .tgz ? (and so on with .tar .tar.gz .tbz2 .tar.bz2)

*** modified file 'bzrlib/commands.py'
--- bzrlib/commands.py 
+++ bzrlib/commands.py 
@@ -1042,19 +1042,32 @@
     If no revision is specified this exports the last committed revision.
 
     Format may be an "exporter" name, such as tar, tgz, tbz2.  If none is
-    given, exports to a directory (equivalent to --format=dir).
-
-    Root may be the top directory for tar, tgz and tbz2 formats."""
+    given, try to find the format with the extension. If no extension
+    is found exports to a directory (equivalent to --format=dir).
+
+    Root may be the top directory for tar, tgz and tbz2 formats. If none
+    is given, the top directory will be the root name of the file."""
     # TODO: list known exporters
     takes_args = ['dest']
     takes_options = ['revision', 'format', 'root']
-    def run(self, dest, revision=None, format='dir', root=None):
+    def run(self, dest, revision=None, format=None, root=None):
+        import os.path
         b = find_branch('.')
         if revision == None:
             rh = b.revision_history()[-1]
         else:
             rh = b.lookup_revision(int(revision))
         t = b.revision_tree(rh)
+        root, ext = os.path.splitext(dest)
+        if not format:
+            if ext in (".tar",):
+                format = "tar"
+            elif ext in (".gz", ".tgz"):
+                format = "tgz"
+            elif ext in (".bz2", ".tbz2"):
+                format = "tbz2"
+            else:
+                format = "dir"
         t.export(dest, format, root)

-- 
William Dodé - http://flibuste.net





More information about the bazaar mailing list