Esempio n. 1
0
    def _branch_updates(self, oldrev, newrev, refname, branch):
        """
        Handle branch updates
        """
        branch = self._u(branch)
        baserev = run_command("git merge-base %s %s" % (oldrev, newrev),
                              cwd=self.cwd)

        if baserev != oldrev:
            # This appears to be a forced updated.
            # We generate a dummy change event which rewinds the branch to the
            # common ancester of oldrev and newrev. The step will then be
            # based on changes between the common ancestor and newrev
            diff = run_command("git diff --raw %s..%s" % (oldrev, baserev),
                                cwd=self.cwd)
            files = [x.split(None, 5)[-1] for x in diff.split('\n')]
            dummy_c = dict(revision=baserev,
                           comments="(rewind branch)",
                           branch=branch,
                           change_ts=None,
                           files=files,
                           author="(automated)")
            self.changes.append(dummy_c)

        if baserev != newrev:
            out = run_command("git rev-list --reverse --pretty=oneline %s..%s"
                               % (baserev, newrev), cwd=self.cwd)
            self._build_changes(out.split("\n"), branch)
Esempio n. 2
0
    def setUp(self):
        # create temp dir
        self.tmpdir = mkdtemp(prefix='goanna_test_')

        # add guard file which we check for before we do an rmtree in tearDown
        self.guard_file = ".no_rmtree_if_this_file_does_not_exist"  # paranoia
        open(os.path.join(self.tmpdir, self.guard_file), 'w').close()

        # extract git repo
        script_dir = os.path.dirname(os.path.realpath(__file__))
        tar_file = os.path.join(script_dir, "data", "svn_repo.tar.gz")
        run_command("tar zxf %s -C %s" % (tar_file, self.tmpdir))

        # path to extracted repo
        self.repodir = os.path.join(self.tmpdir, "repo")
Esempio n. 3
0
 def _branch_creation(self, newrev, refname, branch):
     """
     Handle branch creation
     """
     # A new branch has been created. Generate changes for everything
     # up to `newrev' which does not exist in any branch but `refname'.
     #
     # Note that this may be inaccurate if two new branches are created
     # at the same time, pointing to the same commit, or if there are
     # commits that only exists in a common subset of the new branches.
     ref = run_command("git rev-parse %s" % refname, cwd=self.cwd)
     br = run_command("git rev-parse --not --branches",
                      cwd=self.cwd).split("\n")
     commits = [c for c in br if ref not in c]
     revs = run_command("git rev-list --reverse --pretty=oneline %s %s" %
                         (" ".join(commits), newrev), cwd=self.cwd)
     self._build_changes(revs.split("\n"), self._u(branch))
Esempio n. 4
0
    def _build_changes(self, lines, branch):
        """
        Retrive and store changes given a list of revisions
        """

        def query_git_log(fmt, rev):
            return run_command("git log --no-walk --format='%s' %s --"
                                % (fmt, rev), cwd=self.cwd)

        for line in lines:
            m = re.match(r"^([0-9a-f]+) (.*)$", line.strip())
            assert m
            r = m.group(1)
            files = run_command('git log --name-only --no-walk --format="%n"' +
                                ' %s --' % r, cwd=self.cwd).split()
            c = dict(revision=r,
                     branch=branch,
                     files=files,
                     comments=self._u(query_git_log("%s%n%b", r).strip()),
                     author=self._u(query_git_log("%aN <%aE>", r).strip()),
                     change_ts=query_git_log("%ct", r))
            self.changes.append(c)
Esempio n. 5
0
 def query_git_log(fmt, rev):
     return run_command("git log --no-walk --format='%s' %s --"
                         % (fmt, rev), cwd=self.cwd)
Esempio n. 6
0
 def _svnlook(self, subcommand, exit_on_error=True):
     cmd = "%s %s %s --revision %s" % (self.svnlook_cmd, subcommand,
                                       self.repos_path, self.revision)
     return run_command(cmd, exit_on_error)