[libcxx-commits] [libcxx] a6f38b3 - [libc++][vis-historical] Don't create a git.Repo for each commit

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Wed Dec 17 07:03:40 PST 2025


Author: Louis Dionne
Date: 2025-12-17T10:02:40-05:00
New Revision: a6f38b37c67418902ba575652cf0ab34f152c5c5

URL: https://github.com/llvm/llvm-project/commit/a6f38b37c67418902ba575652cf0ab34f152c5c5
DIFF: https://github.com/llvm/llvm-project/commit/a6f38b37c67418902ba575652cf0ab34f152c5c5.diff

LOG: [libc++][vis-historical] Don't create a git.Repo for each commit

This would lead to "error: too many open files" when processing large
numbers of commits.

Added: 
    

Modified: 
    libcxx/utils/visualize-historical

Removed: 
    


################################################################################
diff  --git a/libcxx/utils/visualize-historical b/libcxx/utils/visualize-historical
index 0a94b152a7137..89c838fad6437 100755
--- a/libcxx/utils/visualize-historical
+++ b/libcxx/utils/visualize-historical
@@ -23,7 +23,7 @@ class Commit:
     This class represents a commit inside a given Git repository.
     """
 
-    def __init__(self, git_repo, sha):
+    def __init__(self, git_repo: git.Repo, sha: str):
         self._git_repo = git_repo
         self._sha = sha
 
@@ -41,7 +41,7 @@ class Commit:
         Return whether a commit is an ancestor of another commit in the Git repository.
         """
         # Is self._sha an ancestor of other._sha?
-        res = subprocess.run(['git', '-C', self._git_repo, 'merge-base', '--is-ancestor', self._sha, other._sha])
+        res = subprocess.run(['git', '-C', self._git_repo.git_dir, 'merge-base', '--is-ancestor', self._sha, other._sha])
         if res.returncode not in (0, 1):
             raise RuntimeError(f'Error when trying to obtain the commit order for {self._sha} and {other._sha}')
         return res.returncode == 0
@@ -57,7 +57,7 @@ class Commit:
         """
         Return the commit information equivalent to `git show` associated to this commit.
         """
-        cmd = ['git', '-C', self._git_repo, 'show', self._sha]
+        cmd = ['git', '-C', self._git_repo.git_dir, 'show', self._sha]
         if not include_
diff :
             cmd.append('--no-patch')
         return subprocess.check_output(cmd, text=True)
@@ -67,22 +67,21 @@ class Commit:
         """
         Return the shortened version of the given SHA.
         """
-        return subprocess.check_output(['git', '-C', self._git_repo, 'rev-parse', '--short', self._sha], text=True).strip()
+        return subprocess.check_output(['git', '-C', self._git_repo.git_dir, 'rev-parse', '--short', self._sha], text=True).strip()
 
     @functools.cached_property
     def fullrev(self):
         """
         Return the full SHA associated to this commit.
         """
-        return subprocess.check_output(['git', '-C', self._git_repo, 'rev-parse', self._sha], text=True).strip()
+        return subprocess.check_output(['git', '-C', self._git_repo.git_dir, 'rev-parse', self._sha], text=True).strip()
 
     @functools.cached_property
     def commit_date(self):
         """
         Return the date of the commit as a `datetime.datetime` object.
         """
-        repo = git.Repo(self._git_repo)
-        return datetime.datetime.fromtimestamp(repo.commit(self._sha).committed_date)
+        return datetime.datetime.fromtimestamp(self._git_repo.commit(self._sha).committed_date)
 
     def prefetch(self):
         """
@@ -226,6 +225,7 @@ def main(argv):
              'https://plotly.com/python-api-reference/generated/plotly.express.trendline_functions.html '
              'details on each option.')
     args = parser.parse_args(argv)
+    repo = git.Repo(args.git_repo)
 
     # Extract benchmark data from the directory.
     data = {}
@@ -233,7 +233,7 @@ def main(argv):
     for file in tqdm.tqdm(files, desc='Parsing LNT files'):
         rows = parse_lnt(file.read_text().splitlines())
         (commit, _) = os.path.splitext(os.path.basename(file))
-        commit = Commit(args.git_repo, commit)
+        commit = Commit(repo, commit)
         data[commit] = rows
 
     # Obtain commit information which is then cached throughout the program. Do this


        


More information about the libcxx-commits mailing list