Exemplo n.º 1
0
        public string GetModifications(string fileName)
        {
            if (!filesystem.FileExists(fileName))
            {
                throw new Exception("File does not exists");
            }

            try
            {
                var working = new SvnPathTarget(fileName, SvnRevisionType.Working);
                var @base   = new SvnPathTarget(fileName, SvnRevisionType.Base);

                using (var client = new SvnClient())
                    using (var ms = new MemoryStream())
                    {
                        if (!client.Diff(@base, working, ms))
                        {
                            return(null);
                        }

                        ms.Position = 0;
                        return(Encoding.UTF8.GetString(ms.ToArray()));
                    }
            }
            catch (Exception)
            {
                return(null);
            }
        }
        private string GetPatchOfChange(long revision, string path)
        {
            if (revision == 1)
            {
                return("");
            }
            path = this.DirectoryPath + path;
            SvnRevisionRange range;

            range = new SvnRevisionRange(revision - 1, revision);
            MemoryStream diffResult = new MemoryStream();
            string       theFile    = String.Empty;
            int          counter    = 0;
            bool         descFlag   = false;

            using (SvnClient client = new SvnClient())
            {
                if (client.Diff(new SvnUriTarget(path), range, diffResult))
                {
                    diffResult.Position = 0;
                    StreamReader strReader = new StreamReader(diffResult);
                    string       diff      = strReader.ReadToEnd();
                    diff = diff.Insert(diff.Length, "\0");
                    if (diff.Length >= 50000)
                    {
                        double size = diff.Length / 500;
                        return(String.Format("File content: {0} kb", size));
                    }
                    foreach (char c in diff)
                    {
                        counter++;
                        if (c != '@' && descFlag == false) //getting past the first description part
                        {
                            continue;
                        }
                        else if (c == '@' && descFlag == false)                                           //we know we are towards the end of it
                        {
                            if (diff.Substring(counter, 1) == "\n" || diff.Substring(counter, 1) == "\r") //at the end of the line with the '@' symbols
                            {
                                descFlag = true;
                            }
                            else
                            {
                                continue;
                            }
                        }
                        else if (descFlag == true) //now reading the actual file
                        {
                            theFile += diff.Substring(counter);
                            break;
                        }
                    }
                }
            }
            return(theFile);
        }
Exemplo n.º 3
0
        public override string GetUnifiedDiff(FilePath path1, SvnRevision revision1, FilePath path2, SvnRevision revision2, bool recursive)
        {
            SvnPathTarget t1   = new SvnPathTarget(path1, GetRevision(revision1));
            SvnPathTarget t2   = new SvnPathTarget(path2, GetRevision(revision2));
            SvnDiffArgs   args = new SvnDiffArgs();

            args.Depth = recursive ? SvnDepth.Infinity : SvnDepth.Children;
            MemoryStream ms = new MemoryStream();

            client.Diff(t1, t2, args, ms);
            ms.Position = 0;
            using (StreamReader sr = new StreamReader(ms)) {
                return(sr.ReadToEnd());
            }
        }
Exemplo n.º 4
0
		public string GetDiff(string file)
		{
			using (var svn = new SvnClient())
			{
				var ms = new MemoryStream();

				svn.Diff(
					new SvnPathTarget(file, SvnRevisionType.Base),
					new SvnPathTarget(file, SvnRevisionType.Working), new SvnDiffArgs {NoProperties = true},
					ms
				);

				if (ms.Length == 0)
					return "";

				ms.Position = 0;

				return new StreamReader(ms, Encoding.UTF8).ReadToEnd();
			}
		}