/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/repository.py

merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
55
55
        one_two,
56
56
        one_six,
57
57
        )
58
 
from bzrlib.trace import mutter, mutter_callsite, warning
 
58
from bzrlib.trace import (
 
59
    log_exception_quietly, note, mutter, mutter_callsite, warning)
59
60
 
60
61
 
61
62
# Old formats display a warning, but only once
102
103
 
103
104
        self._revprops = {}
104
105
        if revprops is not None:
 
106
            self._validate_revprops(revprops)
105
107
            self._revprops.update(revprops)
106
108
 
107
109
        if timestamp is None:
117
119
        self._generate_revision_if_needed()
118
120
        self.__heads = graph.HeadsCache(repository.get_graph()).heads
119
121
 
 
122
    def _validate_unicode_text(self, text, context):
 
123
        """Verify things like commit messages don't have bogus characters."""
 
124
        if '\r' in text:
 
125
            raise ValueError('Invalid value for %s: %r' % (context, text))
 
126
 
 
127
    def _validate_revprops(self, revprops):
 
128
        for key, value in revprops.iteritems():
 
129
            # We know that the XML serializers do not round trip '\r'
 
130
            # correctly, so refuse to accept them
 
131
            if not isinstance(value, basestring):
 
132
                raise ValueError('revision property (%s) is not a valid'
 
133
                                 ' (unicode) string: %r' % (key, value))
 
134
            self._validate_unicode_text(value,
 
135
                                        'revision property (%s)' % (key,))
 
136
 
120
137
    def commit(self, message):
121
138
        """Make the actual commit.
122
139
 
123
140
        :return: The revision id of the recorded revision.
124
141
        """
 
142
        self._validate_unicode_text(message, 'commit message')
125
143
        rev = _mod_revision.Revision(
126
144
                       timestamp=self._timestamp,
127
145
                       timezone=self._timezone,
513
531
        r'.* revision="(?P<revision_id>[^"]+)"'
514
532
        )
515
533
 
516
 
    def abort_write_group(self):
 
534
    def abort_write_group(self, suppress_errors=False):
517
535
        """Commit the contents accrued within the current write group.
518
536
 
 
537
        :param suppress_errors: if true, abort_write_group will catch and log
 
538
            unexpected errors that happen during the abort, rather than
 
539
            allowing them to propagate.  Defaults to False.
 
540
 
519
541
        :seealso: start_write_group.
520
542
        """
521
543
        if self._write_group is not self.get_transaction():
522
544
            # has an unlock or relock occured ?
523
545
            raise errors.BzrError('mismatched lock context and write group.')
524
 
        self._abort_write_group()
 
546
        try:
 
547
            self._abort_write_group()
 
548
        except Exception, exc:
 
549
            self._write_group = None
 
550
            if not suppress_errors:
 
551
                raise
 
552
            mutter('abort_write_group failed')
 
553
            log_exception_quietly()
 
554
            note('bzr: ERROR (ignored): %s', exc)
525
555
        self._write_group = None
526
556
 
527
557
    def _abort_write_group(self):
2806
2836
            # fetching from a stacked repository or into a stacked repository
2807
2837
            # we use the generic fetch logic which uses the VersionedFiles
2808
2838
            # attributes on repository.
 
2839
            #
 
2840
            # XXX: Andrew suggests removing the check on the target
 
2841
            # repository.
2809
2842
            from bzrlib.fetch import RepoFetcher
2810
2843
            fetcher = RepoFetcher(self.target, self.source, revision_id,
2811
2844
                                  pb, find_ghosts)