本文整理汇总了C#中TreeWalk.GetObjectId方法的典型用法代码示例。如果您正苦于以下问题:C# TreeWalk.GetObjectId方法的具体用法?C# TreeWalk.GetObjectId怎么用?C# TreeWalk.GetObjectId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TreeWalk
的用法示例。
在下文中一共展示了TreeWalk.GetObjectId方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetFileContent
public static string GetFileContent(this RevCommit commit, string path, Repository repository)
{
var treeWalk = new TreeWalk(repository) {Recursive = true, Filter = PathFilter.Create(path)};
treeWalk.AddTree(commit.Tree);
if (!treeWalk.Next())
{
return string.Empty;
}
var objectId = treeWalk.GetObjectId(0);
var loader = repository.Open(objectId);
using (var stream = loader.OpenStream())
{
using (var reader = new StreamReader(stream))
{
return reader.ReadToEnd();
}
}
}
示例2: TestFindObjects
public virtual void TestFindObjects()
{
DirCache tree0 = DirCache.NewInCore();
DirCacheBuilder b0 = tree0.Builder();
ObjectReader or = db.NewObjectReader();
ObjectInserter oi = db.NewObjectInserter();
DirCacheEntry aDotB = CreateEntry("a.b", EXECUTABLE_FILE);
b0.Add(aDotB);
DirCacheEntry aSlashB = CreateEntry("a/b", REGULAR_FILE);
b0.Add(aSlashB);
DirCacheEntry aSlashCSlashD = CreateEntry("a/c/d", REGULAR_FILE);
b0.Add(aSlashCSlashD);
DirCacheEntry aZeroB = CreateEntry("a0b", SYMLINK);
b0.Add(aZeroB);
b0.Finish();
NUnit.Framework.Assert.AreEqual(4, tree0.GetEntryCount());
ObjectId tree = tree0.WriteTree(oi);
// Find the directories that were implicitly created above.
TreeWalk tw = new TreeWalk(or);
tw.AddTree(tree);
ObjectId a = null;
ObjectId aSlashC = null;
while (tw.Next())
{
if (tw.PathString.Equals("a"))
{
a = tw.GetObjectId(0);
tw.EnterSubtree();
while (tw.Next())
{
if (tw.PathString.Equals("a/c"))
{
aSlashC = tw.GetObjectId(0);
break;
}
}
break;
}
}
NUnit.Framework.Assert.AreEqual(a, TreeWalk.ForPath(or, "a", tree).GetObjectId(0)
);
NUnit.Framework.Assert.AreEqual(a, TreeWalk.ForPath(or, "a/", tree).GetObjectId(0
));
NUnit.Framework.Assert.AreEqual(null, TreeWalk.ForPath(or, "/a", tree));
NUnit.Framework.Assert.AreEqual(null, TreeWalk.ForPath(or, "/a/", tree));
NUnit.Framework.Assert.AreEqual(aDotB.GetObjectId(), TreeWalk.ForPath(or, "a.b",
tree).GetObjectId(0));
NUnit.Framework.Assert.AreEqual(null, TreeWalk.ForPath(or, "/a.b", tree));
NUnit.Framework.Assert.AreEqual(null, TreeWalk.ForPath(or, "/a.b/", tree));
NUnit.Framework.Assert.AreEqual(aDotB.GetObjectId(), TreeWalk.ForPath(or, "a.b/",
tree).GetObjectId(0));
NUnit.Framework.Assert.AreEqual(aZeroB.GetObjectId(), TreeWalk.ForPath(or, "a0b",
tree).GetObjectId(0));
NUnit.Framework.Assert.AreEqual(aSlashB.GetObjectId(), TreeWalk.ForPath(or, "a/b"
, tree).GetObjectId(0));
NUnit.Framework.Assert.AreEqual(aSlashB.GetObjectId(), TreeWalk.ForPath(or, "b",
a).GetObjectId(0));
NUnit.Framework.Assert.AreEqual(aSlashC, TreeWalk.ForPath(or, "a/c", tree).GetObjectId
(0));
NUnit.Framework.Assert.AreEqual(aSlashC, TreeWalk.ForPath(or, "c", a).GetObjectId
(0));
NUnit.Framework.Assert.AreEqual(aSlashCSlashD.GetObjectId(), TreeWalk.ForPath(or,
"a/c/d", tree).GetObjectId(0));
NUnit.Framework.Assert.AreEqual(aSlashCSlashD.GetObjectId(), TreeWalk.ForPath(or,
"c/d", a).GetObjectId(0));
or.Release();
oi.Release();
}
示例3: add_File
public static GitData_File add_File(this List<GitData_File> gitData_Files, TreeWalk treeWalk)
{
var gitData_File = new GitData_File
{
FilePath = treeWalk.PathString,
Sha1 = treeWalk.GetObjectId(0).sha1()
};
gitData_Files.add(gitData_File);
return gitData_File;
}
示例4: GetFileLineCount
static int GetFileLineCount (NGit.Repository repo, TreeWalk tw) {
ObjectId id = tw.GetObjectId (0);
byte[] data = repo.ObjectDatabase.Open (id).GetBytes ();
return new RawText (data).Size();
}
示例5: Scan
// reduce the visibility of the default constructor
/// <summary>Convert the TreeWalk into DiffEntry headers.</summary>
/// <remarks>Convert the TreeWalk into DiffEntry headers.</remarks>
/// <param name="walk">the TreeWalk to walk through. Must have exactly two trees.</param>
/// <returns>headers describing the changed files.</returns>
/// <exception cref="System.IO.IOException">the repository cannot be accessed.</exception>
public static IList<NGit.Diff.DiffEntry> Scan(TreeWalk walk)
{
IList<NGit.Diff.DiffEntry> r = new AList<NGit.Diff.DiffEntry>();
MutableObjectId idBuf = new MutableObjectId();
while (walk.Next())
{
NGit.Diff.DiffEntry entry = new NGit.Diff.DiffEntry();
walk.GetObjectId(idBuf, 0);
entry.oldId = AbbreviatedObjectId.FromObjectId(idBuf);
walk.GetObjectId(idBuf, 1);
entry.newId = AbbreviatedObjectId.FromObjectId(idBuf);
entry.oldMode = walk.GetFileMode(0);
entry.newMode = walk.GetFileMode(1);
entry.newPath = entry.oldPath = walk.PathString;
if (entry.oldMode == FileMode.MISSING)
{
entry.oldPath = NGit.Diff.DiffEntry.DEV_NULL;
entry.changeType = DiffEntry.ChangeType.ADD;
r.AddItem(entry);
}
else
{
if (entry.newMode == FileMode.MISSING)
{
entry.newPath = NGit.Diff.DiffEntry.DEV_NULL;
entry.changeType = DiffEntry.ChangeType.DELETE;
r.AddItem(entry);
}
else
{
entry.changeType = DiffEntry.ChangeType.MODIFY;
if (RenameDetector.SameType(entry.oldMode, entry.newMode))
{
r.AddItem(entry);
}
else
{
Sharpen.Collections.AddAll(r, BreakModify(entry));
}
}
}
}
return r;
}
示例6: ReadCommit
public string ReadCommit(string commitId, string fileName)
{
var repo = m_git.GetRepository();
var id = ObjectId.FromString(commitId);
RevCommit commit = null;
try
{
commit = ParseCommit(repo, id);
if (commit == null)
return null;
}
catch (Exception ex)
{
Trace.WriteLine(ex.Message);
return null;
}
//var commits = m_git.Log().AddRange(id, id).Call();
//var commit = commits.SingleOrDefault();
//if (commit == null)
// return null;
TreeWalk walk = new TreeWalk(repo);
//RevWalk r = new RevWalk(m_git.GetRepository());
//var tree = r.ParseTree(commit.Tree.Id);
//r.LookupTree(
//walk.AddTree(new FileTreeIterator(repo));
//var tree = ParseTree(repo, commit.Tree.Id);
walk.AddTree(commit.Tree);
var filter = GetGitFriendlyName(fileName);
walk.Filter = PathFilterGroup.CreateFromStrings(new string[]{filter});
//walk.EnterSubtree();
while (walk.Next())
{
var path = walk.PathString;
if (walk.IsSubtree)
{
walk.EnterSubtree();
continue;
}
if (path == filter)
{
var cur = walk.GetObjectId(0);
ObjectLoader ol = repo.Open(cur);
// //Console.WriteLine(string.Format("Path: {0}{1}", walk.PathString, walk.IsSubtree ? "/" : ""));
// //var loader = reader.Open(commit.Tree.Id);
var text = "";
using (var stream = ol.OpenStream())
using (var sr = new System.IO.StreamReader(stream))
{
text = sr.ReadToEnd();
}
return text;
}
}
//walk.Reset();
//reader.Open();
return "";
}
示例7: CalculateCommitDiff
static IEnumerable<Change> CalculateCommitDiff (NGit.Repository repo, TreeWalk walk, RevCommit[] commits)
{
while (walk.Next ()) {
int m0 = walk.GetRawMode (0);
if (walk.TreeCount == 2) {
int m1 = walk.GetRawMode (1);
var change = new Change { ReferenceCommit = commits[0], ComparedCommit = commits[1], ReferencePermissions = walk.GetFileMode (0).GetBits (), ComparedPermissions = walk.GetFileMode (1).GetBits (), Name = walk.NameString, Path = walk.PathString };
if (m0 != 0 && m1 == 0) {
change.ChangeType = ChangeType.Added;
change.ComparedObject = walk.GetObjectId (0);
} else if (m0 == 0 && m1 != 0) {
change.ChangeType = ChangeType.Deleted;
change.ReferenceObject = walk.GetObjectId (0);
} else if (m0 != m1 && walk.IdEqual (0, 1)) {
change.ChangeType = ChangeType.TypeChanged;
change.ReferenceObject = walk.GetObjectId (0);
change.ComparedObject = walk.GetObjectId (1);
} else {
change.ChangeType = ChangeType.Modified;
change.ReferenceObject = walk.GetObjectId (0);
change.ComparedObject = walk.GetObjectId (1);
}
yield return change;
} else {
var raw_modes = new int[walk.TreeCount - 1];
for (int i = 0; i < walk.TreeCount - 1; i++)
raw_modes[i] = walk.GetRawMode (i + 1);
//ComparedCommit = compared,
var change = new Change { ReferenceCommit = commits[0], Name = walk.NameString, Path = walk.PathString };
if (m0 != 0 && raw_modes.All (m1 => m1 == 0)) {
change.ChangeType = ChangeType.Added;
change.ComparedObject = walk.GetObjectId (0);
yield return change;
} else if (m0 == 0 && raw_modes.Any (m1 => m1 != 0)) {
change.ChangeType = ChangeType.Deleted;
yield return change;
// TODO: not sure if this condition suffices in some special cases.
} else if (raw_modes.Select ((m1, i) => new { Mode = m1, Index = i + 1 }).All (x => !walk.IdEqual (0, x.Index))) {
change.ChangeType = ChangeType.Modified;
change.ReferenceObject = walk.GetObjectId (0);
yield return change;
} else if (raw_modes.Select ((m1, i) => new { Mode = m1, Index = i + 1 }).Any (x => m0 != x.Mode && walk.IdEqual (0, x.Index))) {
change.ChangeType = ChangeType.TypeChanged;
change.ReferenceObject = walk.GetObjectId (0);
yield return change;
}
}
}
}
示例8: Scan
/// <summary>
/// Convert the TreeWalk into DiffEntry headers, depending on
/// <code>includeTrees</code>
/// it will add tree objects into result or not.
/// </summary>
/// <param name="walk">
/// the TreeWalk to walk through. Must have exactly two trees and
/// when
/// <code>includeTrees</code>
/// parameter is
/// <code>true</code>
/// it can't
/// be recursive.
/// </param>
/// <param name="includeTrees">include tree object's.</param>
/// <returns>headers describing the changed files.</returns>
/// <exception cref="System.IO.IOException">the repository cannot be accessed.</exception>
/// <exception cref="System.ArgumentException">
/// when
/// <code>includeTrees</code>
/// is true and given TreeWalk is
/// recursive. Or when given TreeWalk doesn't have exactly two
/// trees
/// </exception>
public static IList<NGit.Diff.DiffEntry> Scan(TreeWalk walk, bool includeTrees)
{
if (walk.TreeCount != 2)
{
throw new ArgumentException(JGitText.Get().treeWalkMustHaveExactlyTwoTrees);
}
if (includeTrees && walk.Recursive)
{
throw new ArgumentException(JGitText.Get().cannotBeRecursiveWhenTreesAreIncluded);
}
IList<NGit.Diff.DiffEntry> r = new AList<NGit.Diff.DiffEntry>();
MutableObjectId idBuf = new MutableObjectId();
while (walk.Next())
{
NGit.Diff.DiffEntry entry = new NGit.Diff.DiffEntry();
walk.GetObjectId(idBuf, 0);
entry.oldId = AbbreviatedObjectId.FromObjectId(idBuf);
walk.GetObjectId(idBuf, 1);
entry.newId = AbbreviatedObjectId.FromObjectId(idBuf);
entry.oldMode = walk.GetFileMode(0);
entry.newMode = walk.GetFileMode(1);
entry.newPath = entry.oldPath = walk.PathString;
if (entry.oldMode == FileMode.MISSING)
{
entry.oldPath = NGit.Diff.DiffEntry.DEV_NULL;
entry.changeType = DiffEntry.ChangeType.ADD;
r.AddItem(entry);
}
else
{
if (entry.newMode == FileMode.MISSING)
{
entry.newPath = NGit.Diff.DiffEntry.DEV_NULL;
entry.changeType = DiffEntry.ChangeType.DELETE;
r.AddItem(entry);
}
else
{
if (!entry.oldId.Equals(entry.newId))
{
entry.changeType = DiffEntry.ChangeType.MODIFY;
if (RenameDetector.SameType(entry.oldMode, entry.newMode))
{
r.AddItem(entry);
}
else
{
Sharpen.Collections.AddAll(r, BreakModify(entry));
}
}
else
{
if (entry.oldMode != entry.newMode)
{
entry.changeType = DiffEntry.ChangeType.MODIFY;
r.AddItem(entry);
}
}
}
}
if (includeTrees && walk.IsSubtree)
{
walk.EnterSubtree();
}
}
return r;
}
示例9: AssertCorrectId
private void AssertCorrectId(DirCache treeT, TreeWalk tw)
{
NUnit.Framework.Assert.AreEqual(treeT.GetEntry(tw.PathString).GetObjectId(), tw.GetObjectId
(0));
}
示例10: AssertEntry
/// <exception cref="NGit.Errors.MissingObjectException"></exception>
/// <exception cref="NGit.Errors.IncorrectObjectTypeException"></exception>
/// <exception cref="NGit.Errors.CorruptObjectException"></exception>
/// <exception cref="System.IO.IOException"></exception>
private void AssertEntry(string sha1string, string path, TreeWalk tw)
{
NUnit.Framework.Assert.IsTrue(tw.Next());
NUnit.Framework.Assert.AreEqual(path, tw.PathString);
NUnit.Framework.Assert.AreEqual(sha1string, tw.GetObjectId(1).GetName());
}
示例11: TestMissingSubtree_DetectFileAdded_FileModified
public virtual void TestMissingSubtree_DetectFileAdded_FileModified()
{
ObjectInserter inserter = db.NewObjectInserter();
ObjectId aFileId = inserter.Insert(Constants.OBJ_BLOB, Constants.Encode("a"));
ObjectId bFileId = inserter.Insert(Constants.OBJ_BLOB, Constants.Encode("b"));
ObjectId cFileId1 = inserter.Insert(Constants.OBJ_BLOB, Constants.Encode("c-1"));
ObjectId cFileId2 = inserter.Insert(Constants.OBJ_BLOB, Constants.Encode("c-2"));
// Create sub-a/empty, sub-c/empty = hello.
ObjectId oldTree;
{
Tree root = new Tree(db);
{
Tree subA = root.AddTree("sub-a");
subA.AddFile("empty").SetId(aFileId);
subA.SetId(inserter.Insert(Constants.OBJ_TREE, subA.Format()));
}
{
Tree subC = root.AddTree("sub-c");
subC.AddFile("empty").SetId(cFileId1);
subC.SetId(inserter.Insert(Constants.OBJ_TREE, subC.Format()));
}
oldTree = inserter.Insert(Constants.OBJ_TREE, root.Format());
}
// Create sub-a/empty, sub-b/empty, sub-c/empty.
ObjectId newTree;
{
Tree root = new Tree(db);
{
Tree subA = root.AddTree("sub-a");
subA.AddFile("empty").SetId(aFileId);
subA.SetId(inserter.Insert(Constants.OBJ_TREE, subA.Format()));
}
{
Tree subB = root.AddTree("sub-b");
subB.AddFile("empty").SetId(bFileId);
subB.SetId(inserter.Insert(Constants.OBJ_TREE, subB.Format()));
}
{
Tree subC = root.AddTree("sub-c");
subC.AddFile("empty").SetId(cFileId2);
subC.SetId(inserter.Insert(Constants.OBJ_TREE, subC.Format()));
}
newTree = inserter.Insert(Constants.OBJ_TREE, root.Format());
}
inserter.Flush();
inserter.Release();
TreeWalk tw = new TreeWalk(db);
tw.Reset(oldTree, newTree);
tw.Recursive = true;
tw.Filter = TreeFilter.ANY_DIFF;
NUnit.Framework.Assert.IsTrue(tw.Next());
NUnit.Framework.Assert.AreEqual("sub-b/empty", tw.PathString);
NUnit.Framework.Assert.AreEqual(FileMode.MISSING, tw.GetFileMode(0));
NUnit.Framework.Assert.AreEqual(FileMode.REGULAR_FILE, tw.GetFileMode(1));
NUnit.Framework.Assert.AreEqual(ObjectId.ZeroId, tw.GetObjectId(0));
NUnit.Framework.Assert.AreEqual(bFileId, tw.GetObjectId(1));
NUnit.Framework.Assert.IsTrue(tw.Next());
NUnit.Framework.Assert.AreEqual("sub-c/empty", tw.PathString);
NUnit.Framework.Assert.AreEqual(FileMode.REGULAR_FILE, tw.GetFileMode(0));
NUnit.Framework.Assert.AreEqual(FileMode.REGULAR_FILE, tw.GetFileMode(1));
NUnit.Framework.Assert.AreEqual(cFileId1, tw.GetObjectId(0));
NUnit.Framework.Assert.AreEqual(cFileId2, tw.GetObjectId(1));
NUnit.Framework.Assert.IsFalse(tw.Next());
}
示例12: LoadModulesConfig
/// <summary>
/// Load the config for this walk from
/// <code>.gitmodules</code>
/// .
/// <p>
/// Uses the root tree if
/// <see cref="SetRootTree(NGit.Treewalk.AbstractTreeIterator)">SetRootTree(NGit.Treewalk.AbstractTreeIterator)
/// </see>
/// was
/// previously called, otherwise uses the working tree.
/// <p>
/// If no submodule config is found, loads an empty config.
/// </summary>
/// <returns>this generator</returns>
/// <exception cref="System.IO.IOException">if an error occurred, or if the repository is bare
/// </exception>
/// <exception cref="NGit.Errors.ConfigInvalidException">NGit.Errors.ConfigInvalidException
/// </exception>
public virtual NGit.Submodule.SubmoduleWalk LoadModulesConfig()
{
if (rootTree == null)
{
FilePath modulesFile = new FilePath(repository.WorkTree, Constants.DOT_GIT_MODULES
);
FileBasedConfig config = new FileBasedConfig(modulesFile, repository.FileSystem);
config.Load();
modulesConfig = config;
}
else
{
TreeWalk configWalk = new TreeWalk(repository);
try
{
configWalk.AddTree(rootTree);
// The root tree may be part of the submodule walk, so we need to revert
// it after this walk.
int idx;
for (idx = 0; !rootTree.First; idx++)
{
rootTree.Back(1);
}
try
{
configWalk.Recursive = false;
PathFilter filter = PathFilter.Create(Constants.DOT_GIT_MODULES);
configWalk.Filter = filter;
while (configWalk.Next())
{
if (filter.IsDone(configWalk))
{
modulesConfig = new BlobBasedConfig(null, repository, configWalk.GetObjectId(0));
return this;
}
}
modulesConfig = new Config();
}
finally
{
if (idx > 0)
{
rootTree.Next(idx);
}
}
}
finally
{
configWalk.Release();
}
}
return this;
}