def _changesetFromRevision(self, branch, revision_id): """ Generate changeset for the given Bzr revision """ from datetime import datetime 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.renamed: e = ChangesetEntry(delta[1]) e.action_kind = ChangesetEntry.RENAMED e.old_name = delta[0] e.is_directory = delta[3] == 'directory' entries.append(e) for delta in deltatree.added: e = ChangesetEntry(delta[0]) e.action_kind = ChangesetEntry.ADDED e.is_directory = delta[2] == 'directory' entries.append(e) for delta in deltatree.removed: e = ChangesetEntry(delta[0]) e.action_kind = ChangesetEntry.DELETED e.is_directory = delta[2] == 'directory' 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 timestamp = datetime.fromtimestamp(revision.timestamp, timezone) author = revision.get_apparent_authors()[0] return BzrChangeset(revision.revision_id, timestamp, author, revision.message, entries)
def _changesetFromRevision(self, branch, revision_id): """ Generate changeset for the given Bzr revision """ from datetime import datetime 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.renamed: e = ChangesetEntry(delta[1]) e.action_kind = ChangesetEntry.RENAMED e.old_name = delta[0] e.is_directory = delta[3] == 'directory' entries.append(e) for delta in deltatree.added: e = ChangesetEntry(delta[0]) e.action_kind = ChangesetEntry.ADDED e.is_directory = delta[2] == 'directory' entries.append(e) for delta in deltatree.removed: e = ChangesetEntry(delta[0]) e.action_kind = ChangesetEntry.DELETED e.is_directory = delta[2] == 'directory' 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 timestamp = datetime.fromtimestamp(revision.timestamp, timezone) author = revision.get_apparent_authors()[0] return BzrChangeset(revision.revision_id, timestamp, author, revision.message, entries)
def endElement(self, name): if name == 'patch': cset = DarcsChangeset(self.current['name'], self.current['date'], self.current['author'], self.current['comment'], self.current['entries'], tags=self.current.get('tags',[]), darcs_hash=self.current['hash']) if self.darcsdiff: cset.unidiff = self.darcsdiff.execute(TZ='UTC', stdout=PIPE, patchname=cset.revision)[0].read() self.changesets.append(cset) self.current = None elif name in ['name', 'comment']: val = ''.join(self.current_field) if val[:4] == 'TAG ': self.current.setdefault('tags',[]).append(val[4:]) self.current[name] = val elif name == 'move': entry = ChangesetEntry(self.new_name) entry.action_kind = entry.RENAMED entry.old_name = self.old_name self.current['entries'].append(entry) elif name in ['add_file', 'add_directory', 'modify_file', 'remove_file', 'remove_directory']: current_field = ''.join(self.current_field).strip() if self.inverted: # the filenames in file modifications are outdated # if there are renames for i in self.current['entries']: if i.action_kind == i.RENAMED and current_field.startswith(i.old_name): current_field = current_field.replace(i.old_name, i.name) entry = ChangesetEntry(current_field) entry.action_kind = { 'add_file': entry.ADDED, 'add_directory': entry.ADDED, 'modify_file': entry.UPDATED, 'remove_file': entry.DELETED, 'remove_directory': entry.DELETED }[name] entry.is_directory = name.endswith('directory') self.current['entries'].append(entry)
def endElement(self, name): if name == 'patch': cset = DarcsChangeset(self.current['name'], self.current['date'], self.current['author'], self.current['comment'], self.current['entries'], tags=self.current.get('tags',[]), darcs_hash=self.current['hash']) if self.darcsdiff: cset.unidiff = self.darcsdiff.execute(TZ='UTC', stdout=PIPE, patchname=cset.revision)[0].read() self.changesets.append(cset) self.current = None elif name in ['name', 'comment']: val = ''.join(self.current_field) if val[:4] == 'TAG ': self.current.setdefault('tags',[]).append(val[4:]) self.current[name] = val elif name == 'move': entry = ChangesetEntry(self.new_name) entry.action_kind = entry.RENAMED entry.old_name = self.old_name self.current['entries'].append(entry) elif name in ['add_file', 'add_directory', 'modify_file', 'remove_file', 'remove_directory']: current_field = ''.join(self.current_field).strip() if self.inverted: # the filenames in file modifications are outdated # if there are renames for i in self.current['entries']: if i.action_kind == i.RENAMED and current_field.startswith(i.old_name): current_field = current_field.replace(i.old_name, i.name) entry = ChangesetEntry(current_field) entry.action_kind = { 'add_file': entry.ADDED, 'add_directory': entry.ADDED, 'modify_file': entry.UPDATED, 'remove_file': entry.DELETED, 'remove_directory': entry.DELETED }[name] entry.is_directory = name.endswith('directory') self.current['entries'].append(entry)
def _applyChangeset(self, changeset): from os import walk from os.path import join, isdir from time import sleep # Complete changeset information, determining the is_directory # flag of the removed entries, before updating to the given revision for entry in changeset.entries: if entry.action_kind == entry.DELETED: entry.is_directory = isdir( join(self.repository.basedir, entry.name)) cmd = self.repository.command("update") if self.repository.ignore_externals: cmd.append("--ignore-externals") cmd.extend(["--revision", changeset.revision]) svnup = ExternalCommand(cwd=self.repository.basedir, command=cmd) retry = 0 while True: out, err = svnup.execute(".", stdout=PIPE, stderr=PIPE) if svnup.exit_status == 1: retry += 1 if retry > 3: break delay = 2**retry self.log.error("%s returned status %s saying\n%s", str(svnup), svnup.exit_status, err.read()) self.log.warning("Retrying in %d seconds...", delay) sleep(delay) else: break if svnup.exit_status: raise ChangesetApplicationFailure( "%s returned status %s saying\n%s" % (str(svnup), svnup.exit_status, err.read())) self.log.debug("%s updated to %s", ','.join([e.name for e in changeset.entries]), changeset.revision) # Complete changeset information, determining the is_directory # flag of the added entries implicitly_added_entries = [] known_added_entries = set() for entry in changeset.entries: if entry.action_kind == entry.ADDED: known_added_entries.add(entry.name) fullname = join(self.repository.basedir, entry.name) entry.is_directory = isdir(fullname) # If it is a directory, extend the entries of the # changeset with all its contents, if not already there. if entry.is_directory: for root, subdirs, files in walk(fullname): if '.svn' in subdirs: subdirs.remove('.svn') for f in files: name = join(root, f)[len(self.repository.basedir) + 1:] newe = ChangesetEntry(name) newe.action_kind = newe.ADDED implicitly_added_entries.append(newe) for d in subdirs: name = join(root, d)[len(self.repository.basedir) + 1:] newe = ChangesetEntry(name) newe.action_kind = newe.ADDED newe.is_directory = True implicitly_added_entries.append(newe) for e in implicitly_added_entries: if not e.name in known_added_entries: changeset.entries.append(e) result = [] for line in out: if len(line) > 2 and line[0] == 'C' and line[1] == ' ': self.log.warning("Conflict after svn update: %r", line) result.append(line[2:-1]) return result
def _applyChangeset(self, changeset): from os import walk from os.path import join, isdir from time import sleep # Complete changeset information, determining the is_directory # flag of the removed entries, before updating to the given revision for entry in changeset.entries: if entry.action_kind == entry.DELETED: entry.is_directory = isdir(join(self.repository.basedir, entry.name)) cmd = self.repository.command("update") if self.repository.ignore_externals: cmd.append("--ignore-externals") cmd.extend(["--revision", changeset.revision]) svnup = ExternalCommand(cwd=self.repository.basedir, command=cmd) retry = 0 while True: out, err = svnup.execute(".", stdout=PIPE, stderr=PIPE) if svnup.exit_status == 1: retry += 1 if retry>3: break delay = 2**retry self.log.error("%s returned status %s saying\n%s", str(svnup), svnup.exit_status, err.read()) self.log.warning("Retrying in %d seconds...", delay) sleep(delay) else: break if svnup.exit_status: raise ChangesetApplicationFailure( "%s returned status %s saying\n%s" % (str(svnup), svnup.exit_status, err.read())) self.log.debug("%s updated to %s", ','.join([e.name for e in changeset.entries]), changeset.revision) # Complete changeset information, determining the is_directory # flag of the added entries implicitly_added_entries = [] known_added_entries = set() for entry in changeset.entries: if entry.action_kind == entry.ADDED: known_added_entries.add(entry.name) fullname = join(self.repository.basedir, entry.name) entry.is_directory = isdir(fullname) # If it is a directory, extend the entries of the # changeset with all its contents, if not already there. if entry.is_directory: for root, subdirs, files in walk(fullname): if '.svn' in subdirs: subdirs.remove('.svn') for f in files: name = join(root, f)[len(self.repository.basedir)+1:] newe = ChangesetEntry(name) newe.action_kind = newe.ADDED implicitly_added_entries.append(newe) for d in subdirs: name = join(root, d)[len(self.repository.basedir)+1:] newe = ChangesetEntry(name) newe.action_kind = newe.ADDED newe.is_directory = True implicitly_added_entries.append(newe) for e in implicitly_added_entries: if not e.name in known_added_entries: changeset.entries.append(e) result = [] for line in out: if len(line)>2 and line[0] == 'C' and line[1] == ' ': self.log.warning("Conflict after svn update: %r", line) result.append(line[2:-1]) return result