Example #1
0
def get_tag_set(path):
    class TagCollector(cvs2svn_rcsparse.Sink):
        def __init__(self):
            self.tags = set()

            # A map { branch_tuple : name } for branches on which no
            # revisions have yet been seen:
            self.branches = {}

        def define_tag(self, name, revision):
            revtuple = rev_tuple(revision)
            if len(revtuple) % 2 == 0:
                # This is a tag (as opposed to branch)
                self.tags.add(name)
            else:
                self.branches[revtuple] = name

        def define_revision(
            self, revision, timestamp, author, state, branches, next
            ):
            branch = rev_tuple(revision)[:-1]
            try:
                del self.branches[branch]
            except KeyError:
                pass

        def get_tags(self):
            tags = self.tags
            for branch in self.branches.values():
                tags.add(branch)
            return tags

    tag_collector = TagCollector()
    cvs2svn_rcsparse.parse(open(path, 'rb'), tag_collector)
    return tag_collector.get_tags()
Example #2
0
def main(args):
  [blobfilename] = args
  blobfile = open(blobfilename, 'w+b')
  while True:
    try:
      (rcsfile, marks) = pickle.load(sys.stdin)
    except EOFError:
      break
    parse(open(rcsfile, 'rb'), WriteBlobSink(blobfile, marks))

  blobfile.close()
Example #3
0
def process_file(filename, rev_from, rev_to, force):
    func = get_transform_func(rev_from, rev_to, force)
    tmp_filename = filename + '.tmp'
    infp = open(filename, 'rb')
    outfp = open(tmp_filename, 'wb')
    try:
        writer = WriteRCSFileSink(outfp)
        revfilter = RenumberingFilter(writer, func)
        cvs2svn_rcsparse.parse(infp, revfilter)
    finally:
        outfp.close()
        infp.close()
    os.rename(tmp_filename, filename)
Example #4
0
def process_file(filename, rev_from, rev_to, force):
    func = get_transform_func(rev_from, rev_to, force)
    tmp_filename = filename + '.tmp'
    infp = open(filename, 'rb')
    outfp = open(tmp_filename, 'wb')
    try:
        writer = WriteRCSFileSink(outfp)
        revfilter = RenumberingFilter(writer, func)
        cvs2svn_rcsparse.parse(infp, revfilter)
    finally:
        outfp.close()
        infp.close()
    os.rename(tmp_filename, filename)
Example #5
0
    def destroy_file(self, filename):
        tmp_filename = get_tmp_filename()
        f = open(tmp_filename, 'wb')
        new_filename = rewrite_filename(filename)
        cvs2svn_rcsparse.parse(
            open(filename, 'rb'),
            DestroyerFilterSink(
                self.author_substituter,
                self.log_substituter,
                WriteRCSFileSink(f),
            ))
        f.close()

        # Replace the original file with the new one:
        assert filename == new_filename or not os.path.exists(new_filename)
        os.remove(filename)
        shutil.move(tmp_filename, new_filename)
Example #6
0
    def destroy_file(self, filename):
        tmp_filename = get_tmp_filename()
        f = open(tmp_filename, 'wb')
        new_filename = rewrite_filename(filename)
        cvs2svn_rcsparse.parse(
            open(filename, 'rb'),
            DestroyerFilterSink(
                self.author_substituter,
                self.log_substituter,
                WriteRCSFileSink(f),
                )
            )
        f.close()

        # Replace the original file with the new one:
        assert filename == new_filename or not os.path.exists(new_filename)
        os.remove(filename)
        shutil.move(tmp_filename, new_filename)
Example #7
0
 def process_file(self, cvs_file):
   logger.normal(cvs_file.rcs_path)
   fdc = _FileDataCollector(self, cvs_file)
   try:
     cvs2svn_rcsparse.parse(open(cvs_file.rcs_path, 'rb'), fdc)
   except (cvs2svn_rcsparse.common.RCSParseError, RuntimeError):
     self.collect_data.record_fatal_error(
         "%r is not a valid ,v file" % (cvs_file.rcs_path,)
         )
     # Abort the processing of this file, but let the pass continue
     # with other files:
     return
   except ValueError, e:
     self.collect_data.record_fatal_error(
         "%r is not a valid ,v file (%s)" % (cvs_file.rcs_path, str(e),)
         )
     # Abort the processing of this file, but let the pass continue
     # with other files:
     return
Example #8
0
def get_branch_tree(path):
    """Return the forest of branches in path.

    Return [(branch_revision, [sub_branch, ...]), ...], where
    branch_revision is a revtuple and sub_branch has the same form as
    the whole return value.

    """

    class BranchCollector(cvs2svn_rcsparse.Sink):
        def __init__(self):
            self.branches = {}

        def define_revision(
            self, revision, timestamp, author, state, branches, next
            ):
            parent = rev_tuple(revision)[:-1]
            if len(parent) == 1:
                parent = (1,)
            entry = self.branches.setdefault(parent, [])
            for branch in branches:
                entry.append(rev_tuple(branch)[:-1])

        def _get_subbranches(self, parent):
            retval = []
            try:
                branches = self.branches[parent]
            except KeyError:
                return []
            del self.branches[parent]
            for branch in branches:
                subbranches = self._get_subbranches(branch)
                retval.append((branch, subbranches,))
            return retval

        def get_branches(self):
            retval = self._get_subbranches((1,))
            assert not self.branches
            return retval

    branch_collector = BranchCollector()
    cvs2svn_rcsparse.parse(open(path, 'rb'), branch_collector)
    return branch_collector.get_branches()
Example #9
0
  def process_file(self, cvs_file_items):
    """Read revision information for the file described by CVS_FILE_ITEMS.

    Compute the text record refcounts, discard any records that are
    unneeded, and store the text records for the file to the
    _rcs_trees database."""

    # A map from cvs_rev_id to TextRecord instance:
    self.text_record_db = TextRecordDatabase(self._delta_db, NullDatabase())

    cvs2svn_rcsparse.parse(
        open(cvs_file_items.cvs_file.rcs_path, 'rb'),
        _Sink(self, cvs_file_items),
        )

    self.text_record_db.recompute_refcounts(cvs_file_items)
    self.text_record_db.free_unused()
    self._rcs_trees[cvs_file_items.cvs_file.id] = self.text_record_db
    del self.text_record_db
Example #10
0
  def process_file(self, cvs_file):
    logger.normal(cvs_file.filename)
    fdc = _FileDataCollector(self, cvs_file)
    try:
      cvs2svn_rcsparse.parse(open(cvs_file.filename, 'rb'), fdc)
    except (cvs2svn_rcsparse.common.RCSParseError, ValueError, RuntimeError):
      self.collect_data.record_fatal_error(
          "%r is not a valid ,v file" % (cvs_file.filename,)
          )
      # Abort the processing of this file, but let the pass continue
      # with other files:
      return
    except:
      logger.warn("Exception occurred while parsing %s" % cvs_file.filename)
      raise
    else:
      self.num_files += 1

    return fdc.get_cvs_file_items()
Example #11
0
 def process_file(self, cvs_file):
     logger.normal(cvs_file.rcs_path)
     fdc = _FileDataCollector(self, cvs_file)
     try:
         cvs2svn_rcsparse.parse(open(cvs_file.rcs_path, 'rb'), fdc)
     except (cvs2svn_rcsparse.common.RCSParseError, RuntimeError):
         self.collect_data.record_fatal_error("%r is not a valid ,v file" %
                                              (cvs_file.rcs_path, ))
         # Abort the processing of this file, but let the pass continue
         # with other files:
         return
     except ValueError, e:
         self.collect_data.record_fatal_error(
             "%r is not a valid ,v file (%s)" % (
                 cvs_file.rcs_path,
                 str(e),
             ))
         # Abort the processing of this file, but let the pass continue
         # with other files:
         return
Example #12
0
  def runTest(self):
    self.assert_(os.path.isfile(self.filename + ',v'))
    recorder = RCSRecorder()
    parse(open(self.filename + ',v', 'rb'), recorder)
    v2 = recorder.texts['1.2']
    self.assertEqual(v2, self.v2)
    delta = recorder.texts['1.1']
    s = RCSStream(v2)
    self.assertEqual(s.get_text(), self.v2)
    invdelta = s.invert_diff(delta)
    self.assertEqual(s.get_text(), self.v1)
    delta2 = s.invert_diff(invdelta)

    self.applyTest(self.v2, delta, self.v1)
    self.applyTest(self.v1, invdelta, self.v2)

    if STRICT_INVERSES:
      self.assertEqual(delta2, delta)
    elif delta2 != delta:
      self.applyTest(self.v2, delta2, self.v1)
Example #13
0
  def process_file(self, cvs_file):
    Log().normal(cvs_file.filename)
    fdc = _FileDataCollector(self, cvs_file)
    try:
      cvs2svn_rcsparse.parse(open(cvs_file.filename, 'rb'), fdc)
    except (cvs2svn_rcsparse.common.RCSParseError, ValueError, RuntimeError):
      self.collect_data.record_fatal_error(
          "%r is not a valid ,v file" % (cvs_file.filename,)
          )
      # Abort the processing of this file, but let the pass continue
      # with other files:
      return
    except:
      Log().warn("Exception occurred while parsing %s" % cvs_file.filename)
      raise
    else:
      self.num_files += 1

    cvs_file_items = fdc.get_cvs_file_items()

    del fdc

    self._process_cvs_file_items(cvs_file_items)
Example #14
0
 def filter(self, text):
     fout = StringIO()
     sink = WriteRCSFileSink(fout)
     filter = self.get_filter_sink(sink)
     cvs2svn_rcsparse.parse(StringIO(text), filter)
     return fout.getvalue()
Example #15
0
        self.sink.set_expansion(mode)

    def admin_completed(self):
        self.sink.admin_completed()

    def define_revision(self, revision, timestamp, author, state, branches, next):
        self.sink.define_revision(revision, timestamp, author, state, branches, next)

    def tree_completed(self):
        self.sink.tree_completed()

    def set_description(self, description):
        self.sink.set_description(description)

    def set_revision_info(self, revision, log, text):
        self.sink.set_revision_info(revision, log, text)

    def parse_completed(self):
        self.sink.parse_completed()


if __name__ == "__main__":
    if sys.argv[1:]:
        for path in sys.argv[1:]:
            if os.path.isfile(path) and path.endswith(",v"):
                cvs2svn_rcsparse.parse(open(path, "rb"), WriteRCSFileSink(sys.stdout))
            else:
                sys.stderr.write("%r is being ignored.\n" % path)
    else:
        cvs2svn_rcsparse.parse(sys.stdin, WriteRCSFileSink(sys.stdout))
Example #16
0
        self.sink.admin_completed()

    def define_revision(self, revision, timestamp, author, state, branches,
                        next):
        self.sink.define_revision(revision, timestamp, author, state, branches,
                                  next)

    def tree_completed(self):
        self.sink.tree_completed()

    def set_description(self, description):
        self.sink.set_description(description)

    def set_revision_info(self, revision, log, text):
        self.sink.set_revision_info(revision, log, text)

    def parse_completed(self):
        self.sink.parse_completed()


if __name__ == '__main__':
    if sys.argv[1:]:
        for path in sys.argv[1:]:
            if os.path.isfile(path) and path.endswith(',v'):
                cvs2svn_rcsparse.parse(open(path, 'rb'),
                                       WriteRCSFileSink(sys.stdout))
            else:
                sys.stderr.write('%r is being ignored.\n' % path)
    else:
        cvs2svn_rcsparse.parse(sys.stdin, WriteRCSFileSink(sys.stdout))