Example #1
0
        /// <exception cref="System.IO.IOException"></exception>
        internal virtual void WriteTo(OutputStream os)
        {
            MessageDigest      foot = Constants.NewMessageDigest();
            DigestOutputStream dos  = new DigestOutputStream(os, foot);
            bool extended           = false;

            for (int i = 0; i < entryCnt; i++)
            {
                extended |= sortedEntries[i].IsExtended;
            }
            // Write the header.
            //
            byte[] tmp = new byte[128];
            System.Array.Copy(SIG_DIRC, 0, tmp, 0, SIG_DIRC.Length);
            NB.EncodeInt32(tmp, 4, extended ? 3 : 2);
            NB.EncodeInt32(tmp, 8, entryCnt);
            dos.Write(tmp, 0, 12);
            // Write the individual file entries.
            //
            if (snapshot == null)
            {
                // Write a new index, as no entries require smudging.
                //
                for (int i_1 = 0; i_1 < entryCnt; i_1++)
                {
                    sortedEntries[i_1].Write(dos);
                }
            }
            else
            {
                int smudge_s  = (int)(snapshot.LastModified() / 1000);
                int smudge_ns = ((int)(snapshot.LastModified() % 1000)) * 1000000;
                for (int i_1 = 0; i_1 < entryCnt; i_1++)
                {
                    DirCacheEntry e = sortedEntries[i_1];
                    if (e.MightBeRacilyClean(smudge_s, smudge_ns))
                    {
                        e.SmudgeRacilyClean();
                    }
                    e.Write(dos);
                }
            }
            if (tree != null)
            {
                TemporaryBuffer bb = new TemporaryBuffer.LocalFile();
                tree.Write(tmp, bb);
                bb.Close();
                NB.EncodeInt32(tmp, 0, EXT_TREE);
                NB.EncodeInt32(tmp, 4, (int)bb.Length());
                dos.Write(tmp, 0, 8);
                bb.WriteTo(dos, null);
            }
            os.Write(foot.Digest());
            os.Close();
        }
Example #2
0
        /// <exception cref="System.IO.IOException"></exception>
        private static byte[] ReadFully(InputStream @is)
        {
            TemporaryBuffer b = new TemporaryBuffer.LocalFile();

            try
            {
                b.Copy(@is);
                b.Close();
                return(b.ToByteArray());
            }
            finally
            {
                b.Destroy();
            }
        }
Example #3
0
 private string[] ExtractFileLines(Encoding[] csGuess)
 {
     TemporaryBuffer[] tmp = new TemporaryBuffer[GetParentCount() + 1];
     try
     {
         for (int i = 0; i < tmp.Length; i++)
         {
             tmp[i] = new TemporaryBuffer.LocalFile();
         }
         foreach (HunkHeader h in GetHunks())
         {
             h.ExtractFileLines(tmp);
         }
         string[] r = new string[tmp.Length];
         for (int i_1 = 0; i_1 < tmp.Length; i_1++)
         {
             Encoding cs = csGuess != null ? csGuess[i_1] : null;
             if (cs == null)
             {
                 cs = Constants.CHARSET;
             }
             r[i_1] = RawParseUtils.Decode(cs, tmp[i_1].ToByteArray());
         }
         return(r);
     }
     catch (IOException ioe)
     {
         throw new RuntimeException(JGitText.Get().cannotConvertScriptToText, ioe);
     }
     finally
     {
         foreach (TemporaryBuffer b in tmp)
         {
             if (b != null)
             {
                 b.Destroy();
             }
         }
     }
 }
Example #4
0
        /// <exception cref="System.IO.IOException"></exception>
        internal virtual void WriteTo(OutputStream os)
        {
            MessageDigest      foot = Constants.NewMessageDigest();
            DigestOutputStream dos  = new DigestOutputStream(os, foot);
            bool extended           = false;

            for (int i = 0; i < entryCnt; i++)
            {
                extended |= sortedEntries[i].IsExtended;
            }
            // Write the header.
            //
            byte[] tmp = new byte[128];
            System.Array.Copy(SIG_DIRC, 0, tmp, 0, SIG_DIRC.Length);
            NB.EncodeInt32(tmp, 4, extended ? 3 : 2);
            NB.EncodeInt32(tmp, 8, entryCnt);
            dos.Write(tmp, 0, 12);
            // Write the individual file entries.
            int smudge_s;
            int smudge_ns;

            if (myLock != null)
            {
                // For new files we need to smudge the index entry
                // if they have been modified "now". Ideally we'd
                // want the timestamp when we're done writing the index,
                // so we use the current timestamp as a approximation.
                myLock.CreateCommitSnapshot();
                snapshot  = myLock.GetCommitSnapshot();
                smudge_s  = (int)(snapshot.LastModified() / 1000);
                smudge_ns = ((int)(snapshot.LastModified() % 1000)) * 1000000;
            }
            else
            {
                // Used in unit tests only
                smudge_ns = 0;
                smudge_s  = 0;
            }
            // Check if tree is non-null here since calling updateSmudgedEntries
            // will automatically build it via creating a DirCacheIterator
            bool writeTree = tree != null;

            if (repository != null && entryCnt > 0)
            {
                UpdateSmudgedEntries();
            }
            for (int i_1 = 0; i_1 < entryCnt; i_1++)
            {
                DirCacheEntry e = sortedEntries[i_1];
                if (e.MightBeRacilyClean(smudge_s, smudge_ns))
                {
                    e.SmudgeRacilyClean();
                }
                e.Write(dos);
            }
            if (writeTree)
            {
                TemporaryBuffer bb = new TemporaryBuffer.LocalFile();
                tree.Write(tmp, bb);
                bb.Close();
                NB.EncodeInt32(tmp, 0, EXT_TREE);
                NB.EncodeInt32(tmp, 4, (int)bb.Length());
                dos.Write(tmp, 0, 8);
                bb.WriteTo(dos, null);
            }
            writeIndexChecksum = foot.Digest();
            os.Write(writeIndexChecksum);
            os.Close();
        }