258
258
foreach (string prefix in SEARCH_PATH)
260
@ref = ReadRef(prefix + needle, packed);
263
@ref = Resolve(@ref, 0, null, null, packed);
262
@ref = ReadRef(prefix + needle, packed);
265
@ref = Resolve(@ref, 0, null, null, packed);
269
catch (IOException e)
271
if (!(!needle.Contains("/") && string.Empty.Equals(prefix) && e.InnerException is
272
InvalidObjectIdException))
267
278
FireRefsChanged();
696
707
FireRefsChanged();
710
/// <summary>Adds a set of refs to the set of packed-refs.</summary>
712
/// Adds a set of refs to the set of packed-refs. Only non-symbolic refs are
713
/// added. If a ref with the given name already existed in packed-refs it is
714
/// updated with the new value. Each loose ref which was added to the
715
/// packed-ref file is deleted. If a given ref can't be locked it will not be
716
/// added to the pack file.
718
/// <param name="refs">the refs to be added. Must be fully qualified.</param>
719
/// <exception cref="System.IO.IOException">System.IO.IOException</exception>
720
public virtual void Pack(IList<string> refs)
726
FS fs = parent.FileSystem;
727
// Lock the packed refs file and read the content
728
LockFile lck = new LockFile(packedRefsFile, fs);
731
throw new IOException(MessageFormat.Format(JGitText.Get().cannotLock, packedRefsFile
736
RefDirectory.PackedRefList packed = GetPackedRefs();
737
RefList<Ref> cur = ReadPackedRefs();
738
// Iterate over all refs to be packed
739
foreach (string refName in refs)
741
Ref @ref = ReadRef(refName, cur);
742
if (@ref.IsSymbolic())
746
// can't pack symbolic refs
747
// Add/Update it to packed-refs
748
int idx = cur.Find(refName);
751
cur = cur.Set(idx, PeeledPackedRef(@ref));
755
cur = cur.Add(idx, PeeledPackedRef(@ref));
758
// The new content for packed-refs is collected. Persist it.
759
CommitPackedRefs(lck, cur, packed);
760
// Now delete the loose refs which are now packed
761
foreach (string refName_1 in refs)
763
// Lock the loose ref
764
FilePath refFile = FileFor(refName_1);
765
if (!refFile.Exists())
769
LockFile rLck = new LockFile(refFile, parent.FileSystem);
776
RefDirectory.LooseRef currentLooseRef = ScanRef(null, refName_1);
777
if (currentLooseRef == null || currentLooseRef.IsSymbolic())
781
Ref packedRef = cur.Get(refName_1);
782
ObjectId clr_oid = currentLooseRef.GetObjectId();
783
if (clr_oid != null && clr_oid.Equals(packedRef.GetObjectId()))
785
RefList<RefDirectory.LooseRef> curLoose;
786
RefList<RefDirectory.LooseRef> newLoose;
789
curLoose = looseRefs.Get();
790
int idx = curLoose.Find(refName_1);
795
newLoose = curLoose.Remove(idx);
797
while (!looseRefs.CompareAndSet(curLoose, newLoose));
798
int levels = LevelsIn(refName_1) - 2;
799
Delete(FileFor(refName_1), levels);
810
// Don't fire refsChanged. The refs have not change, only their
816
/// <summary>Make sure a ref is peeled and has the Storage PACKED.</summary>
818
/// Make sure a ref is peeled and has the Storage PACKED. If the given ref
819
/// has this attributes simply return it. Otherwise create a new peeled
820
/// <see cref="NGit.ObjectIdRef">NGit.ObjectIdRef</see>
821
/// where Storage is set to PACKED.
823
/// <param name="f"></param>
824
/// <returns>a ref for Storage PACKED having the same name, id, peeledId as f</returns>
825
/// <exception cref="NGit.Errors.MissingObjectException">NGit.Errors.MissingObjectException
827
/// <exception cref="System.IO.IOException">System.IO.IOException</exception>
828
private Ref PeeledPackedRef(Ref f)
830
if (f.GetStorage().IsPacked() && f.IsPeeled())
838
if (f.GetPeeledObjectId() != null)
840
return new ObjectIdRef.PeeledTag(RefStorage.PACKED, f.GetName(), f.GetObjectId(),
841
f.GetPeeledObjectId());
845
return new ObjectIdRef.PeeledNonTag(RefStorage.PACKED, f.GetName(), f.GetObjectId
699
850
/// <exception cref="System.IO.IOException"></exception>
700
851
internal virtual void Log(RefUpdate update, string msg, bool deref)
862
1015
private void CommitPackedRefs(LockFile lck, RefList<Ref> refs, RefDirectory.PackedRefList
865
new _RefWriter_707(this, lck, oldPackedList, refs, refs).WritePackedRefs();
1018
new _RefWriter_826(this, lck, oldPackedList, refs, refs).WritePackedRefs();
868
private sealed class _RefWriter_707 : RefWriter
1021
private sealed class _RefWriter_826 : RefWriter
870
public _RefWriter_707(RefDirectory _enclosing, LockFile lck, RefDirectory.PackedRefList
1023
public _RefWriter_826(RefDirectory _enclosing, LockFile lck, RefDirectory.PackedRefList
871
1024
oldPackedList, RefList<Ref> refs, RefList<Ref> baseArg1) : base(baseArg1)
873
1026
this._enclosing = _enclosing;
1044
catch (ArgumentException)
1198
catch (ArgumentException notRef)
1046
1200
while (0 < n && char.IsWhiteSpace((char)buf[n - 1]))
1050
1204
string content = RawParseUtils.Decode(buf, 0, n);
1051
throw new IOException(MessageFormat.Format(JGitText.Get().notARef, name, content)
1205
IOException ioException = new IOException(MessageFormat.Format(JGitText.Get().notARef
1206
, name, content), notRef);
1054
1209
return new RefDirectory.LooseUnpeeled(otherSnapshot, name, id);
1142
1297
private class PackedRefList : RefList<Ref>
1144
1299
internal static readonly RefDirectory.PackedRefList NO_PACKED_REFS = new RefDirectory.PackedRefList
1145
(RefList.EmptyList(), FileSnapshot.MISSING_FILE);
1300
(RefList.EmptyList(), FileSnapshot.MISSING_FILE, ObjectId.ZeroId);
1147
1302
internal readonly FileSnapshot snapshot;
1149
internal PackedRefList(RefList<Ref> src, FileSnapshot s) : base(src)
1304
internal readonly ObjectId id;
1306
internal PackedRefList(RefList<Ref> src, FileSnapshot s, ObjectId i) : base(src)