Git Backend

Git backend implementation.

GitRepository

class vcs.backends.git.GitRepository(repo_path, create=False, src_url=None, update_after_clone=False)

Git repository backend.

clone(url, update_after_clone)

Tries to clone changes from external location. if update_after_clone is set To false it’ll prevent the runing update on workdir

get_changeset(revision=None)

Returns GitChangeset object representing commit from git repository at the given revision or head (most recent commit) if None given.

get_changesets(limit=10, offset=None)

Return last n number of MercurialChangeset specified by limit attribute if None is given whole list of revisions is returned :param limit: int limit or None

run_git_command(cmd)

Runs given cmd as git command and returns tuple (returncode, stdout, stderr).

Note

This method exists only until log/blame functionality is implemented at Dulwich (see https://bugs.launchpad.net/bugs/645142). Parsing os command’s output is road to hell...

Parameters:cmd – git command to be executed

GitChangeset

class vcs.backends.git.GitChangeset(repository, revision)

Bases: vcs.backends.base.BaseChangeset

Represents state of the repository at single revision.

id

Returns same as raw_id attribute.

raw_id

Returns raw string identifing this changeset (40-length sha)

short_id

Returns shortened version of raw_id (first 12 characters)

revision

Returns integer representing changeset.

parents

Returns list of parents changesets.

added

Returns list of added FileNode objects.

changed

Returns list of changed FileNode objects.

removed

Returns list of removed RemovedFileNode objects.

Note

Remember that those RemovedFileNode instances are only dummy FileNode objects and trying to access most of it’s attributes or methods would raise NodeError exception.

get_file_annotate(path)

Returns a list of three element tuples with lineno,changeset and line

TODO: This function now uses os underlying ‘git’ command which is generally not good. Should be replaced with algorithm iterating commits.

get_file_changeset(path)

Returns last commit of the file at the given path.

get_file_content(path)

Returns content of the file at given path.

get_file_history(path)

Returns history of file as reversed list of Changeset objects for which file at given path has been modified.

TODO: This function now uses os underlying ‘git’ and ‘grep’ commands which is generally not good. Should be replaced with algorithm iterating commits.

get_file_size(path)

Returns size of the file at given path.

get_node(path)
get_nodes(path)
walk(topurl='')

Similar to os.walk method. Insted of filesystem it walks through changeset starting at given topurl. Returns generator of tuples (topnode, dirnodes, filenodes).

GitInMemoryChangeset

class vcs.backends.git.GitInMemoryChangeset(repository)

Bases: vcs.backends.base.BaseInMemoryChangeset

add(*filenodes)

Marks given FileNode objects as to be committed.

Raises:
  • NodeAlreadyExistsError – if node with same path exists at latest changeset
  • NodeAlreadyAddedError – if node with same path is already marked as added
change(*filenodes)

Marks given FileNode objects to be changed in next commit.

Raises:
  • EmptyRepositoryError – if there are no changesets yet
  • NodeAlreadyExistsError – if node with same path is already marked to be changed
  • NodeAlreadyRemovedError – if node with same path is already marked to be removed
  • NodeDoesNotExistError – if node doesn’t exist in latest changeset
  • NodeNotChangedError – if node hasn’t really be changed
commit(message, author, **kwargs)

Performs in-memory commit.

get_ipaths()

Returns generator of paths from nodes marked as added, changed or removed.

get_paths()

Returns list of paths from nodes marked as added, changed or removed.

remove(*filenodes)

Marks given FileNode (or RemovedFileNode) objects to be removed in next commit.

Raises:
  • EmptyRepositoryError – if there are no changesets yet
  • NodeDoesNotExistError – if node does not exist in latest changeset
  • NodeAlreadyRemovedError – if node has been already marked to be removed
  • NodeAlreadyChangedError – if node has been already marked to be changed
reset()

Resets this instance to initial state (cleans added, changed and removed lists).

Table Of Contents

Previous topic

Backends

Next topic

Mercurial Backend

This Page