Skip to content

Commit 082ad21

Browse files
committed
Remote: keep track of protocol capabilitites
For now we only deal with ofs-delta, but this paves the way for the side-band{,-64k}.
1 parent 1e5e637 commit 082ad21

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

LibGit2Sharp/LibGit2Sharp.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@
171171
<Compile Include="Refspec.cs" />
172172
<Compile Include="GitProtocolException.cs" />
173173
<Compile Include="Core\Compat\StreamExtensions.cs" />
174+
<Compile Include="ProtocolCapabilities.cs" />
174175
</ItemGroup>
175176
<ItemGroup>
176177
<CodeAnalysisDictionary Include="CustomDictionary.xml" />

LibGit2Sharp/ProtocolCapabilities.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using System;
2+
using System.Linq;
3+
4+
namespace LibGit2Sharp
5+
{
6+
public class ProtocolCapabilities
7+
{
8+
public readonly bool OfsDelta;
9+
public readonly bool Sideband;
10+
public readonly bool Sideband64k;
11+
12+
private readonly string OfsDeltaStr = "ofs-delta";
13+
private readonly string SidebandStr = "side-band";
14+
private readonly string Sideband64kStr = "side-band-64k";
15+
16+
public ProtocolCapabilities(string str)
17+
{
18+
var caps = str.Split();
19+
20+
OfsDelta = caps.Contains(OfsDeltaStr);
21+
Sideband = caps.Contains(SidebandStr);
22+
Sideband64k = caps.Contains(Sideband64kStr);
23+
}
24+
25+
public string Common
26+
{
27+
get {
28+
/* Only this one for now */
29+
return OfsDelta ? OfsDeltaStr : "";
30+
}
31+
}
32+
}
33+
}
34+

LibGit2Sharp/Remote.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public class Remote : IEquatable<Remote>
1919
private Lazy<IEnumerable<string>> refnames;
2020
private Lazy<IEnumerable<string>> matching_refs;
2121
private Indexer indexer;
22+
private ProtocolCapabilities caps;
2223

2324
/* Mostly so that the already-existing code doesn't break */
2425
public Remote()
@@ -73,6 +74,9 @@ public void Connect()
7374
if (pkt is PktError)
7475
throw new GitProtocolException((pkt as PktError).Error);
7576
}
77+
78+
/* Figure out what capabilities we have in common */
79+
caps = new ProtocolCapabilities(Refs[0].CapString);
7680
}
7781

7882
public IndexerStats Stats
@@ -94,11 +98,17 @@ public void Download(string path)
9498
/* First, let's see what we want. At this point we don't send any haves */
9599
Stream stream = new MemoryStream();
96100
var writer = new StreamWriter(stream);
101+
bool first = true;
97102
foreach (PktRef p in Refs) {
98103
if (!Refspec.Matches(p.Name))
99104
continue;
100105

101-
writer.Write(Pkt.Line("want " + p.Id.Sha));
106+
if (first) {
107+
writer.Write(Pkt.Line("want " + p.Id.Sha + " " + caps.Common));
108+
first = false;
109+
} else {
110+
writer.Write(Pkt.Line("want " + p.Id.Sha));
111+
}
102112
}
103113
/* Flush after the want lines */
104114
writer.Write("0000");

0 commit comments

Comments
 (0)