/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.5.7 by John Arbash Meinel
Added a bunch more information about changesets. Can now read back in all of the meta information.
1
#!/usr/bin/env python
2
"""\
3
Common entries, like strings, etc, for the changeset reading + writing code.
4
"""
5
6
header_str = 'Bazaar-NG (bzr) changeset v'
7
version = (0, 0, 5)
8
9
def get_header():
10
    return [
11
        header_str + '.'.join([str(v) for v in version]),
12
        'This changeset can be applied with bzr apply-changeset',
13
        ''
14
    ]
15
0.5.36 by John Arbash Meinel
Updated so that read_changeset is able to parse the output
16
def canonicalize_revision(branch, revnos):
17
    """Turn some sort of revision information into a single
18
    set of from-to revision ids.
19
20
    A revision id can be None if there is no associated revison.
21
22
    :param revnos:  A list of revisions to lookup, should be at most 2 long
23
    :return: (old, new)
24
    """
25
    # If only 1 entry is given, then we assume we want just the
26
    # changeset between that entry and it's base (we assume parents[0])
27
    if len(revnos) == 0:
28
        revnos = [None, None]
29
    elif len(revnos) == 1:
30
        revnos = [None, revnos[0]]
31
32
    if revnos[1] is None:
33
        new = branch.last_patch()
34
    else:
35
        new = branch.lookup_revision(revnos[1])
36
    if revnos[0] is None:
37
        old = branch.get_revision(new).parents[0].revision_id
38
    else:
39
        old = branch.lookup_revision(revnos[0])
40
41
    return old, new
42
0.5.39 by John Arbash Meinel
(broken) Working on changing the processing to use a ChangesetTree.
43
class ChangesetTree(object):
44
    """This class is designed to take a base tree, and re-create
45
    a final tree based on the information contained within a
46
    changeset.
47
    """
48
49
    def __init__(self, branch, changeset_info):
50
        """Initialize this ChangesetTree.
51
52
        :param branch:  This is where information will be acquired
53
                        and updated.
54
        :param changeset_info:  Information about a given changeset,
55
                                so that we can identify the base,
56
                                and other information.
57
        """
58
        self.branch = branch
59
        self.changeset_info = changeset_info
60
61
        self._build_tree()
62
63
    def _build_tree(self):
64
        """Build the final description of the tree, based on
65
        the changeset_info object.
66
        """
67
        
68
def format_highres_date(t, offset=0):
69
    """Format a date, such that it includes higher precision in the
70
    seconds field.
71
72
    :param t:   UTC time in fractional seconds
73
    :type t: float
74
    :param offset:  The timezone offset in integer seconds
75
    :type offset: int
76
77
    >>> from bzrlib.osutils import format_date
78
    >>> format_date(1120153132.350850105, 0)
79
    'Thu 2005-06-30 17:38:52 +0000'
80
    >>> format_highres_date(1120153132.350850105, 0)
81
    'Thu 2005-06-30 17:38:52.350850105 +0000'
82
    >>> format_date(1120153132.350850105, -5*3600)
83
    'Thu 2005-06-30 12:38:52 -0500'
84
    >>> format_highres_date(1120153132.350850105, -5*3600)
85
    'Thu 2005-06-30 12:38:52.350850105 -0500'
86
    """
87
    from bzrlib.errors import BzrError
88
    import time
89
    assert isinstance(t, float)
90
    
91
    # This has to be formatted for "original" date, so that the
92
    # revision XML entry will be reproduced faithfully.
93
    if offset == None:
94
        offset = 0
95
    tt = time.gmtime(t + offset)
96
97
    return (time.strftime("%a %Y-%m-%d %H:%M:%S", tt)
98
            + ('%.9f' % (t - int(t)))[1:] # Get the high-res seconds, but ignore the 0
99
            + ' %+03d%02d' % (offset / 3600, (offset / 60) % 60))
100
101
def unpack_highres_date(date):
102
    """This takes the high-resolution date stamp, and
103
    converts it back into the tuple (timestamp, timezone)
104
    Where timestamp is in real seconds, and timezone is an integer
105
    number of seconds offset.
106
107
    :param date: A date formated by format_highres_date
108
    :type date: string
109
110
    """
111
112
if __name__ == '__main__':
113
    import doctest
114
    doctest.testmod()