Search code examples
bazaar

Get file size in bazaar


How can I get the size of a versioned file/files? This seems to be a very common operation but I can't find how (Am I missing something?). Well, I can get it indirectly by catting it and count the bytes but this is very slow.

Any help would be appropriated.


Solution

  • You can't get information about file size from command-line but can get it with python, using bzrlib.

     import bzrlib
     from bzrlib import branch
    
     b = branch.Branch.open('.')
     b.lock_read()
     try:
         rt = b.repository.revision_tree(revision_id)
         fileid = rt.path2id('filename')
         if fileid is None:
             print 'file is not versioned!'
         else:
             print 'file size:', rt.get_file_size(fileid)
    finally:
        b.unlock()