~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/commit.py

  • Committer: Robert Collins
  • Date: 2005-10-08 00:39:04 UTC
  • mfrom: (1185.1.52)
  • Revision ID: robertc@robertcollins.net-20051008003904-aaffaea2778efe3e
merge in martins reweave, integrated to fetch, and a bugfix for commit and upgrade with executable files

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
 
 
65
59
 
66
60
import os
67
61
import re
72
66
from binascii import hexlify
73
67
from cStringIO import StringIO
74
68
 
75
 
from bzrlib.osutils import (local_time_offset,
76
 
                            rand_bytes, compact_date,
 
69
from bzrlib.osutils import (local_time_offset, username,
 
70
                            rand_bytes, compact_date, user_email,
77
71
                            kind_marker, is_inside_any, quotefn,
78
72
                            sha_string, sha_strings, sha_file, isdir, isfile,
79
73
                            split_lines)
80
74
from bzrlib.branch import gen_file_id
81
 
import bzrlib.config
82
75
from bzrlib.errors import (BzrError, PointlessCommit,
83
76
                           HistoryMissing,
84
 
                           ConflictsInTree,
85
 
                           StrictCommitFailed
 
77
                           ConflictsInTree
86
78
                           )
87
 
import bzrlib.gpg as gpg
88
79
from bzrlib.revision import Revision
89
 
from bzrlib.testament import Testament
90
80
from bzrlib.trace import mutter, note, warning
91
81
from bzrlib.xml5 import serializer_v5
92
82
from bzrlib.inventory import Inventory, ROOT_ID
154
144
            working inventory.
155
145
    """
156
146
    def __init__(self,
157
 
                 reporter=None,
158
 
                 config=None):
 
147
                 reporter=None):
159
148
        if reporter is not None:
160
149
            self.reporter = reporter
161
150
        else:
162
151
            self.reporter = NullCommitReporter()
163
 
        if config is not None:
164
 
            self.config = config
165
 
        else:
166
 
            self.config = None
 
152
 
167
153
        
168
154
    def commit(self,
169
155
               branch, message,
173
159
               specific_files=None,
174
160
               rev_id=None,
175
161
               allow_pointless=True,
176
 
               strict=False,
177
 
               verbose=False,
178
 
               revprops=None):
 
162
               verbose=False):
179
163
        """Commit working copy as a new revision.
180
164
 
181
165
        timestamp -- if not None, seconds-since-epoch for a
191
175
 
192
176
        allow_pointless -- If true (default), commit even if nothing
193
177
            has changed and no merges are recorded.
194
 
 
195
 
        strict -- If true, don't allow a commit if the working tree
196
 
            contains unknown files.
197
 
 
198
 
        revprops -- Properties for new revision
199
178
        """
200
179
        mutter('preparing to commit')
201
180
 
204
183
        self.rev_id = rev_id
205
184
        self.specific_files = specific_files
206
185
        self.allow_pointless = allow_pointless
207
 
        self.revprops = revprops
208
 
 
209
 
        if strict and branch.unknowns():
210
 
            raise StrictCommitFailed()
211
186
 
212
187
        if timestamp is None:
213
188
            self.timestamp = time.time()
214
189
        else:
215
190
            self.timestamp = long(timestamp)
216
191
            
217
 
        if self.config is None:
218
 
            self.config = bzrlib.config.BranchConfig(self.branch)
219
 
 
220
192
        if rev_id is None:
221
 
            self.rev_id = _gen_revision_id(self.config, self.timestamp)
 
193
            self.rev_id = _gen_revision_id(self.branch, self.timestamp)
222
194
        else:
223
195
            self.rev_id = rev_id
224
196
 
225
197
        if committer is None:
226
 
            self.committer = self.config.username()
 
198
            self.committer = username(self.branch)
227
199
        else:
228
200
            assert isinstance(committer, basestring), type(committer)
229
201
            self.committer = committer
330
302
                            committer=self.committer,
331
303
                            message=self.message,
332
304
                            inventory_sha1=self.inv_sha1,
333
 
                            revision_id=self.rev_id,
334
 
                            properties=self.revprops)
 
305
                            revision_id=self.rev_id)
335
306
        self.rev.parent_ids = self.parents
336
307
        rev_tmp = StringIO()
337
308
        serializer_v5.write_revision(self.rev, rev_tmp)
338
309
        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)
343
310
        self.branch.revision_store.add(rev_tmp, self.rev_id)
344
311
        mutter('new revision_id is {%s}', self.rev_id)
345
312
 
446
413
            if file_id not in self.new_inv:
447
414
                self.reporter.deleted(self.basis_inv.id2path(file_id))
448
415
 
449
 
def _gen_revision_id(config, when):
 
416
def _gen_revision_id(branch, when):
450
417
    """Return new revision-id."""
451
 
    s = '%s-%s-' % (config.user_email(), compact_date(when))
 
418
    s = '%s-%s-' % (user_email(branch), compact_date(when))
452
419
    s += hexlify(rand_bytes(8))
453
420
    return s