Ejemplo n.º 1
0
 def _cleanup_proc(self, proc):
     if proc:
         for f in (proc.stdin, proc.stdout, proc.stderr):
             if f:
                 f.close()
         terminate(proc)
         proc.wait()
Ejemplo n.º 2
0
 def name_status_gen():
     p[:] = [
         self.repo.log_pipe('--pretty=format:%n%H', '--name-status',
                            sha, '--', base_path)
     ]
     f = p[0].stdout
     for l in f:
         if l == '\n':
             continue
         old_sha = l.rstrip('\n')
         for l in f:
             if l == '\n':
                 break
             _, path = l.rstrip('\n').split('\t', 1)
             # git-log without -z option quotes each pathname
             path = _unquote(path)
             while path not in change:
                 change[path] = old_sha
                 if next_path == [path]:
                     yield old_sha
                 try:
                     path, _ = path.rsplit('/', 1)
                 except ValueError:
                     break
     f.close()
     terminate(p[0])
     p[0].wait()
     p[:] = []
     while True:
         yield None
Ejemplo n.º 3
0
    def stop(self):
        """Stops the webserver, if running

        FIXME: probably needs a nicer way to exit for coverage to work
        """
        if self.pid:
            terminate(self.pid)
Ejemplo n.º 4
0
    def cat_file(self, kind, sha):
        with self.__cat_file_pipe_lock:
            if self.__cat_file_pipe is None:
                self.__cat_file_pipe = self.repo.cat_file_batch()

            try:
                self.__cat_file_pipe.stdin.write(sha + '\n')
                self.__cat_file_pipe.stdin.flush()

                split_stdout_line = self.__cat_file_pipe.stdout.readline() \
                                                               .split()
                if len(split_stdout_line) != 3:
                    raise GitError("internal error (could not split line "
                                   "'%s')" % (split_stdout_line, ))

                _sha, _type, _size = split_stdout_line

                if _type != kind:
                    raise GitError("internal error (got unexpected object "
                                   "kind '%s', expected '%s')" % (_type, kind))

                size = int(_size)
                return self.__cat_file_pipe.stdout.read(size + 1)[:size]
            except:
                # There was an error, we should close the pipe to get to a
                # consistent state (Otherwise it happens that next time we
                # call cat_file we get payload from previous call)
                self.logger.debug("closing cat_file pipe")
                self.__cat_file_pipe.stdin.close()
                terminate(self.__cat_file_pipe)
                self.__cat_file_pipe.wait()
                self.__cat_file_pipe = None
Ejemplo n.º 5
0
    def stop(self):
        """Stops the webserver, if running

        FIXME: probably needs a nicer way to exit for coverage to work
        """
        if self.pid:
            terminate(self)
Ejemplo n.º 6
0
 def name_status_gen():
     p[:] = [self.repo.log_pipe('--pretty=format:%n%H',
                                '--name-status', sha, '--', base_path)]
     f = p[0].stdout
     for l in f:
         if l == '\n':
             continue
         old_sha = l.rstrip('\n')
         for l in f:
             if l == '\n':
                 break
             _, path = l.rstrip('\n').split('\t', 1)
             # git-log without -z option quotes each pathname
             path = _unquote(path)
             while path not in change:
                 change[path] = old_sha
                 if next_path == [path]:
                     yield old_sha
                 try:
                     path, _ = path.rsplit('/', 1)
                 except ValueError:
                     break
     f.close()
     terminate(p[0])
     p[0].wait()
     p[:] = []
     while True:
         yield None
Ejemplo n.º 7
0
    def cat_file(self, kind, sha):
        with self.__cat_file_pipe_lock:
            if self.__cat_file_pipe is None:
                self.__cat_file_pipe = self.repo.cat_file_batch()

            try:
                self.__cat_file_pipe.stdin.write(sha + '\n')
                self.__cat_file_pipe.stdin.flush()

                split_stdout_line = self.__cat_file_pipe.stdout.readline() \
                                                               .split()
                if len(split_stdout_line) != 3:
                    raise GitError("internal error (could not split line "
                                   "'%s')" % (split_stdout_line,))

                _sha, _type, _size = split_stdout_line

                if _type != kind:
                    raise GitError("internal error (got unexpected object "
                                   "kind '%s', expected '%s')"
                                   % (_type, kind))

                size = int(_size)
                return self.__cat_file_pipe.stdout.read(size + 1)[:size]
            except:
                # There was an error, we should close the pipe to get to a
                # consistent state (Otherwise it happens that next time we
                # call cat_file we get payload from previous call)
                self.logger.debug("closing cat_file pipe")
                self.__cat_file_pipe.stdin.close()
                terminate(self.__cat_file_pipe)
                self.__cat_file_pipe.wait()
                self.__cat_file_pipe = None
Ejemplo n.º 8
0
    def get_historian(self, sha, base_path):
        p = []
        change = {}
        next_path = []
        base_path = self._fs_from_unicode(base_path)

        def name_status_gen():
            p[:] = [
                self.repo.log_pipe('--pretty=format:%n%H', '--name-status',
                                   sha, '--', base_path)
            ]
            f = p[0].stdout
            for l in f:
                if l == '\n':
                    continue
                old_sha = l.rstrip('\n')
                for l in f:
                    if l == '\n':
                        break
                    _, path = l.rstrip('\n').split('\t', 1)
                    # git-log without -z option quotes each pathname
                    path = _unquote(path)
                    while path not in change:
                        change[path] = old_sha
                        if next_path == [path]:
                            yield old_sha
                        try:
                            path, _ = path.rsplit('/', 1)
                        except ValueError:
                            break
            f.close()
            terminate(p[0])
            p[0].wait()
            p[:] = []
            while True:
                yield None

        gen = name_status_gen()

        def historian(path):
            path = self._fs_from_unicode(path)
            try:
                return change[path]
            except KeyError:
                next_path[:] = [path]
                return gen.next()

        try:
            yield historian
        finally:
            if p:
                p[0].stdout.close()
                terminate(p[0])
                p[0].wait()
Ejemplo n.º 9
0
    def get_historian(self, sha, base_path):
        p = []
        change = {}
        next_path = []
        base_path = self._fs_from_unicode(base_path)

        def name_status_gen():
            p[:] = [self.repo.log_pipe('--pretty=format:%n%H',
                                       '--name-status', sha, '--', base_path)]
            f = p[0].stdout
            for l in f:
                if l == '\n':
                    continue
                old_sha = l.rstrip('\n')
                for l in f:
                    if l == '\n':
                        break
                    _, path = l.rstrip('\n').split('\t', 1)
                    # git-log without -z option quotes each pathname
                    path = _unquote(path)
                    while path not in change:
                        change[path] = old_sha
                        if next_path == [path]:
                            yield old_sha
                        try:
                            path, _ = path.rsplit('/', 1)
                        except ValueError:
                            break
            f.close()
            terminate(p[0])
            p[0].wait()
            p[:] = []
            while True:
                yield None
        gen = name_status_gen()

        def historian(path):
            path = self._fs_from_unicode(path)
            try:
                return change[path]
            except KeyError:
                next_path[:] = [path]
                return gen.next()

        try:
            yield historian
        finally:
            if p:
                p[0].stdout.close()
                terminate(p[0])
                p[0].wait()
Ejemplo n.º 10
0
 def __del__(self):
     with self.__cat_file_pipe_lock:
         if self.__cat_file_pipe is not None:
             self.__cat_file_pipe.stdin.close()
             terminate(self.__cat_file_pipe)
             self.__cat_file_pipe.wait()
Ejemplo n.º 11
0
 def _cleanup_proc(self, proc):
     if proc:
         _close_proc_pipes(proc)
         terminate(proc)
         proc.wait()
Ejemplo n.º 12
0
 def __del__(self):
     with self.__cat_file_pipe_lock:
         if self.__cat_file_pipe is not None:
             self.__cat_file_pipe.stdin.close()
             terminate(self.__cat_file_pipe)
             self.__cat_file_pipe.wait()