diff --git a/cvs2svn_lib/checkout_internal.py b/cvs2svn_lib/checkout_internal.py index 8fdc132c..166eda21 100644 --- a/cvs2svn_lib/checkout_internal.py +++ b/cvs2svn_lib/checkout_internal.py @@ -134,15 +134,22 @@ def decrement_refcount(self, text_record_db): if self.refcount == 0: text_record_db.discard(self.id) - def checkout(self, text_record_db): + def checkout_as_lines(self, text_record_db): """Workhorse of the checkout process. - Return the text for this revision, decrement our reference count, - and update the databases depending on whether there will be future - checkouts.""" + Return the text for this revision as list of logical lines, + decrement our reference count, and update the databases depending + on whether there will be future checkouts.""" raise NotImplementedError() + def checkout(self, text_record_db): + """Return the text for this revision. + + Just same as checkout_as_lines() but returns text as flat text string.""" + + return "".join(self.checkout_as_lines(text_record_db)) + def free(self, text_record_db): """This instance will never again be checked out; free it. @@ -168,10 +175,10 @@ def __getstate__(self): def __setstate__(self, state): (self.id, self.refcount,) = state - def checkout(self, text_record_db): - text = text_record_db.delta_db[self.id] + def checkout_as_lines(self, text_record_db): + lines = text_record_db.delta_db[self.id] self.decrement_refcount(text_record_db) - return text + return lines def free(self, text_record_db): del text_record_db.delta_db[self.id] @@ -205,12 +212,12 @@ def __setstate__(self, state): def increment_dependency_refcounts(self, text_record_db): text_record_db[self.pred_id].refcount += 1 - def checkout(self, text_record_db): - base_text = text_record_db[self.pred_id].checkout(text_record_db) - rcs_stream = RCSStream(base_text) + def checkout_as_lines(self, text_record_db): + base_lines = text_record_db[self.pred_id].checkout_as_lines(text_record_db) + rcs_stream = RCSStream(base_lines) delta_text = text_record_db.delta_db[self.id] rcs_stream.apply_diff(delta_text) - text = rcs_stream.get_text() + lines = rcs_stream.get_lines() del rcs_stream self.refcount -= 1 if self.refcount == 0: @@ -220,11 +227,11 @@ def checkout(self, text_record_db): del text_record_db[self.id] else: # Store a new CheckedOutTextRecord in place of ourselves: - text_record_db.checkout_db['%x' % self.id] = text + text_record_db.checkout_db['%x' % self.id] = lines new_text_record = CheckedOutTextRecord(self.id) new_text_record.refcount = self.refcount text_record_db.replace(new_text_record) - return text + return lines def free(self, text_record_db): del text_record_db.delta_db[self.id] @@ -251,10 +258,10 @@ def __getstate__(self): def __setstate__(self, state): (self.id, self.refcount,) = state - def checkout(self, text_record_db): - text = text_record_db.checkout_db['%x' % self.id] + def checkout_as_lines(self, text_record_db): + lines = text_record_db.checkout_db['%x' % self.id] self.decrement_refcount(text_record_db) - return text + return lines def free(self, text_record_db): del text_record_db.checkout_db['%x' % self.id] @@ -533,7 +540,7 @@ def set_revision_info(self, revision, log, text): # This is revision 1.1. Write its fulltext: text_record = FullTextRecord(cvs_rev_id) self.revision_collector._writeout( - text_record, self._rcs_stream.get_text() + text_record, self._rcs_stream.get_lines() ) # There will be no more trunk revisions delivered, so free the diff --git a/cvs2svn_lib/rcs_stream.py b/cvs2svn_lib/rcs_stream.py index 0963956d..c4ad79a0 100644 --- a/cvs2svn_lib/rcs_stream.py +++ b/cvs2svn_lib/rcs_stream.py @@ -174,13 +174,21 @@ class RCSStream: def __init__(self, text): """Instantiate and initialize the file content with TEXT.""" - self.set_text(text) + if isinstance(text, bytes): + self.set_text(text) + else: + self.set_lines(text) def get_text(self): """Return the current file content.""" return "".join(self._lines) + def get_lines(self): + """Return the current file content as list of logical lines.""" + + return self._lines + def set_lines(self, lines): """Set the current contents to the specified LINES.