~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/commit.py

[merge] from robert and fix up tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
84
84
                           ConflictsInTree,
85
85
                           StrictCommitFailed
86
86
                           )
 
87
import bzrlib.gpg as gpg
87
88
from bzrlib.revision import Revision
 
89
from bzrlib.testament import Testament
88
90
from bzrlib.trace import mutter, note, warning
89
91
from bzrlib.xml5 import serializer_v5
90
92
from bzrlib.inventory import Inventory, ROOT_ID
152
154
            working inventory.
153
155
    """
154
156
    def __init__(self,
155
 
                 reporter=None):
 
157
                 reporter=None,
 
158
                 config=None):
156
159
        if reporter is not None:
157
160
            self.reporter = reporter
158
161
        else:
159
162
            self.reporter = NullCommitReporter()
160
 
 
 
163
        if config is not None:
 
164
            self.config = config
 
165
        else:
 
166
            self.config = None
161
167
        
162
168
    def commit(self,
163
169
               branch, message,
208
214
        else:
209
215
            self.timestamp = long(timestamp)
210
216
            
211
 
        config = bzrlib.config.BranchConfig(self.branch)
 
217
        if self.config is None:
 
218
            self.config = bzrlib.config.BranchConfig(self.branch)
 
219
 
212
220
        if rev_id is None:
213
 
            self.rev_id = _gen_revision_id(config, self.timestamp)
 
221
            self.rev_id = _gen_revision_id(self.config, self.timestamp)
214
222
        else:
215
223
            self.rev_id = rev_id
216
224
 
217
225
        if committer is None:
218
 
            self.committer = config.username()
 
226
            self.committer = self.config.username()
219
227
        else:
220
228
            assert isinstance(committer, basestring), type(committer)
221
229
            self.committer = committer
328
336
        rev_tmp = StringIO()
329
337
        serializer_v5.write_revision(self.rev, rev_tmp)
330
338
        rev_tmp.seek(0)
 
339
        if self.config.signature_needed():
 
340
            plaintext = Testament(self.rev, self.new_inv).as_short_text()
 
341
            self.branch.store_revision_signature(gpg.GPGStrategy(self.config),
 
342
                                                 plaintext, self.rev_id)
331
343
        self.branch.revision_store.add(rev_tmp, self.rev_id)
332
344
        mutter('new revision_id is {%s}', self.rev_id)
333
345