/// <exception cref="System.IO.FileNotFoundException"></exception> private PackFile GetPackFile(string packName) { foreach (PackFile pack in odb.GetPacks()) { if (packName.Equals(pack.GetPackName())) { return(pack); } } throw new FileNotFoundException(GetPackFilePath(packName)); }
/// <summary> /// Like "git prune-packed" this method tries to prune all loose objects /// which can be found in packs. /// </summary> /// <remarks> /// Like "git prune-packed" this method tries to prune all loose objects /// which can be found in packs. If certain objects can't be pruned (e.g. /// because the filesystem delete operation fails) this is silently ignored. /// </remarks> /// <exception cref="System.IO.IOException">System.IO.IOException</exception> public virtual void PrunePacked() { ObjectDirectory objdb = ((ObjectDirectory)repo.ObjectDatabase); ICollection <PackFile> packs = objdb.GetPacks(); FilePath objects = repo.ObjectsDirectory; string[] fanout = objects.List(); if (fanout != null && fanout.Length > 0) { pm.BeginTask(JGitText.Get().pruneLoosePackedObjects, fanout.Length); try { foreach (string d in fanout) { pm.Update(1); if (d.Length != 2) { continue; } string[] entries = new FilePath(objects, d).List(); if (entries == null) { continue; } foreach (string e in entries) { if (e.Length != Constants.OBJECT_ID_STRING_LENGTH - 2) { continue; } ObjectId id; try { id = ObjectId.FromString(d + e); } catch (ArgumentException) { // ignoring the file that does not represent loose // object continue; } bool found = false; foreach (PackFile p in packs) { if (p.HasObject(id)) { found = true; break; } } if (found) { FileUtils.Delete(objdb.FileFor(id), FileUtils.RETRY | FileUtils.SKIP_MISSING | FileUtils .IGNORE_ERRORS); } } } } finally { pm.EndTask(); } } }