本文整理汇总了C#中GitSharp.Core.ObjectWriter类的典型用法代码示例。如果您正苦于以下问题:C# ObjectWriter类的具体用法?C# ObjectWriter怎么用?C# ObjectWriter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ObjectWriter类属于GitSharp.Core命名空间,在下文中一共展示了ObjectWriter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: testNonRecursiveFiltering
public void testNonRecursiveFiltering()
{
var ow = new ObjectWriter(db);
ObjectId aSth = ow.WriteBlob("a.sth".getBytes());
ObjectId aTxt = ow.WriteBlob("a.txt".getBytes());
DirCache dc = DirCache.read(db);
DirCacheBuilder builder = dc.builder();
var aSthEntry = new DirCacheEntry("a.sth");
aSthEntry.setFileMode(FileMode.RegularFile);
aSthEntry.setObjectId(aSth);
var aTxtEntry = new DirCacheEntry("a.txt");
aTxtEntry.setFileMode(FileMode.RegularFile);
aTxtEntry.setObjectId(aTxt);
builder.add(aSthEntry);
builder.add(aTxtEntry);
builder.finish();
ObjectId treeId = dc.writeTree(ow);
var tw = new GitSharp.Core.TreeWalk.TreeWalk(db);
tw.setFilter(PathSuffixFilter.create(".txt"));
tw.addTree(treeId);
var paths = new LinkedList<string>();
while (tw.next())
{
paths.AddLast(tw.getPathString());
}
var expected = new LinkedList<string>();
expected.AddLast("a.txt");
Assert.AreEqual(expected, paths);
}
示例2: Save
/// <summary>
/// Persist this commit object
/// </summary>
/// <exception cref="IOException"></exception>
public void Save() // [henon] was Commit() in java, but c# won't allow it
{
if (CommitId != null)
{
throw new InvalidOperationException("exists " + CommitId);
}
CommitId = new ObjectWriter(Repository).WriteCommit(this);
}
示例3: HashAndInsertObject
public string HashAndInsertObject(string filename)
{
var writer = new ObjectWriter(_repository);
var objectId = writer.WriteBlob(new FileInfo(filename));
return objectId.ToString();
}
示例4: testMissingSubtree_DetectFileAdded_FileModified
public void testMissingSubtree_DetectFileAdded_FileModified()
{
var ow = new ObjectWriter(db);
ObjectId aFileId = ow.WriteBlob(Constants.CHARSET.GetBytes("a"));
ObjectId bFileId = ow.WriteBlob(Constants.CHARSET.GetBytes("b"));
ObjectId cFileId1 = ow.WriteBlob(Constants.CHARSET.GetBytes("c-1"));
ObjectId cFileId2 = ow.WriteBlob(Constants.CHARSET.GetBytes("c-2"));
// Create sub-a/empty, sub-c/empty = hello.
Func<ObjectId> oldTree = () =>
{
var root = new Core.Tree(db);
Core.Tree subA = root.AddTree("sub-a");
subA.AddFile("empty").Id = aFileId;
subA.Id = ow.WriteTree(subA);
Core.Tree subC = root.AddTree("sub-c");
subC.AddFile("empty").Id = cFileId1;
subC.Id = ow.WriteTree(subC);
return ow.WriteTree(root);
};
// Create sub-a/empty, sub-b/empty, sub-c/empty.
Func<ObjectId> newTree = () =>
{
var root = new Core.Tree(db);
Core.Tree subA = root.AddTree("sub-a");
subA.AddFile("empty").Id = aFileId;
subA.Id = ow.WriteTree(subA);
Core.Tree subB = root.AddTree("sub-b");
subB.AddFile("empty").Id = bFileId;
subB.Id = ow.WriteTree(subB);
Core.Tree subC = root.AddTree("sub-c");
subC.AddFile("empty").Id = cFileId2;
subC.Id = ow.WriteTree(subC);
return ow.WriteTree(root);
};
var tw = new GitSharp.Core.TreeWalk.TreeWalk(db);
tw.reset(new[] { oldTree.Invoke(), newTree.Invoke() });
tw.Recursive = true;
tw.setFilter(TreeFilter.ANY_DIFF);
Assert.IsTrue(tw.next());
Assert.AreEqual("sub-b/empty", tw.getPathString());
Assert.AreEqual(FileMode.Missing, tw.getFileMode(0));
Assert.AreEqual(FileMode.RegularFile, tw.getFileMode(1));
Assert.AreEqual(ObjectId.ZeroId, tw.getObjectId(0));
Assert.AreEqual(bFileId, tw.getObjectId(1));
Assert.IsTrue(tw.next());
Assert.AreEqual("sub-c/empty", tw.getPathString());
Assert.AreEqual(FileMode.RegularFile, tw.getFileMode(0));
Assert.AreEqual(FileMode.RegularFile, tw.getFileMode(1));
Assert.AreEqual(cFileId1, tw.getObjectId(0));
Assert.AreEqual(cFileId2, tw.getObjectId(1));
Assert.IsFalse(tw.next());
}
示例5: test025_computeSha1NoStore
public void test025_computeSha1NoStore()
{
byte[] data = "test025 some data, more than 16 bytes to get good coverage".getBytes("ISO-8859-1");
ObjectId id = new ObjectWriter(db).ComputeBlobSha1(data.Length, new MemoryStream(data));
Assert.AreEqual("4f561df5ecf0dfbd53a0dc0f37262fef075d9dde", id.Name);
}
示例6: Write_Blob
public void Write_Blob()
{
ObjectId id = new ObjectWriter(db).WriteBlob(new FileInfo("Resources/single_file_commit/i-am-a-file"));
Assert.AreEqual("95ea6a6859af6791464bd8b6de76ad5a6f9fad81", id.ToString());
Assert.AreEqual(Inspector.Inspect("Resources/single_file_commit", "95ea6a6859af6791464bd8b6de76ad5a6f9fad81"), new Inspector(db).Inspect(id));
writeTrashFile("i-am-a-file", "and this is the data in me\r\n\r\n");
id = new ObjectWriter(db).WriteBlob(new FileInfo(trash+"/i-am-a-file"));
Assert.AreEqual("95ea6a6859af6791464bd8b6de76ad5a6f9fad81", id.ToString());
}
示例7: GenSha1
private ObjectId GenSha1(string data)
{
var input = new MemoryStream(data.getBytes());
var writer = new ObjectWriter(db);
try
{
return writer.WriteObject(ObjectType.Blob, data.getBytes().Length, input, true);
}
catch (IOException exception)
{
Assert.Fail(exception.ToString());
}
return null;
}
示例8: test023_createCommitNonAnullii
public void test023_createCommitNonAnullii()
{
ObjectId emptyId = new ObjectWriter(db).WriteBlob(new byte[0]);
var almostEmptyTree = new Tree(db);
almostEmptyTree.AddEntry(new FileTreeEntry(almostEmptyTree, emptyId, "empty".getBytes(), false));
ObjectId almostEmptyTreeId = new ObjectWriter(db).WriteTree(almostEmptyTree);
var commit = new Commit(db)
{
TreeId = almostEmptyTreeId,
Author = new PersonIdent("Joe H\u00e4cker", "[email protected]", 4294967295000L, 60),
Committer = new PersonIdent("Joe Hacker", "[email protected]", 4294967295000L, 60),
Encoding = Constants.CHARSET,
Message = "\u00dcbergeeks"
};
ObjectId cid = new ObjectWriter(db).WriteCommit(commit);
Assert.AreEqual("4680908112778718f37e686cbebcc912730b3154", cid.Name);
}
示例9: WriteBlob
private RevObject WriteBlob(Core.Repository repo, string data)
{
var revWalk = new GitSharp.Core.RevWalk.RevWalk(repo);
byte[] bytes = Constants.encode(data);
var ow = new ObjectWriter(repo);
ObjectId id = ow.WriteBlob(bytes);
try
{
Parse(id);
Assert.Fail("Object " + id.Name + " should not exist in test repository");
}
catch (MissingObjectException)
{
// Ok
}
return revWalk.lookupBlob(id);
}
示例10: Save
// [henon] was Commit() in java, but c# won't allow it
/// <summary>
/// Persist this commit object
/// </summary>
/// <exception cref="IOException"></exception>
public void Save()
{
if (CommitId != null)
{
throw new InvalidOperationException("exists " + CommitId);
}
CommitId = new ObjectWriter(Repository).WriteCommit(this);
}
示例11: TestPick
public void TestPick()
{
// B---O
// \----P---T
//
// Cherry-pick "T" onto "O". This shouldn't introduce "p-fail", which
// was created by "P", nor should it modify "a", which was done by "P".
//
DirCache treeB = DirCache.read(db);
DirCache treeO = DirCache.read(db);
DirCache treeP = DirCache.read(db);
DirCache treeT = DirCache.read(db);
{
DirCacheBuilder b = treeB.builder();
DirCacheBuilder o = treeO.builder();
DirCacheBuilder p = treeP.builder();
DirCacheBuilder t = treeT.builder();
b.add(MakeEntry("a", FileMode.RegularFile));
o.add(MakeEntry("a", FileMode.RegularFile));
o.add(MakeEntry("o", FileMode.RegularFile));
p.add(MakeEntry("a", FileMode.RegularFile, "q"));
p.add(MakeEntry("p-fail", FileMode.RegularFile));
t.add(MakeEntry("a", FileMode.RegularFile));
t.add(MakeEntry("t", FileMode.RegularFile));
b.finish();
o.finish();
p.finish();
t.finish();
}
var ow = new ObjectWriter(db);
ObjectId B = Commit(ow, treeB, new ObjectId[] { });
ObjectId O = Commit(ow, treeO, new[] { B });
ObjectId P = Commit(ow, treeP, new[] { B });
ObjectId T = Commit(ow, treeT, new[] { P });
var twm = (ThreeWayMerger)MergeStrategy.SimpleTwoWayInCore.NewMerger(db);
twm.SetBase(P);
bool merge = twm.Merge(new[] { O, T });
Assert.IsTrue(merge);
var tw = new GitSharp.Core.TreeWalk.TreeWalk(db) { Recursive = true };
tw.reset(twm.GetResultTreeId());
Assert.IsTrue(tw.next());
Assert.AreEqual("a", tw.getPathString());
AssertCorrectId(treeO, tw);
Assert.IsTrue(tw.next());
Assert.AreEqual("o", tw.getPathString());
AssertCorrectId(treeO, tw);
Assert.IsTrue(tw.next());
Assert.AreEqual("t", tw.getPathString());
AssertCorrectId(treeT, tw);
Assert.IsFalse(tw.next());
}
示例12: WriteTree
/// <summary>
/// Construct a WriteTree for a given directory
/// </summary>
/// <param name="sourceDirectory"> </param>
/// <param name="db"> </param>
public WriteTree(DirectoryInfo sourceDirectory, Repository db)
: base(sourceDirectory)
{
ow = new ObjectWriter(db);
}
示例13: Save
//renamed from Tag
/**
* Store a tag.
* If author, message or type is set make the tag an annotated tag.
*
* @
*/
public void Save()
{
if (TagId != null)
throw new InvalidOperationException("exists " + TagId);
ObjectId id;
if (author != null || message != null || tagType != null)
{
ObjectId tagid = new ObjectWriter(Repository).WriteTag(this);
TagId = tagid;
id = tagid;
}
else
{
id = Id;
}
RefUpdate ru = Repository.UpdateRef(Constants.R_TAGS + TagName);
ru.NewObjectId = id;
ru.setRefLogMessage("tagged " + TagName, false);
if (ru.forceUpdate() == RefUpdate.RefUpdateResult.LOCK_FAILURE)
throw new ObjectWritingException("Unable to lock tag " + TagName);
}
示例14: test021_createTreeTag
public void test021_createTreeTag()
{
ObjectId emptyId = new ObjectWriter(db).WriteBlob(new byte[0]);
var almostEmptyTree = new Tree(db);
almostEmptyTree.AddEntry(new FileTreeEntry(almostEmptyTree, emptyId, "empty".getBytes(), false));
ObjectId almostEmptyTreeId = new ObjectWriter(db).WriteTree(almostEmptyTree);
var t = new Tag(db)
{
Id = almostEmptyTreeId,
TagType = "tree",
TagName = "test021",
Author = new PersonIdent(jauthor, 1154236443000L, -4*60),
Message = "test021 tagged\n"
};
t.Save();
Assert.AreEqual("b0517bc8dbe2096b419d42424cd7030733f4abe5", t.TagId.Name);
Tag MapTag = db.MapTag("test021");
Assert.AreEqual("tree", MapTag.TagType);
Assert.AreEqual("test021 tagged\n", MapTag.Message);
Assert.AreEqual(new PersonIdent(jauthor, 1154236443000L, -4 * 60), MapTag.Author);
Assert.AreEqual("417c01c8795a35b8e835113a85a5c0c1c77f67fb", MapTag.Id.Name);
}
示例15: HashWithGitSharp
private static string HashWithGitSharp(Stream file)
{
var repository = new Repository(new DirectoryInfo(Path.Combine(Environment.CurrentDirectory, ".git")));
var writer = new ObjectWriter(repository);
return writer.WriteBlob(file.Length, file).ToString();
}