コード例 #1
0
ファイル: PackLock.cs プロジェクト: stephensong/GitSharp
 /**
  * Create the <code>pack-*.keep</code> file, with the given message.
  *
  * @param msg
  *            message to store in the file.
  * @return true if the keep file was successfully written; false otherwise.
  * @throws IOException
  *             the keep file could not be written.
  */
 public bool Lock(string msg)
 {
     if (msg == null) return false;
     if (!msg.EndsWith("\n")) msg += "\n";
     LockFile lf = new LockFile(keepFile);
     if (!lf.Lock()) return false;
     lf.Write(Constants.encode(msg));
     return lf.Commit();
 }
コード例 #2
0
ファイル: RefDatabase.cs プロジェクト: Squelch/GitSharp
        private static void LockAndWriteFile(FileInfo file, byte[] content)
        {
            string name = file.Name;
            var lck = new LockFile(file);
            if (!lck.Lock())
            {
                throw new ObjectWritingException("Unable to lock " + name);
            }

            try
            {
                lck.Write(content);
            }
            catch (IOException ioe)
            {
                throw new ObjectWritingException("Unable to write " + name, ioe);
            }
            if (!lck.Commit())
            {
                throw new ObjectWritingException("Unable to write " + name);
            }
        }
コード例 #3
0
ファイル: RefUpdate.cs プロジェクト: gilran/GitSharp
        private RefUpdateResult updateImpl(RevWalk.RevWalk walk, StoreBase store)
        {
            LockFile @lock;
            RevObject newObj;
            RevObject oldObj;

            @lock = new LockFile(looseFile);
            if ([email protected]())
                return RefUpdateResult.LockFailure;
            try
            {
                OldObjectId = db.IdOf(Name);
                if (expValue != null)
                {
                    ObjectId o;
                    o = OldObjectId != null ? OldObjectId : ObjectId.ZeroId;
                    if (!expValue.Equals(o))
                        return RefUpdateResult.LockFailure;
                }
                if (OldObjectId == null)
                    return store.Store(@lock, RefUpdateResult.New);

                newObj = safeParse(walk, newValue);
                oldObj = safeParse(walk, OldObjectId);
                if (newObj == oldObj)
                    return store.Store(@lock, RefUpdateResult.NoChange);

                if (newObj is RevCommit && oldObj is RevCommit)
                {
                    if (walk.isMergedInto((RevCommit)oldObj, (RevCommit)newObj))
                        return store.Store(@lock, RefUpdateResult.FastForward);
                }

                if (IsForceUpdate)
                    return store.Store(@lock, RefUpdateResult.Forced);
                return RefUpdateResult.Rejected;
            }
            finally
            {
                @lock.Unlock();
            }
        }
コード例 #4
0
 public void save()
 {
     byte[] o = Constants.encode(toText());
     LockFile lf = new LockFile(getFile());
     if (!lf.Lock())
         throw new IOException("Cannot lock " + getFile());
     try
     {
         lf.Write(o);
         if (!lf.Commit())
             throw new IOException("Cannot commit write to " + getFile());
     }
     finally
     {
         lf.Unlock();
     }
 }
コード例 #5
0
ファイル: RefUpdate.cs プロジェクト: HackerBaloo/GitSharp
        private RefUpdateResult UpdateImpl(RevWalk.RevWalk walk, StoreBase store)
        {
            int lastSlash = Name.LastIndexOf('/');
            if (lastSlash > 0)
            {
                if (Repository.getAllRefs().ContainsKey(Name.Slice(0, lastSlash)))
                {
                    return RefUpdateResult.LockFailure;
                }
            }

            string rName = Name + "/";
            foreach (Ref r in Repository.getAllRefs().Values)
            {
                if (r.Name.StartsWith(rName))
                {
                    return RefUpdateResult.LockFailure;
                }
            }

            var @lock = new LockFile(_looseFile);
            if ([email protected]())
            {
                return RefUpdateResult.LockFailure;
            }

            try
            {
                OldObjectId = _db.IdOf(Name);
                if (_expValue != null)
                {
                    ObjectId o = OldObjectId ?? ObjectId.ZeroId;
                    if (!_expValue.Equals(o))
                    {
                        return RefUpdateResult.LockFailure;
                    }
                }

                if (OldObjectId == null)
                {
                    return store.Store(@lock, RefUpdateResult.New);
                }

                RevObject newObj = SafeParse(walk, _newValue);
                RevObject oldObj = SafeParse(walk, OldObjectId);
                if (newObj == oldObj)
                {
                    return store.Store(@lock, RefUpdateResult.NoChange);
                }

                if (newObj is RevCommit && oldObj is RevCommit)
                {
                    if (walk.isMergedInto((RevCommit)oldObj, (RevCommit)newObj))
                    {
                        return store.Store(@lock, RefUpdateResult.FastForward);
                    }
                }

                if (IsForceUpdate)
                {
                    return store.Store(@lock, RefUpdateResult.Forced);
                }

                return RefUpdateResult.Rejected;
            }
            finally
            {
                @lock.Unlock();
            }
        }
コード例 #6
0
ファイル: RefUpdate.cs プロジェクト: drothmaler/GitSharp
        private RefUpdateResult UpdateImpl(RevWalk.RevWalk walk, StoreBase store)
        {
            if (IsNameConflicting())
            {
                return RefUpdateResult.LockFailure;
            }

            var @lock = new LockFile(_looseFile);
            if ([email protected]())
            {
                return RefUpdateResult.LockFailure;
            }

            try
            {
                OldObjectId = _db.IdOf(Name);
                if (_expValue != null)
                {
                    ObjectId o = OldObjectId ?? ObjectId.ZeroId;
                    if (!AnyObjectId.equals(_expValue, o))
                    {
                        return RefUpdateResult.LockFailure;
                    }
                }

                if (OldObjectId == null)
                {
                    return store.Store(@lock, RefUpdateResult.New);
                }

                RevObject newObj = SafeParse(walk, _newValue);
                RevObject oldObj = SafeParse(walk, OldObjectId);
                if (newObj == oldObj)
                {
                    return store.Store(@lock, RefUpdateResult.NoChange);
                }

                if (newObj is RevCommit && oldObj is RevCommit)
                {
                    if (walk.isMergedInto((RevCommit)oldObj, (RevCommit)newObj))
                    {
                        return store.Store(@lock, RefUpdateResult.FastForward);
                    }
                }

                if (IsForceUpdate)
                {
                    return store.Store(@lock, RefUpdateResult.Forced);
                }

                return RefUpdateResult.Rejected;
            }
            finally
            {
                @lock.Unlock();
            }
        }