/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/commit.py

  • Committer: Alexander Belchenko
  • Date: 2007-09-05 08:18:57 UTC
  • mfrom: (2799 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2800.
  • Revision ID: bialix@ukr.net-20070905081857-me1osc2lpuzq6ur1
merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
80
80
        deprecated_function,
81
81
        DEPRECATED_PARAMETER)
82
82
from bzrlib.workingtree import WorkingTree
 
83
from bzrlib.urlutils import unescape_for_display
83
84
import bzrlib.ui
84
85
 
85
86
 
86
87
class NullCommitReporter(object):
87
88
    """I report on progress of a commit."""
88
89
 
 
90
    def started(self, revno, revid, location=None):
 
91
        pass
 
92
 
89
93
    def snapshot_change(self, change, path):
90
94
        pass
91
95
 
121
125
            return
122
126
        self._note("%s %s", change, path)
123
127
 
 
128
    def started(self, revno, rev_id, location=None):
 
129
        if location is not None:
 
130
            location = ' to "' + unescape_for_display(location, 'utf-8') + '"'
 
131
        else:
 
132
            location = ''
 
133
        self._note('Committing revision %d%s.', revno, location)
 
134
 
124
135
    def completed(self, revno, rev_id):
125
136
        self._note('Committed revision %d.', revno)
126
137
    
254
265
            self._check_bound_branch()
255
266
 
256
267
            # Check that the working tree is up to date
257
 
            old_revno,new_revno = self._check_out_of_date_tree()
 
268
            old_revno, new_revno = self._check_out_of_date_tree()
258
269
 
259
270
            if self.config is None:
260
271
                self.config = self.branch.get_config()
275
286
            # information in the progress bar during the relevant stages.
276
287
            self.pb_stage_name = ""
277
288
            self.pb_stage_count = 0
278
 
            self.pb_stage_total = 4
 
289
            self.pb_stage_total = 5
279
290
            if self.bound_branch:
280
291
                self.pb_stage_total += 1
281
292
            self.pb.show_pct = False
290
301
            self._gather_parents()
291
302
            if len(self.parents) > 1 and self.specific_files:
292
303
                raise errors.CannotCommitSelectedFileMerge(self.specific_files)
293
 
            
 
304
 
294
305
            # Collect the changes
295
306
            self._set_progress_stage("Collecting changes",
296
307
                    entries_title="Directory")
297
308
            self.builder = self.branch.get_commit_builder(self.parents,
298
309
                self.config, timestamp, timezone, committer, revprops, rev_id)
 
310
            
299
311
            try:
 
312
                # find the location being committed to
 
313
                if self.bound_branch:
 
314
                    master_location = self.master_branch.base
 
315
                else:
 
316
                    master_location = self.branch.base
 
317
 
 
318
                # report the start of the commit
 
319
                self.reporter.started(new_revno, self.rev_id, master_location)
 
320
 
300
321
                self._update_builder_with_changes()
301
322
                self._check_pointless()
302
323
 
315
336
 
316
337
                # Add revision data to the local branch
317
338
                self.rev_id = self.builder.commit(self.message)
 
339
 
318
340
            except:
319
341
                self.builder.abort()
320
342
                raise
321
343
 
 
344
            self._process_pre_hooks(old_revno, new_revno)
 
345
 
322
346
            # Upload revision data to the master.
323
347
            # this will propagate merged revisions too if needed.
324
348
            if self.bound_branch:
339
363
            rev_tree = self.builder.revision_tree()
340
364
            self.work_tree.set_parent_trees([(self.rev_id, rev_tree)])
341
365
            self.reporter.completed(new_revno, self.rev_id)
342
 
            self._process_hooks(old_revno, new_revno)
 
366
            self._process_post_hooks(old_revno, new_revno)
343
367
        finally:
344
368
            self._cleanup()
345
369
        return self.rev_id
465
489
            new_revno = 1
466
490
        return old_revno,new_revno
467
491
 
468
 
    def _process_hooks(self, old_revno, new_revno):
469
 
        """Process any registered commit hooks."""
 
492
    def _process_pre_hooks(self, old_revno, new_revno):
 
493
        """Process any registered pre commit hooks."""
 
494
        self._set_progress_stage("Running pre_commit hooks")
 
495
        self._process_hooks("pre_commit", old_revno, new_revno)
 
496
 
 
497
    def _process_post_hooks(self, old_revno, new_revno):
 
498
        """Process any registered post commit hooks."""
470
499
        # Process the post commit hooks, if any
471
 
        self._set_progress_stage("Running post commit hooks")
 
500
        self._set_progress_stage("Running post_commit hooks")
472
501
        # old style commit hooks - should be deprecated ? (obsoleted in
473
502
        # 0.15)
474
503
        if self.config.post_commit() is not None:
479
508
                              {'branch':self.branch,
480
509
                               'bzrlib':bzrlib,
481
510
                               'rev_id':self.rev_id})
 
511
        # process new style post commit hooks
 
512
        self._process_hooks("post_commit", old_revno, new_revno)
 
513
 
 
514
    def _process_hooks(self, hook_name, old_revno, new_revno):
 
515
        if not Branch.hooks[hook_name]:
 
516
            return
 
517
        
482
518
        # new style commit hooks:
483
519
        if not self.bound_branch:
484
520
            hook_master = self.branch
493
529
            old_revid = self.parents[0]
494
530
        else:
495
531
            old_revid = bzrlib.revision.NULL_REVISION
496
 
        for hook in Branch.hooks['post_commit']:
 
532
        
 
533
        if hook_name == "pre_commit":
 
534
            future_tree = self.builder.revision_tree()
 
535
            tree_delta = future_tree.changes_from(self.basis_tree,
 
536
                                             include_root=True)
 
537
        
 
538
        for hook in Branch.hooks[hook_name]:
497
539
            # show the running hook in the progress bar. As hooks may
498
540
            # end up doing nothing (e.g. because they are not configured by
499
541
            # the user) this is still showing progress, not showing overall
500
542
            # actions - its up to each plugin to show a UI if it want's to
501
543
            # (such as 'Emailing diff to foo@example.com').
502
 
            self.pb_stage_name = "Running post commit hooks [%s]" % \
503
 
                Branch.hooks.get_hook_name(hook)
 
544
            self.pb_stage_name = "Running %s hooks [%s]" % \
 
545
                (hook_name, Branch.hooks.get_hook_name(hook))
504
546
            self._emit_progress()
505
547
            if 'hooks' in debug.debug_flags:
506
548
                mutter("Invoking commit hook: %r", hook)
507
 
            hook(hook_local, hook_master, old_revno, old_revid, new_revno,
508
 
                self.rev_id)
 
549
            if hook_name == "post_commit":
 
550
                hook(hook_local, hook_master, old_revno, old_revid, new_revno,
 
551
                     self.rev_id)
 
552
            elif hook_name == "pre_commit":
 
553
                hook(hook_local, hook_master,
 
554
                     old_revno, old_revid, new_revno, self.rev_id,
 
555
                     tree_delta, future_tree)
509
556
 
510
557
    def _cleanup(self):
511
558
        """Cleanup any open locks, progress bars etc."""