~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/commit.py

  • Committer: Jelmer Vernooij
  • Date: 2005-10-19 09:34:39 UTC
  • mfrom: (1185.16.78)
  • mto: (1185.16.102)
  • mto: This revision was merged to the branch mainline in revision 1488.
  • Revision ID: jelmer@samba.org-20051019093439-e1d8e3508d1ba46b
MergeĀ fromĀ Martin

Show diffs side-by-side

added added

removed removed

Lines of Context:
56
56
# merges from, then it should still be reported as newly added
57
57
# relative to the basis revision.
58
58
 
 
59
# TODO: Do checks that the tree can be committed *before* running the 
 
60
# editor; this should include checks for a pointless commit and for 
 
61
# unknown or missing files.
 
62
 
 
63
# TODO: If commit fails, leave the message in a file somewhere.
 
64
 
59
65
 
60
66
import os
61
67
import re
75
81
import bzrlib.config
76
82
from bzrlib.errors import (BzrError, PointlessCommit,
77
83
                           HistoryMissing,
78
 
                           ConflictsInTree
 
84
                           ConflictsInTree,
 
85
                           StrictCommitFailed
79
86
                           )
 
87
import bzrlib.gpg as gpg
80
88
from bzrlib.revision import Revision
 
89
from bzrlib.testament import Testament
81
90
from bzrlib.trace import mutter, note, warning
82
91
from bzrlib.xml5 import serializer_v5
83
92
from bzrlib.inventory import Inventory, ROOT_ID
145
154
            working inventory.
146
155
    """
147
156
    def __init__(self,
148
 
                 reporter=None):
 
157
                 reporter=None,
 
158
                 config=None):
149
159
        if reporter is not None:
150
160
            self.reporter = reporter
151
161
        else:
152
162
            self.reporter = NullCommitReporter()
153
 
 
 
163
        if config is not None:
 
164
            self.config = config
 
165
        else:
 
166
            self.config = None
154
167
        
155
168
    def commit(self,
156
169
               branch, message,
160
173
               specific_files=None,
161
174
               rev_id=None,
162
175
               allow_pointless=True,
 
176
               strict=False,
163
177
               verbose=False,
164
178
               revprops=None):
165
179
        """Commit working copy as a new revision.
178
192
        allow_pointless -- If true (default), commit even if nothing
179
193
            has changed and no merges are recorded.
180
194
 
 
195
        strict -- If true, don't allow a commit if the working tree
 
196
            contains unknown files.
 
197
 
181
198
        revprops -- Properties for new revision
182
199
        """
183
200
        mutter('preparing to commit')
189
206
        self.allow_pointless = allow_pointless
190
207
        self.revprops = revprops
191
208
 
 
209
        if strict and branch.unknowns():
 
210
            raise StrictCommitFailed()
 
211
 
192
212
        if timestamp is None:
193
213
            self.timestamp = time.time()
194
214
        else:
195
215
            self.timestamp = long(timestamp)
196
216
            
197
 
        config = bzrlib.config.BranchConfig(self.branch)
 
217
        if self.config is None:
 
218
            self.config = bzrlib.config.BranchConfig(self.branch)
 
219
 
198
220
        if rev_id is None:
199
 
            self.rev_id = _gen_revision_id(config, self.timestamp)
 
221
            self.rev_id = _gen_revision_id(self.config, self.timestamp)
200
222
        else:
201
223
            self.rev_id = rev_id
202
224
 
203
225
        if committer is None:
204
 
            self.committer = config.username()
 
226
            self.committer = self.config.username()
205
227
        else:
206
228
            assert isinstance(committer, basestring), type(committer)
207
229
            self.committer = committer
314
336
        rev_tmp = StringIO()
315
337
        serializer_v5.write_revision(self.rev, rev_tmp)
316
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)
317
343
        self.branch.revision_store.add(rev_tmp, self.rev_id)
318
344
        mutter('new revision_id is {%s}', self.rev_id)
319
345