Esempio n. 1
0
        private ObjectDirectory.PackList ScanPacksImpl(ObjectDirectory.PackList old)
        {
            IDictionary <string, PackFile> forReuse = ReuseMap(old);
            FileSnapshot         snapshot           = FileSnapshot.Save(packDirectory);
            ICollection <string> names = ListPackDirectory();
            IList <PackFile>     list  = new AList <PackFile>(names.Count >> 2);
            bool foundNew = false;

            foreach (string indexName in names)
            {
                // Must match "pack-[0-9a-f]{40}.idx" to be an index.
                //
                if (indexName.Length != 49 || !indexName.EndsWith(".idx"))
                {
                    continue;
                }
                string @base    = Sharpen.Runtime.Substring(indexName, 0, indexName.Length - 4);
                string packName = @base + ".pack";
                if (!names.Contains(packName))
                {
                    // Sometimes C Git's HTTP fetch transport leaves a
                    // .idx file behind and does not download the .pack.
                    // We have to skip over such useless indexes.
                    //
                    continue;
                }
                PackFile oldPack = Sharpen.Collections.Remove(forReuse, packName);
                if (oldPack != null)
                {
                    list.AddItem(oldPack);
                    continue;
                }
                FilePath packFile = new FilePath(packDirectory, packName);
                FilePath idxFile  = new FilePath(packDirectory, indexName);
                list.AddItem(new PackFile(idxFile, packFile));
                foundNew = true;
            }
            // If we did not discover any new files, the modification time was not
            // changed, and we did not remove any files, then the set of files is
            // the same as the set we were given. Instead of building a new object
            // return the same collection.
            //
            if (!foundNew && forReuse.IsEmpty() && snapshot.Equals(old.snapshot))
            {
                old.snapshot.SetClean(snapshot);
                return(old);
            }
            foreach (PackFile p in forReuse.Values)
            {
                p.Close();
            }
            if (list.IsEmpty())
            {
                return(new ObjectDirectory.PackList(snapshot, NO_PACKS.packs));
            }
            PackFile[] r = Sharpen.Collections.ToArray(list, new PackFile[list.Count]);
            Arrays.Sort(r, PackFile.SORT);
            return(new ObjectDirectory.PackList(snapshot, r));
        }
Esempio n. 2
0
        /// <summary>Load the configuration as a Git text style configuration file.</summary>
        /// <remarks>
        /// Load the configuration as a Git text style configuration file.
        /// <p>
        /// If the file does not exist, this configuration is cleared, and thus
        /// behaves the same as though the file exists, but is empty.
        /// </remarks>
        /// <exception cref="System.IO.IOException">the file could not be read (but does exist).
        ///     </exception>
        /// <exception cref="NGit.Errors.ConfigInvalidException">the file is not a properly formatted configuration file.
        ///     </exception>
        public override void Load()
        {
            FileSnapshot oldSnapshot = snapshot;
            FileSnapshot newSnapshot = FileSnapshot.Save(GetFile());

            try
            {
                byte[]   @in     = IOUtil.ReadFully(GetFile());
                ObjectId newHash = Hash(@in);
                if (hash.Equals(newHash))
                {
                    if (oldSnapshot.Equals(newSnapshot))
                    {
                        oldSnapshot.SetClean(newSnapshot);
                    }
                    else
                    {
                        snapshot = newSnapshot;
                    }
                }
                else
                {
                    string decoded;
                    if (@in.Length >= 3 && @in[0] == unchecked ((byte)unchecked ((int)(0xEF))) && @in[1
                        ] == unchecked ((byte)unchecked ((int)(0xBB))) && @in[2] == unchecked ((byte)unchecked (
                                                                                                   (int)(0xBF))))
                    {
                        decoded = RawParseUtils.Decode(RawParseUtils.UTF8_CHARSET, @in, 3, @in.Length);
                        utf8Bom = true;
                    }
                    else
                    {
                        decoded = RawParseUtils.Decode(@in);
                    }
                    FromText(decoded);
                    snapshot = newSnapshot;
                    hash     = newHash;
                }
            }
            catch (FileNotFoundException)
            {
                Clear();
                snapshot = newSnapshot;
            }
            catch (IOException e)
            {
                IOException e2 = new IOException(MessageFormat.Format(JGitText.Get().cannotReadFile
                                                                      , GetFile()));
                Sharpen.Extensions.InitCause(e2, e);
                throw e2;
            }
            catch (ConfigInvalidException e)
            {
                throw new ConfigInvalidException(MessageFormat.Format(JGitText.Get().cannotReadFile
                                                                      , GetFile()), e);
            }
        }
Esempio n. 3
0
        /// <summary>Wait until the lock file information differs from the old file.</summary>
        /// <remarks>
        /// Wait until the lock file information differs from the old file.
        /// <p>
        /// This method tests the last modification date. If both are the same, this
        /// method sleeps until it can force the new lock file's modification date to
        /// be later than the target file.
        /// </remarks>
        /// <exception cref="System.Exception">
        /// the thread was interrupted before the last modified date of
        /// the lock file was different from the last modified date of
        /// the target file.
        /// </exception>
        public virtual void WaitForStatChange()
        {
            FileSnapshot o = FileSnapshot.Save(@ref);
            FileSnapshot n = FileSnapshot.Save(lck);

            while (o.Equals(n))
            {
                Sharpen.Thread.Sleep(25);
                lck.SetLastModified(Runtime.CurrentTimeMillis());
                n = FileSnapshot.Save(lck);
            }
        }
        /// <summary>Load the configuration as a Git text style configuration file.</summary>
        /// <remarks>
        /// Load the configuration as a Git text style configuration file.
        /// <p>
        /// If the file does not exist, this configuration is cleared, and thus
        /// behaves the same as though the file exists, but is empty.
        /// </remarks>
        /// <exception cref="System.IO.IOException">the file could not be read (but does exist).
        ///     </exception>
        /// <exception cref="NGit.Errors.ConfigInvalidException">the file is not a properly formatted configuration file.
        ///     </exception>
        public override void Load()
        {
            FileSnapshot oldSnapshot = snapshot;
            FileSnapshot newSnapshot = FileSnapshot.Save(GetFile());

            try
            {
                byte[]   @in     = IOUtil.ReadFully(GetFile());
                ObjectId newHash = Hash(@in);
                if (hash.Equals(newHash))
                {
                    if (oldSnapshot.Equals(newSnapshot))
                    {
                        oldSnapshot.SetClean(newSnapshot);
                    }
                    else
                    {
                        snapshot = newSnapshot;
                    }
                }
                else
                {
                    FromText(RawParseUtils.Decode(@in));
                    snapshot = newSnapshot;
                    hash     = newHash;
                }
            }
            catch (FileNotFoundException)
            {
                Clear();
                snapshot = newSnapshot;
            }
            catch (IOException e)
            {
                IOException e2 = new IOException(MessageFormat.Format(JGitText.Get().cannotReadFile
                                                                      , GetFile()));
                Sharpen.Extensions.InitCause(e2, e);
                throw e2;
            }
            catch (ConfigInvalidException e)
            {
                throw new ConfigInvalidException(MessageFormat.Format(JGitText.Get().cannotReadFile
                                                                      , GetFile()), e);
            }
        }