2
This code is derived from jgit (http://eclipse.org/jgit).
3
Copyright owners are documented in jgit's IP log.
5
This program and the accompanying materials are made available
6
under the terms of the Eclipse Distribution License v1.0 which
7
accompanies this distribution, is reproduced below, and is
8
available at http://www.eclipse.org/org/documents/edl-v10.php
12
Redistribution and use in source and binary forms, with or
13
without modification, are permitted provided that the following
16
- Redistributions of source code must retain the above copyright
17
notice, this list of conditions and the following disclaimer.
19
- Redistributions in binary form must reproduce the above
20
copyright notice, this list of conditions and the following
21
disclaimer in the documentation and/or other materials provided
22
with the distribution.
24
- Neither the name of the Eclipse Foundation, Inc. nor the
25
names of its contributors may be used to endorse or promote
26
products derived from this software without specific prior
29
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
30
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
31
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
32
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
33
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
34
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
35
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
36
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
37
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
38
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
40
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
41
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45
using System.Collections.Generic;
52
using NGit.Storage.File;
56
namespace NGit.Storage.File
58
[NUnit.Framework.TestFixture]
59
public class GCTest : LocalDiskRepositoryTestCase
61
private TestRepository<FileRepository> tr;
63
private FileRepository repo;
67
private GC.RepoStatistics stats;
69
/// <exception cref="System.Exception"></exception>
70
[NUnit.Framework.SetUp]
71
public override void SetUp()
74
repo = CreateWorkRepository();
75
tr = new TestRepository<FileRepository>((repo));
79
/// <exception cref="System.Exception"></exception>
80
[NUnit.Framework.TearDown]
81
public override void TearDown()
87
/// <exception cref="System.Exception"></exception>
88
[NUnit.Framework.Test]
89
public virtual void PackRefs_looseRefPacked()
91
RevBlob a = tr.Blob("a");
92
tr.LightweightTag("t", a);
94
NUnit.Framework.Assert.AreEqual(repo.GetRef("t").GetStorage(), RefStorage.PACKED);
97
/// <exception cref="System.Exception"></exception>
98
[NUnit.Framework.Test]
99
public virtual void ConcurrentPackRefs_onlyOneWritesPackedRefs()
101
RevBlob a = tr.Blob("a");
102
tr.LightweightTag("t", a);
103
CyclicBarrier syncPoint = new CyclicBarrier(2);
104
Callable<int> packRefs = new _Callable_131(this, syncPoint);
105
ExecutorService pool = Executors.NewFixedThreadPool(2);
108
Future<int> p1 = pool.Submit(packRefs);
109
Future<int> p2 = pool.Submit(packRefs);
110
NUnit.Framework.Assert.AreEqual(1, p1.Get() + p2.Get());
115
pool.AwaitTermination(long.MaxValue, TimeUnit.SECONDS);
119
private sealed class _Callable_131 : Callable<int>
121
public _Callable_131(GCTest _enclosing, CyclicBarrier syncPoint)
123
this._enclosing = _enclosing;
124
this.syncPoint = syncPoint;
127
/// <returns>0 for success, 1 in case of error when writing pack</returns>
128
/// <exception cref="System.Exception"></exception>
134
this._enclosing.gc.PackRefs();
135
return Sharpen.Extensions.ValueOf(0);
139
return Sharpen.Extensions.ValueOf(1);
143
private readonly GCTest _enclosing;
145
private readonly CyclicBarrier syncPoint;
148
/// <exception cref="System.Exception"></exception>
149
[NUnit.Framework.Test]
150
public virtual void PackRefsWhileRefLocked_refNotPackedNoError()
152
RevBlob a = tr.Blob("a");
153
tr.LightweightTag("t1", a);
154
tr.LightweightTag("t2", a);
155
LockFile refLock = new LockFile(new FilePath(repo.Directory, "refs/tags/t1"), repo
166
NUnit.Framework.Assert.AreEqual(repo.GetRef("refs/tags/t1").GetStorage(), RefStorage
168
NUnit.Framework.Assert.AreEqual(repo.GetRef("refs/tags/t2").GetStorage(), RefStorage
172
/// <exception cref="System.Exception"></exception>
173
[NUnit.Framework.Test]
174
public virtual void PackRefsWhileRefUpdated_refUpdateSucceeds()
176
RevBlob a = tr.Blob("a");
177
tr.LightweightTag("t", a);
178
RevBlob b = tr.Blob("b");
179
CyclicBarrier refUpdateLockedRef = new CyclicBarrier(2);
180
CyclicBarrier packRefsDone = new CyclicBarrier(2);
181
ExecutorService pool = Executors.NewFixedThreadPool(2);
184
Future<RefUpdate.Result> result = pool.Submit(new _Callable_185(this, b, refUpdateLockedRef
186
pool.Submit<object>(new _Callable_210(this, refUpdateLockedRef, packRefsDone));
187
NUnit.Framework.Assert.AreEqual(result.Get(), RefUpdate.Result.FORCED);
192
pool.AwaitTermination(long.MaxValue, TimeUnit.SECONDS);
194
NUnit.Framework.Assert.AreEqual(repo.GetRef("refs/tags/t").GetObjectId(), b);
197
private sealed class _Callable_185 : Callable<RefUpdate.Result>
199
public _Callable_185(GCTest _enclosing, RevBlob b, CyclicBarrier refUpdateLockedRef
200
, CyclicBarrier packRefsDone)
202
this._enclosing = _enclosing;
204
this.refUpdateLockedRef = refUpdateLockedRef;
205
this.packRefsDone = packRefsDone;
208
/// <exception cref="System.Exception"></exception>
209
public RefUpdate.Result Call()
211
RefUpdate update = new _RefDirectoryUpdate_190(refUpdateLockedRef, packRefsDone,
212
(RefDirectory)this._enclosing.repo.RefDatabase, this._enclosing.repo.GetRef("refs/tags/t"
214
update.SetForceUpdate(true);
215
update.SetNewObjectId(b);
216
return update.Update();
219
private sealed class _RefDirectoryUpdate_190 : RefDirectoryUpdate
221
public _RefDirectoryUpdate_190(CyclicBarrier refUpdateLockedRef, CyclicBarrier packRefsDone
222
, RefDirectory baseArg1, Ref baseArg2) : base(baseArg1, baseArg2)
224
this.refUpdateLockedRef = refUpdateLockedRef;
225
this.packRefsDone = packRefsDone;
228
public override bool IsForceUpdate()
232
refUpdateLockedRef.Await();
233
packRefsDone.Await();
237
Sharpen.Thread.CurrentThread().Interrupt();
239
return base.IsForceUpdate();
242
private readonly CyclicBarrier refUpdateLockedRef;
244
private readonly CyclicBarrier packRefsDone;
247
private readonly GCTest _enclosing;
249
private readonly RevBlob b;
251
private readonly CyclicBarrier refUpdateLockedRef;
253
private readonly CyclicBarrier packRefsDone;
256
private sealed class _Callable_210 : Callable<object>
258
public _Callable_210(GCTest _enclosing, CyclicBarrier refUpdateLockedRef, CyclicBarrier
261
this._enclosing = _enclosing;
262
this.refUpdateLockedRef = refUpdateLockedRef;
263
this.packRefsDone = packRefsDone;
266
/// <exception cref="System.Exception"></exception>
269
refUpdateLockedRef.Await();
270
this._enclosing.gc.PackRefs();
271
packRefsDone.Await();
275
private readonly GCTest _enclosing;
277
private readonly CyclicBarrier refUpdateLockedRef;
279
private readonly CyclicBarrier packRefsDone;
283
/// <exception cref="System.IO.IOException"></exception>
284
[NUnit.Framework.Test]
285
public virtual void RepackEmptyRepo_noPackCreated()
288
NUnit.Framework.Assert.AreEqual(0, ((ObjectDirectory)repo.ObjectDatabase).GetPacks
292
/// <exception cref="System.Exception"></exception>
293
[NUnit.Framework.Test]
294
public virtual void ConcurrentRepack()
297
// leave the syncPoint in broken state so any awaiting
298
// threads and any threads that call await in the future get
299
// the BrokenBarrierException
301
CyclicBarrier syncPoint = new CyclicBarrier(1);
302
RevBlob a = tr.Blob("a");
303
tr.LightweightTag("t", a);
304
ExecutorService pool = Executors.NewFixedThreadPool(2);
307
_T187790690 repack1 = new _T187790690(this) { syncPoint = syncPoint };
308
//_T187790690 repack2 = new _T187790690(this) { syncPoint = syncPoint };
309
Future<int> result1 = pool.Submit(repack1);
310
//Future<int> result2 = pool.Submit(repack2);
311
NUnit.Framework.Assert.AreEqual(0, result1.Get());// + result2.Get());
316
pool.AwaitTermination(long.MaxValue, TimeUnit.SECONDS);
320
internal class _T187790690 : EmptyProgressMonitor, Callable<int>
322
public CyclicBarrier syncPoint;
323
public override void BeginTask(string title, int totalWork)
325
if (title.Equals(JGitText.Get().writingObjects))
333
Sharpen.Thread.CurrentThread().Interrupt();
338
/// <returns>0 for success, 1 in case of error when writing pack</returns>
339
/// <exception cref="System.Exception"></exception>
340
public virtual int Call()
344
this._enclosing.gc.SetProgressMonitor(this);
345
this._enclosing.gc.Repack();
346
return Sharpen.Extensions.ValueOf(0);
350
Sharpen.Thread.CurrentThread().Interrupt();
358
return Sharpen.Extensions.ValueOf(1);
362
internal _T187790690(GCTest _enclosing)
364
this._enclosing = _enclosing;
367
private readonly GCTest _enclosing;
371
/// <exception cref="System.Exception"></exception>
372
[NUnit.Framework.Test]
373
public virtual void NonReferencedNonExpiredObject_notPruned()
375
RevBlob a = tr.Blob("a");
376
gc.SetExpire(Sharpen.Extensions.CreateDate(LastModified(a)));
377
gc.Prune(Collections.EmptySet<ObjectId>());
378
NUnit.Framework.Assert.IsTrue(repo.HasObject(a));
381
/// <exception cref="System.Exception"></exception>
382
[NUnit.Framework.Test]
383
public virtual void NonReferencedExpiredObject_pruned()
385
RevBlob a = tr.Blob("a");
386
gc.SetExpireAgeMillis(0);
387
gc.Prune(Collections.EmptySet<ObjectId>());
388
NUnit.Framework.Assert.IsFalse(repo.HasObject(a));
391
/// <exception cref="System.Exception"></exception>
392
[NUnit.Framework.Test]
393
public virtual void NonReferencedExpiredObjectTree_pruned()
395
RevBlob a = tr.Blob("a");
396
RevTree t = tr.Tree(tr.File("a", a));
397
gc.SetExpireAgeMillis(0);
398
gc.Prune(Collections.EmptySet<ObjectId>());
399
NUnit.Framework.Assert.IsFalse(repo.HasObject(t));
400
NUnit.Framework.Assert.IsFalse(repo.HasObject(a));
403
/// <exception cref="System.Exception"></exception>
404
[NUnit.Framework.Test]
405
public virtual void NonReferencedObjects_onlyExpiredPruned()
407
RevBlob a = tr.Blob("a");
408
gc.SetExpire(Sharpen.Extensions.CreateDate(LastModified(a) + 1));
410
RevBlob b = tr.Blob("b");
411
gc.Prune(Collections.EmptySet<ObjectId>());
412
NUnit.Framework.Assert.IsFalse(repo.HasObject(a));
413
NUnit.Framework.Assert.IsTrue(repo.HasObject(b));
416
/// <exception cref="System.Exception"></exception>
417
[NUnit.Framework.Test]
418
public virtual void LightweightTag_objectNotPruned()
420
RevBlob a = tr.Blob("a");
421
tr.LightweightTag("t", a);
422
gc.SetExpireAgeMillis(0);
423
gc.Prune(Collections.EmptySet<ObjectId>());
424
NUnit.Framework.Assert.IsTrue(repo.HasObject(a));
427
/// <exception cref="System.Exception"></exception>
428
[NUnit.Framework.Test]
429
public virtual void AnnotatedTag_objectNotPruned()
431
RevBlob a = tr.Blob("a");
432
RevTag t = tr.Tag("t", a);
433
// this doesn't create the refs/tags/t ref
434
tr.LightweightTag("t", t);
435
gc.SetExpireAgeMillis(0);
436
gc.Prune(Collections.EmptySet<ObjectId>());
437
NUnit.Framework.Assert.IsTrue(repo.HasObject(t));
438
NUnit.Framework.Assert.IsTrue(repo.HasObject(a));
441
/// <exception cref="System.Exception"></exception>
442
[NUnit.Framework.Test]
443
public virtual void Branch_historyNotPruned()
445
RevCommit tip = CommitChain(10);
446
tr.Branch("b").Update(tip);
447
gc.SetExpireAgeMillis(0);
448
gc.Prune(Collections.EmptySet<ObjectId>());
451
NUnit.Framework.Assert.IsTrue(repo.HasObject(tip));
453
RevTree t = tip.Tree;
454
NUnit.Framework.Assert.IsTrue(repo.HasObject(t));
455
NUnit.Framework.Assert.IsTrue(repo.HasObject(tr.Get(t, "a")));
456
tip = tip.ParentCount > 0 ? tip.GetParent(0) : null;
461
/// <exception cref="System.Exception"></exception>
462
[NUnit.Framework.Test]
463
public virtual void DeleteBranch_historyPruned()
465
RevCommit tip = CommitChain(10);
466
tr.Branch("b").Update(tip);
467
RefUpdate update = repo.UpdateRef("refs/heads/b");
468
update.SetForceUpdate(true);
470
gc.SetExpireAgeMillis(0);
471
gc.Prune(Collections.EmptySet<ObjectId>());
472
NUnit.Framework.Assert.IsTrue(gc.GetStatistics().numberOfLooseObjects == 0);
475
/// <exception cref="System.Exception"></exception>
476
[NUnit.Framework.Test]
477
public virtual void DeleteMergedBranch_historyNotPruned()
479
RevCommit parent = tr.Commit().Create();
480
RevCommit b1Tip = tr.Branch("b1").Commit().Parent(parent).Add("x", "x").Create();
481
RevCommit b2Tip = tr.Branch("b2").Commit().Parent(parent).Add("y", "y").Create();
482
// merge b1Tip and b2Tip and update refs/heads/b1 to the merge commit
483
Merger merger = ((ThreeWayMerger)MergeStrategy.SIMPLE_TWO_WAY_IN_CORE.NewMerger(repo
485
merger.Merge(b1Tip, b2Tip);
486
NGit.Junit.CommitBuilder cb = tr.Commit();
487
cb.Parent(b1Tip).Parent(b2Tip);
488
cb.SetTopLevelTree(merger.GetResultTreeId());
489
RevCommit mergeCommit = cb.Create();
490
RefUpdate u = repo.UpdateRef("refs/heads/b1");
491
u.SetNewObjectId(mergeCommit);
493
RefUpdate update = repo.UpdateRef("refs/heads/b2");
494
update.SetForceUpdate(true);
496
gc.SetExpireAgeMillis(0);
497
gc.Prune(Collections.EmptySet<ObjectId>());
498
NUnit.Framework.Assert.IsTrue(repo.HasObject(b2Tip));
501
/// <exception cref="System.Exception"></exception>
502
[NUnit.Framework.Test]
503
public virtual void TestPackAllObjectsInOnePack()
505
tr.Branch("refs/heads/master").Commit().Add("A", "A").Add("B", "B").Create();
506
stats = gc.GetStatistics();
507
NUnit.Framework.Assert.AreEqual(4, stats.numberOfLooseObjects);
508
NUnit.Framework.Assert.AreEqual(0, stats.numberOfPackedObjects);
510
stats = gc.GetStatistics();
511
NUnit.Framework.Assert.AreEqual(0, stats.numberOfLooseObjects);
512
NUnit.Framework.Assert.AreEqual(4, stats.numberOfPackedObjects);
513
NUnit.Framework.Assert.AreEqual(1, stats.numberOfPackFiles);
516
/// <exception cref="System.Exception"></exception>
517
[NUnit.Framework.Test]
518
public virtual void TestKeepFiles()
520
BranchBuilder bb = tr.Branch("refs/heads/master");
521
bb.Commit().Add("A", "A").Add("B", "B").Create();
522
stats = gc.GetStatistics();
523
NUnit.Framework.Assert.AreEqual(4, stats.numberOfLooseObjects);
524
NUnit.Framework.Assert.AreEqual(0, stats.numberOfPackedObjects);
525
NUnit.Framework.Assert.AreEqual(0, stats.numberOfPackFiles);
527
stats = gc.GetStatistics();
528
NUnit.Framework.Assert.AreEqual(0, stats.numberOfLooseObjects);
529
NUnit.Framework.Assert.AreEqual(4, stats.numberOfPackedObjects);
530
NUnit.Framework.Assert.AreEqual(1, stats.numberOfPackFiles);
531
Iterator<PackFile> packIt = ((ObjectDirectory)repo.ObjectDatabase).GetPacks().Iterator
533
PackFile singlePack = packIt.Next();
534
NUnit.Framework.Assert.IsFalse(packIt.HasNext());
535
FilePath keepFile = new FilePath(singlePack.GetPackFile().GetPath() + ".keep");
536
NUnit.Framework.Assert.IsFalse(keepFile.Exists());
537
NUnit.Framework.Assert.IsTrue(keepFile.CreateNewFile());
538
bb.Commit().Add("A", "A2").Add("B", "B2").Create();
539
stats = gc.GetStatistics();
540
NUnit.Framework.Assert.AreEqual(4, stats.numberOfLooseObjects);
541
NUnit.Framework.Assert.AreEqual(4, stats.numberOfPackedObjects);
542
NUnit.Framework.Assert.AreEqual(1, stats.numberOfPackFiles);
544
stats = gc.GetStatistics();
545
NUnit.Framework.Assert.AreEqual(0, stats.numberOfLooseObjects);
546
NUnit.Framework.Assert.AreEqual(8, stats.numberOfPackedObjects);
547
NUnit.Framework.Assert.AreEqual(2, stats.numberOfPackFiles);
548
// check that no object is packed twice
549
Iterator<PackFile> packs = ((ObjectDirectory)repo.ObjectDatabase).GetPacks().Iterator
551
PackIndex ind1 = packs.Next().GetIndex();
552
NUnit.Framework.Assert.AreEqual(4, ind1.GetObjectCount());
553
PackIndex ind2 = packs.Next().GetIndex();
554
NUnit.Framework.Assert.AreEqual(4, ind2.GetObjectCount());
555
foreach (PackIndex.MutableEntry e in ind1)
557
if (ind2.HasObject(e.ToObjectId()))
559
NUnit.Framework.Assert.IsFalse(ind2.HasObject(e.ToObjectId()), "the following object is in both packfiles: "
565
/// <exception cref="System.Exception"></exception>
566
[NUnit.Framework.Test]
567
public virtual void TestPackRepoWithNoRefs()
569
tr.Commit().Add("A", "A").Add("B", "B").Create();
570
stats = gc.GetStatistics();
571
NUnit.Framework.Assert.AreEqual(4, stats.numberOfLooseObjects);
572
NUnit.Framework.Assert.AreEqual(0, stats.numberOfPackedObjects);
574
stats = gc.GetStatistics();
575
NUnit.Framework.Assert.AreEqual(4, stats.numberOfLooseObjects);
576
NUnit.Framework.Assert.AreEqual(0, stats.numberOfPackedObjects);
577
NUnit.Framework.Assert.AreEqual(0, stats.numberOfPackFiles);
580
/// <exception cref="System.Exception"></exception>
581
[NUnit.Framework.Test]
582
public virtual void TestPack2Commits()
584
BranchBuilder bb = tr.Branch("refs/heads/master");
585
bb.Commit().Add("A", "A").Add("B", "B").Create();
586
bb.Commit().Add("A", "A2").Add("B", "B2").Create();
587
stats = gc.GetStatistics();
588
NUnit.Framework.Assert.AreEqual(8, stats.numberOfLooseObjects);
589
NUnit.Framework.Assert.AreEqual(0, stats.numberOfPackedObjects);
591
stats = gc.GetStatistics();
592
NUnit.Framework.Assert.AreEqual(0, stats.numberOfLooseObjects);
593
NUnit.Framework.Assert.AreEqual(8, stats.numberOfPackedObjects);
594
NUnit.Framework.Assert.AreEqual(1, stats.numberOfPackFiles);
597
/// <exception cref="System.Exception"></exception>
598
[NUnit.Framework.Test]
599
public virtual void TestPackCommitsAndLooseOne()
601
BranchBuilder bb = tr.Branch("refs/heads/master");
602
RevCommit first = bb.Commit().Add("A", "A").Add("B", "B").Create();
603
bb.Commit().Add("A", "A2").Add("B", "B2").Create();
604
tr.Update("refs/heads/master", first);
605
stats = gc.GetStatistics();
606
NUnit.Framework.Assert.AreEqual(8, stats.numberOfLooseObjects);
607
NUnit.Framework.Assert.AreEqual(0, stats.numberOfPackedObjects);
609
stats = gc.GetStatistics();
610
NUnit.Framework.Assert.AreEqual(0, stats.numberOfLooseObjects);
611
NUnit.Framework.Assert.AreEqual(8, stats.numberOfPackedObjects);
612
NUnit.Framework.Assert.AreEqual(2, stats.numberOfPackFiles);
615
/// <exception cref="System.Exception"></exception>
616
[NUnit.Framework.Test]
617
public virtual void TestNotPackTwice()
619
BranchBuilder bb = tr.Branch("refs/heads/master");
620
RevCommit first = bb.Commit().Message("M").Add("M", "M").Create();
621
bb.Commit().Message("B").Add("B", "Q").Create();
622
bb.Commit().Message("A").Add("A", "A").Create();
623
RevCommit second = tr.Commit().Parent(first).Message("R").Add("R", "Q").Create();
624
tr.Update("refs/tags/t1", second);
625
ICollection<PackFile> oldPacks = ((ObjectDirectory)tr.GetRepository().ObjectDatabase
627
NUnit.Framework.Assert.AreEqual(0, oldPacks.Count);
628
stats = gc.GetStatistics();
629
NUnit.Framework.Assert.AreEqual(11, stats.numberOfLooseObjects);
630
NUnit.Framework.Assert.AreEqual(0, stats.numberOfPackedObjects);
631
gc.SetExpireAgeMillis(0);
633
stats = gc.GetStatistics();
634
NUnit.Framework.Assert.AreEqual(0, stats.numberOfLooseObjects);
635
Iterator<PackFile> pIt = ((ObjectDirectory)repo.ObjectDatabase).GetPacks().Iterator
637
long c = pIt.Next().GetObjectCount();
640
NUnit.Framework.Assert.AreEqual(2, pIt.Next().GetObjectCount());
644
NUnit.Framework.Assert.AreEqual(2, c);
645
NUnit.Framework.Assert.AreEqual(9, pIt.Next().GetObjectCount());
649
/// <exception cref="System.Exception"></exception>
650
[NUnit.Framework.Test]
651
public virtual void TestPackCommitsAndLooseOneNoReflog()
653
BranchBuilder bb = tr.Branch("refs/heads/master");
654
RevCommit first = bb.Commit().Add("A", "A").Add("B", "B").Create();
655
bb.Commit().Add("A", "A2").Add("B", "B2").Create();
656
tr.Update("refs/heads/master", first);
657
stats = gc.GetStatistics();
658
NUnit.Framework.Assert.AreEqual(8, stats.numberOfLooseObjects);
659
NUnit.Framework.Assert.AreEqual(0, stats.numberOfPackedObjects);
660
FileUtils.Delete(new FilePath(repo.Directory, "logs/HEAD"), FileUtils.RETRY | FileUtils
662
FileUtils.Delete(new FilePath(repo.Directory, "logs/refs/heads/master"), FileUtils
663
.RETRY | FileUtils.SKIP_MISSING);
665
stats = gc.GetStatistics();
666
NUnit.Framework.Assert.AreEqual(4, stats.numberOfLooseObjects);
667
NUnit.Framework.Assert.AreEqual(4, stats.numberOfPackedObjects);
668
NUnit.Framework.Assert.AreEqual(1, stats.numberOfPackFiles);
671
/// <exception cref="System.Exception"></exception>
672
[NUnit.Framework.Test]
673
public virtual void TestPackCommitsAndLooseOneWithPruneNow()
675
BranchBuilder bb = tr.Branch("refs/heads/master");
676
RevCommit first = bb.Commit().Add("A", "A").Add("B", "B").Create();
677
bb.Commit().Add("A", "A2").Add("B", "B2").Create();
678
tr.Update("refs/heads/master", first);
679
stats = gc.GetStatistics();
680
NUnit.Framework.Assert.AreEqual(8, stats.numberOfLooseObjects);
681
NUnit.Framework.Assert.AreEqual(0, stats.numberOfPackedObjects);
682
gc.SetExpireAgeMillis(0);
684
stats = gc.GetStatistics();
685
NUnit.Framework.Assert.AreEqual(0, stats.numberOfLooseObjects);
686
NUnit.Framework.Assert.AreEqual(8, stats.numberOfPackedObjects);
687
NUnit.Framework.Assert.AreEqual(2, stats.numberOfPackFiles);
690
/// <exception cref="System.Exception"></exception>
691
[NUnit.Framework.Test]
692
public virtual void TestPackCommitsAndLooseOneWithPruneNowNoReflog()
694
BranchBuilder bb = tr.Branch("refs/heads/master");
695
RevCommit first = bb.Commit().Add("A", "A").Add("B", "B").Create();
696
bb.Commit().Add("A", "A2").Add("B", "B2").Create();
697
tr.Update("refs/heads/master", first);
698
stats = gc.GetStatistics();
699
NUnit.Framework.Assert.AreEqual(8, stats.numberOfLooseObjects);
700
NUnit.Framework.Assert.AreEqual(0, stats.numberOfPackedObjects);
701
FileUtils.Delete(new FilePath(repo.Directory, "logs/HEAD"), FileUtils.RETRY | FileUtils
703
FileUtils.Delete(new FilePath(repo.Directory, "logs/refs/heads/master"), FileUtils
704
.RETRY | FileUtils.SKIP_MISSING);
705
gc.SetExpireAgeMillis(0);
707
stats = gc.GetStatistics();
708
NUnit.Framework.Assert.AreEqual(0, stats.numberOfLooseObjects);
709
NUnit.Framework.Assert.AreEqual(4, stats.numberOfPackedObjects);
710
NUnit.Framework.Assert.AreEqual(1, stats.numberOfPackFiles);
713
/// <exception cref="System.Exception"></exception>
714
[NUnit.Framework.Test]
715
public virtual void TestIndexSavesObjects()
717
BranchBuilder bb = tr.Branch("refs/heads/master");
718
bb.Commit().Add("A", "A").Add("B", "B").Create();
719
bb.Commit().Add("A", "A2").Add("B", "B2").Create();
720
bb.Commit().Add("A", "A3");
721
// this new content in index should survive
722
stats = gc.GetStatistics();
723
NUnit.Framework.Assert.AreEqual(9, stats.numberOfLooseObjects);
724
NUnit.Framework.Assert.AreEqual(0, stats.numberOfPackedObjects);
726
stats = gc.GetStatistics();
727
NUnit.Framework.Assert.AreEqual(1, stats.numberOfLooseObjects);
728
NUnit.Framework.Assert.AreEqual(8, stats.numberOfPackedObjects);
729
NUnit.Framework.Assert.AreEqual(1, stats.numberOfPackFiles);
732
/// <exception cref="System.Exception"></exception>
733
[NUnit.Framework.Test]
734
public virtual void TestIndexSavesObjectsWithPruneNow()
736
BranchBuilder bb = tr.Branch("refs/heads/master");
737
bb.Commit().Add("A", "A").Add("B", "B").Create();
738
bb.Commit().Add("A", "A2").Add("B", "B2").Create();
739
bb.Commit().Add("A", "A3");
740
// this new content in index should survive
741
stats = gc.GetStatistics();
742
NUnit.Framework.Assert.AreEqual(9, stats.numberOfLooseObjects);
743
NUnit.Framework.Assert.AreEqual(0, stats.numberOfPackedObjects);
744
gc.SetExpireAgeMillis(0);
746
stats = gc.GetStatistics();
747
NUnit.Framework.Assert.AreEqual(0, stats.numberOfLooseObjects);
748
NUnit.Framework.Assert.AreEqual(8, stats.numberOfPackedObjects);
749
NUnit.Framework.Assert.AreEqual(1, stats.numberOfPackFiles);
752
/// <exception cref="System.Exception"></exception>
753
[NUnit.Framework.Test]
754
public virtual void TestPruneNone()
756
BranchBuilder bb = tr.Branch("refs/heads/master");
757
bb.Commit().Add("A", "A").Add("B", "B").Create();
758
bb.Commit().Add("A", "A2").Add("B", "B2").Create();
759
new FilePath(repo.Directory, Constants.LOGS + "/refs/heads/master").Delete();
760
stats = gc.GetStatistics();
761
NUnit.Framework.Assert.AreEqual(8, stats.numberOfLooseObjects);
762
gc.SetExpireAgeMillis(0);
763
gc.Prune(Sharpen.Collections.EmptySet<ObjectId>());
764
stats = gc.GetStatistics();
765
NUnit.Framework.Assert.AreEqual(8, stats.numberOfLooseObjects);
767
stats = gc.GetStatistics();
768
NUnit.Framework.Assert.AreEqual(9, stats.numberOfLooseObjects);
769
gc.Prune(Sharpen.Collections.EmptySet<ObjectId>());
770
stats = gc.GetStatistics();
771
NUnit.Framework.Assert.AreEqual(8, stats.numberOfLooseObjects);
774
/// <summary>Create a chain of commits of given depth.</summary>
776
/// Create a chain of commits of given depth.
778
/// Each commit contains one file named "a" containing the index of the
779
/// commit in the chain as its content. The created commit chain is
780
/// referenced from any ref.
782
/// A chain of depth = N will create 3*N objects in Gits object database. For
783
/// each depth level three objects are created: the commit object, the
784
/// top-level tree object and a blob for the content of the file "a".
786
/// <param name="depth">the depth of the commit chain.</param>
787
/// <returns>the commit that is the tip of the commit chain</returns>
788
/// <exception cref="System.Exception">System.Exception</exception>
789
private RevCommit CommitChain(int depth)
793
throw new ArgumentException("Chain depth must be > 0");
795
NGit.Junit.CommitBuilder cb = tr.Commit();
800
tip = cb.Add("a", string.Empty + depth).Message(string.Empty + depth).Create();
807
private long LastModified(AnyObjectId objectId)
809
return ((ObjectDirectory)repo.ObjectDatabase).FileFor(objectId).LastModified();
812
/// <exception cref="System.Exception"></exception>
813
/// <exception cref="System.IO.IOException"></exception>
814
private static void FsTick()
816
RepositoryTestCase.FsTick(null);