~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/commit.py

  • Committer: Martin von Gagern
  • Date: 2010-04-22 06:25:26 UTC
  • mfrom: (0.27.39 trunk)
  • mto: This revision was merged to the branch mainline in revision 5240.
  • Revision ID: martin.vgagern@gmx.net-20100422062526-4lyy2yoor932u80w
Join bzr-bash-completion plugin into core bzr tree.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2011 Canonical Ltd
 
1
# Copyright (C) 2005-2010 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
49
49
# TODO: Change the parameter 'rev_id' to 'revision_id' to be consistent with
50
50
# the rest of the code; add a deprecation of the old name.
51
51
 
 
52
import os
 
53
import re
 
54
import sys
 
55
import time
 
56
 
 
57
from cStringIO import StringIO
 
58
 
52
59
from bzrlib import (
53
60
    debug,
54
61
    errors,
 
62
    revision,
55
63
    trace,
56
64
    tree,
57
 
    ui,
 
65
    xml_serializer,
58
66
    )
59
67
from bzrlib.branch import Branch
60
68
from bzrlib.cleanup import OperationWithCleanups
64
72
                           StrictCommitFailed
65
73
                           )
66
74
from bzrlib.osutils import (get_user_encoding,
67
 
                            is_inside_any,
 
75
                            kind_marker, isdir,isfile, is_inside_any,
 
76
                            is_inside_or_parent_of_any,
68
77
                            minimum_path_selection,
 
78
                            quotefn, sha_file, split_lines,
69
79
                            splitpath,
70
80
                            )
71
 
from bzrlib.trace import mutter, note, is_quiet
 
81
from bzrlib.testament import Testament
 
82
from bzrlib.trace import mutter, note, warning, is_quiet
72
83
from bzrlib.inventory import Inventory, InventoryEntry, make_entry
73
84
from bzrlib import symbol_versioning
 
85
from bzrlib.symbol_versioning import (deprecated_passed,
 
86
        deprecated_function,
 
87
        DEPRECATED_PARAMETER)
 
88
from bzrlib.workingtree import WorkingTree
74
89
from bzrlib.urlutils import unescape_for_display
 
90
import bzrlib.ui
75
91
 
76
92
 
77
93
class NullCommitReporter(object):
173
189
        self.reporter = reporter
174
190
        self.config = config
175
191
 
176
 
    @staticmethod
177
 
    def update_revprops(revprops, branch, authors=None, author=None,
178
 
                        local=False, possible_master_transports=None):
179
 
        if revprops is None:
180
 
            revprops = {}
181
 
        if possible_master_transports is None:
182
 
            possible_master_transports = []
183
 
        if not 'branch-nick' in revprops:
184
 
            revprops['branch-nick'] = branch._get_nick(
185
 
                local,
186
 
                possible_master_transports)
187
 
        if authors is not None:
188
 
            if author is not None:
189
 
                raise AssertionError('Specifying both author and authors '
190
 
                        'is not allowed. Specify just authors instead')
191
 
            if 'author' in revprops or 'authors' in revprops:
192
 
                # XXX: maybe we should just accept one of them?
193
 
                raise AssertionError('author property given twice')
194
 
            if authors:
195
 
                for individual in authors:
196
 
                    if '\n' in individual:
197
 
                        raise AssertionError('\\n is not a valid character '
198
 
                                'in an author identity')
199
 
                revprops['authors'] = '\n'.join(authors)
200
 
        if author is not None:
201
 
            symbol_versioning.warn('The parameter author was deprecated'
202
 
                   ' in version 1.13. Use authors instead',
203
 
                   DeprecationWarning)
204
 
            if 'author' in revprops or 'authors' in revprops:
205
 
                # XXX: maybe we should just accept one of them?
206
 
                raise AssertionError('author property given twice')
207
 
            if '\n' in author:
208
 
                raise AssertionError('\\n is not a valid character '
209
 
                        'in an author identity')
210
 
            revprops['authors'] = author
211
 
        return revprops
212
 
 
213
192
    def commit(self,
214
193
               message=None,
215
194
               timestamp=None,
228
207
               message_callback=None,
229
208
               recursive='down',
230
209
               exclude=None,
231
 
               possible_master_transports=None,
232
 
               lossy=False):
 
210
               possible_master_transports=None):
233
211
        """Commit working copy as a new revision.
234
212
 
235
213
        :param message: the commit message (it or message_callback is required)
262
240
        :param exclude: None or a list of relative paths to exclude from the
263
241
            commit. Pending changes to excluded files will be ignored by the
264
242
            commit.
265
 
        :param lossy: When committing to a foreign VCS, ignore any
266
 
            data that can not be natively represented.
267
243
        """
268
244
        operation = OperationWithCleanups(self._commit)
269
245
        self.revprops = revprops or {}
285
261
               message_callback=message_callback,
286
262
               recursive=recursive,
287
263
               exclude=exclude,
288
 
               possible_master_transports=possible_master_transports,
289
 
               lossy=lossy)
 
264
               possible_master_transports=possible_master_transports)
290
265
 
291
266
    def _commit(self, operation, message, timestamp, timezone, committer,
292
267
            specific_files, rev_id, allow_pointless, strict, verbose,
293
268
            working_tree, local, reporter, message_callback, recursive,
294
 
            exclude, possible_master_transports, lossy):
 
269
            exclude, possible_master_transports):
295
270
        mutter('preparing to commit')
296
271
 
297
272
        if working_tree is None:
329
304
                minimum_path_selection(specific_files))
330
305
        else:
331
306
            self.specific_files = None
332
 
 
 
307
            
333
308
        self.allow_pointless = allow_pointless
334
309
        self.message_callback = message_callback
335
310
        self.timestamp = timestamp
349
324
            not self.branch.repository._format.supports_tree_reference and
350
325
            (self.branch.repository._format.fast_deltas or
351
326
             len(self.parents) < 2))
352
 
        self.pb = ui.ui_factory.nested_progress_bar()
 
327
        self.pb = bzrlib.ui.ui_factory.nested_progress_bar()
353
328
        operation.add_cleanup(self.pb.finished)
354
329
        self.basis_revid = self.work_tree.last_revision()
355
330
        self.basis_tree = self.work_tree.basis_tree()
383
358
        self.pb_stage_count = 0
384
359
        self.pb_stage_total = 5
385
360
        if self.bound_branch:
386
 
            # 2 extra stages: "Uploading data to master branch" and "Merging
387
 
            # tags to master branch"
388
 
            self.pb_stage_total += 2
 
361
            self.pb_stage_total += 1
389
362
        self.pb.show_pct = False
390
363
        self.pb.show_spinner = False
391
364
        self.pb.show_eta = False
403
376
 
404
377
        # Collect the changes
405
378
        self._set_progress_stage("Collecting changes", counter=True)
406
 
        self._lossy = lossy
407
379
        self.builder = self.branch.get_commit_builder(self.parents,
408
 
            self.config, timestamp, timezone, committer, self.revprops,
409
 
            rev_id, lossy=lossy)
410
 
        if not self.builder.supports_record_entry_contents and self.exclude:
411
 
            self.builder.abort()
412
 
            raise errors.ExcludesUnsupported(self.branch.repository)
 
380
            self.config, timestamp, timezone, committer, self.revprops, rev_id)
413
381
 
414
382
        try:
415
383
            self.builder.will_record_deletes()
442
410
        except Exception, e:
443
411
            mutter("aborting commit write group because of exception:")
444
412
            trace.log_exception_quietly()
 
413
            note("aborting commit write group: %r" % (e,))
445
414
            self.builder.abort()
446
415
            raise
447
416
 
453
422
            self._set_progress_stage("Uploading data to master branch")
454
423
            # 'commit' to the master first so a timeout here causes the
455
424
            # local branch to be out of date
456
 
            (new_revno, self.rev_id) = self.master_branch.import_last_revision_info_and_tags(
457
 
                self.branch, new_revno, self.rev_id, lossy=lossy)
458
 
            if lossy:
459
 
                self.branch.fetch(self.master_branch, self.rev_id)
 
425
            self.master_branch.import_last_revision_info(
 
426
                self.branch.repository, new_revno, self.rev_id)
460
427
 
461
428
        # and now do the commit locally.
462
429
        self.branch.set_last_revision_info(new_revno, self.rev_id)
463
430
 
464
 
        # Merge local tags to remote
465
 
        if self.bound_branch:
466
 
            self._set_progress_stage("Merging tags to master branch")
467
 
            tag_conflicts = self.branch.tags.merge_to(self.master_branch.tags)
468
 
            if tag_conflicts:
469
 
                warning_lines = ['    ' + name for name, _, _ in tag_conflicts]
470
 
                note("Conflicting tags in bound branch:\n" +
471
 
                    "\n".join(warning_lines))
472
 
 
473
431
        # Make the working tree be up to date with the branch. This
474
432
        # includes automatic changes scheduled to be made to the tree, such
475
433
        # as updating its basis and unversioning paths that were missing.
493
451
        # A merge with no effect on files
494
452
        if len(self.parents) > 1:
495
453
            return
 
454
        # TODO: we could simplify this by using self.builder.basis_delta.
 
455
 
 
456
        # The initial commit adds a root directory, but this in itself is not
 
457
        # a worthwhile commit.
 
458
        if (self.basis_revid == revision.NULL_REVISION and
 
459
            ((self.builder.new_inventory is not None and
 
460
             len(self.builder.new_inventory) == 1) or
 
461
            len(self.builder._basis_delta) == 1)):
 
462
            raise PointlessCommit()
496
463
        if self.builder.any_changes():
497
464
            return
498
465
        raise PointlessCommit()
723
690
        if self.specific_files or self.exclude:
724
691
            specific_files = self.specific_files or []
725
692
            for path, old_ie in self.basis_inv.iter_entries():
726
 
                if self.builder.new_inventory.has_id(old_ie.file_id):
 
693
                if old_ie.file_id in self.builder.new_inventory:
727
694
                    # already added - skip.
728
695
                    continue
729
696
                if (is_inside_any(specific_files, path)