/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-21 03:58:42 UTC
  • mfrom: (7490.3.4 work)
  • mto: This revision was merged to the branch mainline in revision 7495.
  • Revision ID: jelmer@jelmer.uk-20200221035842-j97r6b74q8cgxb21
merge lp:brz/3.1.

Show diffs side-by-side

added added

removed removed

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