@@ -13,7 +13,6 @@ use futures::prelude::*;
13
13
use indicatif:: ProgressBar ;
14
14
use std:: collections:: { HashMap , HashSet , VecDeque } ;
15
15
16
- use std:: hash:: Hash ;
17
16
use std:: io:: { BufReader , Read } ;
18
17
use std:: sync:: Arc ;
19
18
@@ -76,13 +75,6 @@ async fn validate_repo_is_pushable(
76
75
commit_reader : & CommitReader ,
77
76
head_commit : & Commit ,
78
77
) -> 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
-
86
78
if remote_is_ahead_of_local ( head_commit, remote_repo, commit_reader, branch) . await ? {
87
79
log:: debug!( "remote is ahead of local for commit {:#?}" , head_commit) ;
88
80
if api:: remote:: commits:: can_push ( remote_repo, & branch. name , local_repo, head_commit)
@@ -95,17 +87,6 @@ async fn validate_repo_is_pushable(
95
87
return Err ( OxenError :: upstream_merge_conflict ( ) ) ;
96
88
}
97
89
}
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
- }
109
90
110
91
Ok ( false )
111
92
}
@@ -201,18 +182,22 @@ pub async fn try_push_remote_repo(
201
182
mut head_commit : Commit ,
202
183
requires_merge : bool ,
203
184
) -> Result < ( ) , OxenError > {
204
- let commits_to_sync =
185
+ let commits_to_push =
205
186
get_commit_objects_to_sync ( local_repo, remote_repo, & head_commit, & branch) . await ?;
206
187
188
+ if !commits_to_push_are_synced ( local_repo, & commits_to_push) ? {
189
+ return Err ( OxenError :: incomplete_local_history ( ) ) ;
190
+ }
191
+
207
192
log:: debug!(
208
193
"push_remote_repo commit order after get_commit_objects_to_sync {:?}" ,
209
- commits_to_sync
194
+ commits_to_push
210
195
) ;
211
196
212
197
let maybe_remote_branch = api:: remote:: branches:: get_by_name ( remote_repo, & branch. name ) . await ?;
213
198
214
199
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 ?;
216
201
217
202
log:: debug!( "🐂 Identifying unsynced commits dbs..." ) ;
218
203
let unsynced_db_commits =
@@ -304,8 +289,6 @@ async fn get_commit_objects_to_sync(
304
289
let remote_branch = api:: remote:: branches:: get_by_name ( remote_repo, & branch. name ) . await ?;
305
290
let commit_reader = CommitReader :: new ( local_repo) ?;
306
291
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
309
292
if let Some ( remote_branch) = remote_branch {
310
293
log:: debug!(
311
294
"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(
334
317
. any ( |remote_commit| remote_commit. id == commit. id )
335
318
} ) ;
336
319
} 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
339
322
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.
341
325
let branches: Vec < Branch > = api:: remote:: branches:: list ( remote_repo) . await ?;
342
326
let maybe_remote_head =
343
327
find_local_commit_matching_remote_branch ( local_repo, local_commit, & branches) ?;
@@ -357,7 +341,6 @@ async fn get_commit_objects_to_sync(
357
341
commits_to_sync. len( )
358
342
) ;
359
343
360
- // Filter out any commits_to_sync that are in the remote_history
361
344
commits_to_sync. retain ( |commit| {
362
345
!remote_history
363
346
. iter ( )
@@ -518,7 +501,7 @@ fn find_local_commit_matching_remote_branch(
518
501
let mut queue: VecDeque < Commit > = VecDeque :: new ( ) ;
519
502
queue. push_back ( local_head. clone ( ) ) ;
520
503
521
- while queue. len ( ) > 0 {
504
+ while queue. is_empty ( ) {
522
505
let current_commit = queue. pop_front ( ) . unwrap ( ) ;
523
506
if branches_map. contains_key ( & current_commit. id ) {
524
507
log:: debug!(
@@ -539,77 +522,16 @@ fn find_local_commit_matching_remote_branch(
539
522
Ok ( None )
540
523
}
541
524
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
-
591
525
fn commits_to_push_are_synced (
592
526
local_repo : & LocalRepository ,
593
- local_head : & Commit ,
594
- remote_head : & Commit ,
527
+ commits_to_push : & Vec < Commit > ,
595
528
) -> 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
-
604
529
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) {
606
531
log:: debug!( "commit is not synced {:?}" , commit) ;
607
532
return Ok ( false ) ;
608
533
}
609
534
}
610
-
611
- log:: debug!( "commits to push ARE synced!" ) ;
612
-
613
535
Ok ( true )
614
536
}
615
537
0 commit comments