103
103
/// twice on an instance.
105
105
/// <returns>the Ref after reset</returns>
106
/// <exception cref="System.IO.IOException"></exception>
106
/// <exception cref="NGit.Api.Errors.GitAPIException">NGit.Api.Errors.GitAPIException
108
/// <exception cref="NGit.Api.Errors.CheckoutConflictException"></exception>
107
109
public override Ref Call()
256
270
private void ResetIndexForPaths(RevCommit commit)
258
272
DirCache dc = null;
262
275
dc = repo.LockDirCache();
276
DirCacheBuilder builder = dc.Builder();
264
277
TreeWalk tw = new TreeWalk(repo);
265
tw.AddTree(new DirCacheIterator(dc));
278
tw.AddTree(new DirCacheBuildIterator(builder));
266
279
tw.AddTree(commit.Tree);
267
280
tw.Filter = PathFilterGroup.CreateFromStrings(filepaths);
268
281
tw.Recursive = true;
269
282
while (tw.Next())
271
string path = tw.PathString;
272
// DirCacheIterator dci = tw.getTree(0, DirCacheIterator.class);
273
284
CanonicalTreeParser tree = tw.GetTree<CanonicalTreeParser>(1);
276
// file is not in the commit, remove from index
277
edit.Add(new DirCacheEditor.DeletePath(path));
285
// only keep file in index if it's in the commit
281
288
// revert index to commit
282
// it seams that there is concurrent access to tree
283
// variable, therefore we need to keep references to
284
// entryFileMode and entryObjectId in local
286
FileMode entryFileMode = tree.EntryFileMode;
287
ObjectId entryObjectId = tree.EntryObjectId;
288
edit.Add(new _PathEdit_294(entryFileMode, entryObjectId, path));
289
DirCacheEntry entry = new DirCacheEntry(tw.RawPath);
290
entry.FileMode = tree.EntryFileMode;
291
entry.SetObjectId(tree.EntryObjectId);
293
297
catch (IOException e)
306
private sealed class _PathEdit_294 : DirCacheEditor.PathEdit
308
public _PathEdit_294(FileMode entryFileMode, ObjectId entryObjectId, string baseArg1
311
this.entryFileMode = entryFileMode;
312
this.entryObjectId = entryObjectId;
315
public override void Apply(DirCacheEntry ent)
317
ent.FileMode = entryFileMode;
318
ent.SetObjectId(entryObjectId);
319
ent.LastModified = 0;
322
private readonly FileMode entryFileMode;
324
private readonly ObjectId entryObjectId;
327
310
/// <exception cref="System.IO.IOException"></exception>
328
311
private void ResetIndex(RevCommit commit)
313
DirCache dc = repo.LockDirCache();
314
TreeWalk walk = null;
333
dc = repo.LockDirCache();
335
DirCacheBuilder dcb = dc.Builder();
336
dcb.AddTree(new byte[0], 0, repo.NewObjectReader(), commit.Tree);
339
catch (IOException e)
317
DirCacheBuilder builder = dc.Builder();
318
walk = new TreeWalk(repo);
319
walk.AddTree(commit.Tree);
320
walk.AddTree(new DirCacheIterator(dc));
321
walk.Recursive = true;
324
AbstractTreeIterator cIter = walk.GetTree<AbstractTreeIterator>(0);
327
// Not in commit, don't add to new index
330
DirCacheEntry entry = new DirCacheEntry(walk.RawPath);
331
entry.FileMode = cIter.EntryFileMode;
332
entry.SetObjectIdFromRaw(cIter.IdBuffer, cIter.IdOffset);
333
DirCacheIterator dcIter = walk.GetTree<DirCacheIterator>(1);
334
if (dcIter != null && dcIter.IdEqual(cIter))
336
DirCacheEntry indexEntry = dcIter.GetDirCacheEntry();
337
entry.LastModified = indexEntry.LastModified;
338
entry.SetLength(indexEntry.Length);
352
354
/// <exception cref="System.IO.IOException"></exception>
355
/// <exception cref="NGit.Api.Errors.GitAPIException"></exception>
353
356
private void CheckoutIndex(RevCommit commit)
358
DirCache dc = repo.LockDirCache();
358
dc = repo.LockDirCache();
359
361
DirCacheCheckout checkout = new DirCacheCheckout(repo, dc, commit.Tree);
360
362
checkout.SetFailOnConflict(false);
363
catch (IOException e)
367
catch (NGit.Errors.CheckoutConflictException cce)
369
throw new NGit.Api.Errors.CheckoutConflictException(checkout.GetConflicts(), cce);