~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: Aaron Bentley
  • Date: 2012-07-18 18:30:48 UTC
  • mto: This revision was merged to the branch mainline in revision 6540.
  • Revision ID: aaron@aaronbentley.com-20120718183048-rr45kn62nh6m24vv
Restore uncommitted changes even if revisions are same.

Show diffs side-by-side

added added

removed removed

Lines of Context:
252
252
        """
253
253
        raise NotImplementedError(self._get_config)
254
254
 
 
255
    def _get_uncommitted(self):
 
256
        """Return a serialized TreeTransform for uncommitted changes.
 
257
 
 
258
        :return: a file-like object containing a serialized TreeTransform or
 
259
            None if no uncommitted changes are stored.
 
260
        """
 
261
        raise NotImplementedError(self._get_uncommitted)
 
262
 
 
263
    def _put_uncommitted(self, transform):
 
264
        """Store a serialized TreeTransform for uncommitted changes.
 
265
 
 
266
        :param input: a file-like object.
 
267
        """
 
268
        raise NotImplementedError(self._put_uncommitted)
 
269
 
 
270
    def _uncommitted_branch(self):
 
271
        master = self.get_master_branch()
 
272
        if master is not None:
 
273
            return master
 
274
        else:
 
275
            return self
 
276
 
 
277
    def has_stored_uncommitted(self):
 
278
        """If true, the branch has stored, uncommitted changes in it."""
 
279
        return self._uncommitted_branch()._get_uncommitted() is not None
 
280
 
255
281
    def store_uncommitted(self, creator, message=None):
256
 
        """Store uncommitted changes from a ShelfCreator.
257
 
 
258
 
        :param creator: The ShelfCreator containing uncommitted changes, or
259
 
            None to delete any stored changes.
260
 
        :param message: The message to associate with the changes.
261
 
        :raises: ChangesAlreadyStored if the branch already has changes.
262
 
        """
263
 
        raise NotImplementedError(self.store_uncommitted)
 
282
        branch = self._uncommitted_branch()
 
283
        if branch.has_stored_uncommitted():
 
284
            raise errors.ChangesAlreadyStored
 
285
        transform = StringIO()
 
286
        creator.write_shelf(transform, message)
 
287
        transform.seek(0)
 
288
        branch._put_uncommitted(transform)
264
289
 
265
290
    def get_unshelver(self, tree):
266
 
        """Return a shelf.Unshelver for this branch and tree.
267
 
 
268
 
        :param tree: The tree to use to construct the Unshelver.
269
 
        :return: an Unshelver or None if no changes are stored.
270
 
        """
271
 
        raise NotImplementedError(self.get_unshelver)
 
291
        transform = self._uncommitted_branch()._get_uncommitted()
 
292
        if transform is None:
 
293
            return
 
294
        return shelf.Unshelver.from_tree_and_shelf(tree, transform)
272
295
 
273
296
    def _get_fallback_repository(self, url, possible_transports):
274
297
        """Get the repository we fallback to at url."""
2405
2428
            self.conf_store =  _mod_config.BranchStore(self)
2406
2429
        return self.conf_store
2407
2430
 
2408
 
    def _uncommitted_branch(self):
2409
 
        """Return the branch that may contain uncommitted changes."""
2410
 
        master = self.get_master_branch()
2411
 
        if master is not None:
2412
 
            return master
2413
 
        else:
2414
 
            return self
2415
 
 
2416
 
    def store_uncommitted(self, creator, message=None):
2417
 
        """Store uncommitted changes from a ShelfCreator.
2418
 
 
2419
 
        :param creator: The ShelfCreator containing uncommitted changes, or
2420
 
            None to delete any stored changes.
2421
 
        :param message: The message to associate with the changes.
2422
 
        :raises: ChangesAlreadyStored if the branch already has changes.
2423
 
        """
2424
 
        branch = self._uncommitted_branch()
2425
 
        if creator is None:
2426
 
            branch._transport.delete('stored-transform')
2427
 
            return
2428
 
        if branch._transport.has('stored-transform'):
2429
 
            raise errors.ChangesAlreadyStored
2430
 
        transform = StringIO()
2431
 
        creator.write_shelf(transform, message)
2432
 
        transform.seek(0)
2433
 
        branch._transport.put_file('stored-transform', transform)
2434
 
 
2435
 
    def get_unshelver(self, tree):
2436
 
        """Return a shelf.Unshelver for this branch and tree.
2437
 
 
2438
 
        :param tree: The tree to use to construct the Unshelver.
2439
 
        :return: an Unshelver or None if no changes are stored.
2440
 
        """
2441
 
        branch = self._uncommitted_branch()
 
2431
    def _get_uncommitted(self):
 
2432
        """Return a serialized TreeTransform for uncommitted changes.
 
2433
 
 
2434
        :return: a file-like object containing a serialized TreeTransform or
 
2435
            None if no uncommitted changes are stored.
 
2436
        """
2442
2437
        try:
2443
 
            transform = branch._transport.get('stored-transform')
 
2438
            return self._transport.get('stored-transform')
2444
2439
        except errors.NoSuchFile:
2445
2440
            return None
2446
 
        return shelf.Unshelver.from_tree_and_shelf(tree, transform)
 
2441
 
 
2442
    def _put_uncommitted(self, transform):
 
2443
        """Store a serialized TreeTransform for uncommitted changes.
 
2444
 
 
2445
        :param input: a file-like object.
 
2446
        """
 
2447
        if transform is None:
 
2448
            try:
 
2449
                self._transport.delete('stored-transform')
 
2450
            except errors.NoSuchFile:
 
2451
                pass
 
2452
        else:
 
2453
            self._transport.put_file('stored-transform', transform)
2447
2454
 
2448
2455
    def is_locked(self):
2449
2456
        return self.control_files.is_locked()