|
1 | 1 | using System;
|
| 2 | +using System.IO; |
2 | 3 | using System.Linq;
|
3 | 4 | using System.Collections.Generic;
|
4 | 5 | using LibGit2Sharp.Core;
|
@@ -73,6 +74,43 @@ public void Connect()
|
73 | 74 | }
|
74 | 75 | }
|
75 | 76 |
|
| 77 | + public void Download(string path) |
| 78 | + { |
| 79 | + Ensure.ArgumentNotNullOrEmptyString(path, "path"); |
| 80 | + if (!Directory.Exists(path)) |
| 81 | + Directory.CreateDirectory(path); |
| 82 | + |
| 83 | + /* First, let's see what we want. At this point we don't send any haves */ |
| 84 | + Stream stream = new MemoryStream(); |
| 85 | + var writer = new StreamWriter(stream); |
| 86 | + foreach (PktRef p in Refs) { |
| 87 | + if (!Refspec.Matches(p.Name)) |
| 88 | + continue; |
| 89 | + |
| 90 | + writer.Write(Pkt.Line("want " + p.Id.Sha)); |
| 91 | + } |
| 92 | + /* Flush after the want lines */ |
| 93 | + writer.Write("0000"); |
| 94 | + /* We don't have anything locally, so just download the packfile */ |
| 95 | + writer.Write(Pkt.Line("done")); |
| 96 | + writer.Flush(); |
| 97 | + stream.Seek(0, SeekOrigin.Begin); |
| 98 | + transport.NegotiationStep(stream); |
| 99 | + |
| 100 | + stream = transport.GetStream(); |
| 101 | + var parser = new PktParser(stream); |
| 102 | + var pkt = parser.Next(); |
| 103 | + /* |
| 104 | + * For now, simply check that it's one or the other. After this, |
| 105 | + * the stream contains the pack data, so feed it to the indexer. |
| 106 | + */ |
| 107 | + if (!(pkt is PktAck || pkt is PktNak)) |
| 108 | + throw new GitProtocolException("Expected ACK or NAK, got neither"); |
| 109 | + |
| 110 | + var indexer = new Indexer(path); |
| 111 | + indexer.IndexStream(stream); |
| 112 | + } |
| 113 | + |
76 | 114 | private static readonly LambdaEqualityHelper<Remote> equalityHelper =
|
77 | 115 | new LambdaEqualityHelper<Remote>(new Func<Remote, object>[] { x => x.Name, x => x.Url });
|
78 | 116 |
|
|
0 commit comments