/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 breezy/transform.py

  • Committer: Jelmer Vernooij
  • Date: 2019-06-18 00:07:21 UTC
  • mto: This revision was merged to the branch mainline in revision 7354.
  • Revision ID: jelmer@jelmer.uk-20190618000721-jur3uapii8763cm1
Add abstract methods.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1201
1201
            if kind == 'symlink':
1202
1202
                self.create_symlink(content.decode('utf-8'), trans_id)
1203
1203
 
 
1204
    def create_file(self, contents, trans_id, mode_id=None, sha1=None):
 
1205
        """Schedule creation of a new file.
 
1206
 
 
1207
        :seealso: new_file.
 
1208
 
 
1209
        :param contents: an iterator of strings, all of which will be written
 
1210
            to the target destination.
 
1211
        :param trans_id: TreeTransform handle
 
1212
        :param mode_id: If not None, force the mode of the target file to match
 
1213
            the mode of the object referenced by mode_id.
 
1214
            Otherwise, we will try to preserve mode bits of an existing file.
 
1215
        :param sha1: If the sha1 of this content is already known, pass it in.
 
1216
            We can use it to prevent future sha1 computations.
 
1217
        """
 
1218
        raise NotImplementedError(self.create_file)
 
1219
 
 
1220
    def create_directory(self, trans_id):
 
1221
        """Schedule creation of a new directory.
 
1222
 
 
1223
        See also new_directory.
 
1224
        """
 
1225
        raise NotImplementedError(self.create_directory)
 
1226
 
 
1227
    def create_symlink(self, target, trans_id):
 
1228
        """Schedule creation of a new symbolic link.
 
1229
 
 
1230
        target is a bytestring.
 
1231
        See also new_symlink.
 
1232
        """
 
1233
        raise NotImplementedError(self.create_symlink)
 
1234
 
 
1235
    def create_hardlink(self, path, trans_id):
 
1236
        """Schedule creation of a hard link"""
 
1237
        raise NotImplementedError(self.create_hardlink)
 
1238
 
 
1239
    def cancel_creation(self, trans_id):
 
1240
        """Cancel the creation of new file contents."""
 
1241
        raise NotImplementedError(self.cancel_creation)
 
1242
 
1204
1243
 
1205
1244
class DiskTreeTransform(TreeTransformBase):
1206
1245
    """Tree transform storing its contents on disk."""
3232
3271
    :param target_tree: Tree to change
3233
3272
    :param source_tree: Tree to hard-link from
3234
3273
    """
3235
 
    tt = TreeTransform(target_tree)
3236
 
    try:
 
3274
    with TreeTransform(target_tree) as tt:
3237
3275
        for change in target_tree.iter_changes(source_tree, include_unchanged=True):
3238
3276
            if change.changed_content:
3239
3277
                continue
3245
3283
            tt.delete_contents(trans_id)
3246
3284
            tt.create_hardlink(source_tree.abspath(change.path[0]), trans_id)
3247
3285
        tt.apply()
3248
 
    finally:
3249
 
        tt.finalize()