Ejemplo n.º 1
0
        /// <summary>Detect index changes.</summary>
        /// <remarks>Detect index changes.</remarks>
        private void DetectIndexChanges()
        {
            if (IsBare)
            {
                return;
            }
            FilePath indexFile = GetIndexFile();

            if (snapshot == null)
            {
                snapshot = FileSnapshot.Save(indexFile);
            }
            else
            {
                if (snapshot.IsModified(indexFile))
                {
                    NotifyIndexChanged();
                }
            }
        }
 /// <returns>
 /// returns true if the currently loaded configuration file is older
 /// than the file on disk
 /// </returns>
 public virtual bool IsOutdated()
 {
     return(snapshot.IsModified(GetFile()));
 }
        /// <exception cref="System.IO.IOException"></exception>
        private RefDirectory.LooseRef ScanRef(RefDirectory.LooseRef @ref, string name)
        {
            FilePath     path            = FileFor(name);
            FileSnapshot currentSnapshot = null;

            if (@ref != null)
            {
                currentSnapshot = @ref.GetSnapShot();
                if (!currentSnapshot.IsModified(path))
                {
                    return(@ref);
                }
                name = @ref.GetName();
            }
            int limit = 4096;

            byte[]       buf;
            FileSnapshot otherSnapshot = FileSnapshot.Save(path);

            try
            {
                buf = IOUtil.ReadSome(path, limit);
            }
            catch (FileNotFoundException)
            {
                return(null);
            }
            // doesn't exist; not a reference.
            int n = buf.Length;

            if (n == 0)
            {
                return(null);
            }
            // empty file; not a reference.
            if (IsSymRef(buf, n))
            {
                if (n == limit)
                {
                    return(null);
                }
                // possibly truncated ref
                // trim trailing whitespace
                while (0 < n && char.IsWhiteSpace((char)buf[n - 1]))
                {
                    n--;
                }
                if (n < 6)
                {
                    string content = RawParseUtils.Decode(buf, 0, n);
                    throw new IOException(MessageFormat.Format(JGitText.Get().notARef, name, content)
                                          );
                }
                string target = RawParseUtils.Decode(buf, 5, n);
                if (@ref != null && @ref.IsSymbolic() && @ref.GetTarget().GetName().Equals(target
                                                                                           ))
                {
                    currentSnapshot.SetClean(otherSnapshot);
                    return(@ref);
                }
                return(NewSymbolicRef(otherSnapshot, name, target));
            }
            if (n < Constants.OBJECT_ID_STRING_LENGTH)
            {
                return(null);
            }
            // impossibly short object identifier; not a reference.
            ObjectId id;

            try
            {
                id = ObjectId.FromString(buf, 0);
                if (@ref != null && [email protected]() && @ref.GetTarget().GetObjectId().Equals(id
                                                                                                ))
                {
                    currentSnapshot.SetClean(otherSnapshot);
                    return(@ref);
                }
            }
            catch (ArgumentException)
            {
                while (0 < n && char.IsWhiteSpace((char)buf[n - 1]))
                {
                    n--;
                }
                string content = RawParseUtils.Decode(buf, 0, n);
                throw new IOException(MessageFormat.Format(JGitText.Get().notARef, name, content)
                                      );
            }
            return(new RefDirectory.LooseUnpeeled(otherSnapshot, name, id));
        }