Exemplo n.º 1
0
		void RevertUnimportant(IDestinationDriver driver, string path, string relPath, Action<bool> prepareFileForModifications)
		{
			var relNorm = relPath.ToLowerInvariant().Replace('\\', '/').Trim('/');

			var unimportantPatterns = _unimportants.Where(t => t.Item1.IsMatch(relNorm)).ToArray();

			if (unimportantPatterns.Length == 0)
				return;

			var diff = driver.GetDiff(path);

			var diffLines = diff
				.Split("\r\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)
				// skip header up to @@ marker
				.SkipWhile(s => !s.StartsWith("@@"))
				// get only real diff
				.Where(s => s.StartsWith("-") || s.StartsWith("+"))
			;

			// check if all differences matched to any pattern
			if (diffLines.All(diffLine => unimportantPatterns.Any(t => t.Item2.IsMatch(diffLine))))
			{
				// file contains only unimportant changes and will not be included in commit
				prepareFileForModifications(false);

				// revert all unimportant changes
				driver.Revert(path);

				Console.WriteLine("	Skip unimportant: {0}", relPath);
			}
		}
Exemplo n.º 2
0
		void LoadRevision(IDestinationDriver driver, Commit commit, StreamWriter log)
		{
			var added = new List<string>();

			foreach (var file in commit.Files)
			{
				var filePath = _cache.GetFilePath(file.FileSpec, file.VssVersion);
				if(filePath == null)
				{
					Debugger.Break();
					log.WriteLine("File {0}@{1} absent in cache. Rerun 'VssSvnConverter build-cache'", file.FileSpec, file.VssVersion);
					Console.Error.WriteLine("File {0}@{1} absent in cache. Rerun 'VssSvnConverter build-cache'", file.FileSpec, file.VssVersion);
					Environment.Exit(1);
				}

				var relPath = file.FileSpec.TrimStart('$', '/', '\\');

				// mangle path
				if (_opts.MangleImportPath.Count > 0)
				{
					foreach (var manglePair in _opts.MangleImportPath)
					{
						relPath = manglePair.Item1.Replace(relPath, manglePair.Item2);
					}
				}

				// special mode for check unimportant differenrces
				if (_opts.ImportUnimportantOnly && !_unimportants.Any(t => t.Item1.IsMatch(relPath.ToLowerInvariant().Replace('\\', '/').Trim('/'))))
					continue;

				log.WriteLine("Load: {0} -> {1}", file, relPath);

				var dstPath = Path.Combine(driver.WorkingCopy, relPath);

				var dstDir = Path.GetDirectoryName(dstPath);
				Debug.Assert(dstDir != null);
				if(!Directory.Exists(dstDir))
					driver.AddDirectory(dstDir);

				var addToVcs = !File.Exists(dstPath);

				if(File.Exists(dstPath))
				{
					File.Delete(dstPath);
					log.WriteLine("Deleted: {0}", dstPath);
				}

				if(_useHardLink)
				{
					_useHardLink = CreateHardLink(dstPath, filePath, IntPtr.Zero);
					log.WriteLine("CreateHl: {0} -> {1} result: {2}", filePath, dstPath, _useHardLink);
				}

				if(!_useHardLink)
				{
					File.Copy(filePath, dstPath, true);
					log.WriteLine("Copy: {0} -> {1}", filePath, dstPath);
				}

				// git can not detect modifications if MTime not updated
				File.SetLastWriteTimeUtc(filePath, DateTime.UtcNow);

				if(addToVcs)
					added.Add(dstPath);

				// file can be modified in place if it is not hardlink
				var canBeModifiedInplace = !_useHardLink;
				Action<bool> prepareForModifyInplace = recuireContent => {

					if (canBeModifiedInplace)
						return;

					// make copy of file instead of hardlink
					File.Delete(dstPath);

					if (recuireContent)
					{
						File.Copy(filePath, dstPath, true);
						log.WriteLine("Copy: {0} -> {1}", filePath, dstPath);
					}
					canBeModifiedInplace = true;

				};

				DoCensoring(driver.WorkingCopy, dstPath, _censors, prepareForModifyInplace);

				if (!addToVcs && _unimportants.Count > 0)
					RevertUnimportant(driver, dstPath, relPath, prepareForModifyInplace);
			}

			if(added.Count > 0)
				driver.AddFiles(added.ToArray());
		}