/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/textinv.py

  • Committer: Robert Collins
  • Date: 2007-04-19 02:27:44 UTC
  • mto: This revision was merged to the branch mainline in revision 2426.
  • Revision ID: robertc@robertcollins.net-20070419022744-pfdqz42kp1wizh43
``make docs`` now creates a man page at ``man1/bzr.1`` fixing bug 107388.
(Robert Collins)

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
16
 
 
17
 
from .errors import BzrError
18
 
from .inventory import Inventory
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
16
 
 
17
 
 
18
from bzrlib.errors import BzrError
 
19
from bzrlib.inventory import InventoryEntry, Inventory
19
20
 
20
21
 
21
22
START_MARK = "# bzr inventory format 3\n"
24
25
 
25
26
def escape(s):
26
27
    """Very simple URL-like escaping.
27
 
 
 
28
    
28
29
    (Why not just use backslashes?  Because then we couldn't parse
29
30
    lines just by splitting on spaces.)"""
30
31
    return (s.replace('\\', r'\x5c')
33
34
            .replace('\n', r'\x0a'))
34
35
 
35
36
 
 
37
 
36
38
def unescape(s):
37
 
    if s.find(' ') != -1:
38
 
        raise AssertionError()
 
39
    assert s.find(' ') == -1
39
40
    s = (s.replace(r'\x20', ' ')
40
41
         .replace(r'\x09', '\t')
41
42
         .replace(r'\x0a', '\n')
44
45
    # TODO: What if there's anything else?
45
46
 
46
47
    return s
 
48
    
 
49
                     
47
50
 
48
51
 
49
52
def write_text_inventory(inv, outf):
52
55
    for path, ie in inv.iter_entries():
53
56
        if inv.is_root(ie.file_id):
54
57
            continue
55
 
 
 
58
        
56
59
        outf.write(ie.file_id + ' ')
57
60
        outf.write(escape(ie.name) + ' ')
58
61
        outf.write(ie.kind + ' ')
59
62
        outf.write(ie.parent_id + ' ')
60
 
 
 
63
        
61
64
        if ie.kind == 'file':
62
65
            outf.write(ie.text_id)
63
66
            outf.write(' ' + ie.text_sha1)
70
73
    """Return an inventory read in from tf"""
71
74
    if tf.readline() != START_MARK:
72
75
        raise BzrError("missing start mark")
73
 
 
 
76
    
74
77
    inv = Inventory()
75
78
 
76
79
    for l in tf:
81
84
              'name': unescape(fields[1]),
82
85
              'kind': fields[2],
83
86
              'parent_id': fields[3]}
84
 
        # inv.add(ie)
85
 
 
 
87
        ##inv.add(ie)
 
88
        
86
89
    if l != END_MARK:
87
90
        raise BzrError("missing end mark")
88
91
    return inv