用libgit2.sharp构建跟踪文件的目录树

发布于 2025-02-02 19:41:37 字数 821 浏览 4 评论 0原文

不知道我在这里是否在正确的轨道上。

我一直在尝试通过递归构建字典info对象来构建在Winforms中的文件夹结构树,并通过一些黑客忽略了我忽略的文件和文件夹。

但是我发现有一个git命令基本上为我完成了这一切。 git ls -tree -r -t -name -hame -head

我可以用libgit2实现这一点吗?

谢谢!

编辑(添加解决方法),

所以现在我正在这样做

var info = new ProcessStartInfo("git", "ls-tree -r -t --name-only head")
{
  CreateNoWindow = true,
  RedirectStandardOutput = true,
  UseShellExecute = false,
  WorkingDirectory = "<repo workdir>",
};

var list = new List<TreeNode>();
using (var sr = Process.Start(info)?.StandardOutput)
{
  string? line;
  while ((line = sr?.ReadLine()) != null)
  {
    if (line != null)
      list.Add(new TreeNode(line));
  }
}
treeView.Nodes.Clear();
var rootDirectoryInfo = new DirectoryInfo(path);
treeView.Nodes.AddRange(list.ToArray());

not sure if I am on the right track here.

I have been trying to build a folder structure tree in Winforms by recursively building a DictionaryInfo object and with some hacking ignoring files and folders I ignored and not tracked by git.

But I found that there is a git command that basically does all this for me. git ls-tree -r -t --name-only head

Can I achieve this with libgit2?

Thanks!

Edit (Add workaround)

So right now I am doing this

var info = new ProcessStartInfo("git", "ls-tree -r -t --name-only head")
{
  CreateNoWindow = true,
  RedirectStandardOutput = true,
  UseShellExecute = false,
  WorkingDirectory = "<repo workdir>",
};

var list = new List<TreeNode>();
using (var sr = Process.Start(info)?.StandardOutput)
{
  string? line;
  while ((line = sr?.ReadLine()) != null)
  {
    if (line != null)
      list.Add(new TreeNode(line));
  }
}
treeView.Nodes.Clear();
var rootDirectoryInfo = new DirectoryInfo(path);
treeView.Nodes.AddRange(list.ToArray());

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

妄司 2025-02-09 19:41:37

Libgit2Sharp Wiki页面上有一个示例,它提供了一个起点,可以通过索引中的所有条目进行迭代: https://github.com/libgit2/libgit2sharp/wiki/wiki/git-ls-files-files#libgit2sharp

对于您的情况条目。

There is an example on the LibGit2Sharp wiki page that provides a starting point to iterate through all entries in the index: https://github.com/libgit2/libgit2sharp/wiki/git-ls-files#libgit2sharp

For your case, I think you will want to remove the block checking the stage level of the entry.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文