Skip to content

Commit

Permalink
reckless: populate local submodules for searching
Browse files Browse the repository at this point in the history
Git ls-tree does not report submodule contents which was not previously
accounted for.
  • Loading branch information
endothermicdev committed Feb 19, 2024
1 parent 7149f59 commit 4b6e5c4
Showing 1 changed file with 34 additions and 10 deletions.
44 changes: 34 additions & 10 deletions tools/reckless
Original file line number Diff line number Diff line change
Expand Up @@ -383,13 +383,18 @@ def populate_local_dir(path: str) -> list:
return contents


def populate_local_repo(path: str) -> list:
def populate_local_repo(path: str, parent=None) -> list:
if not Path(os.path.realpath(path)).exists():
logging.warning(f"cannot populate {path}: does not exist")
assert Path(os.path.realpath(path)).exists()
basedir = SourceDir('base')
if parent is None:
basedir = SourceDir('base')
else:
assert isinstance(parent, SourceDir)
basedir = parent

def populate_source_path(parent, mypath):
def populate_source_path(parent: SourceDir, mypath: PosixPath,
relative: str=None):
"""`git ls-tree` lists all files with their full path.
This populates all intermediate directories and the file."""
parentdir = parent
Expand All @@ -410,6 +415,8 @@ def populate_local_repo(path: str) -> list:
else:
if p == revpath[-1]:
relative_path = None
if parentdir.relative:
relative_path = parentdir.relative
elif parentdir.relative:
relative_path = str(Path(parentdir.relative) /
parentdir.name)
Expand All @@ -425,6 +432,16 @@ def populate_local_repo(path: str) -> list:
newfile = SourceFile(mypath.name)
child.contents.append(newfile)

# Submodules contents are populated separately
proc = run(['git', '-C', path, 'submodule', 'status'],
stdout=PIPE, stderr=PIPE, text=True, timeout=5)
if proc.returncode != 0:
logging.debug(f"'git submodule status' of repo {path} failed")
return None
submodules = []
for sub in proc.stdout.splitlines():
submodules.append(sub.split()[1])

# FIXME: Pass in tag or commit hash
ver = 'HEAD'
git_call = ['git', '-C', path, 'ls-tree', '--full-tree', '-r',
Expand All @@ -433,8 +450,21 @@ def populate_local_repo(path: str) -> list:
if proc.returncode != 0:
logging.debug(f'ls-tree of repo {path} failed')
return None

for filepath in proc.stdout.splitlines():
populate_source_path(basedir, Path(filepath))
if filepath in submodules:
if parent is None:
relative_path = filepath
elif basedir.relative:
relative_path = str(Path(basedir.relative) / filepath)
assert relative_path
submodule_dir = SourceDir(filepath, srctype=Source.LOCAL_REPO,
relative=relative_path)
populate_local_repo(Path(path) / filepath, parent=submodule_dir)
submodule_dir.prepopulated = True
basedir.contents.append(submodule_dir)
else:
populate_source_path(basedir, Path(filepath))
return basedir.contents


Expand Down Expand Up @@ -941,12 +971,6 @@ def _git_update(github_source: InstInfo, local_copy: PosixPath):
if git.returncode != 0:
return False

git = run(['git', 'submodule', 'update', '--init', '--recursive'],
cwd=str(local_copy), stdout=PIPE, stderr=PIPE, text=True,
check=False, timeout=60)
if git.returncode != 0:
return False

return True


Expand Down

0 comments on commit 4b6e5c4

Please sign in to comment.