3
3
#![ deny( rust_2018_idioms, missing_docs) ]
4
4
#![ forbid( unsafe_code) ]
5
5
6
+ mod consecutive;
7
+ mod noop;
8
+
6
9
/// The way the negotiation is performed.
7
10
#[ derive( Default , Debug , Copy , Clone , Eq , PartialEq ) ]
8
11
pub enum Algorithm {
@@ -15,21 +18,6 @@ pub enum Algorithm {
15
18
Skipping ,
16
19
}
17
20
18
- // static int next_flush(int stateless_rpc, int count)
19
- // {
20
- // if (stateless_rpc) {
21
- // if (count < LARGE_FLUSH)
22
- // count <<= 1;
23
- // else
24
- // count = count * 11 / 10;
25
- // } else {
26
- // if (count < PIPESAFE_FLUSH)
27
- // count <<= 1;
28
- // else
29
- // count += PIPESAFE_FLUSH;
30
- // }
31
- // return count;
32
- // }
33
21
/// Calculate how many `HAVE` lines we may send in one round, with variation depending on whether the `transport_is_stateless` or not.
34
22
/// `window_size` is the previous (or initial) value of the window size.
35
23
pub fn window_size ( transport_is_stateless : bool , window_size : impl Into < Option < usize > > ) -> usize {
@@ -54,3 +42,47 @@ pub fn window_size(transport_is_stateless: bool, window_size: impl Into<Option<u
54
42
}
55
43
}
56
44
}
45
+
46
+ impl Algorithm {
47
+ /// Create an instance of a negotiator which implements this algorithm.
48
+ pub fn into_negotiator < ' find , Find , E > (
49
+ self ,
50
+ find : Find ,
51
+ cache : impl Into < Option < gix_commitgraph:: Graph > > ,
52
+ ) -> Box < dyn Negotiator >
53
+ where
54
+ Find :
55
+ for < ' a > FnMut ( & gix_hash:: oid , & ' a mut Vec < u8 > ) -> Result < Option < gix_object:: CommitRefIter < ' a > > , E > + ' find ,
56
+ E : std:: error:: Error + Send + Sync + ' static ,
57
+ {
58
+ match & self {
59
+ Algorithm :: Noop => Box :: new ( noop:: Noop ) as Box < dyn Negotiator > ,
60
+ Algorithm :: Consecutive => {
61
+ let _graph = gix_revision:: Graph :: < ' _ , consecutive:: Flags > :: new ( find, cache) ;
62
+ todo ! ( )
63
+ }
64
+ Algorithm :: Skipping => todo ! ( ) ,
65
+ }
66
+ }
67
+ }
68
+
69
+ /// A delegate to implement a negotiation algorithm.
70
+ pub trait Negotiator {
71
+ /// Mark `id` as common between the remote and us.
72
+ ///
73
+ /// These ids are typically the local tips of remote tracking branches.
74
+ fn known_common ( & mut self , id : & gix_hash:: oid ) ;
75
+
76
+ /// Add `id` as starting point of a traversal across commits that aren't necessarily common between the remote and us.
77
+ ///
78
+ /// These tips are usually the commits of local references whose tips should lead to objects that we have in common with the remote.
79
+ fn add_tip ( & mut self , id : & gix_hash:: oid ) ;
80
+
81
+ /// Produce the next id of an object that we want the server to know we have. It's an object we don't know we have in common or not.
82
+ ///
83
+ /// Returns `None` if we have exhausted all options, which might mean we have traversed the entire commit graph.
84
+ fn next_have ( & mut self ) -> Option < gix_hash:: ObjectId > ;
85
+
86
+ /// Mark `id` as being common with the remote (as informed by the remote itself) and return `true` if we knew it was common already.
87
+ fn in_common_with_remote ( & mut self , id : & gix_hash:: oid ) -> bool ;
88
+ }
0 commit comments