Ejemplo n.º 1
0
    def _parent_commit_for_first_lt_child(self):
        '''
        If "change" is going to be the first commit on a new Git branch,
        and if current_branch is a view into a lightweight depot branch
        based on some other branch at some other changelist number, return
        that other branch@change as a sha1/commit that should be a
        commit parent of "change".

        If not, return None.

        Required when the first commit in a lightweight branh is an add,
        not edit, and thus has zero integ actions to connect it to the
        parent branch. We must connect manually. Here.
        '''

        # Not copying from a lightweight branch?
        if not self.current_branch.depot_branch:
            return None

        # Lightweight branch lacks a parent?
        if not self.current_branch.depot_branch.parent_depot_branch_id_list:
            return None

        # Find a commit to go with the parent branch @ changelist
        # upon which dest_db is based.
        dest_db = self.current_branch.depot_branch
        for par_cl in dest_db.parent_changelist_list:
            # Mark for a change/commit we're about to copy to this repo?
            ml = self.p2g.mark_list.cl_to_mark_list(par_cl)
            if ml:
                return ml[0]
            # sha1 we've already copied to this repo?
            commit = ObjectType.commit_for_change(self.ctx, par_cl)
            if commit:
                return commit.sha1
    def _parent_commit_for_first_lt_child(self):
        '''
        If "change" is going to be the first commit on a new Git branch,
        and if current_branch is a view into a lightweight depot branch
        based on some other branch at some other changelist number, return
        that other branch@change as a sha1/commit that should be a
        commit parent of "change".

        If not, return None.

        Required when the first commit in a lightweight branh is an add,
        not edit, and thus has zero integ actions to connect it to the
        parent branch. We must connect manually. Here.
        '''

        # Not copying from a lightweight branch?
        if not self.current_branch.depot_branch:
            return None

        # Lightweight branch lacks a parent?
        if not self.current_branch.depot_branch.parent_depot_branch_id_list:
            return None

        # Find a commit to go with the parent branch @ changelist
        # upon which dest_db is based.
        dest_db = self.current_branch.depot_branch
        for par_cl in dest_db.parent_changelist_list:
            # Mark for a change/commit we're about to copy to this repo?
            ml = self.p2g.mark_list.cl_to_mark_list(par_cl)
            if ml:
                return ml[0]
            # sha1 we've already copied to this repo?
            commit = ObjectType.commit_for_change(self.ctx, par_cl)
            if commit:
                return commit.sha1
    def _calc_merge_parent_list(self):
        '''
        Return a list of marks/sha1s to use as parents for a Git merge commit.

        Returns a 2-tuple of ( [mark/commit parent], [parent branch id] ).
        '''
        parent_commit_id = []
        parent_branch_id = []
        for branch_id, cl in self.branch_id_to_changelist_num.items():
            # Changelists from before the start of history cannot be
            # parents. No merging from beyond the event horizon.
            if cl < self.p2g.rev_range.begin_change_num:
                continue

            # Each Perforce commit maps to zero or more Git commits, one per
            # branch that intersects the integ source files from that commit.

            # Do we have any pending commits for this changelist?
            ml = self.p2g.mark_list.cl_to_mark_list(str(cl))
            for mark in ml:
                ### Must only include mark if mark associated with branch.
                ### Must only include one mark here.
                ### But that requires adding more branch/mark tracking than we
                ### want to add until I have a test that proves we need it.
                if not mark in parent_commit_id:
                    parent_commit_id.append(mark)
                    parent_branch_id.append(branch_id)

            # Do we have any existing commits for this changelist?
            commit = ObjectType.commit_for_change(self.ctx, cl)

            # Does this Git commit occur in our Git repo at this
            # changelist number?
            if (commit and
                (not commit.sha1 in parent_commit_id) and
                p4gf_util.sha1_exists(commit.sha1) ):
                parent_commit_id.append(commit.sha1)
                parent_branch_id.append(branch_id)

        return (parent_commit_id, parent_branch_id)
Ejemplo n.º 4
0
    def _calc_merge_parent_list(self):
        '''
        Return a list of marks/sha1s to use as parents for a Git merge commit.

        Returns a 2-tuple of ( [mark/commit parent], [parent branch id] ).
        '''
        parent_commit_id = []
        parent_branch_id = []
        for branch_id, cl in self.branch_id_to_changelist_num.items():
            # Changelists from before the start of history cannot be
            # parents. No merging from beyond the event horizon.
            if cl < self.p2g.rev_range.begin_change_num:
                continue

            # Each Perforce commit maps to zero or more Git commits, one per
            # branch that intersects the integ source files from that commit.

            # Do we have any pending commits for this changelist?
            ml = self.p2g.mark_list.cl_to_mark_list(str(cl))
            for mark in ml:
                ### Must only include mark if mark associated with branch.
                ### Must only include one mark here.
                ### But that requires adding more branch/mark tracking than we
                ### want to add until I have a test that proves we need it.
                if not mark in parent_commit_id:
                    parent_commit_id.append(mark)
                    parent_branch_id.append(branch_id)

            # Do we have any existing commits for this changelist?
            commit = ObjectType.commit_for_change(self.ctx, cl)

            # Does this Git commit occur in our Git repo at this
            # changelist number?
            if (commit and (not commit.sha1 in parent_commit_id)
                    and p4gf_util.sha1_exists(commit.sha1)):
                parent_commit_id.append(commit.sha1)
                parent_branch_id.append(branch_id)

        return (parent_commit_id, parent_branch_id)
Ejemplo n.º 5
0
    def _git_object_parent_list(self):
        '''
        Fetch the list of parent commits from our git object mirror of the
        original Git commit that created our current Perforce changelist.

        Return None if no such commit found.

        Return empty list [] if commit found but it lacked parents
        (orphan/first commit in a chain of commits).
        '''
        # Find corresponding Git commit object for this changelist. Ignore the
        # sha1 in the changelist DescInfo: it's only there for Git-to-Perforce
        # changelists, not changelists that originated in Perforce.
        commit = ObjectType.commit_for_change(self.ctx, self.p4change.change)
        if not commit:
            # Cached object is missing, see if the change description has
            # what we need (in the 'parents' field of the Git desc info).
            if self.desc_info and self.desc_info.parents:
                LOG.debug2(
                    '_git_object_parent_list() parents from change: {}'.format(
                        self.desc_info.parents))
                return self.desc_info.parents
            else:
                return None

        depot_path = commit.to_depot_path()
        commit_text = p4gf_util.depot_path_to_git_object(
            self.ctx.p4gf, depot_path)
        # Parse out the parent list.
        parent_list = []
        for line in commit_text.splitlines():
            if line.startswith(b'parent '):
                sha1 = line[len(b'parent '):].decode().strip()
                parent_list.append(sha1)
            elif not len(line.strip()):
                # Done with header. Stop scanning.
                break
        return parent_list
    def _git_object_parent_list(self):
        '''
        Fetch the list of parent commits from our git object mirror of the
        original Git commit that created our current Perforce changelist.

        Return None if no such commit found.

        Return empty list [] if commit found but it lacked parents
        (orphan/first commit in a chain of commits).
        '''
        # Find corresponding Git commit object for this changelist. Ignore the
        # sha1 in the changelist DescInfo: it's only there for Git-to-Perforce
        # changelists, not changelists that originated in Perforce.
        commit = ObjectType.commit_for_change(self.ctx, self.p4change.change)
        if not commit:
            # Cached object is missing, see if the change description has
            # what we need (in the 'parents' field of the Git desc info).
            if self.desc_info and self.desc_info.parents:
                LOG.debug2('_git_object_parent_list() parents from change: {}'.format(
                    self.desc_info.parents))
                return self.desc_info.parents
            else:
                return None

        depot_path  = commit.to_depot_path()
        commit_text = p4gf_util.depot_path_to_git_object( self.ctx.p4gf
                                                        , depot_path )
        # Parse out the parent list.
        parent_list = []
        for line in commit_text.splitlines():
            if line.startswith(b'parent '):
                sha1 = line[len(b'parent '):].decode().strip()
                parent_list.append(sha1)
            elif not len(line.strip()):
                # Done with header. Stop scanning.
                break
        return parent_list