Skip to content

Commit 4db0574

Browse files
committedMar 14, 2025
application: adjust logging
1 parent 82c33f1 commit 4db0574

File tree

2 files changed

+29
-16
lines changed

2 files changed

+29
-16
lines changed
 

‎git_hg_sync/application.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ def signal_handler(_sig: int, _frame: FrameType | None) -> None:
3737
self._worker.run()
3838

3939
def _handle_push_event(self, push_event: Push) -> None:
40-
logger.info(f"Handling push event: {push_event.pushid}")
40+
logger.debug(
41+
f"Handling push event: {push_event.pushid} for {push_event.repo_url}"
42+
)
4143
synchronizer = self._repo_synchronizers[push_event.repo_url]
4244
operations_by_destination: dict[str, list[SyncOperation]] = {}
4345

@@ -56,10 +58,13 @@ def _handle_push_event(self, push_event: Push) -> None:
5658
f"Failed to process operations: {destination=} {operations=} {exc=}"
5759
)
5860
raise exc
61+
logger.info(
62+
f"Successfully handled event: {push_event.pushid} for {push_event.repo_url}"
63+
)
5964

6065
def _handle_event(self, event: Push | Tag) -> None:
6166
if event.repo_url not in self._repo_synchronizers:
62-
logger.info(f"Ignoring event for untracked repository: {event.repo_url}")
67+
logger.warning(f"Ignoring event for untracked repository: {event.repo_url}")
6368
return
6469
match event:
6570
case Push():

‎git_hg_sync/repo_synchronizer.py

+22-14
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ def _fetch_all_from_remote(self, repo: Repo, remote: str) -> None:
5252
raise e
5353

5454
def sync(self, destination_url: str, operations: list[SyncOperation]) -> None:
55+
logger.debug(f"Syncing {operations} to {destination_url}")
5556
repo = self._get_clone_repo()
5657
destination_remote = f"hg::{destination_url}"
5758

@@ -69,9 +70,12 @@ def sync(self, destination_url: str, operations: list[SyncOperation]) -> None:
6970
op for op in operations if isinstance(op, SyncBranchOperation)
7071
]
7172
for branch_operation in branch_ops:
72-
push_args.append(
73-
f"{branch_operation.source_commit}:refs/heads/branches/{branch_operation.destination_branch}/tip"
74-
)
73+
try:
74+
push_args.append(
75+
f"{branch_operation.source_commit}:refs/heads/branches/{branch_operation.destination_branch}/tip"
76+
)
77+
except Exception as e:
78+
raise RepoSyncError(branch_operation, e) from e
7579

7680
# Add mercurial metadata to new commits from synced branches
7781
# Some of these commits could be tagged in the same synchronization and
@@ -104,16 +108,20 @@ def sync(self, destination_url: str, operations: list[SyncOperation]) -> None:
104108
if not self._commit_has_mercurial_metadata(
105109
repo, tag_operation.source_commit
106110
):
107-
raise MercurialMetadataNotFoundError()
108-
repo.git.cinnabar(
109-
[
110-
"tag",
111-
"--onto",
112-
f"refs/heads/{tag_operation.tags_destination_branch}",
113-
tag_operation.tag,
114-
tag_operation.source_commit,
115-
]
116-
)
117-
111+
raise MercurialMetadataNotFoundError(tag_operation)
112+
try:
113+
repo.git.cinnabar(
114+
[
115+
"tag",
116+
"--onto",
117+
f"refs/heads/{tag_operation.tags_destination_branch}",
118+
tag_operation.tag,
119+
tag_operation.source_commit,
120+
]
121+
)
122+
except Exception as e:
123+
raise RepoSyncError(tag_operation, e) from e
124+
125+
logger.debug(f"Push arguments: {push_args}")
118126
# Push commits, branches and tags to destination
119127
repo.git.push(*push_args)

0 commit comments

Comments
 (0)
Failed to load comments.