[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: Antwort: Re: cvs2svn.py fails converting repository with the attached file

From: mark benedetto king <mbk_at_lowlatency.com>
Date: 2003-06-27 23:57:49 CEST

On Fri, Jun 27, 2003 at 01:19:26PM -0400, mark benedetto king wrote:
> Aha! We could *invert* the delta as we go. I.e., start with HEAD, work
> back to rev-1, dropping forward-deltas along the way. Neat, though
> it does trade the CPU and IO for the space savings.
>
> Attached is my quick-hack-in-perl RCS delta applyer. It may not be
> completely correct, but it (seems to have) worked for all of my data.
>
> I'm sure it would port pretty quickly to python.
>

Well, sure enough, it did port pretty quickly to python. Along
the way it picked up delta-inversion capability, at almost no cost!

#!/usr/bin/env python

import string

class RCSPatch:

  def __init__(self):
    pass

  def write_to_line(self, line):
    while self.workline < line:
      self.dump(self.original.readline())
      self.workline = self.workline+1

  def delete(self, addr, count):
    self.write_to_line(addr)
    vline = self.workline + self.adjust - 1
    self.odelta.write("a"+str(vline)+" "+str(count)+"\n")
    self.adjust -= count
    while count:
      count = count-1
      self.workline = self.workline+1
      self.odelta.write(self.original.readline())
    
  def add(self, addr, count):
    self.write_to_line(addr+1)
    self.count = count
    self.handler = self.dump_n
    vline = self.workline + self.adjust;
    self.odelta.write("d"+str(vline)+" "+str(count)+"\n")
   
  def opcode(self, line):
    code = line[0]
    [addr, count] = map(string.atol,string.split(line[1:]," "))
    if code == 'd':
      self.delete(addr, count)
    elif code == 'a':
      self.add(addr, count)

  def dispatch(self, line):
    if line == '':
      return 0
    self.handler(line)
    return 1

  def dump(self, line):
    self.out.write(line)

  def dump_n(self, line):
    self.dump(line)
    self.adjust = self.adjust+1
    self.count = self.count-1;
    if not self.count:
      self.handler = self.opcode

  def patch(self, original, idelta, out, odelta):
    self.workline = 1
    self.adjust = 0
    self.count = 0
    self.original = original
    self.out = out
    self.odelta = odelta

    self.handler = self.opcode
    while self.dispatch(idelta.readline()):
      pass
    self.handler = self.dump
    while self.dispatch(original.readline()):
      pass

def apply_patch(iname, idname, oname, odname):
  RCSPatch().patch(open(iname),
                   open(idname),
                   open(oname,'w'),
                   open(odname,'w'))

if __name__ == '__main__':
  import sys
  apply_patch(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4])

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Fri Jun 27 23:58:00 2003

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.