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

  • Committer: Jelmer Vernooij
  • Date: 2020-02-13 23:57:28 UTC
  • mfrom: (7490 work)
  • mto: This revision was merged to the branch mainline in revision 7492.
  • Revision ID: jelmer@jelmer.uk-20200213235728-m6ds0mm3mbs4y182
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
 
17
from __future__ import absolute_import
 
18
 
17
19
from .lazy_import import lazy_import
18
20
lazy_import(globals(), """
19
21
import contextlib
1188
1190
        if revno < 1 or revno > self.revno():
1189
1191
            raise errors.InvalidRevisionNumber(revno)
1190
1192
 
1191
 
    def clone(self, to_controldir, revision_id=None, name=None,
1192
 
              repository_policy=None, tag_selector=None):
 
1193
    def clone(self, to_controldir, revision_id=None, repository_policy=None):
1193
1194
        """Clone this branch into to_controldir preserving all semantic values.
1194
1195
 
1195
1196
        Most API users will want 'create_clone_on_transport', which creates a
1198
1199
        revision_id: if not None, the revision history in the new branch will
1199
1200
                     be truncated to end with revision_id.
1200
1201
        """
1201
 
        result = to_controldir.create_branch(name=name)
 
1202
        result = to_controldir.create_branch()
1202
1203
        with self.lock_read(), result.lock_write():
1203
1204
            if repository_policy is not None:
1204
1205
                repository_policy.configure_branch(result)
1205
 
            self.copy_content_into(
1206
 
                result, revision_id=revision_id, tag_selector=tag_selector)
 
1206
            self.copy_content_into(result, revision_id=revision_id)
1207
1207
        return result
1208
1208
 
1209
1209
    def sprout(self, to_controldir, revision_id=None, repository_policy=None,
1210
 
               repository=None, lossy=False, tag_selector=None):
 
1210
               repository=None, lossy=False):
1211
1211
        """Create a new line of development from the branch, into to_controldir.
1212
1212
 
1213
1213
        to_controldir controls the branch format.
1224
1224
        with self.lock_read(), result.lock_write():
1225
1225
            if repository_policy is not None:
1226
1226
                repository_policy.configure_branch(result)
1227
 
            self.copy_content_into(
1228
 
                result, revision_id=revision_id, tag_selector=tag_selector)
 
1227
            self.copy_content_into(result, revision_id=revision_id)
1229
1228
            master_url = self.get_bound_location()
1230
1229
            if master_url is None:
1231
1230
                result.set_parent(self.user_url)
1258
1257
                revno = 1
1259
1258
        destination.set_last_revision_info(revno, revision_id)
1260
1259
 
1261
 
    def copy_content_into(self, destination, revision_id=None, tag_selector=None):
 
1260
    def copy_content_into(self, destination, revision_id=None):
1262
1261
        """Copy the content of self into destination.
1263
1262
 
1264
1263
        revision_id: if not None, the revision history in the new branch will
1265
1264
                     be truncated to end with revision_id.
1266
 
        tag_selector: Optional callback that receives a tag name
1267
 
            and should return a boolean to indicate whether a tag should be copied
1268
1265
        """
1269
1266
        return InterBranch.get(self, destination).copy_content_into(
1270
 
            revision_id=revision_id, tag_selector=tag_selector)
 
1267
            revision_id=revision_id)
1271
1268
 
1272
1269
    def update_references(self, target):
1273
1270
        if not self._format.supports_reference_locations:
1312
1309
 
1313
1310
    def create_clone_on_transport(self, to_transport, revision_id=None,
1314
1311
                                  stacked_on=None, create_prefix=False,
1315
 
                                  use_existing_dir=False, no_tree=None,
1316
 
                                  tag_selector=None):
 
1312
                                  use_existing_dir=False, no_tree=None):
1317
1313
        """Create a clone of this branch and its bzrdir.
1318
1314
 
1319
1315
        :param to_transport: The transport to clone onto.
1333
1329
        dir_to = self.controldir.clone_on_transport(
1334
1330
            to_transport, revision_id=revision_id, stacked_on=stacked_on,
1335
1331
            create_prefix=create_prefix, use_existing_dir=use_existing_dir,
1336
 
            no_tree=no_tree, tag_selector=tag_selector)
 
1332
            no_tree=no_tree)
1337
1333
        return dir_to.open_branch()
1338
1334
 
1339
1335
    def create_checkout(self, to_location, revision_id=None,
2060
2056
        raise NotImplementedError(klass._get_branch_formats_to_test)
2061
2057
 
2062
2058
    def pull(self, overwrite=False, stop_revision=None,
2063
 
             possible_transports=None, local=False, tag_selector=None):
 
2059
             possible_transports=None, local=False):
2064
2060
        """Mirror source into target branch.
2065
2061
 
2066
2062
        The target branch is considered to be 'local', having low latency.
2070
2066
        raise NotImplementedError(self.pull)
2071
2067
 
2072
2068
    def push(self, overwrite=False, stop_revision=None, lossy=False,
2073
 
             _override_hook_source_branch=None, tag_selector=None):
 
2069
             _override_hook_source_branch=None):
2074
2070
        """Mirror the source branch into the target branch.
2075
2071
 
2076
2072
        The source branch is considered to be 'local', having low latency.
2077
2073
        """
2078
2074
        raise NotImplementedError(self.push)
2079
2075
 
2080
 
    def copy_content_into(self, revision_id=None, tag_selector=None):
 
2076
    def copy_content_into(self, revision_id=None):
2081
2077
        """Copy the content of source into target
2082
2078
 
2083
 
        :param revision_id:
2084
 
            if not None, the revision history in the new branch will
2085
 
            be truncated to end with revision_id.
2086
 
        :param tag_selector: Optional callback that can decide
2087
 
            to copy or not copy tags.
 
2079
        revision_id: if not None, the revision history in the new branch will
 
2080
                     be truncated to end with revision_id.
2088
2081
        """
2089
2082
        raise NotImplementedError(self.copy_content_into)
2090
2083
 
2131
2124
            return format._custom_format
2132
2125
        return format
2133
2126
 
2134
 
    def copy_content_into(self, revision_id=None, tag_selector=None):
 
2127
    def copy_content_into(self, revision_id=None):
2135
2128
        """Copy the content of source into target
2136
2129
 
2137
2130
        revision_id: if not None, the revision history in the new branch will
2148
2141
                if parent:
2149
2142
                    self.target.set_parent(parent)
2150
2143
            if self.source._push_should_merge_tags():
2151
 
                self.source.tags.merge_to(self.target.tags, selector=tag_selector)
 
2144
                self.source.tags.merge_to(self.target.tags)
2152
2145
 
2153
2146
    def fetch(self, stop_revision=None, limit=None, lossy=False):
2154
2147
        if self.target.base == self.source.base:
2209
2202
 
2210
2203
    def pull(self, overwrite=False, stop_revision=None,
2211
2204
             possible_transports=None, run_hooks=True,
2212
 
             _override_hook_target=None, local=False,
2213
 
             tag_selector=None):
 
2205
             _override_hook_target=None, local=False):
2214
2206
        """Pull from source into self, updating my master if any.
2215
2207
 
2216
2208
        :param run_hooks: Private parameter - if false, this branch
2241
2233
            if master_branch:
2242
2234
                # pull from source into master.
2243
2235
                master_branch.pull(
2244
 
                    self.source, overwrite, stop_revision, run_hooks=False,
2245
 
                    tag_selector=tag_selector)
 
2236
                    self.source, overwrite, stop_revision, run_hooks=False)
2246
2237
            return self._pull(
2247
2238
                overwrite, stop_revision, _hook_master=master_branch,
2248
2239
                run_hooks=run_hooks,
2249
2240
                _override_hook_target=_override_hook_target,
2250
 
                merge_tags_to_master=not source_is_master,
2251
 
                tag_selector=tag_selector)
 
2241
                merge_tags_to_master=not source_is_master)
2252
2242
 
2253
2243
    def push(self, overwrite=False, stop_revision=None, lossy=False,
2254
 
             _override_hook_source_branch=None, tag_selector=None):
 
2244
             _override_hook_source_branch=None):
2255
2245
        """See InterBranch.push.
2256
2246
 
2257
2247
        This is the basic concrete implementation of push()
2283
2273
                with master_branch.lock_write():
2284
2274
                    # push into the master from the source branch.
2285
2275
                    master_inter = InterBranch.get(self.source, master_branch)
2286
 
                    master_inter._basic_push(
2287
 
                        overwrite, stop_revision, tag_selector=tag_selector)
 
2276
                    master_inter._basic_push(overwrite, stop_revision)
2288
2277
                    # and push into the target branch from the source. Note
2289
2278
                    # that we push from the source branch again, because it's
2290
2279
                    # considered the highest bandwidth repository.
2291
 
                    result = self._basic_push(
2292
 
                        overwrite, stop_revision, tag_selector=tag_selector)
 
2280
                    result = self._basic_push(overwrite, stop_revision)
2293
2281
                    result.master_branch = master_branch
2294
2282
                    result.local_branch = self.target
2295
2283
                    _run_hooks()
2296
2284
            else:
2297
2285
                master_branch = None
2298
2286
                # no master branch
2299
 
                result = self._basic_push(
2300
 
                    overwrite, stop_revision, tag_selector=tag_selector)
 
2287
                result = self._basic_push(overwrite, stop_revision)
2301
2288
                # TODO: Why set master_branch and local_branch if there's no
2302
2289
                # binding?  Maybe cleaner to just leave them unset? -- mbp
2303
2290
                # 20070504
2306
2293
                _run_hooks()
2307
2294
            return result
2308
2295
 
2309
 
    def _basic_push(self, overwrite, stop_revision, tag_selector=None):
 
2296
    def _basic_push(self, overwrite, stop_revision):
2310
2297
        """Basic implementation of push without bound branches or hooks.
2311
2298
 
2312
2299
        Must be called with source read locked and target write locked.
2325
2312
        if self.source._push_should_merge_tags():
2326
2313
            result.tag_updates, result.tag_conflicts = (
2327
2314
                self.source.tags.merge_to(
2328
 
                    self.target.tags, "tags" in overwrite, selector=tag_selector))
 
2315
                    self.target.tags, "tags" in overwrite))
2329
2316
        self.update_references()
2330
2317
        result.new_revno, result.new_revid = self.target.last_revision_info()
2331
2318
        return result
2333
2320
    def _pull(self, overwrite=False, stop_revision=None,
2334
2321
              possible_transports=None, _hook_master=None, run_hooks=True,
2335
2322
              _override_hook_target=None, local=False,
2336
 
              merge_tags_to_master=True, tag_selector=None):
 
2323
              merge_tags_to_master=True):
2337
2324
        """See Branch.pull.
2338
2325
 
2339
2326
        This function is the core worker, used by GenericInterBranch.pull to
2377
2364
            result.tag_updates, result.tag_conflicts = (
2378
2365
                self.source.tags.merge_to(
2379
2366
                    self.target.tags, "tags" in overwrite,
2380
 
                    ignore_master=not merge_tags_to_master,
2381
 
                    selector=tag_selector))
 
2367
                    ignore_master=not merge_tags_to_master))
2382
2368
            self.update_references()
2383
2369
            result.new_revno, result.new_revid = (
2384
2370
                self.target.last_revision_info())