Back to index

plone3  3.1.7
Public Member Functions | Public Attributes | Static Public Attributes | Private Attributes
ZopeVersionControl.VersionHistory.VersionHistory Class Reference
Inheritance diagram for ZopeVersionControl.VersionHistory.VersionHistory:
Inheritance graph
[legend]
Collaboration diagram for ZopeVersionControl.VersionHistory.VersionHistory:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def getId
def addLogEntry
def getLogEntries
def getLabels
def labelVersion
def createBranch
def createVersion
def hasVersionId
def isLatestVersion
def getLatestVersion
def findBranchId
def getVersionById
def getVersionByLabel
def getVersionByDate
def getVersionIds

Public Attributes

 id

Static Public Attributes

tuple security = ClassSecurityInfo()

Private Attributes

 _eventLog
 _versions
 _branches
 _labels

Detailed Description

A version history maintains the information about the changes
   to a particular version-controlled resource over time.

Definition at line 28 of file VersionHistory.py.


Constructor & Destructor Documentation

def ZopeVersionControl.VersionHistory.VersionHistory.__init__ (   self,
  history_id,
  object 
)

Definition at line 32 of file VersionHistory.py.

00032 
00033     def __init__(self, history_id, object):
00034         # The _versions mapping maps version ids to version objects. All
00035         # of the actual version data is looked up there. The _labels
00036         # mapping maps labels to specific version ids. The _branches map
00037         # manages BranchInfo objects that maintain branch information.
00038         self._eventLog = EventLog()
00039         self._versions = OOBTree()
00040         self._branches = OOBTree()
00041         self._labels = OOBTree()
00042         mainline = self.createBranch('mainline', None)
00043         self.id = history_id


Member Function Documentation

def ZopeVersionControl.VersionHistory.VersionHistory.addLogEntry (   self,
  version_id,
  action,
  path = None,
  message = '' 
)
Add a new log entry associated with this version history.

Definition at line 51 of file VersionHistory.py.

00051 
00052     def addLogEntry(self, version_id, action, path=None, message=''):
00053         """Add a new log entry associated with this version history."""
00054         entry = LogEntry(version_id, action, path, message)
00055         self._eventLog.addEntry(entry)

def ZopeVersionControl.VersionHistory.VersionHistory.createBranch (   self,
  branch_id,
  version_id 
)
Create a new branch associated with the given branch_id. The
   new branch is rooted at the version named by version_id.

Definition at line 84 of file VersionHistory.py.

00084 
00085     def createBranch(self, branch_id, version_id):
00086         """Create a new branch associated with the given branch_id. The
00087            new branch is rooted at the version named by version_id."""
00088         if self._branches.has_key(branch_id):
00089             raise VersionControlError(
00090                 'Activity already exists: %s' % branch_id
00091                 )
00092         branch = BranchInfo(branch_id, version_id)
00093         self._branches[branch_id] = branch
00094         return branch

Here is the caller graph for this function:

def ZopeVersionControl.VersionHistory.VersionHistory.createVersion (   self,
  object,
  branch_id 
)
Create a new version in the line of descent named by the given
   branch_id, returning the newly created version object.

Definition at line 96 of file VersionHistory.py.

00096 
00097     def createVersion(self, object, branch_id):
00098         """Create a new version in the line of descent named by the given
00099            branch_id, returning the newly created version object."""
00100         branch = self._branches.get(branch_id)
00101         if branch is None:
00102             branch = self.createBranch(branch_id, None)
00103         if branch.name != 'mainline':
00104             version_id = '%s.%d' % (branch.name, len(branch) + 1)
00105         else:
00106             version_id = '%d' % (len(branch) + 1)
00107         version = ZopeVersion(version_id, object)
00108 
00109         # Update the  predecessor, successor and branch relationships.
00110         # This is something of a hedge against the future. Versions will
00111         # always know enough to reconstruct their lineage without the help
00112         # of optimized data structures, which will make it easier to change
00113         # internals in the future if we need to.
00114         latest = branch.latest()
00115         if latest is not None:
00116             last = self._versions[latest]
00117             last.next = last.next + (version_id,)
00118             version.prev = latest
00119 
00120         # If the branch is not the mainline, store the branch name in the
00121         # version. Versions have 'mainline' as the default class attribute
00122         # which is the common case and saves a minor bit of storage space.
00123         if branch.name != 'mainline':
00124             version.branch = branch.name
00125 
00126         branch.append(version)
00127         self._versions[version_id] = version
00128         # Call saveState() only after version has been linked into the
00129         # database, ensuring it goes into the correct database.
00130         version.saveState(object)
00131         return version.__of__(self)

Here is the call graph for this function:

Given a version id, return the id of the branch of the version.
   Note that we cheat, since we can find this out from the id.

Definition at line 152 of file VersionHistory.py.

00152 
00153     def findBranchId(self, version_id):
00154         """Given a version id, return the id of the branch of the version.
00155            Note that we cheat, since we can find this out from the id."""
00156         parts = version_id.split('.')
00157         if len(parts) > 1:
00158             return parts[-2]
00159         return 'mainline'

Definition at line 47 of file VersionHistory.py.

00047 
00048     def getId(self):
00049         return self.id

Definition at line 62 of file VersionHistory.py.

00062 
00063     def getLabels(self):
00064         return self._labels.keys()

Return the latest version object within the given branch, or
   None if the branch contains no versions.

Definition at line 144 of file VersionHistory.py.

00144 
00145     def getLatestVersion(self, branch_id):
00146         """Return the latest version object within the given branch, or
00147            None if the branch contains no versions."""
00148         branch = self._branches[branch_id]
00149         version = self._versions[branch.latest()]
00150         return version.__of__(self)

Return a sequence of the log entries for this version history.

Definition at line 57 of file VersionHistory.py.

00057 
00058     def getLogEntries(self):
00059         """Return a sequence of the log entries for this version history."""
00060         return self._eventLog.getEntries()

def ZopeVersionControl.VersionHistory.VersionHistory.getVersionByDate (   self,
  branch_id,
  timestamp 
)
Return the last version committed in the given branch on or
   before the given time value. The timestamp should be a float
   (time.time format) value in UTC.

Definition at line 182 of file VersionHistory.py.

00182 
00183     def getVersionByDate(self, branch_id, timestamp):
00184         """Return the last version committed in the given branch on or
00185            before the given time value. The timestamp should be a float
00186            (time.time format) value in UTC."""
00187         branch = self._branches[branch_id]
00188         tvalue = int(timestamp / 60.0)
00189         while 1:
00190             # Try to find a version with a commit date <= the given time
00191             # using the timestamp index in the branch information.
00192             if branch.m_order:
00193                 try:
00194                     match = branch.m_date.maxKey(tvalue)
00195                     match = branch.m_order[branch.m_date[match]]
00196                     return self._versions[match].__of__(self)
00197                 except ValueError:
00198                     pass
00199 
00200             # If we've run out of lineage without finding a version with
00201             # a commit date <= the given timestamp, we return None. It is
00202             # up to the caller to decide what to do in this situation.
00203             if branch.root is None:
00204                 return None
00205             
00206             # If the branch has a root (a version in another branch), then
00207             # we check the root and do it again with the ancestor branch.
00208             rootver = self._versions[branch.root]
00209             if int(rootver.date_created / 60.0) < tvalue:
00210                 return rootver.__of__(self)
00211             branch = self._branches[rootver.branch]

Return the version object named by the given version id, or
   raise a VersionControlError if the version is not found.

Definition at line 161 of file VersionHistory.py.

00161 
00162     def getVersionById(self, version_id):
00163         """Return the version object named by the given version id, or
00164            raise a VersionControlError if the version is not found."""
00165         version = self._versions.get(version_id)
00166         if version is None:
00167             raise VersionControlError(
00168                 'Unknown version id: %s' % version_id
00169                 )
00170         return version.__of__(self)

Return the version associated with the given label, or None
   if no version matches the given label.

Definition at line 172 of file VersionHistory.py.

00172 
00173     def getVersionByLabel(self, label):
00174         """Return the version associated with the given label, or None
00175            if no version matches the given label."""
00176         version_id = self._labels.get(label)
00177         version = self._versions.get(version_id)
00178         if version is None:
00179             return None
00180         return version.__of__(self)

Return a sequence of version ids for the versions in this
   version history. If a branch_id is given, only version ids
   from that branch will be returned. Note that the sequence
   of ids returned does not include the id of the branch root.

Definition at line 213 of file VersionHistory.py.

00213 
00214     def getVersionIds(self, branch_id=None):
00215         """Return a sequence of version ids for the versions in this
00216            version history. If a branch_id is given, only version ids
00217            from that branch will be returned. Note that the sequence
00218            of ids returned does not include the id of the branch root."""
00219         if branch_id is not None:
00220             return self._branches[branch_id].versionIds()
00221         return self._versions.keys()
00222 
00223 InitializeClass(VersionHistory)
00224 

Return true if history contains a version with the given id.

Definition at line 133 of file VersionHistory.py.

00133 
00134     def hasVersionId(self, version_id):
00135         """Return true if history contains a version with the given id."""
00136         return self._versions.has_key(version_id)

def ZopeVersionControl.VersionHistory.VersionHistory.isLatestVersion (   self,
  version_id,
  branch_id 
)
Return true if version id is the latest in its branch.

Definition at line 138 of file VersionHistory.py.

00138 
00139     def isLatestVersion(self, version_id, branch_id):
00140         """Return true if version id is the latest in its branch."""
00141         branch = self._branches[branch_id]
00142         return version_id == branch.latest()

def ZopeVersionControl.VersionHistory.VersionHistory.labelVersion (   self,
  version_id,
  label,
  force = 0 
)
Associate a particular version in a version history with the
   given label, removing any existing association with that label
   if force is true, or raising an error if force is false and
   an association with the given label already exists.

Definition at line 66 of file VersionHistory.py.

00066 
00067     def labelVersion(self, version_id, label, force=0):
00068         """Associate a particular version in a version history with the
00069            given label, removing any existing association with that label
00070            if force is true, or raising an error if force is false and
00071            an association with the given label already exists."""
00072         current = self._labels.get(label)
00073         if current is not None:
00074             if current == version_id:
00075                 return
00076             if not force:
00077                 raise VersionControlError(
00078                     'The label %s is already associated with a version.' % (
00079                      label
00080                     ))
00081             del self._labels[label]
00082         self._labels[label] = version_id


Member Data Documentation

Definition at line 39 of file VersionHistory.py.

Definition at line 37 of file VersionHistory.py.

Definition at line 40 of file VersionHistory.py.

Definition at line 38 of file VersionHistory.py.

Definition at line 42 of file VersionHistory.py.

tuple ZopeVersionControl.VersionHistory.VersionHistory.security = ClassSecurityInfo() [static]

Reimplemented in ZopeVersionControl.ZopeVersionHistory.ZopeVersionHistory.

Definition at line 44 of file VersionHistory.py.


The documentation for this class was generated from the following file: