2 using System
.Collections
.Generic
;
3 using System
.ComponentModel
;
7 using System
.Windows
.Forms
;
8 using System
.Diagnostics
;
14 public partial class Form1
: Form
16 protected List
<Git
.File
> m_files
;
17 protected OutputTextWriter m_outputWriter
;
20 InitializeComponent();
21 OutputTextWriter m_outputWriter
= new OutputTextWriter(m_outputArea
);
22 System
.Console
.SetOut(m_outputWriter
);
24 Git
.Repo r
= new Git
.Repo("/home/govind/Projects/testme");
28 protected bool ResetRepoTree(Repo repo
)
30 m_files
= repo
.ListFiles();
31 m_workspaceTree
.BeginUpdate();
32 m_workspaceTree
.Nodes
.Clear();
33 TreeNode root
= new TreeNode("root");
35 m_workspaceTree
.Nodes
.Add(root
);
36 Stack
<TreeNode
> nodeStack
= new Stack
<TreeNode
>();
39 foreach (Git
.File f
in m_files
)
41 TreeNode n
= new TreeNode(f
.Name
);
43 System
.Console
.WriteLine("filepath: " + f
.RelativePath
+ " nodepath: " + nodeStack
.Peek().Tag
.ToString());
44 if (f
.RelativePath
== "")
48 else if (f
.RelativePath
== nodeStack
.Peek().Tag
.ToString())
50 nodeStack
.Peek().Nodes
.Add(n
);
55 while (nodeStack
.Count
> 1 && !bDone
)
57 string stackPath
= nodeStack
.Peek().Tag
.ToString();
58 if (f
.RelativePath
== stackPath
)
60 nodeStack
.Peek().Nodes
.Add(n
);
65 string[] pathParts
= f
.RelativePath
.Split(System
.IO
.Path
.DirectorySeparatorChar
);
66 int idx
= pathParts
.Length
- 1;
67 while (idx
> -1 && !bDone
)
69 string subPath
= string.Join(System
.IO
.Path
.DirectorySeparatorChar
.ToString(), pathParts
, 0, idx
);
70 if (stackPath
.Length
> subPath
.Length
)
74 if (subPath
== stackPath
)
76 for (int newPartsIdx
= idx
+ 1; newPartsIdx
< pathParts
.Length
; ++newPartsIdx
)
78 subPath
= subPath
+ System
.IO
.Path
.DirectorySeparatorChar
+ pathParts
[newPartsIdx
];
79 TreeNode pathNode
= new TreeNode(pathParts
[newPartsIdx
]);
80 pathNode
.Tag
= subPath
;
81 nodeStack
.Peek().Nodes
.Add(pathNode
);
82 nodeStack
.Push(pathNode
);
84 nodeStack
.Peek().Nodes
.Add(n
);
94 m_workspaceTree
.EndUpdate();