b.w.Weave(VersionedFile) : class documentation

Part of bzrlib.weave View In Hierarchy

Known subclasses: bzrlib.tests.test_weave.InstrumentedWeave, bzrlib.weave.WeaveFile

weave - versioned text file storage.

A Weave manages versions of line-based text files, keeping track of the originating version for each line.

To clients the "lines" of the file are represented as a list of strings. These strings will typically have terminal newline characters, but this is not required. In particular files commonly do not have a newline at the end of the file.

Texts can be identified in either of two ways:

Typically the index number will be valid only inside this weave and the version-id is used to reference it in the larger world.

The weave is represented as a list mixing edit instructions and literal text. Each entry in _weave can be either a string (or unicode), or a tuple. If a string, it means that the given line should be output in the currently active revisions.

If a tuple, it gives a processing instruction saying in which revisions the enclosed lines are active. The tuple has the form (instruction, version).

The instruction can be '{' or '}' for an insertion block, and '[' and ']' for a deletion block respectively. The version is the integer version index. There is no replace operator, only deletes and inserts. For '}', the end of an insertion, there is no version parameter because it always closes the most recently opened insertion.

Constraints/notes:

_weave
Text of the weave; list of control instruction tuples and strings.
_parents
List of parents, indexed by version number. It is only necessary to store the minimal set of parents for each version; the parent's parents are implied.
_sha1s
List of hex SHA-1 of each version.
_names
List of symbolic names for each version. Each should be unique.
_name_map
For each name, the version number.
_weave_name
Descriptive name of this weave; typically the filename if known. Set by read_weave.
Method __init__ Create a weave.
Method __repr__ Undocumented
Method copy Return a deep copy of self.
Method __eq__ Undocumented
Method __ne__ Undocumented
Method versions See VersionedFile.versions.
Method has_version See VersionedFile.has_version.
Method get_record_stream Get a stream of records for versions.
Method get_parent_map See VersionedFile.get_parent_map.
Method get_parents_with_ghosts Return version names for parents of version_id.
Method insert_record_stream Insert a record stream into this versioned file.
Method get_ancestry See VersionedFile.get_ancestry.
Method annotate Return a list of (version-id, line) tuples for version_id.
Method iter_lines_added_or_present_in_versions See VersionedFile.iter_lines_added_or_present_in_versions().
Method plan_merge Return pseudo-annotation indicating how the two versions merge.
Method get_lines See VersionedFile.get_lines().
Method get_sha1s See VersionedFile.get_sha1s().
Method num_versions How many versions are in this weave?
Method check Check the versioned file for integrity.
Method _check_write_ok Is the versioned file marked as 'finished' ? Raise if it is.
Method _idx_to_name Undocumented
Method _lookup Convert symbolic version name to index.
Method _check_repeated_add Check that a duplicated add is OK.
Method _add_lines See VersionedFile.add_lines.
Method _add Add a single text on top of the weave.
Method _inclusions Return set of all ancestors of given version(s).
Method _check_lines Undocumented
Method _check_versions Check everything in the sequence of indexes is valid
Method _compatible_parents During join check that other_parents are joinable with my_parents.
Method _walk_internal Helper method for weave actions.
Method _extract Yield annotation of lines in included set.
Method _maybe_lookup Convert possible symbolic name to index, or pass through indexes.
Method _imported_parents Return list of parents in self corresponding to indexes in other.
Method _check_version_consistent Check if a version in consistent in this and other.
Method _reweave Reweave self with other - internal helper for join().
Method _copy_weave_content adsorb the content from otherweave.

Inherited from VersionedFile:

Static Method check_not_reserved_id Undocumented
Method copy_to Copy this versioned file to name on transport.
Method add_lines Add a single text on top of the versioned file.
Method add_lines_with_ghosts Add lines to the versioned file, allowing ghosts to be present.
Method get_format_signature Get a text description of the data encoding in this file.
Method make_mpdiffs Create multiparent diffs for specified versions.
Method add_mpdiffs Add mpdiffs to this VersionedFile.
Method get_text Return version contents as a text string.
Method get_texts Return the texts of listed versions as a list of strings.
Method get_ancestry_with_ghosts Return a list of all ancestors of given version(s). This
Method weave_merge Undocumented
Method _add_lines_with_ghosts Helper to do class specific add_lines_with_ghosts.
Method _check_lines_not_unicode Check that lines being added to a versioned file are not unicode.
Method _check_lines_are_lines Check that the lines really are full lines without inline EOL.
Method _extract_blocks Undocumented
Method _get_lf_split_line_list Undocumented
def __init__(self, weave_name=None, access_mode='w', matcher=None, get_scope=None, allow_reserved=False):
Create a weave.
Parametersget_scopeA callable that returns an opaque object to be used for detecting when this weave goes out of scope (should stop answering requests or allowing mutation).
def __repr__(self):
Undocumented
def _check_write_ok(self):
Is the versioned file marked as 'finished' ? Raise if it is.
def copy(self):
Return a deep copy of self.

The copy can be modified without affecting the original weave.

def __eq__(self, other):
Undocumented
def __ne__(self, other):
Undocumented
def _idx_to_name(self, version):
Undocumented
def _lookup(self, name):
Convert symbolic version name to index.
def versions(self):
See VersionedFile.versions.
def has_version(self, version_id):
See VersionedFile.has_version.
def get_record_stream(self, versions, ordering, include_delta_closure):
Get a stream of records for versions.
ParametersversionsThe versions to include. Each version is a tuple (version,).
orderingEither 'unordered' or 'topological'. A topologically sorted stream has compression parents strictly before their children.
include_delta_closureIf True then the closure across any compression parents will be included (in the opaque data).
ReturnsAn iterator of ContentFactory objects, each of which is only valid until the iterator is advanced.
def get_parent_map(self, version_ids):
See VersionedFile.get_parent_map.
def get_parents_with_ghosts(self, version_id):
Return version names for parents of version_id.

Will raise RevisionNotPresent if version_id is not present in the history.

Ghosts that are known about will be included in the parent list, but are not explicitly marked.

def insert_record_stream(self, stream):
Insert a record stream into this versioned file.
ParametersstreamA stream of records to insert.
ReturnsNone
See Also
def _check_repeated_add(self, name, parents, text, sha1):
Check that a duplicated add is OK.

If it is, return the (old) index; otherwise raise an exception.

def _add_lines(self, version_id, parents, lines, parent_texts, left_matching_blocks, nostore_sha, random_id, check_content):
See VersionedFile.add_lines.
def _add(self, version_id, lines, parents, sha1=None, nostore_sha=None):

Add a single text on top of the weave.

Returns the index number of the newly added version.

version_id
Symbolic name for this version. (Typically the revision-id of the revision that added it.) If None, a name will be allocated based on the hash. (sha1:SHAHASH)
parents
List or set of direct parent version numbers.
lines
Sequence of lines to be added in the new version.
Parametersnostore_shaSee VersionedFile.add_lines.
def _inclusions(self, versions):
Return set of all ancestors of given version(s).
def get_ancestry(self, version_ids, topo_sorted=True):
See VersionedFile.get_ancestry.
def _check_lines(self, text):
Undocumented
def _check_versions(self, indexes):
Check everything in the sequence of indexes is valid
def _compatible_parents(self, my_parents, other_parents):
During join check that other_parents are joinable with my_parents.

Joinable is defined as 'is a subset of' - supersets may require regeneration of diffs, but subsets do not.

def annotate(self, version_id):
Return a list of (version-id, line) tuples for version_id.

The index indicates when the line originated in the weave.

def iter_lines_added_or_present_in_versions(self, version_ids=None, pb=None):
See VersionedFile.iter_lines_added_or_present_in_versions().
def _walk_internal(self, version_ids=None):
Helper method for weave actions.
def plan_merge(self, ver_a, ver_b):
Return pseudo-annotation indicating how the two versions merge.

This is computed between versions a and b and their common base.

Weave lines present in none of them are skipped entirely.

def _extract(self, versions):
Yield annotation of lines in included set.

Yields a sequence of tuples (origin, lineno, text), where origin is the origin version, lineno the index in the weave, and text the text of the line.

The set typically but not necessarily corresponds to a version.

def _maybe_lookup(self, name_or_index):
Convert possible symbolic name to index, or pass through indexes.

NOT FOR PUBLIC USE.

def get_lines(self, version_id):
See VersionedFile.get_lines().
def get_sha1s(self, version_ids):
See VersionedFile.get_sha1s().
def num_versions(self):
How many versions are in this weave?
def check(self, progress_bar=None):
Check the versioned file for integrity.
def _imported_parents(self, other, other_idx):
Return list of parents in self corresponding to indexes in other.
def _check_version_consistent(self, other, other_idx, name):
Check if a version in consistent in this and other.

To be consistent it must have:

  • the same text
  • the same direct parents (by name, not index, and disregarding order)

If present & correct return True; if not present in self return False; if inconsistent raise error.

def _reweave(self, other, pb, msg):
Reweave self with other - internal helper for join().
ParametersotherThe other weave to merge
pbAn optional progress bar, indicating how far done we are
msgAn optional message for the progress
def _copy_weave_content(self, otherweave):
adsorb the content from otherweave.
API Documentation for Bazaar, generated by pydoctor at 2022-06-16 00:25:16.