Skip to content

Commit

Permalink
odb: Do absolute-path resolution via rev-parse
Browse files Browse the repository at this point in the history
Instead of manually resolving from `self.workdir /`.

According to
mystor#82 (comment),
the current minimum supported git version is 2.5 or 2.7.3.

This means we can use --absolute-git-dir, which was introduced in 2.13.

--path-format=absolute was introduced in git 2.31.0, which at the time
of this writing is very recent, so a comment has been added to update
that remaining case when it's appropriate.
  • Loading branch information
rwe committed Sep 30, 2021
1 parent c81cf5a commit b654a06
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion gitrevise/odb.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def __init__(self, cwd: Optional[Path] = None) -> None:
self._tempdir = None

self.workdir = Path(self.git("rev-parse", "--show-toplevel", cwd=cwd).decode())
self.gitdir = self.workdir / Path(self.git("rev-parse", "--git-dir").decode())
self.gitdir = Path(self.git("rev-parse", "--absolute-git-dir").decode())

# XXX(nika): Does it make more sense to cache these or call every time?
# Cache for length of time & invalidate?
Expand Down Expand Up @@ -274,6 +274,8 @@ def get_tempdir(self) -> Path:

def git_path(self, path: "StrOrBytesPath") -> Path:
"""Get the path to a file in the .git directory, respecting the environment"""
# NOTE: For git >= 2.31.0, this manual reconstruction from self.workdir
# can be replaced with "git rev-parse --path-format=absolute --git-path …"
return self.workdir / self.git("rev-parse", "--git-path", path).decode()

def new_commit(
Expand Down

0 comments on commit b654a06

Please sign in to comment.