Skip to content

Commit 546a9d8

Browse files
committed
cargo clippy
1 parent 6ffdbd6 commit 546a9d8

File tree

1 file changed

+14
-92
lines changed

1 file changed

+14
-92
lines changed

src/lib/src/core/index/pusher.rs

+14-92
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use futures::prelude::*;
1313
use indicatif::ProgressBar;
1414
use std::collections::{HashMap, HashSet, VecDeque};
1515

16-
use std::hash::Hash;
1716
use std::io::{BufReader, Read};
1817
use std::sync::Arc;
1918

@@ -76,13 +75,6 @@ async fn validate_repo_is_pushable(
7675
commit_reader: &CommitReader,
7776
head_commit: &Commit,
7877
) -> Result<bool, OxenError> {
79-
// Make sure the remote branch is not ahead of the local branch
80-
// log::debug!(
81-
// "validating repo is pushable for commit {:#?} and branch {:#?}",
82-
// head_commit,
83-
// branch
84-
// );
85-
8678
if remote_is_ahead_of_local(head_commit, remote_repo, commit_reader, branch).await? {
8779
log::debug!("remote is ahead of local for commit {:#?}", head_commit);
8880
if api::remote::commits::can_push(remote_repo, &branch.name, local_repo, head_commit)
@@ -95,17 +87,6 @@ async fn validate_repo_is_pushable(
9587
return Err(OxenError::upstream_merge_conflict());
9688
}
9789
}
98-
// } else {
99-
// log::debug!("remote is not ahead of local for commit {:#?}", head_commit);
100-
// }
101-
102-
if cannot_push_incomplete_history(local_repo, remote_repo, head_commit, branch).await? {
103-
log::debug!(
104-
"cannot_push_incomplete_history is true for commit {:#?}",
105-
head_commit
106-
);
107-
return Err(OxenError::incomplete_local_history());
108-
}
10990

11091
Ok(false)
11192
}
@@ -201,18 +182,22 @@ pub async fn try_push_remote_repo(
201182
mut head_commit: Commit,
202183
requires_merge: bool,
203184
) -> Result<(), OxenError> {
204-
let commits_to_sync =
185+
let commits_to_push =
205186
get_commit_objects_to_sync(local_repo, remote_repo, &head_commit, &branch).await?;
206187

188+
if !commits_to_push_are_synced(local_repo, &commits_to_push)? {
189+
return Err(OxenError::incomplete_local_history());
190+
}
191+
207192
log::debug!(
208193
"push_remote_repo commit order after get_commit_objects_to_sync {:?}",
209-
commits_to_sync
194+
commits_to_push
210195
);
211196

212197
let maybe_remote_branch = api::remote::branches::get_by_name(remote_repo, &branch.name).await?;
213198

214199
let (unsynced_entries, _total_size) =
215-
push_missing_commit_objects(local_repo, remote_repo, &commits_to_sync, &branch).await?;
200+
push_missing_commit_objects(local_repo, remote_repo, &commits_to_push, &branch).await?;
216201

217202
log::debug!("🐂 Identifying unsynced commits dbs...");
218203
let unsynced_db_commits =
@@ -304,8 +289,6 @@ async fn get_commit_objects_to_sync(
304289
let remote_branch = api::remote::branches::get_by_name(remote_repo, &branch.name).await?;
305290
let commit_reader = CommitReader::new(local_repo)?;
306291
let mut commits_to_sync: Vec<Commit>;
307-
// TODO: If remote branch does not yet, recreates all commits regardless of shared history.
308-
// Not a huge deal performance-wise right now, but could be for very commit-heavy repos
309292
if let Some(remote_branch) = remote_branch {
310293
log::debug!(
311294
"get_commit_objects_to_sync found remote branch {:?}, calculating missing commits between local and remote heads", remote_branch
@@ -334,10 +317,11 @@ async fn get_commit_objects_to_sync(
334317
.any(|remote_commit| remote_commit.id == commit.id)
335318
});
336319
} else {
337-
// Branch does not exist on remote yet - get all commits?
338-
log::debug!("get_commit_objects_to_sync remote branch does not exist, getting all commits from local head");
320+
// TODO: This logic was already run as a check in cannot_push_incomplete history -
321+
// could likely get it down to 1x w/ a moderate refactor but it is not expensive
339322

340-
// Do the branch thing again
323+
// Remote branch does not exist. Find commits to push with reference to whatever
324+
// remote branch head comes first in the local newbranch history, aka what it was branched off of.
341325
let branches: Vec<Branch> = api::remote::branches::list(remote_repo).await?;
342326
let maybe_remote_head =
343327
find_local_commit_matching_remote_branch(local_repo, local_commit, &branches)?;
@@ -357,7 +341,6 @@ async fn get_commit_objects_to_sync(
357341
commits_to_sync.len()
358342
);
359343

360-
// Filter out any commits_to_sync that are in the remote_history
361344
commits_to_sync.retain(|commit| {
362345
!remote_history
363346
.iter()
@@ -518,7 +501,7 @@ fn find_local_commit_matching_remote_branch(
518501
let mut queue: VecDeque<Commit> = VecDeque::new();
519502
queue.push_back(local_head.clone());
520503

521-
while queue.len() > 0 {
504+
while queue.is_empty() {
522505
let current_commit = queue.pop_front().unwrap();
523506
if branches_map.contains_key(&current_commit.id) {
524507
log::debug!(
@@ -539,77 +522,16 @@ fn find_local_commit_matching_remote_branch(
539522
Ok(None)
540523
}
541524

542-
async fn cannot_push_incomplete_history(
543-
local_repo: &LocalRepository,
544-
remote_repo: &RemoteRepository,
545-
local_head: &Commit,
546-
branch: &Branch,
547-
) -> Result<bool, OxenError> {
548-
log::debug!("Checking if we can push incomplete history.");
549-
match api::remote::commits::list_commit_history(remote_repo, &branch.name).await {
550-
Err(e) => {
551-
log::debug!("got err when checking remote history {:?}", e);
552-
let remote_branches = api::remote::branches::list(remote_repo).await?;
553-
log::debug!("got remote branches {:?}", remote_branches);
554-
555-
let maybe_remote_head =
556-
find_local_commit_matching_remote_branch(local_repo, local_head, &remote_branches)?;
557-
558-
log::debug!("got maybe_remote_head {:?}", maybe_remote_head);
559-
560-
let Some(remote_head) = maybe_remote_head else {
561-
// No commits in the local branch history match any remote branch head.
562-
// This is the empty repo case - require a complete history
563-
return Ok(!api::local::commits::commit_history_is_complete(
564-
local_repo, local_head,
565-
));
566-
};
567-
568-
// Otherwise, we have a remote head that matches a local commit - get commits between and check if they're synced
569-
return Ok(!commits_to_push_are_synced(
570-
local_repo,
571-
local_head,
572-
&remote_head,
573-
)?);
574-
}
575-
Ok(remote_history) => {
576-
log::debug!(
577-
"got remote history {:#?} on branch {:#?}",
578-
remote_history,
579-
branch
580-
);
581-
let remote_head = remote_history.first().unwrap();
582-
return Ok(!commits_to_push_are_synced(
583-
local_repo,
584-
local_head,
585-
remote_head,
586-
)?);
587-
}
588-
}
589-
}
590-
591525
fn commits_to_push_are_synced(
592526
local_repo: &LocalRepository,
593-
local_head: &Commit,
594-
remote_head: &Commit,
527+
commits_to_push: &Vec<Commit>,
595528
) -> Result<bool, OxenError> {
596-
let commit_reader = CommitReader::new(local_repo)?;
597-
let merger = Merger::new(local_repo)?;
598-
599-
let commits_to_push =
600-
merger.list_commits_between_commits(&commit_reader, remote_head, local_head)?;
601-
602-
log::debug!("got commits to push {:?}", commits_to_push);
603-
604529
for commit in commits_to_push {
605-
if !index::commit_sync_status::commit_is_synced(local_repo, &commit) {
530+
if !index::commit_sync_status::commit_is_synced(local_repo, commit) {
606531
log::debug!("commit is not synced {:?}", commit);
607532
return Ok(false);
608533
}
609534
}
610-
611-
log::debug!("commits to push ARE synced!");
612-
613535
Ok(true)
614536
}
615537

0 commit comments

Comments
 (0)