summaryrefslogtreecommitdiff
path: root/git/index
diff options
context:
space:
mode:
Diffstat (limited to 'git/index')
-rw-r--r--git/index/base.py110
-rw-r--r--git/index/fun.py67
-rw-r--r--git/index/typ.py10
-rw-r--r--git/index/util.py3
4 files changed, 97 insertions, 93 deletions
diff --git a/git/index/base.py b/git/index/base.py
index bbbe3028..051423bf 100644
--- a/git/index/base.py
+++ b/git/index/base.py
@@ -13,54 +13,54 @@ from cStringIO import StringIO
from stat import S_ISLNK
from typ import (
- BaseIndexEntry,
- IndexEntry,
- )
+ BaseIndexEntry,
+ IndexEntry,
+)
from util import (
- TemporaryFileSwap,
- post_clear_cache,
- default_index,
- git_working_dir
- )
+ TemporaryFileSwap,
+ post_clear_cache,
+ default_index,
+ git_working_dir
+)
import git.objects
import git.diff as diff
from git.exc import (
- GitCommandError,
- CheckoutError
- )
+ GitCommandError,
+ CheckoutError
+)
from git.objects import (
- Blob,
- Submodule,
- Tree,
- Object,
- Commit,
- )
+ Blob,
+ Submodule,
+ Tree,
+ Object,
+ Commit,
+)
from git.objects.util import Serializable
from git.util import (
- IndexFileSHA1Writer,
- LazyMixin,
- LockedFD,
- join_path_native,
- file_contents_ro,
- to_native_path_linux,
- to_native_path
- )
+ IndexFileSHA1Writer,
+ LazyMixin,
+ LockedFD,
+ join_path_native,
+ file_contents_ro,
+ to_native_path_linux,
+ to_native_path
+)
from fun import (
- entry_key,
- write_cache,
- read_cache,
- aggressive_tree_merge,
- write_tree_from_cache,
- stat_mode_to_index_mode,
- S_IFGITLINK
- )
+ entry_key,
+ write_cache,
+ read_cache,
+ aggressive_tree_merge,
+ write_tree_from_cache,
+ stat_mode_to_index_mode,
+ S_IFGITLINK
+)
from gitdb.base import IStream
from gitdb.db import MemoryDB
@@ -380,7 +380,7 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable):
# END for each path
def _write_path_to_stdin(self, proc, filepath, item, fmakeexc, fprogress,
- read_from_stdout=True):
+ read_from_stdout=True):
"""Write path to proc.stdin and make sure it processes the item, including progress.
:return: stdout string
@@ -572,8 +572,8 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable):
fprogress(filepath, False, filepath)
istream = self.repo.odb.store(IStream(Blob.type, st.st_size, stream))
fprogress(filepath, True, filepath)
- return BaseIndexEntry((stat_mode_to_index_mode(st.st_mode),
- istream.binsha, 0, to_native_path_linux(filepath)))
+ return BaseIndexEntry((stat_mode_to_index_mode(st.st_mode),
+ istream.binsha, 0, to_native_path_linux(filepath)))
@git_working_dir
def _entries_for_paths(self, paths, path_rewriter, fprogress, entries):
@@ -581,9 +581,9 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable):
if path_rewriter:
for path in paths:
abspath = os.path.abspath(path)
- gitrelative_path = abspath[len(self.repo.working_tree_dir)+1:]
- blob = Blob(self.repo, Blob.NULL_BIN_SHA,
- stat_mode_to_index_mode(os.stat(abspath).st_mode),
+ gitrelative_path = abspath[len(self.repo.working_tree_dir) + 1:]
+ blob = Blob(self.repo, Blob.NULL_BIN_SHA,
+ stat_mode_to_index_mode(os.stat(abspath).st_mode),
to_native_path_linux(gitrelative_path))
# TODO: variable undefined
entries.append(BaseIndexEntry.from_blob(blob))
@@ -599,9 +599,8 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable):
# END path handling
return entries_added
-
- def add(self, items, force=True, fprogress=lambda *args: None, path_rewriter=None,
- write=True):
+ def add(self, items, force=True, fprogress=lambda *args: None, path_rewriter=None,
+ write=True):
"""Add files from the working tree, specific blobs or BaseIndexEntries
to the index.
@@ -676,7 +675,7 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable):
:param write:
If True, the index will be written once it was altered. Otherwise
the changes only exist in memory and are not available to git commands.
-
+
:return:
List(BaseIndexEntries) representing the entries just actually added.
@@ -698,23 +697,25 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable):
# HANDLE ENTRIES
if entries:
- null_mode_entries = [ e for e in entries if e.mode == 0 ]
+ null_mode_entries = [e for e in entries if e.mode == 0]
if null_mode_entries:
- raise ValueError("At least one Entry has a null-mode - please use index.remove to remove files for clarity")
+ raise ValueError(
+ "At least one Entry has a null-mode - please use index.remove to remove files for clarity")
# END null mode should be remove
# HANLDE ENTRY OBJECT CREATION
# create objects if required, otherwise go with the existing shas
- null_entries_indices = [ i for i,e in enumerate(entries) if e.binsha == Object.NULL_BIN_SHA ]
+ null_entries_indices = [i for i, e in enumerate(entries) if e.binsha == Object.NULL_BIN_SHA]
if null_entries_indices:
@git_working_dir
def handle_null_entries(self):
for ei in null_entries_indices:
null_entry = entries[ei]
new_entry = self._store_path(null_entry.path, fprogress)
-
+
# update null entry
- entries[ei] = BaseIndexEntry((null_entry.mode, new_entry.binsha, null_entry.stage, null_entry.path))
+ entries[ei] = BaseIndexEntry(
+ (null_entry.mode, new_entry.binsha, null_entry.stage, null_entry.path))
# END for each entry index
# end closure
handle_null_entries(self)
@@ -724,7 +725,7 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable):
# If we have to rewrite the entries, do so now, after we have generated
# all object sha's
if path_rewriter:
- for i,e in enumerate(entries):
+ for i, e in enumerate(entries):
entries[i] = BaseIndexEntry((e.mode, e.binsha, e.stage, path_rewriter(e)))
# END for each entry
# END handle path rewriting
@@ -744,11 +745,11 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable):
# add the new entries to this instance
for entry in entries_added:
self.entries[(entry.path, 0)] = IndexEntry.from_base(entry)
-
+
if write:
self.write()
# END handle write
-
+
return entries_added
def _items_to_rela_paths(self, items):
@@ -993,7 +994,8 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable):
raise GitCommandError(("git-checkout-index", ), 128, stderr)
if failed_files:
valid_files = list(set(iter_checked_out_files) - set(failed_files))
- raise CheckoutError("Some files could not be checked out from the index due to local modifications", failed_files, valid_files, failed_reasons)
+ raise CheckoutError(
+ "Some files could not be checked out from the index due to local modifications", failed_files, valid_files, failed_reasons)
# END stderr handler
if paths is None:
@@ -1037,7 +1039,7 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable):
if entry.path.startswith(dir):
p = entry.path
self._write_path_to_stdin(proc, p, p, make_exc,
- fprogress, read_from_stdout=False)
+ fprogress, read_from_stdout=False)
checked_out_files.append(p)
path_is_directory = True
# END if entry is in directory
@@ -1046,7 +1048,7 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable):
if not path_is_directory:
self._write_path_to_stdin(proc, co_path, path, make_exc,
- fprogress, read_from_stdout=False)
+ fprogress, read_from_stdout=False)
checked_out_files.append(co_path)
# END path is a file
# END for each path
diff --git a/git/index/fun.py b/git/index/fun.py
index cf55064e..4750463c 100644
--- a/git/index/fun.py
+++ b/git/index/fun.py
@@ -2,14 +2,14 @@
# more versatile
# NOTE: Autodoc hates it if this is a docstring
from stat import (
- S_IFDIR,
- S_IFLNK,
- S_ISLNK,
- S_IFDIR,
- S_ISDIR,
- S_IFMT,
- S_IFREG,
- )
+ S_IFDIR,
+ S_IFLNK,
+ S_ISLNK,
+ S_IFDIR,
+ S_ISDIR,
+ S_IFMT,
+ S_IFREG,
+)
S_IFGITLINK = S_IFLNK | S_IFDIR # a submodule
@@ -18,29 +18,29 @@ from cStringIO import StringIO
from git.util import IndexFileSHA1Writer
from git.exc import UnmergedEntriesError
from git.objects.fun import (
- tree_to_stream,
- traverse_tree_recursive,
- traverse_trees_recursive
- )
+ tree_to_stream,
+ traverse_tree_recursive,
+ traverse_trees_recursive
+)
from typ import (
- BaseIndexEntry,
- IndexEntry,
- CE_NAMEMASK,
- CE_STAGESHIFT
- )
+ BaseIndexEntry,
+ IndexEntry,
+ CE_NAMEMASK,
+ CE_STAGESHIFT
+)
CE_NAMEMASK_INV = ~CE_NAMEMASK
from util import (
- pack,
- unpack
- )
+ pack,
+ unpack
+)
from gitdb.base import IStream
from gitdb.typ import str_tree_type
__all__ = ('write_cache', 'read_cache', 'write_tree_from_cache', 'entry_key',
- 'stat_mode_to_index_mode', 'S_IFGITLINK')
+ 'stat_mode_to_index_mode', 'S_IFGITLINK')
def stat_mode_to_index_mode(mode):
@@ -86,7 +86,7 @@ def write_cache(entries, stream, extension_data=None, ShaStreamCls=IndexFileSHA1
assert plen == len(path), "Path %s too long to fit into index" % entry[3]
flags = plen | (entry[2] & CE_NAMEMASK_INV) # clear possible previous values
write(pack(">LLLLLL20sH", entry[6], entry[7], entry[0],
- entry[8], entry[9], entry[10], entry[1], flags))
+ entry[8], entry[9], entry[10], entry[1], flags))
write(path)
real_size = ((tell() - beginoffset + 8) & ~7)
write("\0" * ((beginoffset + real_size) - tell()))
@@ -101,15 +101,15 @@ def write_cache(entries, stream, extension_data=None, ShaStreamCls=IndexFileSHA1
def read_header(stream):
- """Return tuple(version_long, num_entries) from the given stream"""
- type_id = stream.read(4)
- if type_id != "DIRC":
- raise AssertionError("Invalid index file header: %r" % type_id)
- version, num_entries = unpack(">LL", stream.read(4 * 2))
+ """Return tuple(version_long, num_entries) from the given stream"""
+ type_id = stream.read(4)
+ if type_id != "DIRC":
+ raise AssertionError("Invalid index file header: %r" % type_id)
+ version, num_entries = unpack(">LL", stream.read(4 * 2))
- # TODO: handle version 3: extended data, see read-cache.c
- assert version in (1, 2)
- return version, num_entries
+ # TODO: handle version 3: extended data, see read-cache.c
+ assert version in (1, 2)
+ return version, num_entries
def entry_key(*entry):
@@ -160,7 +160,8 @@ def read_cache(stream):
# 4 bytes length of chunk
# repeated 0 - N times
extension_data = stream.read(~0)
- assert len(extension_data) > 19, "Index Footer was not at least a sha on content as it was only %i bytes in size" % len(extension_data)
+ assert len(extension_data) > 19, "Index Footer was not at least a sha on content as it was only %i bytes in size" % len(
+ extension_data)
content_sha = extension_data[-20:]
@@ -265,7 +266,7 @@ def aggressive_tree_merge(odb, tree_shas):
# its a conflict, otherwise we take the changed version
# This should be the most common branch, so it comes first
if( base[0] != ours[0] and base[0] != theirs[0] and ours[0] != theirs[0] ) or \
- (base[1] != ours[1] and base[1] != theirs[1] and ours[1] != theirs[1]):
+ (base[1] != ours[1] and base[1] != theirs[1] and ours[1] != theirs[1]):
# changed by both
out_append(_tree_entry_to_baseindexentry(base, 1))
out_append(_tree_entry_to_baseindexentry(ours, 2))
@@ -299,7 +300,7 @@ def aggressive_tree_merge(odb, tree_shas):
out_append(_tree_entry_to_baseindexentry(base, 1))
out_append(_tree_entry_to_baseindexentry(theirs, 3))
# END theirs changed
- #else:
+ # else:
# theirs didnt change
# pass
# END handle theirs
diff --git a/git/index/typ.py b/git/index/typ.py
index 4a6f6a81..a71fc2c6 100644
--- a/git/index/typ.py
+++ b/git/index/typ.py
@@ -1,13 +1,13 @@
"""Module with additional types used by the index"""
from util import (
- pack,
- unpack
- )
+ pack,
+ unpack
+)
from binascii import (
- b2a_hex,
- )
+ b2a_hex,
+)
from git.objects import Blob
__all__ = ('BlobFilter', 'BaseIndexEntry', 'IndexEntry')
diff --git a/git/index/util.py b/git/index/util.py
index 064a22ce..171bd8fc 100644
--- a/git/index/util.py
+++ b/git/index/util.py
@@ -64,7 +64,8 @@ def default_index(func):
def check_default_index(self, *args, **kwargs):
if self._file_path != self._index_path():
- raise AssertionError("Cannot call %r on indices that do not represent the default git index" % func.__name__)
+ raise AssertionError(
+ "Cannot call %r on indices that do not represent the default git index" % func.__name__)
return func(self, *args, **kwargs)
# END wrpaper method