Skip to content

Commit ec06283

Browse files
jonathantanmygitster
authored andcommitted
fetch-pack: introduce negotiator API
Introduce the new files fetch-negotiator.{h,c}, which contains an API behind which the details of negotiation are abstracted. Currently, only one algorithm is available: the existing one. This patch is written to be easily reviewed: static functions are moved verbatim from fetch-pack.c to negotiator/default.c, and it can be seen that the lines replaced by negotiator->X() calls are present in the X() functions respectively. Signed-off-by: Jonathan Tan <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d093bc7 commit ec06283

File tree

7 files changed

+292
-167
lines changed

7 files changed

+292
-167
lines changed

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -859,6 +859,7 @@ LIB_OBJS += ewah/ewah_bitmap.o
859859
LIB_OBJS += ewah/ewah_io.o
860860
LIB_OBJS += ewah/ewah_rlw.o
861861
LIB_OBJS += exec-cmd.o
862+
LIB_OBJS += fetch-negotiator.o
862863
LIB_OBJS += fetch-object.o
863864
LIB_OBJS += fetch-pack.o
864865
LIB_OBJS += fsck.o
@@ -891,6 +892,7 @@ LIB_OBJS += merge-blobs.o
891892
LIB_OBJS += merge-recursive.o
892893
LIB_OBJS += mergesort.o
893894
LIB_OBJS += name-hash.o
895+
LIB_OBJS += negotiator/default.o
894896
LIB_OBJS += notes.o
895897
LIB_OBJS += notes-cache.o
896898
LIB_OBJS += notes-merge.o

fetch-negotiator.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#include "git-compat-util.h"
2+
#include "fetch-negotiator.h"
3+
#include "negotiator/default.h"
4+
5+
void fetch_negotiator_init(struct fetch_negotiator *negotiator)
6+
{
7+
default_negotiator_init(negotiator);
8+
}

fetch-negotiator.h

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#ifndef FETCH_NEGOTIATOR
2+
#define FETCH_NEGOTIATOR
3+
4+
struct commit;
5+
6+
/*
7+
* An object that supplies the information needed to negotiate the contents of
8+
* the to-be-sent packfile during a fetch.
9+
*
10+
* To set up the negotiator, call fetch_negotiator_init(), then known_common()
11+
* (0 or more times), then add_tip() (0 or more times).
12+
*
13+
* Then, when "have" lines are required, call next(). Call ack() to report what
14+
* the server tells us.
15+
*
16+
* Once negotiation is done, call release(). The negotiator then cannot be used
17+
* (unless reinitialized with fetch_negotiator_init()).
18+
*/
19+
struct fetch_negotiator {
20+
/*
21+
* Before negotiation starts, indicate that the server is known to have
22+
* this commit.
23+
*/
24+
void (*known_common)(struct fetch_negotiator *, struct commit *);
25+
26+
/*
27+
* Once this function is invoked, known_common() cannot be invoked any
28+
* more.
29+
*
30+
* Indicate that this commit and all its ancestors are to be checked
31+
* for commonality with the server.
32+
*/
33+
void (*add_tip)(struct fetch_negotiator *, struct commit *);
34+
35+
/*
36+
* Once this function is invoked, known_common() and add_tip() cannot
37+
* be invoked any more.
38+
*
39+
* Return the next commit that the client should send as a "have" line.
40+
*/
41+
const struct object_id *(*next)(struct fetch_negotiator *);
42+
43+
/*
44+
* Inform the negotiator that the server has the given commit. This
45+
* method must only be called on commits returned by next().
46+
*/
47+
int (*ack)(struct fetch_negotiator *, struct commit *);
48+
49+
void (*release)(struct fetch_negotiator *);
50+
51+
/* internal use */
52+
void *data;
53+
};
54+
55+
void fetch_negotiator_init(struct fetch_negotiator *negotiator);
56+
57+
#endif

0 commit comments

Comments
 (0)