Permalink
Browse files

2008-12-06 Miguel de Icaza <miguel@novell.com>

	* Lib/*: Align some API doc comments, add some API docs.

	* Lib/RefDatabase.cs (Peel): Implement.

	* Lib/Constants.cs: Put all the constants here (not sure where
	some new constants should have gone).

	* Lib/Ref.cs: Update to support `Peeled' property and
	`OriginalName' from newer eGits.
  • Loading branch information...
1 parent e79e1a5 commit ba4711b80fe57fb99a334a4344897a2dbc4753e0 Miguel de Icaza committed Dec 6, 2008
Showing with 357 additions and 243 deletions.
  1. +12 −0 ChangeLog
  2. +85 −0 Lib/Constants.cs
  3. +4 −4 Lib/ObjectLoader.cs
  4. +24 −9 Lib/Ref.cs
  5. +27 −12 Lib/RefDatabase.cs
  6. +10 −9 Lib/Repository.cs
  7. +185 −208 Lib/Tag.cs
  8. +2 −1 Makefile
  9. +8 −0 test.cs
View
@@ -1,3 +1,15 @@
+2008-12-06 Miguel de Icaza <miguel@novell.com>
+
+ * Lib/*: Align some API doc comments, add some API docs.
+
+ * Lib/RefDatabase.cs (Peel): Implement.
+
+ * Lib/Constants.cs: Put all the constants here (not sure where
+ some new constants should have gone).
+
+ * Lib/Ref.cs: Update to support `Peeled' property and
+ `OriginalName' from newer eGits.
+
2008-12-03 Miguel de Icaza <miguel@novell.com>
* test.cs: make the sample program dump all the refs.
View
@@ -0,0 +1,85 @@
+/*
+ * Copyright (C) 2007, Dave Watson <dwatson@mimvista.com>
+ * Copyright (C) 2008, Robin Rosenberg <robin.rosenberg@dewire.com>
+ * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org>
+ * Copyright (C) 2008, Kevin Thompson <kevin.thompson@theautomaters.com>
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * - Neither the name of the Git Development Community nor the
+ * names of its contributors may be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+using System.Globalization;
+using System.Text;
+
+namespace Gitty.Lib
+{
+ public sealed class Constants {
+ /// <summary>
+ /// Prefix for branch refs
+ /// </summary>
+ public static readonly string HeadsPrefix = "refs/heads";
+
+ /// <summary>
+ /// Prefix for remote refs
+ /// </summary>
+ public static readonly string RemotesPrefix = "refs/remotes";
+
+ /// <summary>
+ /// Special name for the "HEAD" symbolic ref
+ /// </summary>
+ public static readonly string Head = "HEAD";
+
+ public static readonly string Master = "master";
+
+ /// <summary>
+ /// Text string that identifies an object as an annotated tag.
+ /// <summary>
+ /// <remarks>
+ /// Annotated tags store a pointer to any other object, and an additional
+ /// message. It is most commonly used to record a stable release of the
+ /// project.
+ /// </summary>
+ public static readonly string TypeTag = "tag";
+
+ public static readonly Encoding Encoding = Encoding.UTF8;
+
+ public static readonly string RefsSlash = "refs/";
+
+ public static readonly string TagsPrefix = "refs/tags";
+
+ public static readonly string TagsSlash = TagsPrefix + "/";
+
+ public static readonly string HeadsSlash = HeadsPrefix + "/";
+
+ public static readonly string[] RefSearchPaths = { "", RefsSlash, TagsSlash, HeadsSlash, RemotesPrefix + "/" };
+ }
+}
View
@@ -77,10 +77,10 @@ public abstract class ObjectLoader
}
}
- // I'm not entirely sure how Java's protected works, but it seems
- // this method was callable from a class that didn't inherit from this one,
- // so instead I've marked this as internal for now, though I think
- // public would probably be better - NR
+ // I'm not entirely sure how Java's protected works, but it seems
+ // this method was callable from a class that didn't inherit from this one,
+ // so instead I've marked this as internal for now, though I think
+ // public would probably be better - NR
internal bool HasComputedId
{
get
View
@@ -69,27 +69,42 @@ static Storage()
}
}
- public Ref(Storage storage, string refName, ObjectId id )
- {
- this.StorageFormat = storage;
- this.Name = refName;
- this.ObjectId = id;
+ public Ref(Storage storage, string origName, string refName, ObjectId id)
+ : this (storage, origName, refName, id, null, false)
+ {
}
- public Ref(Storage storage, string refName, ObjectId id, ObjectId peeledObjectId)
- : this(storage, refName, id)
+ public Ref(Storage storage, string refName, ObjectId id)
+ : this (storage, refName, refName, id, null, false)
+ {
+ }
+
+ public Ref(Storage storage, string refName, ObjectId id, ObjectId peeledObjectId, bool peeled)
+ : this (storage, refName, refName, id, peeledObjectId, peeled)
+
+ {
+ }
+
+ public Ref(Storage storage, string origName, string refName, ObjectId id, ObjectId peeledObjectId, bool peeled)
{
- this.PeeledObjectId = peeledObjectId;
+ StorageFormat = storage;
+ OriginalName = origName;
+ Name = refName;
+ ObjectId = id;
+ PeeledObjectId = peeledObjectId;
+ Peeled = peeled;
}
public string Name { get; private set; }
+ public string OriginalName { get; private set; }
public Storage StorageFormat { get; private set; }
public ObjectId ObjectId { get; private set; }
public ObjectId PeeledObjectId { get; private set; }
+ public bool Peeled { get; private set; }
public override string ToString()
{
- return "Ref[" + Name + "=" + this.ObjectId.ToString() + "]";
+ return "Ref[" + (OriginalName == Name ? "" : "(" + OriginalName + ")") + Name + "=" + this.ObjectId.ToString() + "]";
}
}
}
View
@@ -50,16 +50,6 @@ namespace Gitty.Lib
[Complete]
public class RefDatabase
{
-
- public class Constants
- {
- public readonly static Encoding Encoding = Encoding.UTF8;
- public readonly static string RefsSlash = "refs/";
- public readonly static string TagsSlash = Tag.Constants.TagsPrefix + "/";
- public readonly static string HeadsSlash = Repository.Constants.HeadsPrefix + "/";
- public readonly static string[] RefSearchPaths = { "", RefsSlash, TagsSlash, HeadsSlash, Repository.Constants.RemotesPrefix + "/" };
- }
-
public Repository Repository { get; private set; }
private DirectoryInfo _gitDir;
@@ -169,7 +159,7 @@ public Ref ReadRef(String partialName)
Dictionary<String, Ref> avail = new Dictionary<String, Ref>();
ReadPackedRefs(avail);
ReadLooseRefs(avail, Constants.RefsSlash, _refsDir);
- ReadOneLooseRef(avail, Repository.Constants.Head, PathUtil.CombineFilePath(_gitDir, Repository.Constants.Head));
+ ReadOneLooseRef(avail, Constants.Head, PathUtil.CombineFilePath(_gitDir, Constants.Head));
return avail;
}
@@ -381,7 +371,7 @@ private void RefreshPackedRefs()
throw new IOException("Peeled line before ref.");
ObjectId id = ObjectId.FromString(p.Substring(1));
- last = new Ref(Ref.Storage.Packed, last.Name, last.ObjectId, id);
+ last = new Ref(Ref.Storage.Packed, last.Name, last.Name, last.ObjectId, id, true);
newPackedRefs.Add(last.Name, last);
continue;
}
@@ -415,6 +405,31 @@ private void RefreshPackedRefs()
}
}
+ internal Ref Peel (Ref dref)
+ {
+ if (dref.Peeled)
+ return dref;
+
+ ObjectId peeled = null;
+ try {
+ object target = Repository.MapObject (dref.ObjectId, dref.Name);
+
+ while (target is Tag){
+ Tag tag = (Tag) target;
+ peeled = tag.Id;
+
+ if (tag.TagType == Constants.TypeTag)
+ target = Repository.MapObject (tag.Id, dref.Name);
+ else
+ break;
+ }
+ } catch (IOException){
+ // Ignore a read error.  Callers will also get the same error
+ // if they try to use the result of getPeeledObjectId.
+ }
+ return new Ref (dref.StorageFormat, dref.Name, dref.ObjectId, peeled, true);
+ }
+
private string ReadLine(FileInfo file)
{
using (BufferedReader br = OpenReader(file))
View
@@ -73,15 +73,6 @@ namespace Gitty.Lib
*/
public class Repository
{
-
- public sealed class Constants
- {
- public static readonly string HeadsPrefix = "refs/heads";
- public static readonly string RemotesPrefix = "refs/remotes";
- public static readonly string Head = "HEAD";
- public static readonly string Master = "master";
- }
-
private RefDatabase _refs;
private List<PackFile> _packs;
@@ -905,6 +896,16 @@ public RepositoryState GetRespositoryState()
{
return _refs.GetAllRefs ();
}
+
+ public Dictionary<string, Ref> GetTags ()
+ {
+ return _refs.GetTags ();
+ }
+
+ public Ref Peel (Ref pRef)
+ {
+ return _refs.Peel (pRef);
+ }
/**
* Check validty of a ref name. It must not contain character that has
Oops, something went wrong.

0 comments on commit ba4711b

Please sign in to comment.