Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix binary diff #26

Merged
merged 8 commits into from
Nov 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM python:3.8

WORKDIR /usr/src/colcon-cache

COPY requirements.txt .
COPY test/requirements.txt ./test/
RUN pip install -r test/requirements.txt

COPY . .
RUN colcon build \
--symlink-install

RUN colcon test && \
colcon test-result --verbose
16 changes: 9 additions & 7 deletions colcon_cache/task/lock/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,19 +110,21 @@ def compute_current_checksums(self, args, lockfile): # noqa: D102

lockfile.metadata['reference_revision'] = reference_commit.hexsha

diff_args = []
diff_args.append('--diff-filter={}'.format(args.git_diff_filter))
diff_args.append(reference_commit.hexsha)
diff_args.append(args.path)
diff = repo.git.diff(diff_args)

h = hashlib.sha1()
for _, checksum in lockfile.dependencies.items():
h.update(bytes.fromhex(checksum))

h.update(bytes.fromhex(reference_commit.hexsha))
lockfile.checksums.reference = h.hexdigest()

diff = reference_commit.diff(None, paths=[args.path])
if diff:
h.update(diff.encode('utf-8'))
for change_type in sorted(args.git_diff_filter):
for change in diff.iter_change_type(change_type):
h.update(change.change_type.encode('utf-8'))
h.update(change.a_path.encode('utf-8'))
h.update(change.b_path.encode('utf-8'))
if not change.deleted_file:
hash_object = repo.git.hash_object(change.b_path)
h.update(bytes.fromhex(hash_object))
lockfile.checksums.current = h.hexdigest()
Empty file.
4 changes: 4 additions & 0 deletions test/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ def test_main():
with open(test_file, 'w') as f:
f.write('def test_empty():\n assert False\n')

test_file = \
ws_base / 'src' / 'test-repo' / 'test-package-c' / 'trash.txt'
os.remove(test_file)

main(argv=argv + ['cache', 'lock'])

main(argv=argv + ['list', '--packages-select-cache-modified'])
Expand Down