source: tailor/vcpx/changes.py @ 11

Revision 11, 2.8 KB checked in by lele@…, 9 years ago (diff)

First cut at Version Control Patch eXchanger

Line 
1#! /usr/bin/python
2# -*- mode: python; coding: utf-8 -*-
3# :Progetto: vcpx -- Changesets
4# :Creato:   ven 11 giu 2004 15:31:18 CEST
5# :Autore:   Lele Gaifax <lele@nautilus.homeip.net>
6#
7
8"""
9Changesets are an object representation of a set of changes to some files.
10"""
11
12__docformat__ = 'reStructuredText'
13
14class ChangesetEntry(object):
15    """
16    Represent a changed entry in a Changeset.
17
18    For our scope, this simply means an entry `name`, the original
19    `old_revision`, the `new_revision` after this change, an
20    `action_kind` to denote the kind of change, and finally a `status`
21    to indicate possible conflicts.
22    """
23   
24    ADDED = 'A'
25    DELETED = 'D'
26    UPDATED = 'U'
27    RENAMED = 'R'
28
29    APPLIED = 'A'
30    CONFLICT = 'C'
31   
32    __slots__ = ('name', 'old_name',
33                 'old_revision', 'new_revision',
34                 'action_kind', 'status')
35
36    def __init__(self, name):
37        self.name = name
38        self.old_name = None
39        self.old_revision = None
40        self.new_revision = None
41        self.action_kind = None
42        self.status = None
43
44    def __str__(self):
45        return "%s %s->%s" % (self.name, self.old_revision, self.new_revision)
46
47
48class Changeset(object):
49    """
50    Represent a single upstream Changeset.
51
52    This is a container of each file affected by this revision of the tree.
53    """
54
55    def __init__(self, revision, date, author, log, entries, **other):
56        """
57        Initialize a new ChangeSet.
58        """
59       
60        self.revision = revision
61        self.date = date
62        self.author = author
63        self.log = log
64        self.entries = entries
65
66    def __str__(self):
67        s = []
68        s.append('Revision: %s' % self.revision)
69        s.append('Date: %s' % self.date)
70        s.append('Author: %s' % self.author)
71        for ak in ['Added', 'Modified', 'Removed', 'Renamed']:
72            entries = getattr(self, ak.lower()+'Entries')()
73            if entries:
74                s.append('%s: %s' % (ak, ','.join([e.name
75                                                   for e in self.entries])))
76        s.append('Log: %s' % self.log)
77
78    def addedEntries(self):
79        """
80        Filter the changesets and extract the added entries.
81        """
82       
83        return [e for e in self.entries if e.action_kind == e.ADDED]
84
85    def modifiedEntries(self):
86        """
87        Filter the changesets and extract the modified entries.
88        """
89
90        return [e for e in self.entries if e.action_kind == e.UPDATE]
91
92    def removedEntries(self):
93        """
94        Filter the changesets and extract the deleted entries.
95        """
96
97        return [e for e in self.entries if e.action_kind == e.DELETED]
98
99    def renamedEntries(self):
100        """
101        Filter the changesets and extract the renamed entries.
102        """
103
104        return [e for e in self.entries if e.action_kind == e.RENAMED]
Note: See TracBrowser for help on using the repository browser.