コード例 #1
0
        /// <summary>Save the configuration as a Git text style configuration file.</summary>
        /// <remarks>
        /// Save the configuration as a Git text style configuration file.
        /// <p>
        /// <b>Warning:</b> Although this method uses the traditional Git file
        /// locking approach to protect against concurrent writes of the
        /// configuration file, it does not ensure that the file has not been
        /// modified since the last read, which means updates performed by other
        /// objects accessing the same backing file may be lost.
        /// </remarks>
        /// <exception cref="System.IO.IOException">the file could not be written.</exception>
        public override void Save()
        {
            byte[]   @out = Constants.Encode(ToText());
            LockFile lf   = new LockFile(GetFile(), fs);

            if (!lf.Lock())
            {
                throw new LockFailedException(GetFile());
            }
            try
            {
                lf.SetNeedSnapshot(true);
                lf.Write(@out);
                if (!lf.Commit())
                {
                    throw new IOException(MessageFormat.Format(JGitText.Get().cannotCommitWriteTo, GetFile
                                                                   ()));
                }
            }
            finally
            {
                lf.Unlock();
            }
            snapshot = lf.GetCommitSnapshot();
            hash     = Hash(@out);
            // notify the listeners
            FireConfigChangedEvent();
        }
コード例 #2
0
        /// <exception cref="System.IO.IOException"></exception>
        private RefDirectory.PackedRefList ReadPackedRefs()
        {
            FileSnapshot   snapshot = FileSnapshot.Save(packedRefsFile);
            BufferedReader br;
            MessageDigest  digest = Constants.NewMessageDigest();

            try
            {
                br = new BufferedReader(new InputStreamReader(new DigestInputStream(new FileInputStream
                                                                                        (packedRefsFile), digest), Constants.CHARSET));
            }
            catch (FileNotFoundException)
            {
                // Ignore it and leave the new list empty.
                return(RefDirectory.PackedRefList.NO_PACKED_REFS);
            }
            try
            {
                return(new RefDirectory.PackedRefList(ParsePackedRefs(br), snapshot, ObjectId.FromRaw
                                                          (digest.Digest())));
            }
            finally
            {
                br.Close();
            }
        }
コード例 #3
0
 /// <summary>The constructor</summary>
 /// <param name="base">the base configuration file</param>
 /// <param name="cfgLocation">the location of the configuration file on the file system
 ///     </param>
 /// <param name="fs">
 /// the file system abstraction which will be necessary to perform
 /// certain file system operations.
 /// </param>
 public FileBasedConfig(Config @base, FilePath cfgLocation, FS fs) : base(@base)
 {
     configFile    = cfgLocation;
     this.fs       = fs;
     this.snapshot = FileSnapshot.DIRTY;
     this.hash     = ObjectId.ZeroId;
 }
コード例 #4
0
ファイル: LockFile.cs プロジェクト: shoff/ngit
 private void SaveStatInformation()
 {
     if (needSnapshot)
     {
         commitSnapshot = FileSnapshot.Save(lck);
     }
 }
コード例 #5
0
        internal virtual void Stored(RefDirectoryUpdate update, FileSnapshot snapshot)
        {
            ObjectId target = update.GetNewObjectId().Copy();
            Ref      leaf   = update.GetRef().GetLeaf();

            PutLooseRef(new RefDirectory.LooseUnpeeled(snapshot, leaf.GetName(), target));
        }
コード例 #6
0
 /// <summary>Create a repository using the local file system.</summary>
 /// <remarks>Create a repository using the local file system.</remarks>
 /// <param name="options">description of the repository's important paths.</param>
 /// <exception cref="System.IO.IOException">
 /// the user configuration file or repository configuration file
 /// cannot be accessed.
 /// </exception>
 protected internal FileRepository(BaseRepositoryBuilder options) : base(options)
 {
     systemConfig = SystemReader.GetInstance().OpenSystemConfig(null, FileSystem);
     userConfig   = SystemReader.GetInstance().OpenUserConfig(systemConfig, FileSystem);
     repoConfig   = new FileBasedConfig(userConfig, FileSystem.Resolve(Directory, Constants
                                                                       .CONFIG), FileSystem);
     LoadSystemConfig();
     LoadUserConfig();
     LoadRepoConfig();
     repoConfig.AddChangeListener(new _ConfigChangedListener_171(this));
     refs           = new RefDirectory(this);
     objectDatabase = new ObjectDirectory(repoConfig, options.GetObjectDirectory(), options
                                          .GetAlternateObjectDirectories(), FileSystem);
     //
     //
     //
     if (objectDatabase.Exists())
     {
         long repositoryFormatVersion = ((FileBasedConfig)GetConfig()).GetLong(ConfigConstants
                                                                               .CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_REPO_FORMAT_VERSION, 0);
         if (repositoryFormatVersion > 0)
         {
             throw new IOException(MessageFormat.Format(JGitText.Get().unknownRepositoryFormat2
                                                        , Sharpen.Extensions.ValueOf(repositoryFormatVersion)));
         }
     }
     if (!IsBare)
     {
         snapshot = FileSnapshot.Save(GetIndexFile());
     }
 }
コード例 #7
0
        private static RefDirectory.LooseSymbolicRef NewSymbolicRef(FileSnapshot snapshot
                                                                    , string name, string target)
        {
            Ref dst = new ObjectIdRef.Unpeeled(RefStorage.NEW, target, null);

            return(new RefDirectory.LooseSymbolicRef(snapshot, name, dst));
        }
コード例 #8
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));
        }
コード例 #9
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);
            }
        }
コード例 #10
0
        /// <exception cref="System.IO.IOException"></exception>
        private ObjectDirectory.CachedPackList ScanCachedPacks(ObjectDirectory.CachedPackList
                                                               old)
        {
            FileSnapshot s = FileSnapshot.Save(cachedPacksFile);

            byte[] buf;
            try
            {
                buf = IOUtil.ReadFully(cachedPacksFile);
            }
            catch (FileNotFoundException)
            {
                buf = new byte[0];
            }
            if (old != null && old.snapshot.Equals(s) && Arrays.Equals(old.raw, buf))
            {
                old.snapshot.SetClean(s);
                return(old);
            }
            AList <LocalCachedPack> list = new AList <LocalCachedPack>(4);
            ICollection <ObjectId>  tips = new HashSet <ObjectId>();
            int ptr = 0;

            while (ptr < buf.Length)
            {
                if (buf[ptr] == '#' || buf[ptr] == '\n')
                {
                    ptr = RawParseUtils.NextLF(buf, ptr);
                    continue;
                }
                if (buf[ptr] == '+')
                {
                    tips.AddItem(ObjectId.FromString(buf, ptr + 2));
                    ptr = RawParseUtils.NextLF(buf, ptr + 2);
                    continue;
                }
                IList <string> names = new AList <string>(4);
                while (ptr < buf.Length && buf[ptr] == 'P')
                {
                    int end = RawParseUtils.NextLF(buf, ptr);
                    if (buf[end - 1] == '\n')
                    {
                        end--;
                    }
                    names.AddItem(RawParseUtils.Decode(buf, ptr + 2, end));
                    ptr = RawParseUtils.NextLF(buf, end);
                }
                if (!tips.IsEmpty() && !names.IsEmpty())
                {
                    list.AddItem(new LocalCachedPack(this, tips, names));
                    tips = new HashSet <ObjectId>();
                }
            }
            list.TrimToSize();
            return(new ObjectDirectory.CachedPackList(s, Sharpen.Collections.UnmodifiableList
                                                          (list), buf));
        }
コード例 #11
0
        public virtual void TestOldFile()
        {
            FilePath f1 = CreateFile("oldfile");

            WaitNextSec(f1);
            FileSnapshot save = FileSnapshot.Save(f1);

            Sharpen.Thread.Sleep(3500);
            NUnit.Framework.Assert.IsFalse(save.IsModified(f1));
        }
コード例 #12
0
        public virtual void TestNewFileNoWait()
        {
            FilePath f1 = CreateFile("newfile");

            WaitNextSec(f1);
            FileSnapshot save = FileSnapshot.Save(f1);

            Sharpen.Thread.Sleep(1500);
            NUnit.Framework.Assert.IsTrue(save.IsModified(f1));
        }
コード例 #13
0
        public virtual void TestActuallyIsModifiedTrivial()
        {
            FilePath f1 = CreateFile("simple");

            WaitNextSec(f1);
            FileSnapshot save = FileSnapshot.Save(f1);

            Append(f1, unchecked ((byte)'x'));
            WaitNextSec(f1);
            NUnit.Framework.Assert.IsTrue(save.IsModified(f1));
        }
コード例 #14
0
ファイル: LockFile.cs プロジェクト: shoff/ngit
        /// <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);
            }
        }
コード例 #15
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
                {
                    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);
            }
        }
コード例 #16
0
        /// <summary>Save the configuration as a Git text style configuration file.</summary>
        /// <remarks>
        /// Save the configuration as a Git text style configuration file.
        /// <p>
        /// <b>Warning:</b> Although this method uses the traditional Git file
        /// locking approach to protect against concurrent writes of the
        /// configuration file, it does not ensure that the file has not been
        /// modified since the last read, which means updates performed by other
        /// objects accessing the same backing file may be lost.
        /// </remarks>
        /// <exception cref="System.IO.IOException">the file could not be written.</exception>
        public override void Save()
        {
            byte[] @out;
            string text = ToText();

            if (utf8Bom)
            {
                ByteArrayOutputStream bos = new ByteArrayOutputStream();
                bos.Write(unchecked ((int)(0xEF)));
                bos.Write(unchecked ((int)(0xBB)));
                bos.Write(unchecked ((int)(0xBF)));
                bos.Write(Sharpen.Runtime.GetBytesForString(text, RawParseUtils.UTF8_CHARSET.Name
                                                                ()));
                @out = bos.ToByteArray();
            }
            else
            {
                @out = Constants.Encode(text);
            }
            LockFile lf = new LockFile(GetFile(), fs);

            if (!lf.Lock())
            {
                throw new LockFailedException(GetFile());
            }
            try
            {
                lf.SetNeedSnapshot(true);
                lf.Write(@out);
                if (!lf.Commit())
                {
                    throw new IOException(MessageFormat.Format(JGitText.Get().cannotCommitWriteTo, GetFile
                                                                   ()));
                }
            }
            finally
            {
                lf.Unlock();
            }
            snapshot = lf.GetCommitSnapshot();
            hash     = Hash(@out);
            // notify the listeners
            FireConfigChangedEvent();
        }
コード例 #17
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();
                }
            }
        }
コード例 #18
0
ファイル: FileBasedConfig.cs プロジェクト: LunarLanding/ngit
		/// <summary>The constructor</summary>
		/// <param name="base">the base configuration file</param>
		/// <param name="cfgLocation">the location of the configuration file on the file system
		/// 	</param>
		/// <param name="fs">
		/// the file system abstraction which will be necessary to perform
		/// certain file system operations.
		/// </param>
		public FileBasedConfig(Config @base, FilePath cfgLocation, FS fs) : base(@base)
		{
			configFile = cfgLocation;
			this.fs = fs;
			this.snapshot = FileSnapshot.DIRTY;
			this.hash = ObjectId.ZeroId;
		}
コード例 #19
0
ファイル: FileBasedConfig.cs プロジェクト: LunarLanding/ngit
		/// <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);
			}
		}
コード例 #20
0
ファイル: FileBasedConfig.cs プロジェクト: LunarLanding/ngit
		/// <summary>Save the configuration as a Git text style configuration file.</summary>
		/// <remarks>
		/// Save the configuration as a Git text style configuration file.
		/// <p>
		/// <b>Warning:</b> Although this method uses the traditional Git file
		/// locking approach to protect against concurrent writes of the
		/// configuration file, it does not ensure that the file has not been
		/// modified since the last read, which means updates performed by other
		/// objects accessing the same backing file may be lost.
		/// </remarks>
		/// <exception cref="System.IO.IOException">the file could not be written.</exception>
		public override void Save()
		{
			byte[] @out;
			string text = ToText();
			if (utf8Bom)
			{
				ByteArrayOutputStream bos = new ByteArrayOutputStream();
				bos.Write(unchecked((int)(0xEF)));
				bos.Write(unchecked((int)(0xBB)));
				bos.Write(unchecked((int)(0xBF)));
				bos.Write(Sharpen.Runtime.GetBytesForString(text, RawParseUtils.UTF8_CHARSET.Name
					()));
				@out = bos.ToByteArray();
			}
			else
			{
				@out = Constants.Encode(text);
			}
			LockFile lf = new LockFile(GetFile(), fs);
			if (!lf.Lock())
			{
				throw new LockFailedException(GetFile());
			}
			try
			{
				lf.SetNeedSnapshot(true);
				lf.Write(@out);
				if (!lf.Commit())
				{
					throw new IOException(MessageFormat.Format(JGitText.Get().cannotCommitWriteTo, GetFile
						()));
				}
			}
			finally
			{
				lf.Unlock();
			}
			snapshot = lf.GetCommitSnapshot();
			hash = Hash(@out);
			// notify the listeners
			FireConfigChangedEvent();
		}
コード例 #21
0
 internal LooseSymbolicRef(FileSnapshot snapshot, string refName, Ref target) : base
         (refName, target)
 {
     this.snapShot = snapshot;
 }
コード例 #22
0
 internal LooseUnpeeled(FileSnapshot snapShot, string refName, ObjectId id) : base
         (RefStorage.LOOSE, refName, id)
 {
     this.snapShot = snapShot;
 }
コード例 #23
0
 internal PackList(FileSnapshot monitor, PackFile[] packs)
 {
     this.snapshot = monitor;
     this.packs    = packs;
 }
コード例 #24
0
 internal virtual void StoredSymbolicRef(RefDirectoryUpdate u, FileSnapshot snapshot
                                         , string target)
 {
     PutLooseRef(NewSymbolicRef(snapshot, u.GetRef().GetName(), target));
     FireRefsChanged();
 }
コード例 #25
0
			internal PackList(FileSnapshot monitor, PackFile[] packs)
			{
				this.snapshot = monitor;
				this.packs = packs;
			}
コード例 #26
0
ファイル: FileRepository.cs プロジェクト: kenji-tan/ngit
 /// <summary>Create a repository using the local file system.</summary>
 /// <remarks>Create a repository using the local file system.</remarks>
 /// <param name="options">description of the repository's important paths.</param>
 /// <exception cref="System.IO.IOException">
 /// the user configuration file or repository configuration file
 /// cannot be accessed.
 /// </exception>
 protected internal FileRepository(BaseRepositoryBuilder options)
     : base(options)
 {
     systemConfig = SystemReader.GetInstance().OpenSystemConfig(null, FileSystem);
     userConfig = SystemReader.GetInstance().OpenUserConfig(systemConfig, FileSystem);
     repoConfig = new FileBasedConfig(userConfig, FileSystem.Resolve(Directory, Constants
         .CONFIG), FileSystem);
     LoadSystemConfig();
     LoadUserConfig();
     LoadRepoConfig();
     repoConfig.AddChangeListener(new _ConfigChangedListener_171(this));
     refs = new RefDirectory(this);
     objectDatabase = new ObjectDirectory(repoConfig, options.GetObjectDirectory(), options
         .GetAlternateObjectDirectories(), FileSystem);
     //
     //
     //
     if (objectDatabase.Exists())
     {
         long repositoryFormatVersion = ((FileBasedConfig)GetConfig()).GetLong(ConfigConstants
             .CONFIG_CORE_SECTION, null, ConfigConstants.CONFIG_KEY_REPO_FORMAT_VERSION, 0);
         if (repositoryFormatVersion > 0)
         {
             throw new IOException(MessageFormat.Format(JGitText.Get().unknownRepositoryFormat2
                 , Sharpen.Extensions.ValueOf(repositoryFormatVersion)));
         }
     }
     if (!IsBare)
     {
         snapshot = FileSnapshot.Save(GetIndexFile());
     }
 }
コード例 #27
0
ファイル: FileRepository.cs プロジェクト: kenji-tan/ngit
 public override void NotifyIndexChanged()
 {
     snapshot = FileSnapshot.Save(GetIndexFile());
     FireEvent(new IndexChangedEvent());
 }
コード例 #28
0
			internal CachedPackList(FileSnapshot sn, IList<LocalCachedPack> list, byte[] buf)
			{
				snapshot = sn;
				packs = list;
				raw = buf;
			}
コード例 #29
0
ファイル: FileRepository.cs プロジェクト: kenji-tan/ngit
 /// <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();
         }
     }
 }
コード例 #30
0
ファイル: FileBasedConfig.cs プロジェクト: kenji-tan/ngit
 /// <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);
     }
 }
コード例 #31
0
ファイル: FileBasedConfig.cs プロジェクト: kenji-tan/ngit
 /// <summary>Save the configuration as a Git text style configuration file.</summary>
 /// <remarks>
 /// Save the configuration as a Git text style configuration file.
 /// <p>
 /// <b>Warning:</b> Although this method uses the traditional Git file
 /// locking approach to protect against concurrent writes of the
 /// configuration file, it does not ensure that the file has not been
 /// modified since the last read, which means updates performed by other
 /// objects accessing the same backing file may be lost.
 /// </remarks>
 /// <exception cref="System.IO.IOException">the file could not be written.</exception>
 public override void Save()
 {
     byte[] @out = Constants.Encode(ToText());
     LockFile lf = new LockFile(GetFile(), fs);
     if (!lf.Lock())
     {
         throw new LockFailedException(GetFile());
     }
     try
     {
         lf.SetNeedSnapshot(true);
         lf.Write(@out);
         if (!lf.Commit())
         {
             throw new IOException(MessageFormat.Format(JGitText.Get().cannotCommitWriteTo, GetFile
                 ()));
         }
     }
     finally
     {
         lf.Unlock();
     }
     snapshot = lf.GetCommitSnapshot();
     hash = Hash(@out);
     // notify the listeners
     FireConfigChangedEvent();
 }
コード例 #32
0
 internal LoosePeeledTag(FileSnapshot snapshot, string refName, ObjectId id, ObjectId
                         p) : base(RefStorage.LOOSE, refName, id, p)
 {
     this.snapShot = snapshot;
 }
コード例 #33
0
        /// <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));
        }
コード例 #34
0
 internal CachedPackList(FileSnapshot sn, IList <LocalCachedPack> list, byte[] buf)
 {
     snapshot = sn;
     packs    = list;
     raw      = buf;
 }
コード例 #35
0
 public override void NotifyIndexChanged()
 {
     snapshot = FileSnapshot.Save(GetIndexFile());
     FireEvent(new IndexChangedEvent());
 }
コード例 #36
0
ファイル: LockFile.cs プロジェクト: kenji-tan/ngit
 private void SaveStatInformation()
 {
     if (needSnapshot)
     {
         commitSnapshot = FileSnapshot.Save(lck);
     }
 }
コード例 #37
0
 internal PackedRefList(RefList <Ref> src, FileSnapshot s, ObjectId i) : base(src)
 {
     snapshot = s;
     id       = i;
 }