コード例 #1
0
ファイル: RefLogWriter.cs プロジェクト: kkl713/GitSharp
        internal static void renameTo(Repository db, RefUpdate from, RefUpdate to)
        {
            var           logdir        = new DirectoryInfo(Path.Combine(db.Directory.FullName, Constants.LOGS).Replace('/', Path.DirectorySeparatorChar));
            var           reflogFrom    = new FileInfo(Path.Combine(logdir.FullName, from.Name).Replace('/', Path.DirectorySeparatorChar));
            DirectoryInfo refLogFromDir = reflogFrom.Directory;

            if (!reflogFrom.Exists)
            {
                return;
            }

            var reflogTo    = new FileInfo(Path.Combine(logdir.FullName, to.Name).Replace('/', Path.DirectorySeparatorChar));
            var reflogToDir = reflogTo.Directory;
            var tmp         = new FileInfo(Path.Combine(logdir.FullName, "tmp-renamed-log.." + Thread.CurrentThread.ManagedThreadId));

            if (!reflogFrom.RenameTo(tmp.FullName))
            {
                throw new IOException("Cannot rename " + reflogFrom + " to (" + tmp + ")" + reflogTo);
            }

            RefUpdate.DeleteEmptyDir(refLogFromDir, RefUpdate.Count(from.Name, '/') - 1);
            if (reflogToDir != null && !reflogToDir.Exists)
            {
                try { reflogToDir.Create(); }
                catch (IOException)
                {
                    throw new IOException("Cannot create directory " + reflogToDir);
                }
            }

            if (!tmp.RenameTo(reflogTo.FullName))
            {
                throw new IOException("Cannot rename (" + tmp + ")" + reflogFrom + " to " + reflogTo);
            }
        }
コード例 #2
0
        public override RefRename newRename(string fromName, string toName)
        {
            RefUpdate from = newUpdate(fromName, false);
            RefUpdate to   = newUpdate(toName, false);

            return(new RefDirectoryRename((RefDirectoryUpdate)from, (RefDirectoryUpdate)to));
        }
コード例 #3
0
        private bool renameLog(RefUpdate src, RefUpdate dst)
        {
            FileInfo srcLog = _refdb.logFor(src.getName());
            FileInfo dstLog = _refdb.logFor(dst.getName());

            if (!srcLog.Exists)
            {
                return(true);
            }

            if (!rename(srcLog.FullName, dstLog.FullName))
            {
                return(false);
            }

            // There be dragons



            try
            {
                int levels = RefDirectory.levelsIn(src.getName()) - 2;
                RefDirectory.delete(srcLog, levels);
                return(true);
            }
            catch (IOException)
            {
                rename(dstLog.FullName, srcLog.FullName);
                return(false);
            }
        }
コード例 #4
0
        /**
         * Store a tag.
         * If author, message or type is set make the tag an annotated tag.
         *
         * @
         */
        public void Save()  //renamed from Tag
        {
            if (TagId != null)
            {
                throw new InvalidOperationException("exists " + TagId);
            }
            ObjectId id;

            if (author != null || message != null || tagType != null)
            {
                ObjectId tagid = new ObjectWriter(Repository).WriteTag(this);
                TagId = tagid;
                id    = tagid;
            }
            else
            {
                id = Id;
            }

            RefUpdate ru = Repository.UpdateRef(Constants.RefsTags + TagName);

            ru.NewObjectId = id;
            ru.SetRefLogMessage("tagged " + TagName, false);
            if (ru.ForceUpdate() == RefUpdate.RefUpdateResult.LockFailure)
            {
                throw new ObjectWritingException("Unable to lock tag " + TagName);
            }
        }
コード例 #5
0
ファイル: RefDatabase.cs プロジェクト: kkl713/GitSharp
        ///	<summary>
        /// An set of update operations for renaming a ref
        ///	</summary>
        ///	<param name="fromRef"> Old ref name </param>
        ///	<param name="toRef"> New ref name </param>
        ///	<returns> a RefUpdate operation to rename a ref </returns>
        ///	<exception cref="IOException"> </exception>
        public RefRename NewRename(string fromRef, string toRef)
        {
            RefreshPackedRefs();
            Ref f             = ReadRefBasic(fromRef, 0);
            var t             = new Ref(Ref.Storage.New, toRef, null);
            var refUpdateFrom = new RefUpdate(this, f, FileForRef(f.Name));
            var refUpdateTo   = new RefUpdate(this, t, FileForRef(t.Name));

            return(new RefRename(refUpdateTo, refUpdateFrom));
        }
コード例 #6
0
ファイル: RefRename.cs プロジェクト: dev218/GitSharp
        /// <summary>
        /// Initialize a new rename operation.
        /// </summary>
        /// <param name="src">operation to read and delete the source.</param>
        /// <param name="dst">operation to create (or overwrite) the destination.</param>
        protected RefRename(RefUpdate src, RefUpdate dst) {
            source = src;
            destination = dst;

            Repository repo = destination.getRepository();
            string cmd = "";
            if (source.getName().StartsWith(Constants.R_HEADS)
                && destination.getName().StartsWith(Constants.R_HEADS))
                cmd = "Branch: ";
            setRefLogMessage(cmd + "renamed "
                             + repo.ShortenRefName(source.getName()) + " to "
                             + repo.ShortenRefName(destination.getName()));
        }
コード例 #7
0
ファイル: RefLogWriter.cs プロジェクト: georgeck/GitSharp
        internal static void append(RefUpdate u, string msg)
        {
            ObjectId oldId = u.OldObjectId;
            ObjectId newId = u.NewObjectId;
            Repository db = u.Repository;
            PersonIdent ident = u.RefLogIdent;

            AppendOneRecord(oldId, newId, ident, msg, db, u.Name);

            if (!u.Name.Equals(u.OriginalName))
            {
                AppendOneRecord(oldId, newId, ident, msg, db, u.OriginalName);
            }
        }
コード例 #8
0
ファイル: RefLogWriter.cs プロジェクト: kkl713/GitSharp
        internal static void append(RefUpdate u, string msg)
        {
            ObjectId    oldId = u.OldObjectId;
            ObjectId    newId = u.NewObjectId;
            Repository  db    = u.Repository;
            PersonIdent ident = u.RefLogIdent;

            AppendOneRecord(oldId, newId, ident, msg, db, u.Name);

            if (!u.Name.Equals(u.OriginalName))
            {
                AppendOneRecord(oldId, newId, ident, msg, db, u.OriginalName);
            }
        }
コード例 #9
0
        /// <summary>
        /// Initialize a new rename operation.
        /// </summary>
        /// <param name="src">operation to read and delete the source.</param>
        /// <param name="dst">operation to create (or overwrite) the destination.</param>
        protected RefRename(RefUpdate src, RefUpdate dst)
        {
            source      = src;
            destination = dst;

            Repository repo = destination.getRepository();
            string     cmd  = "";

            if (source.getName().StartsWith(Constants.R_HEADS) &&
                destination.getName().StartsWith(Constants.R_HEADS))
            {
                cmd = "Branch: ";
            }
            setRefLogMessage(cmd + "renamed "
                             + repo.ShortenRefName(source.getName()) + " to "
                             + repo.ShortenRefName(destination.getName()));
        }
コード例 #10
0
        public void log(RefUpdate update, string msg, bool deref)
        {
            ObjectId oldId = update.getOldObjectId();
            ObjectId newId = update.getNewObjectId();
            Ref      @ref  = update.getRef();

            PersonIdent ident = update.getRefLogIdent();

            if (ident == null)
            {
                ident = new PersonIdent(parent);
            }
            else
            {
                ident = new PersonIdent(ident);
            }

            var r = new StringBuilder();

            r.Append(ObjectId.ToString(oldId));
            r.Append(' ');
            r.Append(ObjectId.ToString(newId));
            r.Append(' ');
            r.Append(ident.ToExternalString());
            r.Append('\t');
            r.Append(msg);
            r.Append('\n');
            byte[] rec = Constants.encode(r.ToString());

            if (deref && @ref.isSymbolic())
            {
                log(@ref.getName(), rec);
                log(@ref.getLeaf().getName(), rec);
            }
            else
            {
                log(@ref.getName(), rec);
            }
        }
コード例 #11
0
        private static char shortTypeOf(RefUpdate.RefUpdateResult r)
        {
            switch (r)
            {
                case RefUpdate.RefUpdateResult.LockFailure:
                case RefUpdate.RefUpdateResult.IOFailure:
                case RefUpdate.RefUpdateResult.Rejected:
                    return '!';

                case RefUpdate.RefUpdateResult.New:
                    return '*';

                case RefUpdate.RefUpdateResult.Forced:
                    return '+';

                case RefUpdate.RefUpdateResult.NoChange:
                    return '=';

                default:
                    return ' ';
            }
        }
コード例 #12
0
        private static char shortTypeOf(RefUpdate.RefUpdateResult r)
        {
            switch (r)
            {
                case RefUpdate.RefUpdateResult.LOCK_FAILURE:
                case RefUpdate.RefUpdateResult.IO_FAILURE:
                case RefUpdate.RefUpdateResult.REJECTED:
                    return '!';

                case RefUpdate.RefUpdateResult.NEW:
                    return '*';

                case RefUpdate.RefUpdateResult.FORCED:
                    return '+';

                case RefUpdate.RefUpdateResult.NO_CHANGE:
                    return '=';

                default:
                    return ' ';
            }
        }
コード例 #13
0
        private bool linkHEAD(RefUpdate target)
        {
            try
            {
                RefUpdate u = _refdb.newUpdate(Constants.HEAD, false);
                u.disableRefLog();
                switch (u.link(target.getName()))
                {
                case RefUpdate.RefUpdateResult.NEW:
                case RefUpdate.RefUpdateResult.FORCED:
                case RefUpdate.RefUpdateResult.NO_CHANGE:
                    return(true);

                default:
                    return(false);
                }
            }
            catch (IOException)
            {
                return(false);
            }
        }
コード例 #14
0
 protected StoreBase(RefUpdate refUpdate)
 {
     _refUpdate = refUpdate;
 }
コード例 #15
0
 public static ObjectId getOldObjectId(this RefUpdate refUpdate)
 {
     return(refUpdate.OldObjectId);
 }
コード例 #16
0
 public UpdateStore(RefUpdate refUpdate)
 {
     _refUpdate = refUpdate;
 }
コード例 #17
0
        private bool renameLog(RefUpdate src, RefUpdate dst)
        {
            FileInfo srcLog = _refdb.logFor(src.getName());
            FileInfo dstLog = _refdb.logFor(dst.getName());

            if (!srcLog.Exists)
                return true;

            if (!rename(srcLog.FullName, dstLog.FullName))
                return false;

            // There be dragons

            try
            {
                int levels = RefDirectory.levelsIn(src.getName()) - 2;
                RefDirectory.delete(srcLog, levels);
                return true;
            }
            catch (IOException)
            {
                rename(dstLog.FullName, srcLog.FullName);
                return false;
            }
        }
コード例 #18
0
ファイル: RefUpdateTest.cs プロジェクト: georgeck/GitSharp
 private void delete(RefUpdate @ref, RefUpdate.RefUpdateResult expected,
     bool exists, bool removed)
 {
     Assert.AreEqual(exists, db.getAllRefs().ContainsKey(@ref.Name));
     Assert.AreEqual(expected, @ref.Delete());
     Assert.AreEqual(!removed, db.getAllRefs().ContainsKey(@ref.Name));
 }
コード例 #19
0
 public static void setNewObjectId(this RefUpdate refUpdate, AnyObjectId id)
 {
     refUpdate.NewObjectId = id.Copy();
 }
コード例 #20
0
 public static void setForceUpdate(this RefUpdate refUpdate, bool b)
 {
     refUpdate.IsForceUpdate = b;
 }
コード例 #21
0
 public DeleteStore(RefUpdate refUpdate)
 {
     _refUpdate = refUpdate;
 }
コード例 #22
0
 public static string getName(this RefUpdate refUpdate)
 {
     return(refUpdate.Name);
 }
コード例 #23
0
 public static Ref getRef(this RefUpdate refUpdate)
 {
     return(refUpdate.Ref);
 }
コード例 #24
0
 public static RefUpdate.RefUpdateResult getResult(this RefUpdate refUpdate)
 {
     return(refUpdate.Result);
 }
コード例 #25
0
 public static void setOldObjectId(this RefUpdate refUpdate, AnyObjectId id)
 {
     refUpdate.OldObjectId = id != null?id.ToObjectId() : null;;
 }
コード例 #26
0
 public override RefUpdateResult Store(LockFile lockFile, RefUpdateResult status)
 {
     return(RefUpdate.UpdateRepositoryStore(lockFile, status));
 }
コード例 #27
0
ファイル: RefRename.cs プロジェクト: kkl713/GitSharp
 public RefRename(RefUpdate toUpdate, RefUpdate fromUpdate)
 {
     _renameResult  = RefResult.NotAttempted;
     _newToUpdate   = toUpdate;
     _oldFromDelete = fromUpdate;
 }
コード例 #28
0
 public DeleteStore(RefUpdate refUpdate) : base(refUpdate)
 {
 }
コード例 #29
0
ファイル: RefRename.cs プロジェクト: kkl713/GitSharp
        /// <summary>
        /// The result of the new ref update
        /// </summary>
        /// <returns></returns>
        /// <exception cref="IOException"></exception>
        public RefResult Rename()
        {
            Ref        oldRef        = _oldFromDelete.Repository.getRef(Constants.HEAD);
            bool       renameHeadToo = oldRef != null && oldRef.Name == _oldFromDelete.Name;
            Repository db            = _oldFromDelete.Repository;

            RefLogWriter.renameTo(db, _oldFromDelete, _newToUpdate);
            _newToUpdate.SetRefLogMessage(null, false);
            string tmpRefName = "RENAMED-REF.." + Thread.CurrentThread.ManagedThreadId;

            RefUpdate tmpUpdateRef = db.UpdateRef(tmpRefName);

            if (renameHeadToo)
            {
                try
                {
                    _oldFromDelete.Repository.Link(Constants.HEAD, tmpRefName);
                }
                catch (IOException)
                {
                    RefLogWriter.renameTo(db, _newToUpdate, _oldFromDelete);
                    return(_renameResult = RefResult.LockFailure);
                }
            }

            tmpUpdateRef.NewObjectId   = _oldFromDelete.OldObjectId;
            tmpUpdateRef.IsForceUpdate = true;
            RefResult update = tmpUpdateRef.Update();

            if (update != RefResult.Forced && update != RefResult.New && update != RefResult.NoChange)
            {
                RefLogWriter.renameTo(db, _newToUpdate, _oldFromDelete);
                if (renameHeadToo)
                {
                    _oldFromDelete.Repository.Link(Constants.HEAD, _oldFromDelete.Name);
                }

                return(_renameResult = update);
            }

            _oldFromDelete.ExpectedOldObjectId = _oldFromDelete.OldObjectId;
            _oldFromDelete.IsForceUpdate       = true;
            RefResult delete = _oldFromDelete.Delete();

            if (delete != RefResult.Forced)
            {
                if (db.getRef(_oldFromDelete.Name) != null)
                {
                    RefLogWriter.renameTo(db, _newToUpdate, _oldFromDelete);
                    if (renameHeadToo)
                    {
                        _oldFromDelete.Repository.Link(Constants.HEAD, _oldFromDelete.Name);
                    }
                }
                return(_renameResult = delete);
            }

            _newToUpdate.NewObjectId = tmpUpdateRef.NewObjectId;
            RefResult updateResult = _newToUpdate.Update();

            if (updateResult != RefResult.New)
            {
                RefLogWriter.renameTo(db, _newToUpdate, _oldFromDelete);
                if (renameHeadToo)
                {
                    _oldFromDelete.Repository.Link(Constants.HEAD, _oldFromDelete.Name);
                }
                _oldFromDelete.ExpectedOldObjectId = null;
                _oldFromDelete.NewObjectId         = _oldFromDelete.OldObjectId;
                _oldFromDelete.IsForceUpdate       = true;
                _oldFromDelete.SetRefLogMessage(null, false);
                RefResult undelete = _oldFromDelete.Update();
                if (undelete != RefResult.New && undelete != RefResult.LockFailure)
                {
                    return(_renameResult = RefResult.IOFailure);
                }
                return(_renameResult = RefResult.LockFailure);
            }

            if (renameHeadToo)
            {
                _oldFromDelete.Repository.Link(Constants.HEAD, _newToUpdate.Name);
            }
            else
            {
                db.fireRefsMaybeChanged();
            }

            RefLogWriter.append(this, _newToUpdate.Name, "Branch: renamed "
                                + Repository.ShortenRefName(_oldFromDelete.Name) + " to "
                                + Repository.ShortenRefName(_newToUpdate.Name));

            if (renameHeadToo)
            {
                RefLogWriter.append(this, Constants.HEAD, "Branch: renamed "
                                    + Repository.ShortenRefName(_oldFromDelete.Name) + " to "
                                    + Repository.ShortenRefName(_newToUpdate.Name));
            }

            return(_renameResult = RefResult.Renamed);
        }
コード例 #30
0
ファイル: RefUpdateTest.cs プロジェクト: georgeck/GitSharp
 private void delete(RefUpdate @ref, RefUpdate.RefUpdateResult expected)
 {
     delete(@ref, expected, true, true);
 }
コード例 #31
0
ファイル: RefUpdate.cs プロジェクト: stschake/GitSharp
 protected StoreBase(RefUpdate refUpdate)
 {
     _refUpdate = refUpdate;
 }
コード例 #32
0
 private bool linkHEAD(RefUpdate target)
 {
     try
     {
         RefUpdate u = _refdb.newUpdate(Constants.HEAD, false);
         u.disableRefLog();
         switch (u.link(target.getName()))
         {
             case RefUpdate.RefUpdateResult.NEW:
             case RefUpdate.RefUpdateResult.FORCED:
             case RefUpdate.RefUpdateResult.NO_CHANGE:
                 return true;
             default:
                 return false;
         }
     }
     catch (IOException e)
     {
         return false;
     }
 }
コード例 #33
0
ファイル: RefUpdate.cs プロジェクト: stschake/GitSharp
 public UpdateStore(RefUpdate refUpdate)
     : base(refUpdate)
 {
 }
コード例 #34
0
 public static ObjectId getNewObjectId(this RefUpdate refUpdate)
 {
     return(refUpdate.NewObjectId);
 }
コード例 #35
0
 public static bool isForceUpdate(this RefUpdate refUpdate)
 {
     return(refUpdate.IsForceUpdate);
 }
コード例 #36
0
        protected override RefUpdate.RefUpdateResult doRename()
        {
            if (source.getRef().isSymbolic())
            {
                return(RefUpdate.RefUpdateResult.IO_FAILURE); // not supported
            }
            var rw = new RevWalk.RevWalk(_refdb.getRepository());

            _objId      = source.getOldObjectId();
            _updateHead = needToUpdateHEAD();
            _tmp        = _refdb.newTemporaryUpdate();
            try
            {
                // First backup the source so its never unreachable.
                _tmp.setNewObjectId(_objId);
                _tmp.setForceUpdate(true);
                _tmp.disableRefLog();
                switch (_tmp.update(rw))
                {
                case RefUpdate.RefUpdateResult.NEW:
                case RefUpdate.RefUpdateResult.FORCED:
                case RefUpdate.RefUpdateResult.NO_CHANGE:
                    break;

                default:
                    return(_tmp.getResult());
                }

                // Save the source's log under the temporary name, we must do
                // this before we delete the source, otherwise we lose the log.
                if (!renameLog(source, _tmp))
                {
                    return(RefUpdate.RefUpdateResult.IO_FAILURE);
                }

                // If HEAD has to be updated, link it now to destination.
                // We have to link before we delete, otherwise the delete
                // fails because its the current branch.
                RefUpdate dst = destination;
                if (_updateHead)
                {
                    if (!linkHEAD(destination))
                    {
                        renameLog(_tmp, source);
                        return(RefUpdate.RefUpdateResult.LOCK_FAILURE);
                    }

                    // Replace the update operation so HEAD will log the rename.
                    dst = _refdb.newUpdate(Constants.HEAD, false);
                    dst.setRefLogIdent(destination.getRefLogIdent());
                    dst.setRefLogMessage(destination.getRefLogMessage(), false);
                }

                // Delete the source name so its path is free for replacement.
                source.setExpectedOldObjectId(_objId);
                source.setForceUpdate(true);
                source.disableRefLog();
                if (source.delete(rw) != RefUpdate.RefUpdateResult.FORCED)
                {
                    renameLog(_tmp, source);
                    if (_updateHead)
                    {
                        linkHEAD(source);
                    }
                    return(source.getResult());
                }

                // Move the log to the destination.
                if (!renameLog(_tmp, destination))
                {
                    renameLog(_tmp, source);
                    source.setExpectedOldObjectId(ObjectId.ZeroId);
                    source.setNewObjectId(_objId);
                    source.update(rw);
                    if (_updateHead)
                    {
                        linkHEAD(source);
                    }
                    return(RefUpdate.RefUpdateResult.IO_FAILURE);
                }

                // Create the destination, logging the rename during the creation.
                dst.setExpectedOldObjectId(ObjectId.ZeroId);
                dst.setNewObjectId(_objId);
                if (dst.update(rw) != RefUpdate.RefUpdateResult.NEW)
                {
                    // If we didn't create the destination we have to undo
                    // our work. Put the log back and restore source.
                    if (renameLog(destination, _tmp))
                    {
                        renameLog(_tmp, source);
                    }
                    source.setExpectedOldObjectId(ObjectId.ZeroId);
                    source.setNewObjectId(_objId);
                    source.update(rw);
                    if (_updateHead)
                    {
                        linkHEAD(source);
                    }
                    return(dst.getResult());
                }

                return(RefUpdate.RefUpdateResult.RENAMED);
            }
            finally
            {
                // Always try to free the temporary name.
                try
                {
                    _refdb.delete(_tmp);
                }
                catch (IOException)
                {
                    _refdb.fileFor(_tmp.getName()).Delete();
                }
            }
        }
コード例 #37
0
ファイル: RefLogWriter.cs プロジェクト: georgeck/GitSharp
        internal static void renameTo(Repository db, RefUpdate from, RefUpdate to)
        {
            var logdir = new DirectoryInfo(Path.Combine(db.Directory.FullName, Constants.LOGS).Replace('/', Path.DirectorySeparatorChar));
            var reflogFrom = new FileInfo(Path.Combine(logdir.FullName, from.Name).Replace('/', Path.DirectorySeparatorChar));
            DirectoryInfo refLogFromDir = reflogFrom.Directory;
            if (!reflogFrom.Exists) return;

            var reflogTo = new FileInfo(Path.Combine(logdir.FullName, to.Name).Replace('/', Path.DirectorySeparatorChar));
            var reflogToDir = reflogTo.Directory;
            var tmp = new FileInfo(Path.Combine(logdir.FullName, "tmp-renamed-log.." + Thread.CurrentThread.ManagedThreadId));
            if (!reflogFrom.RenameTo(tmp.FullName))
            {
                throw new IOException("Cannot rename " + reflogFrom + " to (" + tmp + ")" + reflogTo);
            }

            RefUpdate.DeleteEmptyDir(refLogFromDir, RefUpdate.Count(from.Name, '/') - 1);
            if (reflogToDir != null && !reflogToDir.Exists)
            {
                try { reflogToDir.Create(); }
                catch(IOException)
                {
                    throw new IOException("Cannot create directory " + reflogToDir);
                }
            }

            if (!tmp.RenameTo(reflogTo.FullName))
            {
                throw new IOException("Cannot rename (" + tmp + ")" + reflogFrom + " to " + reflogTo);
            }
        }
コード例 #38
0
ファイル: RefDatabase.cs プロジェクト: stschake/GitSharp
 ///	<summary>
 /// An set of update operations for renaming a ref
 ///	</summary>
 ///	<param name="fromRef"> Old ref name </param>
 ///	<param name="toRef"> New ref name </param>
 ///	<returns> a RefUpdate operation to rename a ref </returns>
 ///	<exception cref="IOException"> </exception>
 public RefRename NewRename(string fromRef, string toRef)
 {
     RefreshPackedRefs();
     Ref f = ReadRefBasic(fromRef, 0);
     var t = new Ref(Ref.Storage.New, toRef, null);
     var refUpdateFrom = new RefUpdate(this, f, FileForRef(f.Name));
     var refUpdateTo = new RefUpdate(this, t, FileForRef(t.Name));
     return new RefRename(refUpdateTo, refUpdateFrom);
 }
コード例 #39
0
 public static ObjectId getExpectedOldObjectId(this RefUpdate refUpdate)
 {
     return(refUpdate.ExpectedOldObjectId);
 }