Skip to content

Commit 37d98aa

Browse files
committed
transport: transports can indicate support for fetch by oid
1 parent 7a00adc commit 37d98aa

File tree

5 files changed

+60
-3
lines changed

5 files changed

+60
-3
lines changed

include/git2/sys/remote.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright (C) the libgit2 contributors. All rights reserved.
3+
*
4+
* This file is part of libgit2, distributed under the GNU GPL v2 with
5+
* a Linking Exception. For full terms see the included COPYING file.
6+
*/
7+
8+
#ifndef INCLUDE_sys_git_remote_h
9+
#define INCLUDE_sys_git_remote_h
10+
11+
/**
12+
* @file git2/sys/remote.h
13+
* @brief Low-level remote functionality for custom transports
14+
* @defgroup git_remote Low-level remote functionality
15+
* @ingroup Git
16+
* @{
17+
*/
18+
19+
GIT_BEGIN_DECL
20+
21+
typedef enum {
22+
/** Remote supports fetching an advertised object by ID. */
23+
GIT_REMOTE_CAPABILITY_TIP_OID = (1 << 0),
24+
25+
/** Remote supports fetching an individual reachable object. */
26+
GIT_REMOTE_CAPABILITY_REACHABLE_OID = (1 << 1),
27+
} git_remote_capability_t;
28+
29+
/** @} */
30+
GIT_END_DECL
31+
#endif

src/transports/local.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "git2/pack.h"
2929
#include "git2/commit.h"
3030
#include "git2/revparse.h"
31+
#include "git2/sys/remote.h"
3132

3233
typedef struct {
3334
git_transport parent;
@@ -260,7 +261,8 @@ static int local_capabilities(unsigned int *capabilities, git_transport *transpo
260261
{
261262
GIT_UNUSED(transport);
262263

263-
*capabilities = 0;
264+
*capabilities = GIT_REMOTE_CAPABILITY_TIP_OID |
265+
GIT_REMOTE_CAPABILITY_REACHABLE_OID;
264266
return 0;
265267
}
266268

src/transports/smart.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "smart.h"
99

1010
#include "git2.h"
11+
#include "git2/sys/remote.h"
1112
#include "refs.h"
1213
#include "refspec.h"
1314
#include "proxy.h"
@@ -228,9 +229,16 @@ static int git_smart__set_connect_opts(
228229

229230
static int git_smart__capabilities(unsigned int *capabilities, git_transport *transport)
230231
{
231-
GIT_UNUSED(transport);
232+
transport_smart *t = GIT_CONTAINER_OF(transport, transport_smart, parent);
232233

233234
*capabilities = 0;
235+
236+
if (t->caps.want_tip_sha1)
237+
*capabilities |= GIT_REMOTE_CAPABILITY_TIP_OID;
238+
239+
if (t->caps.want_reachable_sha1)
240+
*capabilities |= GIT_REMOTE_CAPABILITY_REACHABLE_OID;
241+
234242
return 0;
235243
}
236244

src/transports/smart.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
#define GIT_CAP_REPORT_STATUS "report-status"
3131
#define GIT_CAP_THIN_PACK "thin-pack"
3232
#define GIT_CAP_SYMREF "symref"
33+
#define GIT_CAP_WANT_TIP_SHA1 "allow-tip-sha1-in-want"
34+
#define GIT_CAP_WANT_REACHABLE_SHA1 "allow-reachable-sha1-in-want"
3335

3436
extern bool git_smart__ofs_delta_enabled;
3537

@@ -128,7 +130,9 @@ typedef struct transport_smart_caps {
128130
include_tag:1,
129131
delete_refs:1,
130132
report_status:1,
131-
thin_pack:1;
133+
thin_pack:1,
134+
want_tip_sha1:1,
135+
want_reachable_sha1:1;
132136
} transport_smart_caps;
133137

134138
typedef int (*packetsize_cb)(size_t received, void *payload);

src/transports/smart_protocol.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,18 @@ int git_smart__detect_caps(git_pkt_ref *pkt, transport_smart_caps *caps, git_vec
205205
continue;
206206
}
207207

208+
if (!git__prefixcmp(ptr, GIT_CAP_WANT_TIP_SHA1)) {
209+
caps->common = caps->want_tip_sha1 = 1;
210+
ptr += strlen(GIT_CAP_DELETE_REFS);
211+
continue;
212+
}
213+
214+
if (!git__prefixcmp(ptr, GIT_CAP_WANT_REACHABLE_SHA1)) {
215+
caps->common = caps->want_reachable_sha1 = 1;
216+
ptr += strlen(GIT_CAP_DELETE_REFS);
217+
continue;
218+
}
219+
208220
/* We don't know this capability, so skip it */
209221
ptr = strchr(ptr, ' ');
210222
}

0 commit comments

Comments
 (0)