Пример #1
0
        public (MemoryStream, IRepositoryPair.FileType) ReadFile(string path, string branch = "master")
        {
            var(data, code) = SharedRepository.ExecuteWithExitCode($"show \"{branch}\":\"{path}\"");
            if (code != 0)
            {
                throw new FileNotFoundException($"File not found `{branch}:{path}'");
            }
            if (!string.IsNullOrWhiteSpace(path))
            {
                path = $"-- \"{path}\"";
            }
            var log = SharedRepository.Execute($"log -1 --pretty=\"\" \"{branch}\" --numstat {path}");

            using (var r = new StreamReader(new MemoryStream(log)))
            {
                if (r.ReadLine()[0] == '-')
                {
                    return(new MemoryStream(data), IRepositoryPair.FileType.Binary);
                }
                else
                {
                    return(new MemoryStream(data), IRepositoryPair.FileType.Text);
                }
            }
        }
Пример #2
0
        public CommitInfo ReadCommitInfo(string path, string branch = "master")
        {
            if (!string.IsNullOrWhiteSpace(path))
            {
                path = $"-- \"{path}\"";
            }
            var(data, code) = SharedRepository.ExecuteWithExitCode($"log -1 --pretty=\"%s\" \"{branch}\" {path}");
            if (code != 0)
            {
                return(null);
            }
            var      message     = System.Text.Encoding.UTF8.GetString(data).Trim();
            var      hashes      = System.Text.Encoding.UTF8.GetString(SharedRepository.Execute($"log -1 --pretty=\"%H %h\" \"{branch}\" -- {path}")).Trim().Split(" ");
            var      authorName  = System.Text.Encoding.UTF8.GetString(SharedRepository.Execute($"log -1 --pretty=\"%an\" \"{branch}\" -- {path}")).Trim();
            var      authorEmail = System.Text.Encoding.UTF8.GetString(SharedRepository.Execute($"log -1 --pretty=\"%ae\" \"{branch}\" -- {path}")).Trim();
            var      datestring  = System.Text.Encoding.UTF8.GetString(SharedRepository.Execute($"log -1 --pretty=\"%ad\" \"{branch}\" -- {path}")).Trim();
            DateTime date;

            DateTime.TryParseExact(datestring,
                                   "ddd MMM d HH:mm:ss yyyy K",
                                   System.Globalization.CultureInfo.InvariantCulture,
                                   System.Globalization.DateTimeStyles.None, out date);
            var shortHash = hashes.Count() >= 2 ? hashes[1] : "";

            return(new CommitInfo()
            {
                Message = message,
                Hash = hashes[0],
                ShortHash = shortHash,
                AuthorName = authorName,
                AuthorEmail = authorEmail,
                Date = date
            });
        }
Пример #3
0
 public MemoryStream ReadFileWithoutTypeCheck(string path, string branch = "master")
 {
     var(data, code) = SharedRepository.ExecuteWithExitCode($"show --binary \"{branch}\":\"{path}\"");
     if (code != 0)
     {
         throw new FileNotFoundException($"File not found `{branch}:{path}'");
     }
     return(new MemoryStream(data));
 }