-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdiff.py
More file actions
67 lines (56 loc) · 2.37 KB
/
Copy pathdiff.py
File metadata and controls
67 lines (56 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import click
from codesage.snapshot.versioning import SnapshotVersionManager
from codesage.snapshot.differ import SnapshotDiffer
# This would be loaded from the config file
# For now, we'll use a default config.
DEFAULT_CONFIG = {
"snapshot": {
"versioning": {
"max_versions": 10,
"retention_days": 30
}
}
}
SNAPSHOT_DIR = ".codesage/snapshots"
@click.command()
@click.argument('version1')
@click.argument('version2')
@click.option('--project', '-p', required=True, help='The name of the project.')
@click.option('--output', '-o', type=click.Path(), help='Output file for the diff report.')
@click.option('--format', '-f', type=click.Choice(['json', 'markdown']), default='json', help='Output format.')
def diff(version1, version2, project, output, format):
"""
Compare two snapshots and show the differences.
"""
manager = SnapshotVersionManager(SNAPSHOT_DIR, project, DEFAULT_CONFIG['snapshot'])
from codesage.snapshot.models import ProjectSnapshot
import json
from pathlib import Path
def load_snapshot_from_path_or_version(path_or_version: str):
path = Path(path_or_version)
if path.is_file() and path.exists():
with open(path, 'r') as f:
data = json.load(f)
return ProjectSnapshot.model_validate(data)
return manager.load_snapshot(path_or_version)
snapshot1 = load_snapshot_from_path_or_version(version1)
if not snapshot1:
click.echo(f"Snapshot {version1} not found.", err=True)
return
snapshot2 = load_snapshot_from_path_or_version(version2)
if not snapshot2:
click.echo(f"Snapshot {version2} not found.", err=True)
return
differ = SnapshotDiffer()
diff_data = differ.diff(snapshot1, snapshot2)
if output:
# TODO: Implement file output
click.echo(f"Diff report will be saved to {output} in {format} format.")
click.echo(f"Comparing {version1} and {version2}:")
click.echo(f" Added files: {len(diff_data.added_files)}")
click.echo(f" Removed files: {len(diff_data.removed_files)}")
click.echo(f" Modified files: {len(diff_data.modified_files)}")
click.echo(f" Added dependencies: {len(diff_data.dependency_changes.added_edges)}")
click.echo(f" Removed dependencies: {len(diff_data.dependency_changes.removed_edges)}")
if __name__ == '__main__':
diff()