예제 #1
0
파일: git.py 프로젝트: lupine37/gps
 def _worktrees(self, visitor):
     """
     A generator that returns the list of worktrees via `visitor.branches`
     """
     # "--no-pager" results in segfault with git 2.11
     p = ProcessWrapper(['git', 'worktree', 'list', '--porcelain'],
                        directory=self.working_dir.path)
     trees = []
     current = []
     while True:
         line = yield p.wait_line()
         if line is None:
             # Do not report if we only have the current directory
             if len(trees) > 1:
                 visitor.branches(CAT_WORKTREES,
                                  'vcs-git-worktrees-symbolic',
                                  not CAN_RENAME, trees)
             break
         elif not line:
             trees.append(current)
         elif line.startswith('worktree '):
             current = GPS.VCS2.Branch(
                 name='"%s"' % line[9:],  # quoted not to expand '/'
                 active=self.working_dir == GPS.File(line[9:]),
                 annotation='',
                 id='')  # unique id
         elif line.startswith('HEAD '):
             current[3] = line[5:]  # unique id
         elif line.startswith('branch '):
             current[2] = line[7:]  # details
         elif line.startswith('detached'):
             current[2] = 'detached'  # details
예제 #2
0
파일: gerrit.py 프로젝트: zackboll/gps
    def async_branches(self, visitor):
        p = ProcessWrapper(
            ['ssh',
             '-x',
             '-p' if self.port else '', self.port,
             self.host,
             'gerrit',
             'query',
             '--format=json',
             '--current-patch-set',
             'project:%s' % self.project,
             'status:open'], block_exit=False)
        reviews = []
        while True:
            line = yield p.wait_line()
            if line is None:
                if reviews:
                    visitor.branches(
                        CAT_REVIEWS, 'vcs-gerrit-symbolic',
                        not CAN_RENAME, reviews)
                break

            patch = json.loads(line)
            if patch and patch.get(u'subject', None) is not None:
                review = '0'
                workflow = ''
                patchset = patch[u'currentPatchSet']
                if patchset.get(u'approvals', None) is not None:
                    for a in patchset[u'approvals']:
                        if a[u'type'] == u'Workflow':
                            workflow = '|%s' % a['value']
                        elif a[u'type'] == u'Code-Review':
                            review = a['value']

                id = {'url': patch.get(u'url', ''),
                      'number': patch.get(u'number', '')}

                reviews.append(
                    ('%s: %s' % (patchset[u'author'][u'username'],
                                 patch[u'subject']),
                     False,   # not active
                     '%s%s' % (review, workflow),
                     json.dumps(id)))
예제 #3
0
    def async_branches(self, visitor):
        # We use -q to hide warnings which could for instance occur
        # when redirecting ports if ~/.ssh/config contains
        #   Host ...
        #      RemoteForward 3142 localhost:22

        if not self.gerrit_accessible:
            return

        p = ProcessWrapper(
            [
                'ssh',
                '-x',
                '-q',  # Hide warnings
                '-p' if self.port else '',
                self.port,
                self.host,
                'gerrit',
                'query',
                '--format=json',
                '--current-patch-set',
                'project:%s' % self.project,
                'status:open'
            ],
            block_exit=False)

        reviews = []
        while True:
            line = yield p.wait_line()
            if line is None:
                if reviews:
                    visitor.branches(CAT_REVIEWS, 'vcs-gerrit-symbolic',
                                     not CAN_RENAME, reviews)
                break

            if line.startswith('Bad port'):
                # Seems like Gerrit can't be accessed
                GPS.Console().write('Can\'t access Gerrit %s:%s\n' %
                                    (self.host, self.port))
                self.gerrit_accessible = False
                break

            patch = json.loads(line)
            if patch and patch.get(u'subject', None) is not None:
                review = '0'
                workflow = ''
                patchset = patch[u'currentPatchSet']
                if patchset.get(u'approvals', None) is not None:
                    for a in patchset[u'approvals']:
                        if a[u'type'] == u'Workflow':
                            workflow = '|%s' % a['value']
                        elif a[u'type'] == u'Code-Review':
                            review = a['value']

                id = {
                    'url': patch.get(u'url', ''),
                    'number': patch.get(u'number', '')
                }

                reviews.append((
                    '%s: %s' %
                    (patchset[u'author'][u'username'], patch[u'subject']),
                    False,  # not active
                    '%s%s' % (review, workflow),
                    json.dumps(id)))