/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-03-22 19:12:43 UTC
  • mfrom: (7490.7.6 work)
  • mto: (7490.7.7 work)
  • mto: This revision was merged to the branch mainline in revision 7501.
  • Revision ID: jelmer@jelmer.uk-20200322191243-yx8ils8lvfmfh7rq
Merge lp:brz/3.1.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1194
1194
        if revno < 1 or revno > self.revno():
1195
1195
            raise errors.InvalidRevisionNumber(revno)
1196
1196
 
1197
 
    def clone(self, to_controldir, revision_id=None, name=None, repository_policy=None):
 
1197
    def clone(self, to_controldir, revision_id=None, name=None,
 
1198
              repository_policy=None, tag_selector=None):
1198
1199
        """Clone this branch into to_controldir preserving all semantic values.
1199
1200
 
1200
1201
        Most API users will want 'create_clone_on_transport', which creates a
1207
1208
        with self.lock_read(), result.lock_write():
1208
1209
            if repository_policy is not None:
1209
1210
                repository_policy.configure_branch(result)
1210
 
            self.copy_content_into(result, revision_id=revision_id)
 
1211
            self.copy_content_into(
 
1212
                result, revision_id=revision_id, tag_selector=tag_selector)
1211
1213
        return result
1212
1214
 
1213
1215
    def sprout(self, to_controldir, revision_id=None, repository_policy=None,
1214
 
               repository=None, lossy=False):
 
1216
               repository=None, lossy=False, tag_selector=None):
1215
1217
        """Create a new line of development from the branch, into to_controldir.
1216
1218
 
1217
1219
        to_controldir controls the branch format.
1228
1230
        with self.lock_read(), result.lock_write():
1229
1231
            if repository_policy is not None:
1230
1232
                repository_policy.configure_branch(result)
1231
 
            self.copy_content_into(result, revision_id=revision_id)
 
1233
            self.copy_content_into(
 
1234
                result, revision_id=revision_id, tag_selector=tag_selector)
1232
1235
            master_url = self.get_bound_location()
1233
1236
            if master_url is None:
1234
1237
                result.set_parent(self.user_url)
1261
1264
                revno = 1
1262
1265
        destination.set_last_revision_info(revno, revision_id)
1263
1266
 
1264
 
    def copy_content_into(self, destination, revision_id=None):
 
1267
    def copy_content_into(self, destination, revision_id=None, tag_selector=None):
1265
1268
        """Copy the content of self into destination.
1266
1269
 
1267
1270
        revision_id: if not None, the revision history in the new branch will
1268
1271
                     be truncated to end with revision_id.
 
1272
        tag_selector: Optional callback that receives a tag name
 
1273
            and should return a boolean to indicate whether a tag should be copied
1269
1274
        """
1270
1275
        return InterBranch.get(self, destination).copy_content_into(
1271
 
            revision_id=revision_id)
 
1276
            revision_id=revision_id, tag_selector=tag_selector)
1272
1277
 
1273
1278
    def update_references(self, target):
1274
1279
        if not self._format.supports_reference_locations:
1313
1318
 
1314
1319
    def create_clone_on_transport(self, to_transport, revision_id=None,
1315
1320
                                  stacked_on=None, create_prefix=False,
1316
 
                                  use_existing_dir=False, no_tree=None):
 
1321
                                  use_existing_dir=False, no_tree=None,
 
1322
                                  tag_selector=None):
1317
1323
        """Create a clone of this branch and its bzrdir.
1318
1324
 
1319
1325
        :param to_transport: The transport to clone onto.
1333
1339
        dir_to = self.controldir.clone_on_transport(
1334
1340
            to_transport, revision_id=revision_id, stacked_on=stacked_on,
1335
1341
            create_prefix=create_prefix, use_existing_dir=use_existing_dir,
1336
 
            no_tree=no_tree)
 
1342
            no_tree=no_tree, tag_selector=tag_selector)
1337
1343
        return dir_to.open_branch()
1338
1344
 
1339
1345
    def create_checkout(self, to_location, revision_id=None,
2060
2066
        raise NotImplementedError(klass._get_branch_formats_to_test)
2061
2067
 
2062
2068
    def pull(self, overwrite=False, stop_revision=None,
2063
 
             possible_transports=None, local=False):
 
2069
             possible_transports=None, local=False, tag_selector=None):
2064
2070
        """Mirror source into target branch.
2065
2071
 
2066
2072
        The target branch is considered to be 'local', having low latency.
2070
2076
        raise NotImplementedError(self.pull)
2071
2077
 
2072
2078
    def push(self, overwrite=False, stop_revision=None, lossy=False,
2073
 
             _override_hook_source_branch=None):
 
2079
             _override_hook_source_branch=None, tag_selector=None):
2074
2080
        """Mirror the source branch into the target branch.
2075
2081
 
2076
2082
        The source branch is considered to be 'local', having low latency.
2077
2083
        """
2078
2084
        raise NotImplementedError(self.push)
2079
2085
 
2080
 
    def copy_content_into(self, revision_id=None):
 
2086
    def copy_content_into(self, revision_id=None, tag_selector=None):
2081
2087
        """Copy the content of source into target
2082
2088
 
2083
 
        revision_id: if not None, the revision history in the new branch will
2084
 
                     be truncated to end with revision_id.
 
2089
        :param revision_id:
 
2090
            if not None, the revision history in the new branch will
 
2091
            be truncated to end with revision_id.
 
2092
        :param tag_selector: Optional callback that can decide
 
2093
            to copy or not copy tags.
2085
2094
        """
2086
2095
        raise NotImplementedError(self.copy_content_into)
2087
2096
 
2128
2137
            return format._custom_format
2129
2138
        return format
2130
2139
 
2131
 
    def copy_content_into(self, revision_id=None):
 
2140
    def copy_content_into(self, revision_id=None, tag_selector=None):
2132
2141
        """Copy the content of source into target
2133
2142
 
2134
2143
        revision_id: if not None, the revision history in the new branch will
2145
2154
                if parent:
2146
2155
                    self.target.set_parent(parent)
2147
2156
            if self.source._push_should_merge_tags():
2148
 
                self.source.tags.merge_to(self.target.tags)
 
2157
                self.source.tags.merge_to(self.target.tags, selector=tag_selector)
2149
2158
 
2150
2159
    def fetch(self, stop_revision=None, limit=None, lossy=False):
2151
2160
        if self.target.base == self.source.base:
2206
2215
 
2207
2216
    def pull(self, overwrite=False, stop_revision=None,
2208
2217
             possible_transports=None, run_hooks=True,
2209
 
             _override_hook_target=None, local=False):
 
2218
             _override_hook_target=None, local=False,
 
2219
             tag_selector=None):
2210
2220
        """Pull from source into self, updating my master if any.
2211
2221
 
2212
2222
        :param run_hooks: Private parameter - if false, this branch
2237
2247
            if master_branch:
2238
2248
                # pull from source into master.
2239
2249
                master_branch.pull(
2240
 
                    self.source, overwrite, stop_revision, run_hooks=False)
 
2250
                    self.source, overwrite, stop_revision, run_hooks=False,
 
2251
                    tag_selector=tag_selector)
2241
2252
            return self._pull(
2242
2253
                overwrite, stop_revision, _hook_master=master_branch,
2243
2254
                run_hooks=run_hooks,
2244
2255
                _override_hook_target=_override_hook_target,
2245
 
                merge_tags_to_master=not source_is_master)
 
2256
                merge_tags_to_master=not source_is_master,
 
2257
                tag_selector=tag_selector)
2246
2258
 
2247
2259
    def push(self, overwrite=False, stop_revision=None, lossy=False,
2248
 
             _override_hook_source_branch=None):
 
2260
             _override_hook_source_branch=None, tag_selector=None):
2249
2261
        """See InterBranch.push.
2250
2262
 
2251
2263
        This is the basic concrete implementation of push()
2277
2289
                with master_branch.lock_write():
2278
2290
                    # push into the master from the source branch.
2279
2291
                    master_inter = InterBranch.get(self.source, master_branch)
2280
 
                    master_inter._basic_push(overwrite, stop_revision)
 
2292
                    master_inter._basic_push(
 
2293
                        overwrite, stop_revision, tag_selector=tag_selector)
2281
2294
                    # and push into the target branch from the source. Note
2282
2295
                    # that we push from the source branch again, because it's
2283
2296
                    # considered the highest bandwidth repository.
2284
 
                    result = self._basic_push(overwrite, stop_revision)
 
2297
                    result = self._basic_push(
 
2298
                        overwrite, stop_revision, tag_selector=tag_selector)
2285
2299
                    result.master_branch = master_branch
2286
2300
                    result.local_branch = self.target
2287
2301
                    _run_hooks()
2288
2302
            else:
2289
2303
                master_branch = None
2290
2304
                # no master branch
2291
 
                result = self._basic_push(overwrite, stop_revision)
 
2305
                result = self._basic_push(
 
2306
                    overwrite, stop_revision, tag_selector=tag_selector)
2292
2307
                # TODO: Why set master_branch and local_branch if there's no
2293
2308
                # binding?  Maybe cleaner to just leave them unset? -- mbp
2294
2309
                # 20070504
2297
2312
                _run_hooks()
2298
2313
            return result
2299
2314
 
2300
 
    def _basic_push(self, overwrite, stop_revision):
 
2315
    def _basic_push(self, overwrite, stop_revision, tag_selector=None):
2301
2316
        """Basic implementation of push without bound branches or hooks.
2302
2317
 
2303
2318
        Must be called with source read locked and target write locked.
2316
2331
        if self.source._push_should_merge_tags():
2317
2332
            result.tag_updates, result.tag_conflicts = (
2318
2333
                self.source.tags.merge_to(
2319
 
                    self.target.tags, "tags" in overwrite))
 
2334
                    self.target.tags, "tags" in overwrite, selector=tag_selector))
2320
2335
        self.update_references()
2321
2336
        result.new_revno, result.new_revid = self.target.last_revision_info()
2322
2337
        return result
2324
2339
    def _pull(self, overwrite=False, stop_revision=None,
2325
2340
              possible_transports=None, _hook_master=None, run_hooks=True,
2326
2341
              _override_hook_target=None, local=False,
2327
 
              merge_tags_to_master=True):
 
2342
              merge_tags_to_master=True, tag_selector=None):
2328
2343
        """See Branch.pull.
2329
2344
 
2330
2345
        This function is the core worker, used by GenericInterBranch.pull to
2368
2383
            result.tag_updates, result.tag_conflicts = (
2369
2384
                self.source.tags.merge_to(
2370
2385
                    self.target.tags, "tags" in overwrite,
2371
 
                    ignore_master=not merge_tags_to_master))
 
2386
                    ignore_master=not merge_tags_to_master,
 
2387
                    selector=tag_selector))
2372
2388
            self.update_references()
2373
2389
            result.new_revno, result.new_revid = (
2374
2390
                self.target.last_revision_info())