Пример #1
0
		private static IEnumerable<string> ReadCvsIgnoreFile(FileContent file)
		{
			var content = file.Data.ToString();

			int start = 0;
			bool seenEscape = false;

			for (int i = 0; i < content.Length; i++)
			{
				if (content[i] == '\\')
				{
					seenEscape = !seenEscape;
				}
				else
				{
					if (Char.IsWhiteSpace(content[i]))
					{
						if (!seenEscape)
						{
							// end of filename
							if (start < i)
								yield return content.Substring(start, i - start);
							start = i + 1;
						}
					}

					seenEscape = false;
				}
			}

			if (start < content.Length)
				yield return content.Substring(start);
		}
Пример #2
0
		public static FileContent Rewrite(FileContent file)
		{
			string newFilename;
			var lastSlash = file.Name.LastIndexOf('/');
			if (lastSlash >= 0)
				newFilename = file.Name.Remove(lastSlash + 1) + ".gitignore";
			else
				newFilename = ".gitignore";

			if (file.IsDead)
			{
				return FileContent.CreateDeadFile(newFilename);
			}
			else
			{
				var lines = from i in ReadCvsIgnoreFile(file)
							where i.Length > 0
							select TranslateEntry(i);

				var newContent = lines.Aggregate(
						new StringBuilder(),
						(buf, line) => buf.AppendFormat("{0}{1}", line, Environment.NewLine),
						buf => buf.ToString());

				var bytes = Encoding.UTF8.GetBytes(newContent);
				return new FileContent(newFilename, new FileContentData(bytes));
			}
		}
Пример #3
0
		private static void UpdateCache(string cachedPath, FileContent contents)
		{
			if (contents.Data.Length > int.MaxValue)
				throw new NotSupportedException("Cannot currently cope with files larger than 2 GB");

			Directory.CreateDirectory(Path.GetDirectoryName(cachedPath));
			var tempFile = cachedPath + ".tmp";

			try
			{
				// create temp file in case we're interrupted
				using (var stream = new FileStream(tempFile, FileMode.CreateNew))
				{
					stream.Write(contents.Data.Data, 0, (int)contents.Data.Length);
				}
				File.Move(tempFile, cachedPath);
			}
			finally
			{
				try { File.Delete(tempFile); } catch { }
			}
		}
Пример #4
0
		public static bool IsIgnoreFile(FileContent file)
		{
			return String.Equals(Path.GetFileName(file.Name), ".cvsignore", StringComparison.OrdinalIgnoreCase);
		}
Пример #5
0
 public static bool IsIgnoreFile(FileContent file)
 {
     return(String.Equals(Path.GetFileName(file.Name), ".cvsignore", StringComparison.OrdinalIgnoreCase));
 }