def __init__(self, linearized_ancestor, revision): """ Initializes a new MonotoneChangeset. The linearized_ancestor parameters is the fake ancestor used for linearization. The very first revision tailorized has lin_ancestor==None """ Changeset.__init__(self, revision=revision, date=None, author=None, log="") self.lin_ancestor = linearized_ancestor self.real_ancestors = None
def __str__(self): s = [Changeset.__str__(self)] s.append('linearized ancestor: %s' % self.lin_ancestor) s.append('real ancestor(s): %s' % (self.real_ancestors and ','.join(self.real_ancestors) or 'None')) return '\n'.join(s)
def __collect(self, timestamp, author, changelog, entry, revision): """Register a change set about an entry.""" from vcpx.changes import Changeset key = (timestamp, author, changelog) if self.changesets.has_key(key): cs = self.changesets[key] for e in cs.entries: if e.name == entry: return e return cs.addEntry(entry, revision) else: cs = Changeset(_getGlobalCVSRevision(timestamp, author), timestamp, author, changelog) self.changesets[key] = cs return cs.addEntry(entry, revision)
def _changesetFromRevision(self, branch, revision_id): """ Generate changeset for the given Bzr revision """ from datetime import datetime from vcpx.changes import ChangesetEntry, Changeset from vcpx.tzinfo import FixedOffset, UTC revision = branch.repository.get_revision(revision_id) deltatree = branch.get_revision_delta(branch.revision_id_to_revno(revision_id)) entries = [] for delta in deltatree.added: e = ChangesetEntry(delta[0]) e.action_kind = ChangesetEntry.ADDED entries.append(e) for delta in deltatree.removed: e = ChangesetEntry(delta[0]) e.action_kind = ChangesetEntry.DELETED entries.append(e) for delta in deltatree.renamed: e = ChangesetEntry(delta[1]) e.action_kind = ChangesetEntry.RENAMED e.old_name = delta[0] entries.append(e) for delta in deltatree.modified: e = ChangesetEntry(delta[0]) e.action_kind = ChangesetEntry.UPDATED entries.append(e) if revision.timezone is not None: timezone = FixedOffset(revision.timezone / 60) else: timezone = UTC return Changeset(revision.revision_id, datetime.fromtimestamp(revision.timestamp, timezone), revision.committer, revision.message, entries)
def _parseDarcsPull(self, output): """Process 'darcs pull' output to Changesets. """ from datetime import datetime from time import strptime from sha import new from vcpx.changes import Changeset l = output.readline() while l and not (l.startswith('Would pull the following changes:') or l == 'No remote changes to pull in!\n'): l = output.readline() if l <> 'No remote changes to pull in!\n': ## Sat Jul 17 01:22:08 CEST 2004 lele@nautilus ## * Refix _getUpstreamChangesets for darcs fsep = re.compile('[ :]+') l = output.readline() while not l.startswith('Making no changes: this is a dry run.'): # Assume it's a line like # Sun Jan 2 00:24:04 UTC 2005 [email protected] # Use a regular expression matching multiple spaces or colons # to split it, and use the first 7 fields to build up a datetime. pieces = fsep.split(l.rstrip(), 8) assert len(pieces)>=7, "Cannot parse %r as a patch timestamp" % l date = ' '.join(pieces[:8]) author = pieces[8] y,m,d,hh,mm,ss,d1,d2,d3 = strptime(date, "%a %b %d %H %M %S %Z %Y") date = datetime(y,m,d,hh,mm,ss,0,UTC) l = output.readline().rstrip() assert (l.startswith(' *') or l.startswith(' UNDO:') or l.startswith(' tagged')), \ "Got %r but expected the start of the log" % l if l.startswith(' *'): name = l[4:] else: name = l[2:] changelog = [] l = output.readline() while l.startswith(' '): changelog.append(l[2:-1]) l = output.readline() cset = Changeset(name, date, author, '\n'.join(changelog)) compactdate = date.strftime("%Y%m%d%H%M%S") if name.startswith('UNDO: '): name = name[6:] inverted = 't' else: inverted = 'f' if name.startswith('tagged '): name = name[7:] if cset.tags is None: cset.tags = [name] else: cset.tags.append(name) name = "TAG " + name phash = new() phash.update(name) phash.update(author) phash.update(compactdate) phash.update(''.join(changelog)) phash.update(inverted) cset.darcs_hash = '%s-%s-%s.gz' % (compactdate, new(author).hexdigest()[:5], phash.hexdigest()) yield cset while not l.strip(): l = output.readline()
def _parseDarcsPull(self, output): """Process 'darcs pull' output to Changesets. """ from datetime import datetime from time import strptime from sha import new from vcpx.changes import Changeset l = output.readline() while l and not (l.startswith('Would pull the following changes:') or l == 'No remote changes to pull in!\n'): l = output.readline() if l <> 'No remote changes to pull in!\n': ## Sat Jul 17 01:22:08 CEST 2004 lele@nautilus ## * Refix _getUpstreamChangesets for darcs fsep = re.compile('[ :]+') l = output.readline() while not l.startswith('Making no changes: this is a dry run.'): # Assume it's a line like # Sun Jan 2 00:24:04 UTC 2005 [email protected] # Use a regular expression matching multiple spaces or colons # to split it, and use the first 7 fields to build up a datetime. pieces = fsep.split(l.rstrip(), 8) assert len( pieces) >= 7, "Cannot parse %r as a patch timestamp" % l date = ' '.join(pieces[:8]) author = pieces[8] y, m, d, hh, mm, ss, d1, d2, d3 = strptime( date, "%a %b %d %H %M %S %Z %Y") date = datetime(y, m, d, hh, mm, ss, 0, UTC) l = output.readline().rstrip() assert (l.startswith(' *') or l.startswith(' UNDO:') or l.startswith(' tagged')), \ "Got %r but expected the start of the log" % l if l.startswith(' *'): name = l[4:] else: name = l[2:] changelog = [] l = output.readline() while l.startswith(' '): changelog.append(l[2:-1]) l = output.readline() cset = Changeset(name, date, author, '\n'.join(changelog)) compactdate = date.strftime("%Y%m%d%H%M%S") if name.startswith('UNDO: '): name = name[6:] inverted = 't' else: inverted = 'f' if name.startswith('tagged '): name = name[7:] if cset.tags is None: cset.tags = [name] else: cset.tags.append(name) name = "TAG " + name phash = new() phash.update(name) phash.update(author) phash.update(compactdate) phash.update(''.join(changelog)) phash.update(inverted) cset.darcs_hash = '%s-%s-%s.gz' % (compactdate, new(author).hexdigest()[:5], phash.hexdigest()) yield cset while not l.strip(): l = output.readline()
def testParsePull(self): """Verify basic darcs pull parser behaviour""" from vcpx.changes import Changeset output = self.getDarcsOutput('darcs-pull_parser_test') hashes = self.getDarcsOutput('darcs-pull_parser_test', ext='.hashes') class FauxRepository(object): name = 'foo' dswd = DarcsSourceWorkingDir(FauxRepository()) results = list(dswd._parseDarcsPull(output)) expected_changesets = [ Changeset( 'Monotone add is no longer recursive by default ' '(as of 2006-11-02).', datetime(2006, 12, 12, 05, 30, 20, tzinfo=UTC), '*****@*****.**', 'Use add --recursive when adding subtrees.'), Changeset('Fix ticket #87', datetime(2006, 12, 14, 23, 45, 04, tzinfo=UTC), 'Edgar Alves <*****@*****.**>', ''), Changeset( "Don't assume the timestamp in darcs log is exactly " "28 chars long", datetime(2006, 11, 17, 20, 26, 28, tzinfo=UTC), '*****@*****.**', ''), Changeset('tagged Version 0.9.27', datetime(2006, 12, 11, 21, 07, 48, tzinfo=UTC), '*****@*****.**', ''), Changeset( 'darcs: factor parsing from process invocation in DarcsSourceWorkingDir._getUpstreamChangesets', datetime(2007, 1, 6, 1, 52, 50, tzinfo=UTC), 'Kevin Turner <*****@*****.**>', ''), ] for changeset, expected_hash in zip(expected_changesets, hashes): changeset.darcs_hash = expected_hash.strip() self.failUnlessEqual(len(expected_changesets), len(results)) for expected, result in zip(expected_changesets, results): self.failUnlessEqual(expected, result, "%s != %s" % (expected, result)) self.failUnlessEqual( expected.darcs_hash, result.darcs_hash, 'hash failed for %s\n %s !=\n %s' % (result, expected.darcs_hash, result.darcs_hash)) output = self.getDarcsOutput('darcs-pull_parser_test2') results = list(dswd._parseDarcsPull(output)) first = results[0] self.failUnlessEqual(first.revision, 'Added some basic utility functions') self.failUnlessEqual(first.date, datetime(2003, 10, 10, 16, 23, 44, tzinfo=UTC)) self.failUnlessEqual(first.author, 'John Goerzen <*****@*****.**>') self.failUnlessEqual( first.log, '\n\n([email protected]/tla-buildpackage--head--1.0--patch-2)' ) last = results[-1] self.failUnlessEqual( last.log, 'Keywords:\n\nAdded some code in Python to get things going.\n')