~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/weavefile.py

  • Committer: NamNguyen
  • Date: 2007-08-01 06:14:14 UTC
  • mto: (2789.1.1 ianc-integration)
  • mto: This revision was merged to the branch mainline in revision 2790.
  • Revision ID: namnguyen-20070801061414-u0tzrfgcz6z604lz
``Branch.hooks`` now supports ``pre_commit`` hook.

The hook's signature is

::

  hook(local, master, old_revno, old_revid, new_revno, new_revid,
       deleted_paths, added_paths, future_revision_tree)

``deleted_paths`` and ``added_paths`` are lists of paths. Renamed paths are
recorded in both ``deleted_paths`` and ``added_paths`` (i.e. deleted then
added).

``future_revision_tree`` is obtained from ``CommitBuilder.revision_tree``
to save hooks from getting it from the branch again.

For example, hooks can get a file:

::

  for path in added_paths:
      id = future_revision_tree.path2id(path)
      if future_revision_tree.kind(id) == 'file':
          file = future_revision_tree.get_file(id)
          ...

or export a tree and do ``make check`` or similar

::

  import bzrlib.export
  bzrlib.export.export(future_revision_tree, 'tmp_space')


If the commit is to be rejected, hooks should raise an ``Exception``.

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
17
# Author: Martin Pool <mbp@canonical.com>
18
18
 
53
53
 
54
54
def write_weave_v5(weave, f):
55
55
    """Write weave to file f."""
56
 
    f.write(FORMAT_1)
 
56
    print >>f, FORMAT_1,
57
57
 
58
58
    for version, included in enumerate(weave._parents):
59
59
        if included:
60
60
            # mininc = weave.minimal_parents(version)
61
61
            mininc = included
62
 
            f.write('i ')
63
 
            f.write(' '.join(str(i) for i in mininc))
64
 
            f.write('\n')
 
62
            print >>f, 'i',
 
63
            for i in mininc:
 
64
                print >>f, i,
 
65
            print >>f
65
66
        else:
66
 
            f.write('i\n')
67
 
        f.write('1 ' + weave._sha1s[version] + '\n')
68
 
        f.write('n ' + weave._names[version] + '\n')
69
 
        f.write('\n')
 
67
            print >>f, 'i'
 
68
        print >>f, '1', weave._sha1s[version]
 
69
        print >>f, 'n', weave._names[version]
 
70
        print >>f
70
71
 
71
 
    f.write('w\n')
 
72
    print >>f, 'w'
72
73
 
73
74
    for l in weave._weave:
74
75
        if isinstance(l, tuple):
 
76
            assert l[0] in '{}[]'
75
77
            if l[0] == '}':
76
 
                f.write('}\n')
 
78
                print >>f, '}'
77
79
            else:
78
 
                f.write('%s %d\n' % l)
 
80
                print >>f, '%s %d' % l
79
81
        else: # text line
80
82
            if not l:
81
 
                f.write(', \n')
 
83
                print >>f, ', '
82
84
            elif l[-1] == '\n':
83
 
                f.write('. ' + l)
 
85
                assert l.find('\n', 0, -1) == -1
 
86
                print >>f, '.', l,
84
87
            else:
85
 
                f.write(', ' + l + '\n')
 
88
                assert l.find('\n') == -1
 
89
                print >>f, ',', l
86
90
 
87
 
    f.write('W\n')
 
91
    print >>f, 'W'
88
92
 
89
93
 
90
94
 
99
103
 
100
104
def _read_weave_v5(f, w):
101
105
    """Private helper routine to read a weave format 5 file into memory.
102
 
 
 
106
    
103
107
    This is only to be used by read_weave and WeaveFile.__init__.
104
108
    """
105
109
    #  200   0   2075.5080   1084.0360   bzrlib.weavefile:104(_read_weave_v5)
115
119
    #  200   0    851.7250    501.1120   bzrlib.weavefile:104(_read_weave_v5)
116
120
    # +59363 0    311.8780    311.8780   +<method 'append' of 'list' objects>
117
121
    # +200   0     30.2500     30.2500   +<method 'readlines' of 'file' objects>
118
 
 
 
122
                  
119
123
    from weave import WeaveFormatError
120
124
 
121
125
    lines = iter(f.readlines())
122
 
 
 
126
    
123
127
    try:
124
128
        l = lines.next()
125
129
    except StopIteration:
137
141
                w._parents.append(map(int, l[2:].split(' ')))
138
142
            else:
139
143
                w._parents.append([])
 
144
 
140
145
            l = lines.next()[:-1]
 
146
            assert '1 ' == l[0:2]
141
147
            w._sha1s.append(l[2:])
 
148
                
142
149
            l = lines.next()
 
150
            assert 'n ' == l[0:2]
143
151
            name = l[2:-1]
 
152
            assert name not in w._name_map
144
153
            w._names.append(name)
145
154
            w._name_map[name] = ver
 
155
                
146
156
            l = lines.next()
 
157
            assert l == '\n'
 
158
 
147
159
            ver += 1
148
160
        elif l == 'w\n':
149
161
            break
162
174
        elif l == '}\n':
163
175
            w._weave.append(('}', None))
164
176
        else:
 
177
            assert l[0] in '{[]', l
 
178
            assert l[1] == ' ', l
165
179
            w._weave.append((intern(l[0]), int(l[2:])))
 
180
 
166
181
    return w
 
182