~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/textinv.py

  • Committer: Ian Clatworthy
  • Date: 2007-11-30 04:28:32 UTC
  • mto: (3054.1.1 ianc-integration)
  • mto: This revision was merged to the branch mainline in revision 3055.
  • Revision ID: ian.clatworthy@internode.on.net-20071130042832-6prruj0kzg3fodm8
chapter 2 tweaks

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
 
from __future__ import absolute_import
18
17
 
19
18
from bzrlib.errors import BzrError
20
 
from bzrlib.inventory import Inventory
 
19
from bzrlib.inventory import InventoryEntry, Inventory
21
20
 
22
21
 
23
22
START_MARK = "# bzr inventory format 3\n"
26
25
 
27
26
def escape(s):
28
27
    """Very simple URL-like escaping.
29
 
 
 
28
    
30
29
    (Why not just use backslashes?  Because then we couldn't parse
31
30
    lines just by splitting on spaces.)"""
32
31
    return (s.replace('\\', r'\x5c')
37
36
 
38
37
 
39
38
def unescape(s):
40
 
    if s.find(' ') != -1:
41
 
        raise AssertionError()
 
39
    assert s.find(' ') == -1
42
40
    s = (s.replace(r'\x20', ' ')
43
41
         .replace(r'\x09', '\t')
44
42
         .replace(r'\x0a', '\n')
47
45
    # TODO: What if there's anything else?
48
46
 
49
47
    return s
50
 
 
51
 
 
 
48
    
 
49
                     
52
50
 
53
51
 
54
52
def write_text_inventory(inv, outf):
57
55
    for path, ie in inv.iter_entries():
58
56
        if inv.is_root(ie.file_id):
59
57
            continue
60
 
 
 
58
        
61
59
        outf.write(ie.file_id + ' ')
62
60
        outf.write(escape(ie.name) + ' ')
63
61
        outf.write(ie.kind + ' ')
64
62
        outf.write(ie.parent_id + ' ')
65
 
 
 
63
        
66
64
        if ie.kind == 'file':
67
65
            outf.write(ie.text_id)
68
66
            outf.write(' ' + ie.text_sha1)
75
73
    """Return an inventory read in from tf"""
76
74
    if tf.readline() != START_MARK:
77
75
        raise BzrError("missing start mark")
78
 
 
 
76
    
79
77
    inv = Inventory()
80
78
 
81
79
    for l in tf:
87
85
              'kind': fields[2],
88
86
              'parent_id': fields[3]}
89
87
        ##inv.add(ie)
90
 
 
 
88
        
91
89
    if l != END_MARK:
92
90
        raise BzrError("missing end mark")
93
91
    return inv