/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 breezy/plugins/fastimport/marks_file.py

  • Committer: Breezy landing bot
  • Author(s): Jelmer Vernooij
  • Date: 2020-07-20 02:17:05 UTC
  • mfrom: (7518.1.2 merge-3.1)
  • Revision ID: breezy.the.bot@gmail.com-20200720021705-5f11tmo1hdqjxm6x
Merge lp:brz/3.1.

Merged from https://code.launchpad.net/~jelmer/brz/merge-3.1/+merge/387628

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
    """
28
28
    # Check that the file is readable and in the right format
29
29
    try:
30
 
        f = open(filename, 'r')
 
30
        f = open(filename, 'rb')
31
31
    except IOError:
32
32
        warning("Could not import marks file %s - not importing marks",
33
33
                filename)
38
38
        revision_ids = {}
39
39
 
40
40
        line = f.readline()
41
 
        if line == 'format=1\n':
 
41
        if line == b'format=1\n':
42
42
            # Cope with old-style marks files
43
43
            # Read the branch info
44
44
            branch_names = {}
45
 
            for string in f.readline().rstrip('\n').split('\0'):
 
45
            for string in f.readline().rstrip(b'\n').split(b'\0'):
46
46
                if not string:
47
47
                    continue
48
 
                name, integer = string.rsplit('.', 1)
 
48
                name, integer = string.rsplit(b'.', 1)
49
49
                branch_names[name] = int(integer)
50
50
            line = f.readline()
51
51
 
52
52
        while line:
53
 
            line = line.rstrip('\n')
54
 
            mark, revid = line.split(' ', 1)
55
 
            mark = mark.lstrip(':')
56
 
            revision_ids[mark] = revid.encode('utf-8')
 
53
            line = line.rstrip(b'\n')
 
54
            mark, revid = line.split(b' ', 1)
 
55
            mark = mark.lstrip(b':')
 
56
            revision_ids[mark] = revid
57
57
            line = f.readline()
58
58
    finally:
59
59
        f.close()
67
67
    :param revision_ids: dictionary mapping marks -> bzr revision-ids
68
68
    """
69
69
    try:
70
 
        f = open(filename, 'w')
 
70
        f = open(filename, 'wb')
71
71
    except IOError:
72
72
        warning("Could not open export-marks file %s - not exporting marks",
73
73
                filename)
75
75
 
76
76
    try:
77
77
        # Write the revision info
78
 
        for mark in revision_ids:
79
 
            f.write(':%s %s\n' % (mark.lstrip(b':').decode('utf-8'),
80
 
                                  revision_ids[mark].decode('utf-8')))
 
78
        for mark, revid in sorted(revision_ids.items()):
 
79
            f.write(b':%s %s\n' % (mark.lstrip(b':'), revid))
81
80
    finally:
82
81
        f.close()