/// <exception cref="System.IO.IOException"></exception> internal override ICollection <CachedPack> GetCachedPacks() { ObjectDirectory.CachedPackList list = cachedPacks.Get(); if (list == null || list.snapshot.IsModified(cachedPacksFile)) { list = ScanCachedPacks(list); } ICollection <CachedPack> result = list.GetCachedPacks(); bool resultIsCopy = false; foreach (FileObjectDatabase.AlternateHandle h in MyAlternates()) { ICollection <CachedPack> altPacks = h.GetCachedPacks(); if (altPacks.IsEmpty()) { continue; } if (result.IsEmpty()) { result = altPacks; continue; } if (!resultIsCopy) { result = new AList <CachedPack>(result); resultIsCopy = true; } Sharpen.Collections.AddAll(result, altPacks); } return(result); }
/// <exception cref="System.IO.IOException"></exception> private ObjectDirectory.CachedPackList ScanCachedPacks(ObjectDirectory.CachedPackList old) { FileSnapshot s = FileSnapshot.Save(cachedPacksFile); byte[] buf; try { buf = IOUtil.ReadFully(cachedPacksFile); } catch (FileNotFoundException) { buf = new byte[0]; } if (old != null && old.snapshot.Equals(s) && Arrays.Equals(old.raw, buf)) { old.snapshot.SetClean(s); return(old); } AList <LocalCachedPack> list = new AList <LocalCachedPack>(4); ICollection <ObjectId> tips = new HashSet <ObjectId>(); int ptr = 0; while (ptr < buf.Length) { if (buf[ptr] == '#' || buf[ptr] == '\n') { ptr = RawParseUtils.NextLF(buf, ptr); continue; } if (buf[ptr] == '+') { tips.AddItem(ObjectId.FromString(buf, ptr + 2)); ptr = RawParseUtils.NextLF(buf, ptr + 2); continue; } IList <string> names = new AList <string>(4); while (ptr < buf.Length && buf[ptr] == 'P') { int end = RawParseUtils.NextLF(buf, ptr); if (buf[end - 1] == '\n') { end--; } names.AddItem(RawParseUtils.Decode(buf, ptr + 2, end)); ptr = RawParseUtils.NextLF(buf, end); } if (!tips.IsEmpty() && !names.IsEmpty()) { list.AddItem(new LocalCachedPack(this, tips, names)); tips = new HashSet <ObjectId>(); } } list.TrimToSize(); return(new ObjectDirectory.CachedPackList(s, Sharpen.Collections.UnmodifiableList (list), buf)); }