Skip to content

Commit

Permalink
Attempt to fix Windows filelocks of git objects
Browse files Browse the repository at this point in the history
  • Loading branch information
TheLastProject committed Dec 8, 2017
1 parent 0c3cdca commit 291d3ab
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 67 deletions.
26 changes: 13 additions & 13 deletions pext/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1195,23 +1195,23 @@ def fix_git_url_for_dulwich(url: str) -> str:
@staticmethod
def get_remote_url(directory: str) -> str:
"""Get the url of the given remote for the specified git-managed directory."""
repo = UpdateManager._path_to_repo(directory)
config = repo.get_config()
return config.get(("remote".encode(), "origin".encode()), "url".encode()).decode()
with UpdateManager._path_to_repo(directory) as repo:
config = repo.get_config()
return config.get(("remote".encode(), "origin".encode()), "url".encode()).decode()

@staticmethod
def update(directory: str) -> bool:
"""If an update is available, attempt to update the git-managed directory."""
# Get current commit
repo = UpdateManager._path_to_repo(directory)
old_commit = repo[repo.head()]
with UpdateManager._path_to_repo(directory) as repo:
old_commit = repo[repo.head()]

# Update
remote_url = UpdateManager.fix_git_url_for_dulwich(UpdateManager.get_remote_url(directory))
porcelain.pull(repo, remote_url)
# Update
remote_url = UpdateManager.fix_git_url_for_dulwich(UpdateManager.get_remote_url(directory))
porcelain.pull(repo, remote_url)

# See if anything was updated
return old_commit != repo[repo.head()]
# See if anything was updated
return old_commit != repo[repo.head()]

@staticmethod
def get_version(directory: str) -> Optional[str]:
Expand All @@ -1222,9 +1222,9 @@ def get_version(directory: str) -> Optional[str]:
@staticmethod
def get_last_updated(directory: str) -> Optional[datetime]:
"""Return the time of the latest update of the git-managed directory."""
repo = UpdateManager._path_to_repo(directory)
commit = repo[repo.head()]
return datetime.fromtimestamp(commit.commit_time)
with UpdateManager._path_to_repo(directory) as repo:
commit = repo[repo.head()]
return datetime.fromtimestamp(commit.commit_time)

def check_core_update(self) -> Optional[str]:
"""Check if there is an update of the core and if so, return the name of the new version."""
Expand Down
107 changes: 53 additions & 54 deletions pext/git_describe.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,57 +34,56 @@ def describe(directory):
Examples: "abcdefg", "v0.1" or "v0.1-5-abcdefg".
"""
# Get the repository
repo = Repo(directory)

# Get a list of all tags
refs = repo.get_refs()
tags = {}
for key, value in refs.items():
key = key.decode()
obj = repo.get_object(value)
if u'tags' not in key:
continue

_, tag = key.rsplit(u'/', 1)

try:
commit = obj.object
except AttributeError:
continue
else:
commit = repo.get_object(commit[1])
tags[tag] = [
datetime.datetime(*time.gmtime(commit.commit_time)[:6]),
commit.id.decode('utf-8'),
]

sorted_tags = sorted(tags.items(), key=lambda tag: tag[1][0], reverse=True)

# If there are no tags, return the current commit
if len(sorted_tags) == 0:
return repo[repo.head()].id.decode('utf-8')[:7]

# We're now 0 commits from the top
commit_count = 0

# Get the latest commit
latest_commit = repo[repo.head()]

# Walk through all commits
walker = repo.get_walker()
for entry in walker:
# Check if tag
commit_id = entry.commit.id.decode('utf-8')
for tag in sorted_tags:
tag_name = tag[0]
tag_commit = tag[1][1]
if commit_id == tag_commit:
if commit_count == 0:
return tag_name
else:
return "{}-{}-{}".format(tag_name, commit_count, latest_commit.id.decode('utf-8')[:7])

commit_count += 1

# We couldn't find the latest tag in the history, so return the commit (fallback)
return latest_commit.id.decode('utf-8')[:7]
with Repo(directory) as repo:
# Get a list of all tags
refs = repo.get_refs()
tags = {}
for key, value in refs.items():
key = key.decode()
obj = repo.get_object(value)
if u'tags' not in key:
continue

_, tag = key.rsplit(u'/', 1)

try:
commit = obj.object
except AttributeError:
continue
else:
commit = repo.get_object(commit[1])
tags[tag] = [
datetime.datetime(*time.gmtime(commit.commit_time)[:6]),
commit.id.decode('utf-8'),
]

sorted_tags = sorted(tags.items(), key=lambda tag: tag[1][0], reverse=True)

# If there are no tags, return the current commit
if len(sorted_tags) == 0:
return repo[repo.head()].id.decode('utf-8')[:7]

# We're now 0 commits from the top
commit_count = 0

# Get the latest commit
latest_commit = repo[repo.head()]

# Walk through all commits
walker = repo.get_walker()
for entry in walker:
# Check if tag
commit_id = entry.commit.id.decode('utf-8')
for tag in sorted_tags:
tag_name = tag[0]
tag_commit = tag[1][1]
if commit_id == tag_commit:
if commit_count == 0:
return tag_name
else:
return "{}-{}-{}".format(tag_name, commit_count, latest_commit.id.decode('utf-8')[:7])

commit_count += 1

# We couldn't find the latest tag in the history, so return the commit (fallback)
return latest_commit.id.decode('utf-8')[:7]

0 comments on commit 291d3ab

Please sign in to comment.