public override Annotations GetAnnotationsFile(string filename) { var textLines = File.ReadAllLines(filename); string dir = filename.GetFilePath(); Strings arguments = new Strings(); arguments.Add("annotate"); arguments.Add("--xml"); arguments.Add(filename); Command command = new Command(program, dir, arguments); List <Line> lines = new List <Line>(); var output = command.GetOutput(); if (command.GetExitCode() != 0) { throw GetCommandException(command); } var entries = output.ToXML().GetElementsByTagName("entry"); for (int i = 0; i < entries.Count; i++) { // <entry line-number="1555"> // <commit revision="1182"> // <author>[email protected]</author> // <date>2012-08-26T19:31:06.283991Z</date> // </commit> // </entry> var entry = entries[i]; int lineNum = int.Parse(entry.Attributes.GetNamedItem("line-number").Value); var commit = GetFirstChildElement(entry, "commit"); string editor = GetFirstChildElement(commit, "author").InnerText; string dateText = GetFirstChildElement(commit, "date").InnerText.Substring(0, 23); DateTime edited = DateTime.Parse(dateText);//, dateFormat); lines.Add(new Line() { editor = editor, line = textLines[lineNum - 1], time = Epoch.ToLong(edited) }); } return(new AnnotationsVCS(lines)); }
public override Annotations GetAnnotationsFile(string filename) { var textLines = File.ReadAllLines(filename); FileAttributes attr = File.GetAttributes(filename); string editor = File.GetAccessControl(filename).GetOwner(typeof(System.Security.Principal.NTAccount)).ToString(); long edited = Epoch.ToLong(File.GetLastAccessTime(filename)); List <Line> lines = new List <Line>(); for (int i = 0; i < textLines.Length; i++) { lines.Add(new Line() { editor = editor, line = textLines[i], time = edited }); } return(new AnnotationsVCS(lines)); }
override public Annotations GetAnnotationsDir(string directory) { List <FSEntry> files = new List <FSEntry>(); foreach (var file in Directory.EnumerateFileSystemEntries(directory)) { FileAttributes attr = File.GetAttributes(file); string editor = File.GetAccessControl(file).GetOwner(typeof(System.Security.Principal.NTAccount)).ToString(); long edited = Epoch.ToLong(File.GetLastAccessTime(file)); string commitHash = null, authorName = null, authorEmail = null, subject = null; // Get the most recent edit Strings arguments = new Strings(); arguments.Add("log"); arguments.Add("--pretty=format:ch:%H%nan:%an%nae:%ae%nat:%at%nsj:%sj"); arguments.Add("-n"); arguments.Add("1"); arguments.Add(file.GetFileName()); Command command = new Command(program, directory, arguments); foreach (string output in command.GetOutput()) { string key = output.Substring(0, 3); string value = output.Substring(3); if (key == "ch:") { commitHash = value; } else if (key == "ct:") { edited = long.Parse(value); } else if (key == "an:") { authorName = value; } else if (key == "ae:") { authorEmail = value; } else if (key == "sj:") { subject = value; } } if (commitHash != null) { editor = authorName; if (authorEmail != null) { editor += " <" + authorEmail + ">"; } } files.Add(new FSEntry { editor = editor, name = file, modified = edited }); } return(new AnnotationsFS(files)); }