def make_tracker_branch_from_name(self, branch_name): """Return the WorkingBranch for 'branch_name' or None if invalid. Usage example: >>> naming = Naming() >>> make_branch = naming.make_tracker_branch_from_name >>> make_branch('dev/arcyd/ok/mywork/master/99') ... # doctest: +NORMALIZE_WHITESPACE abdt_naming.TrackerBranch("dev/arcyd/ok/mywork/master/99") >>> make_branch('dev/arcyd/trackers/x/ok/r/master/do/99') Traceback (most recent call last): ... Error >>> make_branch('invalid/mywork/master') Traceback (most recent call last): ... Error :branch_name: string name of the working branch :returns: WorkingBranch or None if invalid """ if branch_name == abdt_naming.RESERVED_BRANCH_NAME: raise abdt_naming.Error() # ignore the reserved branch if branch_name.startswith(abdt_naming.TRACKING_BRANCH_PREFIX): raise abdt_naming.Error() # ignore all new tracker branches suffix = phlsys_string.after_prefix(branch_name, self._tracking_branch_prefix) if not suffix: # review branches must start with the prefix raise abdt_naming.Error() # suffix should be status/description/base(/...)/id # 0 / 1 / 2 (/...)/-1 parts = suffix.split("/") if len(parts) < 4: raise abdt_naming.Error() description = parts[1] base = "/".join(parts[2:-1]) review_branch = self._review_branch_prefix review_branch += description review_branch += "/" + base return abdt_naming.TrackerBranch( naming=self, branch=branch_name, review_branch=review_branch, status=parts[0], description=description, base=base, rev_id=parts[-1], remote=self._remote, )
def make_review_branch_from_name(self, branch_name): """Return the ReviewBranch for 'branch_name' or None if invalid. Usage example: >>> naming = Naming() >>> make_branch = naming.make_review_branch_from_name >>> make_branch('arcyd-review/mywork/master') ... # doctest: +NORMALIZE_WHITESPACE abdt_naming.ReviewBranch("arcyd-review/mywork/master") >>> make_branch('invalid/mywork/master') Traceback (most recent call last): ... Error :branch_name: string name of the review branch :returns: ReviewBranch or None if invalid """ suffix = phlsys_string.after_prefix(branch_name, self._review_branch_prefix) if not suffix: # review branches must start with the prefix raise abdt_naming.Error() parts = suffix.split("/") if len(parts) < 2: # suffix should be description/base(/...) raise abdt_naming.Error() base = "/".join(parts[1:]) return abdt_naming.ReviewBranch( naming=self, branch=branch_name, description=parts[0], base=base, remote=self._remote )
def make_tracker_branch_from_name(self, branch_name): """Return the WorkingBranch for 'branch_name' or None if invalid. Usage example: >>> naming = Naming() >>> make_branch = naming.make_tracker_branch_from_name >>> make_branch('dev/arcyd/ok/mywork/master/99') ... # doctest: +NORMALIZE_WHITESPACE abdt_naming.TrackerBranch("dev/arcyd/ok/mywork/master/99") >>> make_branch('dev/arcyd/trackers/x/ok/r/master/do/99') Traceback (most recent call last): ... Error >>> make_branch('invalid/mywork/master') Traceback (most recent call last): ... Error :branch_name: string name of the working branch :returns: WorkingBranch or None if invalid """ if branch_name == abdt_naming.RESERVED_BRANCH_NAME: raise abdt_naming.Error() # ignore the reserved branch if branch_name.startswith(abdt_naming.TRACKING_BRANCH_PREFIX): raise abdt_naming.Error() # ignore all new tracker branches suffix = phlsys_string.after_prefix(branch_name, self._tracking_branch_prefix) if not suffix: # review branches must start with the prefix raise abdt_naming.Error() # suffix should be status/description/base(/...)/id # 0 / 1 / 2 (/...)/-1 parts = suffix.split("/") if len(parts) < 4: raise abdt_naming.Error() description = parts[1] base = '/'.join(parts[2:-1]) review_branch = self._review_branch_prefix review_branch += description review_branch += "/" + base return abdt_naming.TrackerBranch(naming=self, branch=branch_name, review_branch=review_branch, status=parts[0], description=description, base=base, rev_id=parts[-1], remote=self._remote)
def make_tracker_branch_from_name(self, branch_name): """Return the WorkingBranch for 'branch_name' or None if invalid. :branch_name: string name of the working branch :returns: WorkingBranch or None if invalid """ if branch_name == self._reserve_branch_prefix: raise abdt_naming.Error() # ignore the reserved branch suffix = phlsys_string.after_prefix( branch_name, self._tracking_branch_prefix) if not suffix: # review branches must start with the prefix raise abdt_naming.Error() # suffix should be status/r/base(/...)/description/id # 0/1/ 2 (/...)/ -2 /-1 parts = suffix.split("/") if len(parts) < 5: # suffix should be status/base(/...)/description/id raise abdt_naming.Error() review_prefix = parts[1] + '/' if review_prefix != self._review_branch_prefix: # doesn't begin with our review branch prefix raise abdt_naming.Error() base = '/'.join(parts[2:-2]) review_branch = '/'.join(parts[1:-1]) return abdt_naming.TrackerBranch( naming=self, branch=branch_name, review_branch=review_branch, status=parts[0], base=base, description=parts[-2], rev_id=parts[-1], remote=self._remote)
def make_tracker_branch_from_name(self, branch_name): """Return the WorkingBranch for 'branch_name' or None if invalid. :branch_name: string name of the working branch :returns: WorkingBranch or None if invalid """ if branch_name == self._reserve_branch_prefix: raise abdt_naming.Error() # ignore the reserved branch suffix = phlsys_string.after_prefix(branch_name, self._tracking_branch_prefix) if not suffix: # review branches must start with the prefix raise abdt_naming.Error() # suffix should be status/r/base(/...)/description/id # 0/1/ 2 (/...)/ -2 /-1 parts = suffix.split("/") if len(parts) < 5: # suffix should be status/base(/...)/description/id raise abdt_naming.Error() review_prefix = parts[1] + '/' if review_prefix != self._review_branch_prefix: # doesn't begin with our review branch prefix raise abdt_naming.Error() base = '/'.join(parts[2:-2]) review_branch = '/'.join(parts[1:-1]) return abdt_naming.TrackerBranch(naming=self, branch=branch_name, review_branch=review_branch, status=parts[0], base=base, description=parts[-2], rev_id=parts[-1], remote=self._remote)
def make_review_branch_from_name(self, branch_name): """Return the ReviewBranch for 'branch_name' or None if invalid. Usage example: >>> naming = Naming() >>> make_branch = naming.make_review_branch_from_name >>> make_branch('r/master/mywork') ... # doctest: +NORMALIZE_WHITESPACE abdt_naming.ReviewBranch("r/master/mywork") >>> make_branch('invalid/master/mywork') Traceback (most recent call last): ... Error :branch_name: string name of the review branch :returns: ReviewBranch or None if invalid """ suffix = phlsys_string.after_prefix(branch_name, self._review_branch_prefix) if not suffix: # review branches must start with the prefix raise abdt_naming.Error() parts = suffix.split("/") if len(parts) < 2: # suffix should be description/base(/...) raise abdt_naming.Error() base = '/'.join(parts[0:-1]) return abdt_naming.ReviewBranch(naming=self, branch=branch_name, description=parts[-1], base=base, remote=self._remote)