Skip to content

Commit c576d4f

Browse files
author
Edward Thomson
authored
Merge pull request libgit2#4115 from gsaralms/users/gsaral/optionalOfsDelta
Changes to provide option to turn off/on ofs_delta
2 parents 4f9f8e0 + 61acc9f commit c576d4f

File tree

4 files changed

+21
-1
lines changed

4 files changed

+21
-1
lines changed

include/git2/common.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ typedef enum {
178178
GIT_OPT_ENABLE_STRICT_SYMBOLIC_REF_CREATION,
179179
GIT_OPT_SET_SSL_CIPHERS,
180180
GIT_OPT_GET_USER_AGENT,
181+
GIT_OPT_ENABLE_OFS_DELTA,
181182
} git_libgit2_opt_t;
182183

183184
/**
@@ -305,6 +306,16 @@ typedef enum {
305306
* >
306307
* > - `ciphers` is the list of ciphers that are eanbled.
307308
*
309+
* * opts(GIT_OPT_ENABLE_OFS_DELTA, int enabled)
310+
*
311+
* > Enable or disable the use of "offset deltas" when creating packfiles,
312+
* > and the negotiation of them when talking to a remote server.
313+
* > Offset deltas store a delta base location as an offset into the
314+
* > packfile from the current location, which provides a shorter encoding
315+
* > and thus smaller resultant packfiles.
316+
* > Packfiles containing offset deltas can still be read.
317+
* > This defaults to enabled.
318+
*
308319
* @param option Option key
309320
* @param ... value to set the option
310321
* @return 0 on success, <0 on failure

src/settings.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "global.h"
1717
#include "object.h"
1818
#include "refs.h"
19+
#include "transports/smart.h"
1920

2021
void git_libgit2_version(int *major, int *minor, int *rev)
2122
{
@@ -222,6 +223,10 @@ int git_libgit2_opts(int key, ...)
222223
}
223224
break;
224225

226+
case GIT_OPT_ENABLE_OFS_DELTA:
227+
git_smart__ofs_delta_enabled = (va_arg(ap, int) != 0);
228+
break;
229+
225230
default:
226231
giterr_set(GITERR_INVALID, "invalid option key");
227232
error = -1;

src/transports/smart.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
#define GIT_CAP_THIN_PACK "thin-pack"
2727
#define GIT_CAP_SYMREF "symref"
2828

29+
extern bool git_smart__ofs_delta_enabled;
30+
2931
enum git_pkt_type {
3032
GIT_PKT_CMD,
3133
GIT_PKT_FLUSH,

src/transports/smart_protocol.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
/* The minimal interval between progress updates (in seconds). */
2020
#define MIN_PROGRESS_UPDATE_INTERVAL 0.5
2121

22+
bool git_smart__ofs_delta_enabled = true;
23+
2224
int git_smart__store_refs(transport_smart *t, int flushes)
2325
{
2426
gitno_buffer *buf = &t->buffer;
@@ -138,7 +140,7 @@ int git_smart__detect_caps(git_pkt_ref *pkt, transport_smart_caps *caps, git_vec
138140
if (*ptr == ' ')
139141
ptr++;
140142

141-
if (!git__prefixcmp(ptr, GIT_CAP_OFS_DELTA)) {
143+
if (git_smart__ofs_delta_enabled && !git__prefixcmp(ptr, GIT_CAP_OFS_DELTA)) {
142144
caps->common = caps->ofs_delta = 1;
143145
ptr += strlen(GIT_CAP_OFS_DELTA);
144146
continue;

0 commit comments

Comments
 (0)