コード例 #1
0
ファイル: Commit.cs プロジェクト: eatplayhate/versionr
		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;
        }
コード例 #2
0
ファイル: Record.cs プロジェクト: eatplayhate/versionr
 protected void RecordFeedback(Versionr.Status.StatusEntry entry, StatusCode code, bool auto)
 {
     string name = Workspace.GetLocalCanonicalName(entry.CanonicalName);
     int index = name.LastIndexOf('/');
     if (index != name.Length - 1)
         name = name.Insert(index + 1, "#b#");
     var previous = Status.GetStatusText(entry);
     var now = Status.GetStatusText(code, true);
     string output = "#" + now.Item1 + "#(" + now.Item2 + ")## ";
     while (output.Length < 20)
         output = " " + output;
     Printer.PrintMessage(output + " " + name + "##" + (auto ? " #q#(auto)##" : ""));
 }
コード例 #3
0
ファイル: Record.cs プロジェクト: eatplayhate/versionr
		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));
        }
コード例 #4
0
ファイル: Resolve.cs プロジェクト: eatplayhate/versionr
 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;
 }
コード例 #5
0
ファイル: Status.cs プロジェクト: eatplayhate/versionr
        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;
        }
コード例 #6
0
ファイル: Status.cs プロジェクト: eatplayhate/versionr
        public static Tuple<char, string> GetStatusText(Versionr.StatusCode code, bool staged)
        {
            switch (code)
            {
                case StatusCode.Added:
                    return staged ? new Tuple<char, string>('s', "added")
                        : new Tuple<char, string>('e', "error");
                case StatusCode.Conflict:
                    return staged ? new Tuple<char, string>('e', "conflict")
                        : new Tuple<char, string>('e', "conflict");
                case StatusCode.Obstructed:
                    return staged ? new Tuple<char, string>('e', "obstructed")
                        : new Tuple<char, string>('e', "obstructed");
                case StatusCode.Copied:
                    return staged ? new Tuple<char, string>('s', "copied")
                        : new Tuple<char, string>('w', "copied");
                case StatusCode.Deleted:
                    return staged ? new Tuple<char, string>('c', "deleted")
                        : new Tuple<char, string>('w', "missing");
                case StatusCode.Missing:
                    return staged ? new Tuple<char, string>('e', "error")
                        : new Tuple<char, string>('w', "missing");
                case StatusCode.Masked:
                    return staged ? new Tuple<char, string>('c', "merged")
                        : new Tuple<char, string>('w', "ignored");
                case StatusCode.Modified:
                    return staged ? new Tuple<char, string>('s', "modified")
                        : new Tuple<char, string>('M', "changed");
                case StatusCode.Renamed:
                    return staged ? new Tuple<char, string>('s', "renamed")
                        : new Tuple<char, string>('w', "renamed");
                case StatusCode.Unversioned:
                    return staged ? new Tuple<char, string>('e', "error")
                        : new Tuple<char, string>('a', "unversioned");
				case StatusCode.Ignored:
					return staged ? new Tuple<char, string>('e', "error")
						: new Tuple<char, string>('q', "ignored");
				case StatusCode.Unchanged:
					return staged ? new Tuple<char, string>('e', "unchanged")
						: new Tuple<char, string>('q', "unchanged");
				default:
                    throw new Exception();
            }
        }
コード例 #7
0
ファイル: Status.cs プロジェクト: eatplayhate/versionr
 public static Tuple<char, string> GetStatusText(Versionr.Status.StatusEntry x)
 {
     return GetStatusText(x.Code, x.Staged);
 }
コード例 #8
0
ファイル: Status.cs プロジェクト: eatplayhate/versionr
		private string GetStatus(Versionr.Status.StatusEntry x, bool flat = false)
		{
			if (!flat && x.Code == StatusCode.Unversioned)
			{
				return new string(' ', s_FileLeadingSpaces);
			}
			else
			{
				var info = GetStatusText(x);
				string format = (flat) ? "    {0}{1, 12} " : "    {0}{1, -11} ";
                return String.Format(format, "#" + info.Item1 + "#", info.Item2 + ":");
			}
		}
コード例 #9
0
ファイル: Status.cs プロジェクト: eatplayhate/versionr
		private void PrintFile(Area ws, string localRestrictedPath, Versionr.Status.StatusEntry x, bool flat = false)
		{
			string name = ws.GetLocalCanonicalName(x.CanonicalName);

			if (FilterOptions.WindowsPaths)
				name = name.Replace('/', '\\');

			if (localRestrictedPath != null)
				name = name.Substring(localRestrictedPath.Length);
			int index = name.LastIndexOf('/');
			if (index != name.Length - 1)
				name = name.Insert(index + 1, "#b#");
			if (name.Length == 0)
				name = "#q#<parent directory>##";
			if (x.IsSymlink)
				name += " #q# -> " + (x.FilesystemEntry != null ? x.FilesystemEntry.SymlinkTarget : x.VersionControlRecord.Fingerprint);
			Printer.WriteLineMessage("{1}##{0}", name, GetStatus(x, flat));
			if (x.Code == StatusCode.Renamed || x.Code == StatusCode.Copied)
				Printer.WriteLineMessage("                  #q#<== {0}", x.VersionControlRecord.CanonicalName);
		}
コード例 #10
0
ファイル: Diff.cs プロジェクト: eatplayhate/versionr
        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;
        }
コード例 #11
0
ファイル: Log.cs プロジェクト: eatplayhate/versionr
		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;
		}