/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: 2018-07-04 12:50:55 UTC
  • mfrom: (7027.2.8 git-fixes)
  • Revision ID: breezy.the.bot@gmail.com-20180704125055-8nni25pn2439p48v
Fix eol handling in knits on Python 3, port fastimport plugin to Python 3.

Merged from https://code.launchpad.net/~jelmer/brz/fastimport-fixes/+merge/348924

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
    """
30
30
    # Check that the file is readable and in the right format
31
31
    try:
32
 
        f = open(filename)
 
32
        f = open(filename, 'r')
33
33
    except IOError:
34
34
        warning("Could not import marks file %s - not importing marks",
35
35
            filename)
36
36
        return None
37
37
 
38
 
    # Read the revision info
39
 
    revision_ids = {}
40
 
 
41
 
    line = f.readline()
42
 
    if line == 'format=1\n':
43
 
        # Cope with old-style marks files
44
 
        # Read the branch info
45
 
        branch_names = {}
46
 
        for string in f.readline().rstrip('\n').split('\0'):
47
 
            if not string:
48
 
                continue
49
 
            name, integer = string.rsplit('.', 1)
50
 
            branch_names[name] = int(integer)
51
 
        line = f.readline()
52
 
 
53
 
    while line:
54
 
        line = line.rstrip('\n')
55
 
        mark, revid = line.split(' ', 1)
56
 
        mark = mark.lstrip(':')
57
 
        revision_ids[mark] = revid
58
 
        line = f.readline()
59
 
    f.close()
 
38
    try:
 
39
        # Read the revision info
 
40
        revision_ids = {}
 
41
 
 
42
        line = f.readline()
 
43
        if line == 'format=1\n':
 
44
            # Cope with old-style marks files
 
45
            # Read the branch info
 
46
            branch_names = {}
 
47
            for string in f.readline().rstrip('\n').split('\0'):
 
48
                if not string:
 
49
                    continue
 
50
                name, integer = string.rsplit('.', 1)
 
51
                branch_names[name] = int(integer)
 
52
            line = f.readline()
 
53
 
 
54
        while line:
 
55
            line = line.rstrip('\n')
 
56
            mark, revid = line.split(' ', 1)
 
57
            mark = mark.lstrip(':')
 
58
            revision_ids[mark] = revid.encode('utf-8')
 
59
            line = f.readline()
 
60
    finally:
 
61
        f.close()
60
62
    return revision_ids
61
63
 
62
64
 
73
75
            filename)
74
76
        return
75
77
 
76
 
    # Write the revision info
77
 
    for mark in revision_ids:
78
 
        f.write(':%s %s\n' % (str(mark).lstrip(':'), revision_ids[mark]))
79
 
    f.close()
 
78
    try:
 
79
        # Write the revision info
 
80
        for mark in revision_ids:
 
81
            f.write(':%s %s\n' % (mark.lstrip(b':').decode('utf-8'),
 
82
                revision_ids[mark].decode('utf-8')))
 
83
    finally:
 
84
        f.close()