Skip to content

Commit

Permalink
Merge branch 'release/1.3.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
Rizziepit committed Jun 30, 2015
2 parents 774562e + 1572498 commit f47905f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 39 deletions.
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
1.3.0
1.3.1
78 changes: 40 additions & 38 deletions elasticgit/workspace.py
Expand Up @@ -129,77 +129,79 @@ def fast_forward(self, branch_name='master', remote_name='origin'):
DeprecationWarning)
return self.pull(branch_name=branch_name, remote_name=remote_name)

def reindex_diff(self, diff_index):
changed_model_set = set([])
for diff in diff_index:
if diff.new_file:
path_info = self.sm.path_info(diff.b_blob.path)
if path_info is not None:
changed_model_set.add(path_info[0])
elif diff.renamed:
path_info = self.sm.path_info(diff.a_blob.path)
if path_info is not None:
changed_model_set.add(path_info[0])
else:
path_info = self.sm.path_info(diff.a_blob.path)
if path_info is not None:
changed_model_set.add(path_info[0])

for model_class in changed_model_set:
self.reindex(model_class)

def pull(self, branch_name='master', remote_name='origin'):
"""
Fetch & Merge in an upstream's commits.
:param str branch_name:
The name of the branch to fast forward & merge in
:param str remote_name:
The name of the remote to fetch from.
"""
changes = self.sm.pull(branch_name=branch_name,
remote_name=remote_name)

def index_diff(self, diff_index):
# NOTE: This is probably more complicated than it needs to be
# If we have multiple remotes GitPython gets confused about
# deletes. It marks things as deletes because it may not
# exist on another remote.
#
# Here we loop over all changes, track the models that've
# changed and then reindex fully to make sure we're in sync.
if len(self.repo.remotes) > 1 and any(changes):
return self.reindex_diff(changes)
if len(self.repo.remotes) > 1 and any(diff_index):
return self.reindex_diff(diff_index)

# NOTE: There's a very unlikely scenario where we're dealing with
# renames. This generally can only happen when a repository
# has been manually modififed. If that's the case then
# reindex everything as well
if any(changes.iter_change_type('R')):
return self.reindex_diff(changes)
if any(diff_index.iter_change_type('R')):
return self.reindex_diff(diff_index)

# unindex deleted blobs
for diff in changes.iter_change_type('D'):
for diff in diff_index.iter_change_type('D'):
path_info = self.sm.path_info(diff.a_blob.path)
if path_info is None:
continue
self.im.raw_unindex(*path_info)

# reindex added blobs
for diff in changes.iter_change_type('A'):
for diff in diff_index.iter_change_type('A'):
path_info = self.sm.path_info(diff.b_blob.path)
if path_info is None:
continue
obj = self.sm.get(*path_info)
self.im.index(obj)

# reindex modified blobs
for diff in changes.iter_change_type('M'):
for diff in diff_index.iter_change_type('M'):
path_info = self.sm.path_info(diff.a_blob.path)
if path_info is None:
continue
obj = self.sm.get(*path_info)
self.im.index(obj)

def reindex_diff(self, diff_index):
changed_model_set = set([])
for diff in diff_index:
if diff.new_file:
path_info = self.sm.path_info(diff.b_blob.path)
if path_info is not None:
changed_model_set.add(path_info[0])
elif diff.renamed:
path_info = self.sm.path_info(diff.a_blob.path)
if path_info is not None:
changed_model_set.add(path_info[0])
else:
path_info = self.sm.path_info(diff.a_blob.path)
if path_info is not None:
changed_model_set.add(path_info[0])

for model_class in changed_model_set:
self.reindex(model_class)

def pull(self, branch_name='master', remote_name='origin'):
"""
Fetch & Merge in an upstream's commits.
:param str branch_name:
The name of the branch to fast forward & merge in
:param str remote_name:
The name of the remote to fetch from.
"""
changes = self.sm.pull(branch_name=branch_name,
remote_name=remote_name)
return self.index_diff(changes)

def reindex_iter(self, model_class, refresh_index=True):
"""
Reindex everything that Git knows about in an iterator
Expand Down

0 comments on commit f47905f

Please sign in to comment.