|
1 | 1 | using FastFetch.Git; |
2 | 2 | using FastFetch.Jobs; |
3 | 3 | using GVFS.Common; |
| 4 | +using GVFS.Common.FileSystem; |
4 | 5 | using GVFS.Common.Git; |
5 | 6 | using GVFS.Common.Http; |
6 | 7 | using GVFS.Common.Tracing; |
@@ -129,6 +130,38 @@ public static bool TryLoadFileList(Enlistment enlistment, string filesInput, Lis |
129 | 130 | return true; |
130 | 131 | } |
131 | 132 |
|
| 133 | + public static void AppendToNewlineSeparatedFile(string filename, string newContent) |
| 134 | + { |
| 135 | + AppendToNewlineSeparatedFile(new PhysicalFileSystem(), filename, newContent); |
| 136 | + } |
| 137 | + |
| 138 | + public static void AppendToNewlineSeparatedFile(PhysicalFileSystem fileSystem, string filename, string newContent) |
| 139 | + { |
| 140 | + using (Stream fileStream = fileSystem.OpenFileStream(filename, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite, false)) |
| 141 | + { |
| 142 | + using (StreamReader reader = new StreamReader(fileStream)) |
| 143 | + using (StreamWriter writer = new StreamWriter(fileStream)) |
| 144 | + { |
| 145 | + long position = reader.BaseStream.Seek(0, SeekOrigin.End); |
| 146 | + if (position > 0) |
| 147 | + { |
| 148 | + reader.BaseStream.Seek(position - 1, SeekOrigin.Begin); |
| 149 | + } |
| 150 | + |
| 151 | + string lastCharacter = reader.ReadToEnd(); |
| 152 | + if (lastCharacter != "\n" && lastCharacter != string.Empty) |
| 153 | + { |
| 154 | + writer.Write("\n"); |
| 155 | + } |
| 156 | + |
| 157 | + writer.Write(newContent.Trim()); |
| 158 | + writer.Write("\n"); |
| 159 | + } |
| 160 | + |
| 161 | + fileStream.Close(); |
| 162 | + } |
| 163 | + } |
| 164 | + |
132 | 165 | /// <param name="branchOrCommit">A specific branch to filter for, or null for all branches returned from info/refs</param> |
133 | 166 | public virtual void FastFetch(string branchOrCommit, bool isBranch) |
134 | 167 | { |
@@ -198,12 +231,22 @@ public void FastFetchWithStats( |
198 | 231 | } |
199 | 232 | } |
200 | 233 |
|
201 | | - new Thread( |
202 | | - () => |
203 | | - { |
204 | | - blobEnumerator.PerformDiff(previousCommit, commitToFetch); |
205 | | - this.HasFailures |= blobEnumerator.HasFailures; |
206 | | - }).Start(); |
| 234 | + ThreadStart performDiff = () => |
| 235 | + { |
| 236 | + blobEnumerator.PerformDiff(previousCommit, commitToFetch); |
| 237 | + this.HasFailures |= blobEnumerator.HasFailures; |
| 238 | + }; |
| 239 | + |
| 240 | + if (readFilesAfterDownload) |
| 241 | + { |
| 242 | + // Call synchronously to ensure that blobEnumerator.FileAddOperations |
| 243 | + // is completely populated when ReadFilesJob starts |
| 244 | + performDiff(); |
| 245 | + } |
| 246 | + else |
| 247 | + { |
| 248 | + new Thread(performDiff).Start(); |
| 249 | + } |
207 | 250 |
|
208 | 251 | BlockingCollection<string> availableBlobs = new BlockingCollection<string>(); |
209 | 252 |
|
@@ -303,7 +346,7 @@ protected virtual void UpdateRefs(string branchOrCommit, bool isBranch, GitRefs |
303 | 346 | } |
304 | 347 |
|
305 | 348 | // Update shallow file to ensure this is a valid shallow repo |
306 | | - File.AppendAllText(Path.Combine(this.Enlistment.WorkingDirectoryRoot, GVFSConstants.DotGit.Shallow), commitSha + "\n"); |
| 349 | + AppendToNewlineSeparatedFile(Path.Combine(this.Enlistment.WorkingDirectoryRoot, GVFSConstants.DotGit.Shallow), commitSha); |
307 | 350 | } |
308 | 351 |
|
309 | 352 | protected bool UpdateRef(ITracer tracer, string refName, string targetCommitish) |
|
0 commit comments