Skip to content

Commit

Permalink
2008-12-03 Miguel de Icaza <miguel@novell.com>
Browse files Browse the repository at this point in the history
	* test.cs: make the sample program dump all the refs.

	* Lib/Repository.cs: Expose GetAllRefs.

	* Lib/RefDatabase.cs (ReadOneLooseRef): Do not crash if the
	refName is not present in the looseKeys.

	(RefreshPackedRefs): If the packed-refs file does not exist, do
	not try to continue, it would otherwise crash.
  • Loading branch information
Miguel de Icaza committed Dec 3, 2008
1 parent 37c2a7c commit e79e1a5
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 5 deletions.
10 changes: 10 additions & 0 deletions ChangeLog
@@ -1,5 +1,15 @@
2008-12-03 Miguel de Icaza <miguel@novell.com> 2008-12-03 Miguel de Icaza <miguel@novell.com>


* test.cs: make the sample program dump all the refs.

* Lib/Repository.cs: Expose GetAllRefs.

* Lib/RefDatabase.cs (ReadOneLooseRef): Do not crash if the
refName is not present in the looseKeys.

(RefreshPackedRefs): If the packed-refs file does not exist, do
not try to continue, it would otherwise crash.

* Lib/WindowedFile.cs: Implement another file from the original * Lib/WindowedFile.cs: Implement another file from the original
Java implementation. Java implementation.


Expand Down
8 changes: 6 additions & 2 deletions Lib/RefDatabase.cs
Expand Up @@ -202,8 +202,9 @@ private void ReadLooseRefs(Dictionary<string, Ref> avail, string prefix, Directo


private void ReadOneLooseRef(Dictionary<string, Ref> avail, string refName, FileSystemInfo ent) private void ReadOneLooseRef(Dictionary<string, Ref> avail, string refName, FileSystemInfo ent)
{ {
CachedRef reff = looseRefs[refName]; CachedRef reff;
if (reff != null)
if (looseRefs.TryGetValue (refName, out reff) && reff != null)
{ {
if (reff.LastModified == ent.LastWriteTime) if (reff.LastModified == ent.LastWriteTime)
{ {
Expand Down Expand Up @@ -346,6 +347,9 @@ private Ref ReadRefBasic(string name, int depth)


private void RefreshPackedRefs() private void RefreshPackedRefs()
{ {
if (!_packedRefsFile.Exists)
return;

DateTime currTime = _packedRefsFile.LastWriteTime; DateTime currTime = _packedRefsFile.LastWriteTime;
long currLen = currTime == DateTime.MinValue ? 0 : _packedRefsFile.Length; long currLen = currTime == DateTime.MinValue ? 0 : _packedRefsFile.Length;
if (currTime == packedRefsLastModified && currLen == packedRefsLength) if (currTime == packedRefsLastModified && currLen == packedRefsLength)
Expand Down
7 changes: 6 additions & 1 deletion Lib/Repository.cs
@@ -1,4 +1,4 @@
/* /*
* Copyright (C) 2007, Dave Watson <dwatson@mimvista.com> * Copyright (C) 2007, Dave Watson <dwatson@mimvista.com>
* Copyright (C) 2008, Robin Rosenberg <robin.rosenberg@dewire.com> * Copyright (C) 2008, Robin Rosenberg <robin.rosenberg@dewire.com>
* Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org> * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org>
Expand Down Expand Up @@ -901,6 +901,11 @@ public RepositoryState GetRespositoryState()
return RepositoryState.Safe; return RepositoryState.Safe;
} }


public Dictionary<string, Ref> GetAllRefs ()
{
return _refs.GetAllRefs ();
}

/** /**
* Check validty of a ref name. It must not contain character that has * Check validty of a ref name. It must not contain character that has
* a special meaning in a Git object reference expression. Some other * a special meaning in a Git object reference expression. Some other
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -87,7 +87,7 @@ test.exe: Gitty.Lib.CSharp.dll
$(CSC) -r:Gitty.Lib.CSharp.dll -debug test.cs $(CSC) -r:Gitty.Lib.CSharp.dll -debug test.cs


run: test.exe run: test.exe
mono test.exe mono --debug test.exe


clean: clean:
rm -f *.dll *.mdb *.exe rm -f *.dll *.mdb *.exe
7 changes: 6 additions & 1 deletion test.cs
Expand Up @@ -7,6 +7,11 @@ class X {
static void Main (string [] args) static void Main (string [] args)
{ {
var repo = new Repository (new DirectoryInfo ("/cvs/egit/.git")); var repo = new Repository (new DirectoryInfo ("/cvs/egit/.git"));


Console.WriteLine ("Refs:");
var refs = repo.GetAllRefs ();
foreach (var k in refs){
Console.WriteLine (" {0} -> {1}", k.Key, k.Value);
}
} }
} }

0 comments on commit e79e1a5

Please sign in to comment.