/// <summary> /// Writes a symref (e.g. HEAD) to disk /// * @param name /// </summary> /// <param name="name">symref name</param> /// <param name="target">pointed to ref</param> public void Link(string name, string target) { lock (locker) { byte[] content = Constants.encode("ref: " + target + "\n"); LockAndWriteFile(FileForRef(name), content); UncacheSymRef(name); Repository.fireRefsMaybeChanged(); } }
internal void Stored(string origName, string name, ObjectId id, DateTime time) { lock (locker) { _looseRefs[name] = new Ref(Ref.Storage.Loose, name, name, id); _looseRefsMTime[name] = time; SetModified(); } Repository.fireRefsMaybeChanged(); }
private Dictionary <string, Ref> ReadRefs() { var avail = new Dictionary <string, Ref>(); ReadPackedRefs(avail); ReadLooseRefs(avail, Constants.Refs, _refsDir); try { Ref r = ReadRefBasic(Constants.HEAD, 0); if (r != null && r.ObjectId != null) { avail[Constants.HEAD] = r; } } catch (IOException) { // ignore here } Repository.fireRefsMaybeChanged(); return(avail); }
/// <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); }