Beispiel #1
0
    def load(self):
        self.commits = []
        # git command produces output like
        #0992e5111fcac424e3b0e944a077716428ab4f84
        # Julien Nabet
        #  2012-04-30 19:50:19 +0200
        #  M       canvas/source/null/null_canvasfont.cxx
        #  M       canvas/source/null/null_canvasfont.hxx
        #  M       canvas/source/null/null_canvashelper.cxx
        #  M       canvas/source/null/null_canvashelper.hxx
        #  M       unusedcode.easy
        git_cmd = ('git log --name-status --pretty=format:"%H %n %cn %n %ci"' +
                ' --since {0} --before {1}').format(
            self.timeBegin.strftime("%Y-%m-%d"),
            self.timeEnd.strftime("%Y-%m-%d")
            )

        log_process = subprocess.Popen(
                git_cmd,
                shell=True,
                cwd=self.repoPath,
                stdout=subprocess.PIPE)

        line = 'dummy'
        files_seen = 0
        while line:
            c = Commit(self.proj, VcsTypes.Git)
            hash_line = log_process.stdout.readline()
            author_line = log_process.stdout.readline()
            date_line = log_process.stdout.readline()
            if not hash_line.strip():
                break

            if date_line.strip():
                last_date = datetime.strptime(
                        date_line.strip()[0: -6], "%Y-%m-%d %H:%M:%S" )
            c.id = hash_line.strip()
            c.author = author_line.strip()
            c.date = last_date
            line = log_process.stdout.readline()
            while line.strip():
                f = line.strip()[2:].strip()
                if self.langDecider.isCode(f):
                    lang = self.langDecider.getLang(f)
                    suff = self.langDecider.getSuffixFor(lang)
                    # why filtered? because we've already filtered these diffs implicitly
                    path = (self.pb.getFilterOutputPath(self.proj, lang) +
                            ("%09d" % files_seen) +
                            suff)
                    files_seen += 1
                    c.addFile(f, path)
                line = log_process.stdout.readline()

            if (len(c.files) > 0 and
                    c.date <= self.timeEnd and
                    c.date >= self.timeBegin):
                self.commits.append(c)
        log_process.kill()
Beispiel #2
0
    def load(self):
        self.commits = []
        date_range = '"{0} to {1}"'.format(
                self.timeBegin.strftime("%Y-%m-%d"),
                self.timeEnd.strftime("%Y-%m-%d")
                )
        hg_cmd = ('hg log --template=' +
                '"{author|user}\\n{date|isodate}\\n{node|short}\\n{files}\\n"' +
                ' --date ' + date_range)
        # grab the authors, dates, hashes, and files out of the log
        log_process = subprocess.Popen(
                hg_cmd,
                shell=True,
                cwd=self.repoPath,
                stdout=subprocess.PIPE)
        files_seen = 0
        line = log_process.stdout.readline()
        while line:
            c = Commit(self.proj, VcsTypes.Hg)
            author_line = line
            date_line = log_process.stdout.readline().strip()
            hash_line = log_process.stdout.readline().strip()
            date = datetime.strptime(date_line[0:len(date_line) - 6],
                    "%Y-%m-%d %H:%M" )
            c.id = hash_line.strip()
            c.author = author_line.strip()
            c.date = date
            files = log_process.stdout.readline().strip().split()
            line = log_process.stdout.readline()
            for f in files:
                if self.langDecider.isCode(f):
                    lang = self.langDecider.getLang(f)
                    suff = self.langDecider.getSuffixFor(lang)
                    # why filtered? because we've already filtered these diffs implicitly
                    path = (self.pb.getFilterOutputPath(self.proj, lang) +
                            ("%09d" % files_seen) +
                            suff)
                    files_seen += 1
                    c.addFile(f, path)

            if (len(c.files) > 0 and
                    c.date <= self.timeEnd and
                    c.date >= self.timeBegin):
                self.commits.append(c)
        log_process.kill()