Example #1
0
    def __init__(self, repos, sha):
        try:
            msg, props = repos.git.read_commit(sha)
        except PyGIT.GitErrorSha:
            raise NoSuchChangeset(sha)

        self.props = props

        assert 'children' not in props
        _children = list(repos.git.children(sha))
        if _children:
            props['children'] = _children

        # use 1st author/committer as changeset owner/timestamp
        if repos._use_committer_time:
            _, time_ = _parse_user_time(props['committer'][0])
        else:
            _, time_ = _parse_user_time(props['author'][0])

        if repos._use_committer_id:
            user_, _ = _parse_user_time(props['committer'][0])
        else:
            user_, _ = _parse_user_time(props['author'][0])

        # try to resolve email address to trac uid
        user_ = repos.rlookup_uid(user_) or user_

        Changeset.__init__(self, repos, rev=sha, message=msg, author=user_, date=time_)
Example #2
0
    def __init__(self, repos, sha):
        if sha is None:
            raise NoSuchChangeset(sha)
        
        try:
            msg, props = repos.git.read_commit(sha)
        except PyGIT.GitErrorSha:
            raise NoSuchChangeset(sha)

        self.props = props

        assert 'children' not in props
        _children = list(repos.git.children(sha))
        if _children:
            props['children'] = _children

        # use 1st author/committer as changeset owner/timestamp
        if repos._use_committer_time:
            _, time_ = _parse_user_time(props['committer'][0])
        else:
            _, time_ = _parse_user_time(props['author'][0])

        if repos._use_committer_id:
            user_, _ = _parse_user_time(props['committer'][0])
        else:
            user_, _ = _parse_user_time(props['author'][0])

        # try to resolve email address to trac uid
        user_ = repos.rlookup_uid(user_) or user_

        Changeset.__init__(self, repos, rev=sha, message=msg, author=user_, date=time_)
Example #3
0
    def __init__(self, repos, sha):
        self.repos = repos
        try:
            (msg, props) = repos.git.read_commit(sha)
        except PyGIT.GitErrorSha:
            raise NoSuchChangeset(sha)
        self.props = props

        assert "children" not in props
        _children = list(repos.git.children(sha))
        if _children:
            props["children"] = _children

        # use 1st committer as changeset owner/timestamp
        (user_, time_) = _parse_user_time(props["committer"][0])

        Changeset.__init__(self, repos, sha, msg, user_, time_)
Example #4
0
        def __init__(self, git, sha):
                self.git = git
                try:
                        (msg, props) = git.read_commit(sha)
                except PyGIT.GitErrorSha:
                        raise NoSuchChangeset(sha)
                self.props = props

                assert 'children' not in props
                _children = list(git.children(sha))
                if _children:
                        props['children'] = _children

                # use 1st committer as changeset owner/timestamp
                (user_, time_) = _parse_user_time(props['committer'][0])

                Changeset.__init__(self, sha, msg, user_, time_)
Example #5
0
    def __init__(self, repos, sha):
        if sha is None:
            raise NoSuchChangeset(sha)

        try:
            msg, props = repos.git.read_commit(sha)
        except PyGIT.GitErrorSha:
            raise NoSuchChangeset(sha)

        self.props = props

        assert 'children' not in props
        _children = list(repos.git.children(sha))
        if _children:
            props['children'] = _children

        committer, author = self._get_committer_and_author()
        # use 1st author/committer as changeset owner/timestamp
        c_user = a_user = c_time = a_time = None
        if committer:
            c_user, c_time = _parse_user_time(committer)
        if author:
            a_user, a_time = _parse_user_time(author)

        if repos.use_committer_time:
            time = c_time or a_time
        else:
            time = a_time or c_time

        if repos.use_committer_id:
            user = c_user or a_user
        else:
            user = a_user or c_user

        # try to resolve email address to trac uid
        user = repos.rlookup_uid(user) or user

        Changeset.__init__(self,
                           repos,
                           rev=sha,
                           message=msg,
                           author=user,
                           date=time)
Example #6
0
 def __init__(self, repos, n):
     log = repos.repo.changelog
     log_data = log.read(n)
     manifest, user, timeinfo, files, desc = log_data[:5]
     extra = {}
     if len(log_data) > 5: # extended changelog, since [hg 2f35961854fb]
         extra = log_data[5]
     time = repos.hg_time(timeinfo)
     Changeset.__init__(self, repos, repos.hg_display(n), to_unicode(desc),
                        to_unicode(user), time)
     self.repos = repos
     self.n = n
     self.manifest_n = manifest
     self.files = files
     self.parents = [repos.hg_display(p) for p in log.parents(n) \
                     if p != nullid]
     self.children = [repos.hg_display(c) for c in log.children(n)]
     self.tags = [t for t in repos.repo.nodetags(n)]
     self.branch = extra.pop("branch", None) 
     self.extra = extra
Example #7
0
    def test_custom_commands_refs(self):
        message = "And now something very similar wth refs. Lookit test:#39" + \
            "affects test2:#40 & #41"
        test_changeset12 = Changeset(None, 1245, message, "test_person",
                                     time.time())
        self.check_ticket_comment(test_changeset12)

        tickets = self.obj1._parse_message(message)
        self.assertEqual(tickets.keys(), [])

        tickets = self.obj2._parse_message(message)
        self.assertEqual(tickets.keys(), [])

        self.obj1.config.set("multicommitupdater", "commands.refs",
                             "relevant-to lookit affects related")
        self.obj2.config.set("multicommitupdater", "commands.refs",
                             "relevant-to lookit affects related")

        tickets = self.obj1._parse_message(message)
        self.assertEqual(tickets.keys(), [39])
        self.assertEqual(tickets.get(39), [self.obj1.cmd_refs])

        tickets = self.obj2._parse_message(message)
        sorted_keys = tickets.keys()
        sorted_keys.sort()
        self.assertEqual(sorted_keys, [40, 41])
        self.assertEqual(tickets.get(40), [self.obj2.cmd_refs])
        self.assertEqual(tickets.get(41), [self.obj2.cmd_refs])

        # :(
        message = "can we still ref tickets using one of the old " + \
            "commands? re test:#42, re test2:#43"
        test_changeset13 = Changeset(None, 1246, message, "test_person",
                                     time.time())
        self.check_ticket_comment(test_changeset13)

        tickets = self.obj1._parse_message(message)
        self.assertEqual(tickets.keys(), [])

        tickets = self.obj2._parse_message(message)
        self.assertEqual(tickets.keys(), [])
Example #8
0
    def __init__(self, repos, sha):
        if sha is None:
            raise NoSuchChangeset(sha)

        try:
            msg, props = repos.git.read_commit(sha)
        except PyGIT.GitErrorSha:
            raise NoSuchChangeset(sha)

        self.props = props

        assert 'children' not in props
        _children = list(repos.git.children(sha))
        if _children:
            props['children'] = _children

        committer, author = self._get_committer_and_author()
        # use 1st author/committer as changeset owner/timestamp
        c_user = a_user = c_time = a_time = None
        if committer:
            c_user, c_time = _parse_user_time(committer)
        if author:
            a_user, a_time = _parse_user_time(author)

        if repos.use_committer_time:
            time = c_time or a_time
        else:
            time = a_time or c_time

        if repos.use_committer_id:
            user = c_user or a_user
        else:
            user = a_user or c_user

        # try to resolve email address to trac uid
        user = repos.rlookup_uid(user) or user

        Changeset.__init__(self, repos, rev=sha, message=msg, author=user,
                           date=time)
Example #9
0
    def test_erroneous_capital_letters(self):
        message = "Did some more stuff. Fixes Test:#3, refs test2:#4"
        test_changeset2 = Changeset(None, 1235, message, "test_person",
                                    time.time())
        self.check_ticket_comment(test_changeset2)

        tickets = self.obj1._parse_message(message)
        self.assertEqual(tickets.keys(), [3])
        self.assertEqual(tickets.get(3), [self.obj1.cmd_close])

        tickets = self.obj2._parse_message(message)
        self.assertEqual(tickets.keys(), [4])
        self.assertEqual(tickets.get(4), [self.obj2.cmd_refs])
Example #10
0
File: util.py Project: ohanar/trac
def get_changes(repos, revs, log=None):
    changes = {}
    for rev in revs:
        if rev in changes:
            continue
        try:
            changeset = repos.get_changeset(rev)
        except NoSuchChangeset:
            changeset = Changeset(repos, rev, '', '',
                                  datetime(1970, 1, 1, tzinfo=utc))
            if log is not None:
                log.warning("Unable to get changeset [%s]", rev)
        changes[rev] = changeset
    return changes
Example #11
0
    def test_one_env(self):
        message = "These things are only applicable to test2. See test" + \
            "2:#27, closes test2:#28"
        test_changeset7 = Changeset(None, 1240, message, "test_person",
                                    time.time())
        self.check_ticket_comment(test_changeset7)

        tickets = self.obj1._parse_message(message)
        self.assertEqual(tickets, {})

        tickets = self.obj2._parse_message(message)
        sorted_keys = tickets.keys()
        sorted_keys.sort()
        self.assertEqual(sorted_keys, [27, 28])
        self.assertEqual(tickets.get(27), [self.obj2.cmd_refs])
        self.assertEqual(tickets.get(28), [self.obj2.cmd_close])
Example #12
0
 def test_simple_case(self):
     message = "Fixed some stuff. Re test:#1, closes test2:#2"
     test_changeset = Changeset(None, 1234, message, "test_person",
                                time.time())
     self.check_ticket_comment(test_changeset)
     # For each object in turn:
     # Get tickets and commands
     tickets = self.obj1._parse_message(message)
     # First, check we've got the tickets we were expecting
     self.assertEqual(tickets.keys(), [1])
     # Now check the actions are right
     self.assertEqual(tickets.get(1), [self.obj1.cmd_refs])
     # Same checks for obj2:
     tickets = self.obj2._parse_message(message)
     self.assertEqual(tickets.keys(), [2])
     self.assertEqual(tickets.get(2), [self.obj2.cmd_close])
Example #13
0
    def test_envelope(self):
        message = "Today, I shall be putting my messages in an envelope. " + \
            "[re test:#32], [re test2:#33]"
        test_changeset9 = Changeset(None, 1242, message, "test_person",
                                    time.time())
        self.check_ticket_comment(test_changeset9)

        # With no envelope set, this works as normal
        tickets = self.obj1._parse_message(message)
        self.assertEqual(tickets.keys(), [32])
        self.assertEqual(tickets.get(32), [self.obj1.cmd_refs])

        tickets = self.obj2._parse_message(message)
        self.assertEqual(tickets.keys(), [33])
        self.assertEqual(tickets.get(33), [self.obj2.cmd_refs])

        # With a different envelope set, the messages should be ignored
        self.obj1.config.set("multicommitupdater", "envelope", "{}")
        self.obj2.config.set("multicommitupdater", "envelope", "<>")

        tickets = self.obj1._parse_message(message)
        self.assertEqual(tickets.keys(), [])

        tickets = self.obj2._parse_message(message)
        self.assertEqual(tickets.keys(), [])

        # Changing one envelope to '[]' should mean only that environment
        # picks up the message
        self.obj1.config.set("multicommitupdater", "envelope", "[]")

        tickets = self.obj1._parse_message(message)
        self.assertEqual(tickets.keys(), [32])
        self.assertEqual(tickets.get(32), [self.obj1.cmd_refs])

        tickets = self.obj2._parse_message(message)
        self.assertEqual(tickets.keys(), [])

        # When both envelopes are '[]', both environments pick up the actions
        self.obj2.config.set("multicommitupdater", "envelope", "[]")
        tickets = self.obj1._parse_message(message)
        self.assertEqual(tickets.keys(), [32])
        self.assertEqual(tickets.get(32), [self.obj1.cmd_refs])

        tickets = self.obj2._parse_message(message)
        self.assertEqual(tickets.keys(), [33])
        self.assertEqual(tickets.get(33), [self.obj2.cmd_refs])
Example #14
0
    def test_spaces(self):
        message = "Today I am feeling spacey! Closes test:#29, #30. See " + \
            "test2:#31"
        test_changeset8 = Changeset(None, 1241, message, "test_person",
                                    time.time())
        self.check_ticket_comment(test_changeset8)

        tickets = self.obj1._parse_message(message)
        sorted_keys = tickets.keys()
        sorted_keys.sort()
        self.assertEqual(sorted_keys, [29, 30])
        self.assertEqual(tickets.get(29), [self.obj1.cmd_close])
        self.assertEqual(tickets.get(30), [self.obj1.cmd_close])

        tickets = self.obj2._parse_message(message)
        self.assertEqual(tickets.keys(), [31])
        self.assertEqual(tickets.get(31), [self.obj2.cmd_refs])
Example #15
0
    def test_all_documented_synonyms_ref(self):
        message = "Yet more things. references test:#11, refs test2:#12, " + \
            "addresses test:#13, re test2:#14, see test:#15"
        test_changeset4 = Changeset(None, 1237, message, "test_person",
                                    time.time())
        self.check_ticket_comment(test_changeset4)

        tickets = self.obj1._parse_message(message)
        sorted_keys = tickets.keys()
        sorted_keys.sort()
        self.assertEqual(sorted_keys, [11, 13, 15])
        self.assertEqual(tickets.get(11), [self.obj1.cmd_refs])
        self.assertEqual(tickets.get(13), [self.obj1.cmd_refs])
        self.assertEqual(tickets.get(15), [self.obj1.cmd_refs])

        tickets = self.obj2._parse_message(message)
        sorted_keys = tickets.keys()
        sorted_keys.sort()
        self.assertEqual(sorted_keys, [12, 14])
        self.assertEqual(tickets.get(12), [self.obj2.cmd_refs])
        self.assertEqual(tickets.get(14), [self.obj2.cmd_refs])
Example #16
0
    def test_multiple_tickets_one_command_simple(self):
        message = "And even more things. re test:#16,#17,#18. Closes " + \
            "test2:#19,#20"
        test_changeset5 = Changeset(None, 1238, message, "test_person",
                                    time.time())
        self.check_ticket_comment(test_changeset5)

        tickets = self.obj1._parse_message(message)
        sorted_keys = tickets.keys()
        sorted_keys.sort()
        self.assertEqual(sorted_keys, [16, 17, 18])
        self.assertEqual(tickets.get(16), [self.obj1.cmd_refs])
        self.assertEqual(tickets.get(17), [self.obj1.cmd_refs])
        self.assertEqual(tickets.get(18), [self.obj1.cmd_refs])

        tickets = self.obj2._parse_message(message)
        sorted_keys = tickets.keys()
        sorted_keys.sort()
        self.assertEqual(sorted_keys, [19, 20])
        self.assertEqual(tickets.get(19), [self.obj2.cmd_close])
        self.assertEqual(tickets.get(20), [self.obj2.cmd_close])
Example #17
0
    def test_all_documented_synonyms_close(self):
        message = "More things. close test:#5, closed test2:#6, closes " + \
            "test:#7, fix test2:#8, fixed test:#9, fixes test2:#10."
        test_changeset3 = Changeset(None, 1236, message, "test_person",
                                    time.time())
        self.check_ticket_comment(test_changeset3)

        tickets = self.obj1._parse_message(message)
        sorted_keys = tickets.keys()
        sorted_keys.sort()
        self.assertEqual(sorted_keys, [5, 7, 9])
        self.assertEqual(tickets.get(5), [self.obj1.cmd_close])
        self.assertEqual(tickets.get(7), [self.obj1.cmd_close])
        self.assertEqual(tickets.get(9), [self.obj1.cmd_close])

        tickets = self.obj2._parse_message(message)
        sorted_keys = tickets.keys()
        sorted_keys.sort()
        self.assertEqual(sorted_keys, [6, 8, 10])
        self.assertEqual(tickets.get(6), [self.obj2.cmd_close])
        self.assertEqual(tickets.get(8), [self.obj2.cmd_close])
        self.assertEqual(tickets.get(10), [self.obj2.cmd_close])
Example #18
0
    def test_multiple_tickets_one_command_complex(self):
        message = "Woo, even more things. Look at us go! Refs test:#21 & " + \
            "#22, closes test:#23. See test2:#24,#25 and #26."
        test_changeset6 = Changeset(None, 1239, message, "test_person",
                                    time.time())
        self.check_ticket_comment(test_changeset6)

        tickets = self.obj1._parse_message(message)
        sorted_keys = tickets.keys()
        sorted_keys.sort()
        self.assertEqual(sorted_keys, [21, 22, 23])
        self.assertEqual(tickets.get(21), [self.obj1.cmd_refs])
        self.assertEqual(tickets.get(22), [self.obj1.cmd_refs])
        self.assertEqual(tickets.get(23), [self.obj1.cmd_close])

        tickets = self.obj2._parse_message(message)
        sorted_keys = tickets.keys()
        sorted_keys.sort()
        self.assertEqual(sorted_keys, [24, 25, 26])
        self.assertEqual(tickets.get(24), [self.obj2.cmd_refs])
        self.assertEqual(tickets.get(25), [self.obj2.cmd_refs])
        self.assertEqual(tickets.get(26), [self.obj2.cmd_refs])
Example #19
0
 def __init__(self, repos, rev, desc, user, time, log):
     self.repos = repos
     self.rev = rev
     self.log = log
     Changeset.__init__(self, repos, rev, desc, user, datetime.datetime.fromtimestamp(time,utc))
Example #20
0
 def __init__(self, repos, rev, desc, user, time, log):
     self.repos = repos
     self.rev = rev
     self.log = log
     Changeset.__init__(self, repos, rev, desc, user,
                        datetime.datetime.fromtimestamp(time, utc))
Example #21
0
    def test_custom_commands_close(self):
        message = "this time, we're going to use some close commands that " + \
            "aren't on the default list. Nukes test:#34, #35 and " + \
            "obliterates test2:#36"
        test_changeset10 = Changeset(None, 1243, message, "test_person",
                                     time.time())
        self.check_ticket_comment(test_changeset10)

        # Nothing happens if we stick with the default commands
        tickets = self.obj1._parse_message(message)
        self.assertEqual(tickets.keys(), [])

        tickets = self.obj2._parse_message(message)
        self.assertEqual(tickets.keys(), [])

        # Adding 'nukes' to the list should make our first command work
        self.obj1.config.set("multicommitupdater", "commands.close",
                             "ends nukes completes")
        self.obj2.config.set("multicommitupdater", "commands.close",
                             "ends nukes completes")

        tickets = self.obj1._parse_message(message)
        sorted_keys = tickets.keys()
        sorted_keys.sort()
        self.assertEqual(sorted_keys, [34, 35])
        self.assertEqual(tickets.get(34), [self.obj1.cmd_close])
        self.assertEqual(tickets.get(35), [self.obj1.cmd_close])

        tickets = self.obj2._parse_message(message)
        self.assertEqual(tickets.keys(), [])

        # And adding 'obliterates' should take care of the second
        self.obj1.config.set("multicommitupdater", "commands.close",
                             "ends nukes obliterates completes")
        self.obj2.config.set("multicommitupdater", "commands.close",
                             "ends nukes obliterates completes")

        tickets = self.obj1._parse_message(message)
        sorted_keys = tickets.keys()
        sorted_keys.sort()
        self.assertEqual(sorted_keys, [34, 35])
        self.assertEqual(tickets.get(34), [self.obj1.cmd_close])
        self.assertEqual(tickets.get(35), [self.obj1.cmd_close])

        tickets = self.obj2._parse_message(message)
        self.assertEqual(tickets.keys(), [36])
        self.assertEqual(tickets.get(36), [self.obj2.cmd_close])

        # Sad path test
        message = "now we're checking that tickets aren't closed by " + \
            "default commands when the list has been overwritten. " + \
            "closes test:#37, fixes test2:#38"
        test_changeset11 = Changeset(None, 1244, message, "test_person",
                                     time.time())
        self.check_ticket_comment(test_changeset11)

        tickets = self.obj1._parse_message(message)
        self.assertEqual(tickets.keys(), [])

        tickets = self.obj2._parse_message(message)
        self.assertEqual(tickets.keys(), [])
Example #22
0
 def get_changeset(self, rev):
     assert rev % 3 == 1  # allow only 3n + 1
     return Changeset(
         self, rev, 'message-%d' % rev, 'author-%d' % rev,
         datetime(2001, 1, 1, tzinfo=utc) + timedelta(seconds=rev))