ShortenRefName() public static method

public static ShortenRefName ( string refName ) : string
refName string
return string
Ejemplo n.º 1
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()));
        }
Ejemplo n.º 2
0
        /// <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);
        }