/// <summary>Consume data from the input stream until the packfile is indexed.</summary> /// <remarks>Consume data from the input stream until the packfile is indexed.</remarks> /// <param name="progress">progress feedback</param> /// <exception cref="System.IO.IOException">System.IO.IOException</exception> public virtual void Index(ProgressMonitor progress) { progress.Start(2); try { try { ReadPackHeader(); entries = new PackedObjectInfo[(int)objectCount]; baseById = new ObjectIdSubclassMap<IndexPack.DeltaChain>(); baseByPos = new LongMap<IndexPack.UnresolvedDelta>(); deferredCheckBlobs = new AList<PackedObjectInfo>(); progress.BeginTask(JGitText.Get().receivingObjects, (int)objectCount); for (int done = 0; done < objectCount; done++) { IndexOneObject(); progress.Update(1); if (progress.IsCancelled()) { throw new IOException(JGitText.Get().downloadCancelled); } } ReadPackFooter(); EndInput(); if (!deferredCheckBlobs.IsEmpty()) { DoDeferredCheckBlobs(); } progress.EndTask(); if (deltaCount > 0) { if (packOut == null) { throw new IOException(JGitText.Get().needPackOut); } ResolveDeltas(progress); if (entryCount < objectCount) { if (!fixThin) { throw new IOException(MessageFormat.Format(JGitText.Get().packHasUnresolvedDeltas , (objectCount - entryCount))); } FixThinPack(progress); } } if (packOut != null && (keepEmpty || entryCount > 0)) { packOut.GetChannel().Force(true); } packDigest = null; baseById = null; baseByPos = null; if (dstIdx != null && (keepEmpty || entryCount > 0)) { WriteIdx(); } } finally { try { if (readCurs != null) { readCurs.Release(); } } finally { readCurs = null; } try { inflater.Release(); } finally { inflater = null; objectDatabase.Close(); } progress.EndTask(); if (packOut != null) { packOut.Close(); } } if (keepEmpty || entryCount > 0) { if (dstPack != null) { dstPack.SetReadOnly(); } if (dstIdx != null) { dstIdx.SetReadOnly(); } } } catch (IOException err) { if (dstPack != null) { FileUtils.Delete(dstPack); } if (dstIdx != null) { FileUtils.Delete(dstIdx); } throw; } }
/// <summary>Create a new pack indexer utility.</summary> /// <remarks>Create a new pack indexer utility.</remarks> /// <param name="db"></param> /// <param name="src"> /// stream to read the pack data from. If the stream is buffered /// use /// <see cref="BUFFER_SIZE">BUFFER_SIZE</see> /// as the buffer size for the stream. /// </param> /// <param name="dstBase"></param> /// <exception cref="System.IO.IOException">the output packfile could not be created. /// </exception> public IndexPack(Repository db, InputStream src, FilePath dstBase) { repo = db; objectDatabase = db.ObjectDatabase.NewCachedDatabase(); @in = src; inflater = new IndexPack.InflaterStream(this); readCurs = objectDatabase.NewReader(); buf = new byte[BUFFER_SIZE]; readBuffer = new byte[BUFFER_SIZE]; objectDigest = Constants.NewMessageDigest(); tempObjectId = new MutableObjectId(); packDigest = Constants.NewMessageDigest(); if (dstBase != null) { FilePath dir = dstBase.GetParentFile(); string nam = dstBase.GetName(); dstPack = new FilePath(dir, nam + ".pack"); dstIdx = new FilePath(dir, nam + ".idx"); packOut = new RandomAccessFile(dstPack, "rw"); packOut.SetLength(0); } else { dstPack = null; dstIdx = null; } }