2 using System
.Collections
.Generic
;
7 public class Commit
: Treeish
9 protected List
<string> m_Parents
;
10 public List
<string> Parents
14 if (null == m_Parents
&& !Populate())
18 return new List
<string>(m_Parents
);
20 internal set { m_Parents = value; }
23 public override string Name { get { return "Commit"; }
internal set { }
}
25 protected string m_hash
;
26 public override string ID { get { return m_hash; }
internal set { m_hash = value; }
}
28 protected string m_author
;
29 public string AuthorName
33 if (null == m_author
&& !Populate())
39 internal set { m_author = value; }
42 protected string m_authorEmail
;
43 public string AuthorEmail
47 if (null == m_authorEmail
&& !Populate())
53 internal set { m_authorEmail = value; }
56 protected string m_date
;
61 if (null == m_date
&& !Populate())
67 internal set { m_date = value; }
70 protected string m_subject
;
75 if (null == m_subject
&& !Populate())
81 internal set { m_subject = value; }
84 protected string m_body
;
89 if (null == m_body
&& !GetBody())
95 internal set { m_body = value; }
98 internal static string FormatString { get { return " --pretty=format:\"%H %P\t%an\t%ae\t%ad\t%s\" "; }
}
100 internal string FullFormatString { get { return " --pretty=format:\"%H %P\t%an\t%ae\t%ad\t%s\" "; }
} //use this to get body too
102 public Commit(string path
, string id
) : base(path
)
107 protected Commit(string path
) : base(path
)
111 public static Commit
GetCommit(string path
, string record
)
113 Commit c
= new Commit(path
);
118 protected bool GetBody()
120 Executioner e
= Executioner
.GetExecutioner(m_path
, true);
121 string output
, error
;
122 if (0 == e
.Execute("git-show", "--name-only --pretty=format:%b " + ID
, "", out output
, out error
))
124 m_body
= output
.Trim();
130 protected bool Populate()
132 Executioner e
= Executioner
.GetExecutioner(m_path
, true);
133 string output
, error
;
134 if (0 == e
.Execute("git-show", FormatString
+ ID
, "", out output
, out error
))
136 return Populate(output
.Trim());
141 internal bool Populate(string record
)
145 int idx1
= record
.IndexOf(" ");
146 string id
= record
.Substring(0, idx1
);
147 int idx2
= record
.IndexOf("\t", idx1
+ 1);
148 string[] parents
= record
.Substring(idx1
+ 1, (idx2
- idx1
) - 1).Split(" ".ToCharArray());
149 idx1
= record
.IndexOf("\t", idx2
+ 1);
150 string authorName
= record
.Substring(idx2
+ 1, (idx1
- idx2
) - 1);
151 idx2
= record
.IndexOf("\t", idx1
+ 1);
152 string authorEmail
= record
.Substring(idx1
+ 1, (idx2
- idx1
) - 1);
153 idx1
= record
.IndexOf("\t", idx2
+ 1);
154 string date
= record
.Substring(idx2
+ 1, (idx1
- idx2
) - 1);
156 string subject
= record
.Substring(idx1
+ 1);
158 Parents
= new List
<string>(parents
);
159 AuthorName
= authorName
;
160 AuthorEmail
= authorEmail
;
164 catch (IndexOutOfRangeException ex
)
166 System
.Console
.WriteLine(ex
.Message
+ " " + ex
.StackTrace
);