~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: Aaron Bentley
  • Date: 2012-07-19 15:34:45 UTC
  • mto: This revision was merged to the branch mainline in revision 6540.
  • Revision ID: aaron@aaronbentley.com-20120719153445-uja9jerhh7sxpqjp
Move uncommitted API to BzrBranch/RemoteBranch.

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
 
        """Return the branch that may contain uncommitted changes."""
272
 
        master = self.get_master_branch()
273
 
        if master is not None:
274
 
            return master
275
 
        else:
276
 
            return self
277
 
 
278
255
    def has_stored_uncommitted(self):
279
256
        """If true, the branch has stored, uncommitted changes in it."""
280
 
        return self._uncommitted_branch()._get_uncommitted() is not None
 
257
        raise NotImplementedError(self.has_stored_uncommitted)
281
258
 
282
259
    def store_uncommitted(self, creator, message=None):
283
260
        """Store uncommitted changes from a ShelfCreator.
287
264
        :param message: The message to associate with the changes.
288
265
        :raises: ChangesAlreadyStored if the branch already has changes.
289
266
        """
290
 
        branch = self._uncommitted_branch()
291
 
        if creator is None:
292
 
            branch._put_uncommitted(None)
293
 
            return
294
 
        if branch.has_stored_uncommitted():
295
 
            raise errors.ChangesAlreadyStored
296
 
        transform = StringIO()
297
 
        creator.write_shelf(transform, message)
298
 
        transform.seek(0)
299
 
        branch._put_uncommitted(transform)
 
267
        raise NotImplementedError(self.store_uncommitted)
300
268
 
301
269
    def get_unshelver(self, tree):
302
270
        """Return a shelf.Unshelver for this branch and tree.
304
272
        :param tree: The tree to use to construct the Unshelver.
305
273
        :return: an Unshelver or None if no changes are stored.
306
274
        """
307
 
        transform = self._uncommitted_branch()._get_uncommitted()
308
 
        if transform is None:
309
 
            return
310
 
        return shelf.Unshelver.from_tree_and_shelf(tree, transform)
 
275
        raise NotImplementedError(self.get_unshelver)
311
276
 
312
277
    def _get_fallback_repository(self, url, possible_transports):
313
278
        """Get the repository we fallback to at url."""
2470
2435
        else:
2471
2436
            self._transport.put_file('stored-transform', transform)
2472
2437
 
 
2438
    def _uncommitted_branch(self):
 
2439
        """Return the branch that may contain uncommitted changes."""
 
2440
        master = self.get_master_branch()
 
2441
        if master is not None:
 
2442
            return master
 
2443
        else:
 
2444
            return self
 
2445
 
 
2446
    def has_stored_uncommitted(self):
 
2447
        """If true, the branch has stored, uncommitted changes in it."""
 
2448
        return self._uncommitted_branch()._get_uncommitted() is not None
 
2449
 
 
2450
    def store_uncommitted(self, creator, message=None):
 
2451
        """Store uncommitted changes from a ShelfCreator.
 
2452
 
 
2453
        :param creator: The ShelfCreator containing uncommitted changes, or
 
2454
            None to delete any stored changes.
 
2455
        :param message: The message to associate with the changes.
 
2456
        :raises: ChangesAlreadyStored if the branch already has changes.
 
2457
        """
 
2458
        branch = self._uncommitted_branch()
 
2459
        if creator is None:
 
2460
            branch._put_uncommitted(None)
 
2461
            return
 
2462
        if branch.has_stored_uncommitted():
 
2463
            raise errors.ChangesAlreadyStored
 
2464
        transform = StringIO()
 
2465
        creator.write_shelf(transform, message)
 
2466
        transform.seek(0)
 
2467
        branch._put_uncommitted(transform)
 
2468
 
 
2469
    def get_unshelver(self, tree):
 
2470
        """Return a shelf.Unshelver for this branch and tree.
 
2471
 
 
2472
        :param tree: The tree to use to construct the Unshelver.
 
2473
        :return: an Unshelver or None if no changes are stored.
 
2474
        """
 
2475
        transform = self._uncommitted_branch()._get_uncommitted()
 
2476
        if transform is None:
 
2477
            return
 
2478
        return shelf.Unshelver.from_tree_and_shelf(tree, transform)
 
2479
 
2473
2480
    def is_locked(self):
2474
2481
        return self.control_files.is_locked()
2475
2482