Example #1
0
		protected override bool RunInternal(Area ws, Versionr.Status status, IList<Versionr.Status.StatusEntry> targets, FileBaseCommandVerbOptions options)
		{
            CommitVerbOptions localOptions = options as CommitVerbOptions;

            if (localOptions.Message == null && localOptions.MessageFile == null)
            {
                Printer.PrintError("#x#Error:## A commit message must be specified with the --message or --message-file options.");
                return false;
            }

            if (targets != null && targets.Count > 0)
            {
                ws.RecordChanges(status, targets, localOptions.Missing, false, RecordFeedback);
            }
            string message = localOptions.Message;
            if (localOptions.MessageFile != null)
            {
                using (var fs = System.IO.File.OpenText(localOptions.MessageFile))
                {
                    message = fs.ReadToEnd();
                }
            }
            else
            {
                message = message.Replace("\\\"", "\"");
                message = message.Replace("\\n", "\n");
                message = message.Replace("\\t", "\t");
            }
            if (!ws.Commit(message, localOptions.Force))
                return false;
            return true;
        }
Example #2
0
 protected override bool ComputeTargets(FileBaseCommandVerbOptions options)
 {
     if (!base.ComputeTargets(options))
     {
         RecordVerbOptions localOptions = options as RecordVerbOptions;
         return localOptions.All || localOptions.Tracked;
     }
     return true;
 }
Example #3
0
		protected override bool RunInternal(Area ws, Versionr.Status status, IList<Versionr.Status.StatusEntry> targets, FileBaseCommandVerbOptions options)
		{
			RecordVerbOptions localOptions = options as RecordVerbOptions;
			return ws.RecordChanges(status, targets, localOptions.Missing, localOptions.Interactive, new Action<Versionr.Status.StatusEntry, StatusCode, bool>(RecordFeedback));
        }
Example #4
0
        protected override bool RunInternal(Area ws, Versionr.Status status, IList <Versionr.Status.StatusEntry> targets, FileBaseCommandVerbOptions options)
        {
            BomCheckEOLOptions localOptions = options as BomCheckEOLOptions;

            LocalOptions = localOptions;
            try
            {
                List <Versionr.Status.StatusEntry> realTargets = new List <Status.StatusEntry>();
                foreach (var x in targets)
                {
                    if (!x.IsDirectory && x.FilesystemEntry != null)
                    {
                        if (localOptions.Recorded && x.Staged == false)
                        {
                            continue;
                        }
                        realTargets.Add(x);
                    }
                }
                Printer.PrintMessage("{0} files in initial list...", realTargets.Count);

                CheckEOLStats cs = new CheckEOLStats();

                List <Task> tasks = new List <Task>();
                foreach (var x in realTargets)
                {
                    tasks.Add(GetTaskFactory(options).StartNew(() =>
                    {
                        var newFileType = Versionr.Utilities.FileClassifier.Classify(x.FilesystemEntry.Info);
                        if (newFileType == Versionr.Utilities.FileEncoding.Binary)
                        {
                            return;
                        }
                        // Displaying local modifications
                        Encoding encoding = BomClean.VSREncodingToEncoding(newFileType);
                        string fullText;
                        using (var fs = x.FilesystemEntry.Info.OpenRead())
                            using (var sr = new System.IO.StreamReader(fs, encoding))
                            {
                                fullText = sr.ReadToEnd();
                            }
                        IdentifyLineEndings(x.CanonicalName, fullText, localOptions, cs);
                    }));
                    if (System.Diagnostics.Debugger.IsAttached)
                    {
                        tasks[tasks.Count - 1].Wait();
                    }
                }
                Task.WaitAll(tasks.ToArray());
                if ((cs.CRLFFiles + cs.CRFiles + cs.LFFiles + cs.MixedFiles) > 1)
                {
                    Printer.PrintMessage("Final Count:");
                    if (cs.CRLFFiles > 0)
                    {
                        Printer.PrintMessage("\t#b#{0}## CRLF", cs.CRLFFiles);
                    }
                    if (cs.LFFiles > 0)
                    {
                        Printer.PrintMessage("\t#b#{0}## LF", cs.LFFiles);
                    }
                    if (cs.CRFiles > 0)
                    {
                        Printer.PrintMessage("\t#b#{0}## CR", cs.CRFiles);
                    }
                    if (cs.MixedFiles > 0)
                    {
                        Printer.PrintMessage("\t#w#{0}## Mixed", cs.MixedFiles);
                    }
                }
            }
            finally
            {
            }
            return(true);
        }
Example #5
0
        protected override bool RunInternal(Area ws, Versionr.Status status, IList <Versionr.Status.StatusEntry> targets, FileBaseCommandVerbOptions options)
        {
            BomTabOptions localOptions = options as BomTabOptions;

            try
            {
                List <Versionr.Status.StatusEntry> realTargets = new List <Status.StatusEntry>();
                foreach (var x in targets)
                {
                    if (x.VersionControlRecord != null && !x.IsDirectory && x.FilesystemEntry != null)
                    {
                        realTargets.Add(x);
                    }
                }
                Printer.PrintMessage("Found {0} files for processing...", realTargets.Count);
                TabStats    ts    = new TabStats();
                List <Task> tasks = new List <Task>();
                foreach (var x in realTargets)
                {
                    tasks.Add(GetTaskFactory(options).StartNew(() =>
                    {
                        var newFileType = Versionr.Utilities.FileClassifier.Classify(x.FilesystemEntry.Info);
                        if (newFileType == Versionr.Utilities.FileEncoding.Binary)
                        {
                            return;
                        }
                        ProcessFile(AddTabs, localOptions.Trim, localOptions.TabSize, x, ts);
                    }));
                    if (System.Diagnostics.Debugger.IsAttached)
                    {
                        tasks[tasks.Count - 1].Wait();
                    }
                }
                Task.WaitAll(tasks.ToArray());
                if (ts.Files > 0)
                {
                    if (AddTabs)
                    {
                        Printer.PrintMessage("Updated {0} files and inserted {1} tabs.", ts.Files, ts.Insertions);
                    }
                    else
                    {
                        Printer.PrintMessage("Updated {0} files and inserted {1} spaces.", ts.Files, ts.Insertions * localOptions.TabSize);
                    }
                }
            }
            finally
            {
            }
            return(true);
        }
Example #6
0
 protected override bool RunInternal(Area ws, Versionr.Status status, IList<Versionr.Status.StatusEntry> targets, FileBaseCommandVerbOptions options)
 {
     ResolveVerbOptions localOptions = options as ResolveVerbOptions;
     ws.Resolve(targets, UnrecordFeedback);
     return true;
 }
Example #7
0
        protected override bool RunInternal(Area ws, Versionr.Status status, IList <Versionr.Status.StatusEntry> targets, FileBaseCommandVerbOptions options)
        {
            BomSetEOLOptions localOptions = options as BomSetEOLOptions;

            LocalOptions = localOptions;
            try
            {
                List <Versionr.Status.StatusEntry> realTargets = new List <Status.StatusEntry>();
                foreach (var x in targets)
                {
                    if (!x.IsDirectory && x.FilesystemEntry != null)
                    {
                        if (localOptions.Recorded && x.Staged == false)
                        {
                            continue;
                        }
                        realTargets.Add(x);
                    }
                }
                Printer.PrintMessage("{0} files in initial list...", realTargets.Count);

                EOLStats cs = new EOLStats();

                List <Task> tasks = new List <Task>();
                foreach (var x in realTargets)
                {
                    tasks.Add(GetTaskFactory(options).StartNew(() =>
                    {
                        var newFileType = Versionr.Utilities.FileClassifier.Classify(x.FilesystemEntry.Info);
                        if (newFileType == Versionr.Utilities.FileEncoding.Binary)
                        {
                            return;
                        }
                        // Displaying local modifications
                        Encoding encoding = BomClean.VSREncodingToEncoding(newFileType);
                        string fullText;
                        using (var fs = x.FilesystemEntry.Info.OpenRead())
                            using (var sr = new System.IO.StreamReader(fs, encoding))
                            {
                                fullText = sr.ReadToEnd();
                            }
                        string resultString;
                        BomClean.LineEndingType let;
                        if (UnifyLineEndings(fullText, localOptions, out resultString, out let))
                        {
                            x.FilesystemEntry.Info.IsReadOnly = false;
                            using (var fs = x.FilesystemEntry.Info.Open(System.IO.FileMode.Create))
                                using (var sw = new System.IO.StreamWriter(fs, encoding))
                                {
                                    sw.Write(resultString);
                                }
                            cs.LEFixes++;
                            Printer.PrintMessage("#b#{0}##: => #s#{1}", x.CanonicalName, let == BomClean.LineEndingType.CR ? "CR" : let == BomClean.LineEndingType.CRLF ? "CRLF" : "LF");
                        }
                    }));
                    if (System.Diagnostics.Debugger.IsAttached)
                    {
                        tasks[tasks.Count - 1].Wait();
                    }
                }
                Task.WaitAll(tasks.ToArray());
                if (cs.LEFixes > 0)
                {
                    Printer.PrintMessage("Updated line endings for {0} files.", cs.LEFixes);
                }
            }
            finally
            {
            }
            return(true);
        }
Example #8
0
        protected override bool RunInternal(Area ws, Versionr.Status status, IList<Versionr.Status.StatusEntry> targets, FileBaseCommandVerbOptions options)
        {
            StatusVerbOptions localOptions = (StatusVerbOptions)options;
            if (localOptions.Objects != null && localOptions.Objects.Count > 0)
            {
                if (targets.Count == 0)
                {
                    Printer.PrintError("#x#Error:##\n  Could not find objects matching pattern #b#{0}##", GetPatterns(localOptions.Objects));
                    if (ActiveDirectory.FullName != Workspace.Root.FullName)
                        Printer.PrintMessage("  - Relative to folder \"#b#{0}##\"", Workspace.GetLocalPath(ActiveDirectory.FullName));
                    return false;
                }
            }
            var ss = status;
            if (!string.IsNullOrEmpty(ss.RestrictedPath))
                Printer.WriteLineMessage("  Computing status for path: #b#{0}##", ss.RestrictedPath);

            int[] codeCount = new int[(int)StatusCode.Count];
            if (status.MergeInputs.Count > 0)
                Printer.WriteLineMessage("Workspace has #b#{0}## pending merges.", status.MergeInputs.Count);
            foreach (var x in status.MergeInputs)
            {
                Printer.WriteLineMessage(" #c#{0}#q# from branch \"#b#{1}##\" (rev {2})", x.ID, Workspace.GetBranch(x.Branch).Name, x.Revision);
            }
			if (status.MergeInputs.Count > 0)
				Printer.WriteLineMessage("");
			IEnumerable<Versionr.Status.StatusEntry> operands = targets.Where(x => { codeCount[(int)x.Code]++; return x.Code != StatusCode.Ignored; });
            if (!localOptions.All)
                operands = operands.Where(x => x.Code != StatusCode.Unchanged);
            string localRestrictedPath = null;
            if (ss.RestrictedPath != null)
                localRestrictedPath = ws.GetLocalCanonicalName(ss.RestrictedPath);


			if (!localOptions.NoList)
			{
				if (localOptions.Flat)
				{
					foreach (var x in operands.OrderBy(x => x.CanonicalName))
					{
						PrintFile(ws, localRestrictedPath, x, true);
					}
				}
				else
				{
					var staged = operands.OrderBy(x => x.CanonicalName).Where(y => y.Staged);
					if (staged.Count() > 0)
					{
						Printer.WriteLineMessage("");
						Printer.WriteLineMessage(" Changes recorded for commit:");
						Printer.WriteLineMessage("  (use \"vsr unrecord <file>...\" to unrecord)");
						Printer.WriteLineMessage("");
						foreach (var x in staged)
						{
							PrintFile(ws, localRestrictedPath, x);
						}
					}

					var nonstaged = operands.OrderBy(x => x.CanonicalName).Where(y => !y.Staged && y.Code != StatusCode.Unversioned);
					if (nonstaged.Count() > 0)
					{
						Printer.WriteLineMessage("");
						Printer.WriteLineMessage(" Changes not staged:");
						Printer.WriteLineMessage("  (use \"vsr record <file>...\" to add files to this record)");
						Printer.WriteLineMessage("  (use \"vsr revert <file>...\" to revert changes from working directory)");
						Printer.WriteLineMessage("");
						foreach (var x in nonstaged)
						{
							PrintFile(ws, localRestrictedPath, x);
						}
					}

					var untracked = operands.OrderBy(x => x.CanonicalName).Where(y => y.Code == StatusCode.Unversioned);
					if (untracked.Count() > 0)
					{
						Printer.WriteLineMessage("");
						Printer.WriteLineMessage(" Untracked files:");
						Printer.WriteLineMessage("  (use \"vsr record <file>...\" to add files to this record)");
						Printer.WriteLineMessage("");
						foreach (var x in untracked)
						{
							PrintFile(ws, localRestrictedPath, x);
						}
					}
				}
			}

			if (localOptions.Summary)
            {
                Printer.WriteLineMessage("\n#b#Summary:##");
                for (int i = 0; i < codeCount.Length; i++)
                    Printer.WriteLineMessage("  {0} #b#{2}## #q#{1}##", codeCount[i], codeCount[i] != 1 ? "Objects" : "Object", ((StatusCode)i).ToString());
                Printer.WriteLineMessage("\n  {0}#q# files in ##{1}#q# diectories ({2} ignored)", ss.Files, ss.Directories, ss.IgnoredObjects);
            }

            foreach (var x in Workspace.Externs)
            {
                bool include = true;
                if (!string.IsNullOrEmpty(ss.RestrictedPath))
                    include = Workspace.PathContains(ss.RestrictedPath, System.IO.Path.Combine(ws.Root.FullName, x.Value.Location));
                else
                    include = Filter(new KeyValuePair<string, object>[] { new KeyValuePair<string, object>(x.Value.Location, new object()) }).FirstOrDefault().Value != null;
                if (include)
                {
                    System.IO.DirectoryInfo directory = new System.IO.DirectoryInfo(System.IO.Path.Combine(Workspace.Root.FullName, x.Value.Location));
                    if (directory.Exists)
                    {
                        Printer.WriteLineMessage("\nExternal #c#{0}## ({1}):", x.Key, x.Value.Location);
                        new Status() { DirectExtern = true }.Run(directory, options);
                    }
                    else
                        Printer.WriteLineMessage("\nExternal #c#{0}## ({1}): #e#missing##", x.Key, x.Value.Location);
                }
            }
            return true;
        }
Example #9
0
 protected override bool ComputeTargets(FileBaseCommandVerbOptions localOptions)
 {
     return true;
 }
Example #10
0
        protected override bool RunInternal(Area ws, Versionr.Status status, IList<Versionr.Status.StatusEntry> targets, FileBaseCommandVerbOptions options)
		{
            DiffVerbOptions localOptions = options as DiffVerbOptions;

			Objects.Version version = null;
			Objects.Version parent = null;
			if (!string.IsNullOrEmpty(localOptions.Version))
			{
				version = Workspace.GetPartialVersion(localOptions.Version);
				if (version == null)
				{
					Printer.PrintError("No version found matching {0}", localOptions.Version);
					return false;
				}
				if (version.Parent.HasValue)
					parent = Workspace.GetVersion(version.Parent.Value);

				if (parent == null)
				{
					Printer.PrintMessage("Version {0} has no parent", version.ID);
					return true;
				}
                Printer.PrintMessage("Showing changes for version #c#{0}", version.ID);
			}

            bool showUnchangedObjects = localOptions.Objects.Count != 0;

			List<Task> tasks = new List<Task>();
            List<string> tempFiles = new List<string>();
            List<System.Diagnostics.Process> diffProcesses = new List<System.Diagnostics.Process>();
            try
            {
                if (version == null)
                {
                    foreach (var x in targets)
                    {
                        if (x.VersionControlRecord != null && !x.IsDirectory && x.FilesystemEntry != null && x.Code == StatusCode.Modified)
                        {
                            if (Utilities.FileClassifier.Classify(x.FilesystemEntry.Info) == Utilities.FileEncoding.Binary)
                            {
                                Printer.PrintMessage("File: #b#{0}## is binary #w#different##.", x.CanonicalName);
                                continue;
                            }
                            // Displaying local modifications
                            string tmp = Utilities.DiffTool.GetTempFilename();
                            if (Workspace.ExportRecord(x.CanonicalName, Workspace.Version, tmp))
                            {
                                Printer.PrintMessage("Displaying changes for file: #b#{0}", x.CanonicalName);
                                if (localOptions.External)
                                {
                                    tempFiles.Add(tmp);
                                    bool nonblocking = Workspace.Directives.NonBlockingDiff.HasValue && Workspace.Directives.NonBlockingDiff.Value;
                                    var t = Utilities.LimitedTaskDispatcher.Factory.StartNew(() =>
                                    {
                                        var diffResult = Utilities.DiffTool.Diff(tmp, x.Name + "-base", Workspace.GetLocalCanonicalName(x.VersionControlRecord), x.Name, ws.Directives.ExternalDiff, nonblocking);
                                        if (diffResult != null)
                                        {
                                            lock (diffProcesses)
                                            {
                                                diffProcesses.Add(diffResult);
                                            }
                                        }
                                    });
                                    if (nonblocking)
                                        tasks.Add(t);
                                    else
                                        t.Wait();
                                }
                                else
                                {
                                    try
                                    {
                                        RunInternalDiff(tmp, System.IO.Path.Combine(Workspace.RootDirectory.FullName, Workspace.GetLocalCanonicalName(x.VersionControlRecord)));
                                    }
                                    finally
                                    {
                                        System.IO.File.Delete(tmp);
                                    }
                                }
                            }
                        }
                        else if (x.Code == StatusCode.Unchanged && showUnchangedObjects && !x.IsDirectory)
                        {
                            var filter = Filter(new KeyValuePair<string, Objects.Record>[] { new KeyValuePair<string, Objects.Record>(x.CanonicalName, x.VersionControlRecord) }).FirstOrDefault();
                            if (filter.Value != null && filter.Key == true) // check if the file was really specified
                                Printer.PrintMessage("Object: #b#{0}## is #s#unchanged##.", x.CanonicalName);
                        }
                        else if (x.VersionControlRecord == null && showUnchangedObjects)
                        {
                            var filter = Filter(new KeyValuePair<string, bool>[] { new KeyValuePair<string, bool>(x.CanonicalName, true) }).FirstOrDefault();
                            if (filter.Value != false && filter.Key == true) // check if the file was really specified
                                Printer.PrintMessage("Object: #b#{0}## is #c#unversioned##.", x.CanonicalName);
                        }
                    }
                }
                else
                {
                    if (localOptions.Local)
                    {
                        var records = ws.GetRecords(version);
                        Dictionary<string, Objects.Record> recordMap = new Dictionary<string, Objects.Record>();
                        foreach (var x in records)
                            recordMap[x.CanonicalName] = x;
                        foreach (var x in targets)
                        {
                            Objects.Record otherRecord = null;
                            if (recordMap.TryGetValue(x.CanonicalName, out otherRecord))
                            {
                                if (x.VersionControlRecord != null && x.VersionControlRecord.DataIdentifier == otherRecord.DataIdentifier)
                                    continue;
                                if (Utilities.FileClassifier.Classify(x.FilesystemEntry.Info) == Utilities.FileEncoding.Binary)
                                {
                                    Printer.PrintMessage("File: #b#{0}## is binary #w#different##.", x.CanonicalName);
                                    continue;
                                }
                                string tmp = Utilities.DiffTool.GetTempFilename();
                                if (Workspace.ExportRecord(x.CanonicalName, version, tmp))
                                {
                                    Printer.PrintMessage("Displaying changes for file: #b#{0}", x.CanonicalName);
                                    if (localOptions.External)
                                    {
                                        tempFiles.Add(tmp);
                                        bool nonblocking = Workspace.Directives.NonBlockingDiff.HasValue && Workspace.Directives.NonBlockingDiff.Value;
                                        var t = Utilities.LimitedTaskDispatcher.Factory.StartNew(() =>
                                        {
                                            var diffResult = Utilities.DiffTool.Diff(tmp, x.Name + "-base", Workspace.GetLocalCanonicalName(x.VersionControlRecord), x.Name, ws.Directives.ExternalDiff, nonblocking);
                                            if (diffResult != null)
                                            {
                                                lock (diffProcesses)
                                                {
                                                    diffProcesses.Add(diffResult);
                                                }
                                            }
                                        });
                                        if (nonblocking)
                                            tasks.Add(t);
                                        else
                                            t.Wait();
                                    }
                                    else
                                    {
                                        try
                                        {
                                            RunInternalDiff(tmp, System.IO.Path.Combine(Workspace.RootDirectory.FullName, Workspace.GetLocalCanonicalName(x.VersionControlRecord)));
                                        }
                                        finally
                                        {
                                            System.IO.File.Delete(tmp);
                                        }
                                    }
                                }
                            }
                            else
                                Printer.PrintMessage("File: #b#{0}## is not in other version.", x.CanonicalName);
                        }
                    }
                    else
                    {
                        List<KeyValuePair<string, Objects.Record>> updates = ws.GetAlterations(version)
                            .Where(x => x.Type == Objects.AlterationType.Update)
                            .Select(x => ws.GetRecord(x.NewRecord.Value))
                            .Select(x => new KeyValuePair<string, Objects.Record>(x.CanonicalName, x)).ToList();
                        foreach (var pair in Filter(updates))
                        {
                            Objects.Record rec = pair.Value;
                            string tmpVersion = Utilities.DiffTool.GetTempFilename();
                            if (!Workspace.ExportRecord(rec.CanonicalName, version, tmpVersion))
                                continue;

                            string tmpParent = Utilities.DiffTool.GetTempFilename();
                            if (!Workspace.ExportRecord(rec.CanonicalName, parent, tmpParent))
                            {
                                System.IO.File.Delete(tmpVersion);
                                continue;
                            }

                            Printer.PrintMessage("Displaying changes for file: #b#{0}", rec.CanonicalName);
                            if (localOptions.External)
                            {
                                tempFiles.Add(tmpVersion);
                                tempFiles.Add(tmpParent);
                                bool nonblocking = Workspace.Directives.NonBlockingDiff.HasValue && Workspace.Directives.NonBlockingDiff.Value;
                                var t = Utilities.LimitedTaskDispatcher.Factory.StartNew(() =>
                                {
                                    var diffResult = Utilities.DiffTool.Diff(tmpParent, rec.Name + "-" + parent.ShortName, tmpVersion, rec.Name + "-" + version.ShortName, ws.Directives.ExternalDiff, nonblocking);
                                    if (diffResult != null)
                                    {
                                        lock (diffProcesses)
                                        {
                                            diffProcesses.Add(diffResult);
                                        }
                                    }
                                });
                                if (nonblocking)
                                    tasks.Add(t);
                                else
                                    t.Wait();
                            }
                            else
                            {
                                try
                                {
                                    RunInternalDiff(tmpParent, tmpVersion);
                                }
                                finally
                                {
                                    System.IO.File.Delete(tmpVersion);
                                    System.IO.File.Delete(tmpParent);
                                }
                            }
                        }
                    }
                }
            }
            finally
            {
                Task.WaitAll(tasks.ToArray());
                foreach (var x in diffProcesses)
                    x.WaitForExit();
                foreach (var x in tempFiles)
                    System.IO.File.Delete(x);
            }
            return true;
        }
Example #11
0
		protected override bool RunInternal(Area ws, Versionr.Status status, IList<Versionr.Status.StatusEntry> targets, FileBaseCommandVerbOptions options)
		{
			LogVerbOptions localOptions = options as LogVerbOptions;
			if (JruntingMode)
				localOptions.Detail = LogVerbOptions.DetailMode.Jrunting;

			Printer.EnableDiagnostics = localOptions.Verbose;

			bool targetedBranch = false;
			Objects.Version version = null;
			if (!string.IsNullOrEmpty(localOptions.Branch))
			{
				bool multipleBranches = false;
				var branch = ws.GetBranchByPartialName(localOptions.Branch, out multipleBranches);
				if (branch == null || multipleBranches)
				{
					Printer.PrintError("No unique branch found for {0}", localOptions.Branch);
					return false;
				}
				version = ws.GetBranchHeadVersion(branch);
				targetedBranch = true;
			}
			else if (!string.IsNullOrEmpty(localOptions.Version))
			{
				version = ws.GetPartialVersion(localOptions.Version);
				if (version == null)
				{
					Printer.PrintError("Couldn't find matching version for {0}", localOptions.Version);
					return false;
				}
			}

			if (localOptions.Limit == -1)
				localOptions.Limit = (version == null || targetedBranch) ? 10 : 1;
            if (version == null)
                version = ws.Version;

            int? nullableLimit = localOptions.Limit;
            if (nullableLimit.Value <= 0)
                nullableLimit = null;
            
            var history = (localOptions.ShowMerged ? ws.GetLogicalHistory(version, nullableLimit) : ws.GetHistory(version, nullableLimit)).AsEnumerable();

			m_Tip = Workspace.Version;
			Objects.Version last = null;
			m_Branches = new Dictionary<Guid, Objects.Branch>();
			foreach (var x in ApplyHistoryFilter(history, localOptions))
			{
				last = x.Item1;
				FormatLog(x.Item1, x.Item2, localOptions);
			}

			if (!localOptions.Jrunting && last != null && last.ID == m_Tip.ID && version == null)
			{
				var branch = Workspace.CurrentBranch;
				var heads = Workspace.GetBranchHeads(branch);
				bool isHead = heads.Any(x => x.Version == last.ID);
				bool isOnlyHead = heads.Count == 1;
				if (!isHead)
					Printer.PrintMessage("\nCurrent version #b#{0}## is #e#not the head## of branch #b#{1}## (#b#\"{2}\"##)", m_Tip.ShortName, branch.ShortID, branch.Name);
				else if (!isOnlyHead)
					Printer.PrintMessage("\nCurrent version #b#{0}## is #w#not only the head## of branch #b#{1}## (#b#\"{2}\"##)", m_Tip.ShortName, branch.ShortID, branch.Name);
			}

			return true;
		}
Example #12
0
        protected override bool RunInternal(Area ws, Versionr.Status status, IList <Versionr.Status.StatusEntry> targets, FileBaseCommandVerbOptions options)
        {
            BomCleanOptions localOptions = options as BomCleanOptions;

            LocalOptions = localOptions;
            try
            {
                List <Versionr.Status.StatusEntry> realTargets = new List <Status.StatusEntry>();
                foreach (var x in targets)
                {
                    if (x.VersionControlRecord != null && !x.IsDirectory && x.FilesystemEntry != null && x.Code == StatusCode.Modified)
                    {
                        if (localOptions.Recorded && x.Staged == false)
                        {
                            continue;
                        }
                        realTargets.Add(x);
                    }
                }
                Printer.PrintMessage("{0} files in initial list...", realTargets.Count);
                Dictionary <string, Versionr.Objects.Record> recordMap = new Dictionary <string, Versionr.Objects.Record>();
                foreach (var x in ws.GetRecords(Workspace.Version))
                {
                    recordMap[x.CanonicalName] = x;
                }
                Printer.PrintMessage("Original version: #s#{0}##", Workspace.Version.ID);

                CleanStats cs = new CleanStats();

                List <Task> tasks = new List <Task>();
                foreach (var x in realTargets)
                {
                    tasks.Add(GetTaskFactory(options).StartNew(() =>
                    {
                        var newFileType = Versionr.Utilities.FileClassifier.Classify(x.FilesystemEntry.Info);
                        if (newFileType == Versionr.Utilities.FileEncoding.Binary)
                        {
                            return;
                        }
                        // Displaying local modifications
                        string tmp = Versionr.Utilities.DiffTool.GetTempFilename();
                        Versionr.Objects.Record rec;
                        if (recordMap.TryGetValue(x.CanonicalName, out rec))
                        {
                            Encoding encoding = VSREncodingToEncoding(newFileType);
                            string messages   = string.Format("File #b#{0}##:", x.CanonicalName);
                            ws.RestoreRecord(rec, DateTime.Now, tmp);
                            var oldFileType = Versionr.Utilities.FileClassifier.Classify(new System.IO.FileInfo(tmp));
                            bool fixBOM     = false;
                            bool fixLines   = false;
                            if (oldFileType != newFileType && localOptions.BOM)
                            {
                                bool allowFix = true;
                                if ((oldFileType == FileEncoding.ASCII || oldFileType == FileEncoding.Latin1) &&
                                    (newFileType == FileEncoding.ASCII || newFileType == FileEncoding.Latin1))
                                {
                                    allowFix = false;
                                }
                                if (allowFix)
                                {
                                    fixBOM = true;
                                    lock (cs)
                                    {
                                        cs.BOMFixes++;
                                    }
                                    messages += string.Format("\n - Fixing changed encoding: {0} -> {1}", oldFileType, newFileType);
                                }
                            }
                            var fullText = new Lazy <string>(() =>
                            {
                                using (var fs = x.FilesystemEntry.Info.OpenRead())
                                    using (var sr = new System.IO.StreamReader(fs, encoding))
                                    {
                                        return(sr.ReadToEnd());
                                    }
                            });
                            var oldFullText = new Lazy <string>(() =>
                            {
                                using (var fs = new System.IO.FileInfo(tmp).OpenRead())
                                    using (var sr = new System.IO.StreamReader(fs, VSREncodingToEncoding(oldFileType)))
                                    {
                                        return(sr.ReadToEnd());
                                    }
                            });
                            if (localOptions.Newlines)
                            {
                                // Fast version - all the same, except the newlines changed
                                string resultString;
                                bool lcheckResult = NewLineCheckFast(fullText.Value, oldFullText.Value, ref messages, out resultString);
                                if (lcheckResult == true)
                                {
                                    if (resultString != null)
                                    {
                                        lock (cs)
                                        {
                                            cs.LEFixes++;
                                        }
                                        fixLines = true;
                                        fullText = new Lazy <string>(() => { return(resultString); });
                                    }
                                }
                                // Slow version - need to use diff engine
                            }
                            if (fixBOM || fixLines)
                            {
                                Encoding targetEncoding           = VSREncodingToEncoding(oldFileType);
                                x.FilesystemEntry.Info.IsReadOnly = false;
                                using (var fs = x.FilesystemEntry.Info.Open(System.IO.FileMode.Create))
                                    using (var sw = new System.IO.StreamWriter(fs, targetEncoding))
                                    {
                                        sw.Write(fullText.Value);
                                    }
                                Printer.PrintMessage(messages);
                            }
                            new System.IO.FileInfo(tmp).IsReadOnly = false;
                            System.IO.File.Delete(tmp);
                        }
                    }));
                    if (System.Diagnostics.Debugger.IsAttached)
                    {
                        tasks[tasks.Count - 1].Wait();
                    }
                }
                Task.WaitAll(tasks.ToArray());
                if (cs.BOMFixes > 0)
                {
                    Printer.PrintMessage("Updated encoding/BOM for {0} files.", cs.BOMFixes);
                }
                if (cs.LEFixes > 0)
                {
                    Printer.PrintMessage("Updated line endings for {0} files.", cs.LEFixes);
                }
            }
            finally
            {
            }
            return(true);
        }