~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/code/interfaces/branch.py

  • Committer: Launchpad Patch Queue Manager
  • Date: 2009-07-15 01:45:35 UTC
  • mfrom: (8852.2.3 bzr-identity-speed-fixes)
  • Revision ID: launchpad@pqm.canonical.com-20090715014535-8qhv29cuw0ce8plr
[r=mwhudson][ui=none] Refactor the bazaar_identity function to work
        based on method calls to the branch rather than objects passed in.

Show diffs side-by-side

added added

removed removed

Lines of Context:
778
778
        series as a branch.
779
779
        """
780
780
 
 
781
    def associatedSuiteSourcePackages():
 
782
        """Return the suite source packages that this branch is linked to."""
 
783
 
781
784
    # subscription-related methods
782
785
    @operation_parameters(
783
786
        person=Reference(
1096
1099
        """
1097
1100
 
1098
1101
 
1099
 
def bazaar_identity(branch, associated_series, is_dev_focus):
 
1102
def bazaar_identity(branch, is_dev_focus):
1100
1103
    """Return the shortest lp: style branch identity."""
1101
1104
    lp_prefix = config.codehosting.bzr_lp_prefix
1102
1105
 
1116
1119
            return lp_prefix + branch.product.name
1117
1120
 
1118
1121
        # If there are no associated series, then use the unique name.
1119
 
        associated_series = list(associated_series)
1120
 
        if [] == associated_series:
 
1122
        associated_series = sorted(
 
1123
            branch.associatedProductSeries(), key=attrgetter('datecreated'))
 
1124
        if len(associated_series) == 0:
1121
1125
            return lp_prefix + branch.unique_name
1122
 
 
1123
 
        use_series = sorted(
1124
 
            associated_series, key=attrgetter('datecreated'))[-1]
 
1126
        # Use the most recently created series.
 
1127
        use_series = associated_series[-1]
1125
1128
        return "%(prefix)s%(product)s/%(series)s" % {
1126
1129
            'prefix': lp_prefix,
1127
1130
            'product': use_series.product.name,
1128
1131
            'series': use_series.name}
1129
1132
 
1130
1133
    if branch.sourcepackage is not None:
1131
 
        sourcepackage = branch.sourcepackage
1132
 
        linked_branches = sourcepackage.linked_branches
1133
 
        for pocket, linked_branch in linked_branches:
1134
 
            if linked_branch == branch:
1135
 
                return lp_prefix + sourcepackage.getPocketPath(pocket)
 
1134
        suite_sourcepackages = branch.associatedSuiteSourcePackages()
 
1135
        # Take the first link if there is one.
 
1136
        if len(suite_sourcepackages) > 0:
 
1137
            suite_source_package = suite_sourcepackages[0]
 
1138
            return lp_prefix + suite_source_package.path
1136
1139
 
1137
1140
    return lp_prefix + branch.unique_name
1138
1141