IEnumerable <KeyValuePair <bool, ResolvedAlteration> > FilterAlterations(Objects.Version v) { var enumeration = GetAlterations(v) .Select(x => new KeyValuePair <string, ResolvedAlteration>(x.Record.CanonicalName, x)); return(Filter(enumeration)); }
protected override bool RunInternal(object options) { ExtractVerbOptions localOptions = options as ExtractVerbOptions; FilterOptions = localOptions; Objects.Version version = Workspace.GetPartialVersion(localOptions.Version); if (version == null) { Printer.PrintError("No version found matching {0}", localOptions.Version); return(false); } IList <Versionr.Objects.Record> targets = null; if (ComputeTargets(localOptions)) { ApplyFilters(Workspace.GetRecords(version), localOptions, ref targets); } else { targets = Workspace.GetRecords(version); } if ((targets != null && targets.Count > 0)) { return(RunInternal(Workspace, targets, localOptions)); } Printer.PrintWarning("No files selected for {0}", localOptions.Verb); return(false); }
protected override bool RunInternal(object options) { TagVerbOptions localOptions = options as TagVerbOptions; Objects.Version ver = Workspace.GetPartialVersion(localOptions.Version); if (ver == null) { Printer.PrintMessage("#e#Error:## can't find version #b#\"{0}\"## for tag alteration.", localOptions.Version); return(false); } if (localOptions.TagsToAdd != null) { foreach (var x in localOptions.TagsToAdd) { if (!x.StartsWith("#")) { Printer.PrintMessage("Can't add tag #b#{0}##. Tag is required to start with a \"\\#\"", x); return(false); } if (x.Length == 1) { Printer.PrintMessage("Can't add an empty tag."); return(false); } } } if (localOptions.TagsToRemove != null) { foreach (var x in localOptions.TagsToRemove) { if (!x.StartsWith("#")) { Printer.PrintMessage("Can't remove tag #b#{0}##. Tag is required to start with a \"\\#\"", x); return(false); } if (x.Length == 1) { Printer.PrintMessage("Can't remove an empty tag."); return(false); } } } if (localOptions.TagsToAdd != null) { foreach (var x in localOptions.TagsToAdd) { Workspace.AddTag(ver.ID, x.Substring(1)); } } if (localOptions.TagsToRemove != null) { foreach (var x in localOptions.TagsToRemove) { Workspace.RemoveTag(ver.ID, x.Substring(1)); } } return(true); }
public WorkspaceHook(Area area, string username, Objects.Branch branch, Objects.Version v, Objects.Version old = null) : base() { m_Area = area; m_Username = username; m_Branch = branch; m_Version = v; m_OldVersion = old; }
protected override bool RunInternal(object options) { TagFindVerbOptions localOptions = options as TagFindVerbOptions; if (localOptions.Tags == null || localOptions.Tags.Count == 0) { Printer.PrintMessage("#e#Error:## no tag specified to search for!"); return(false); } bool first = true; List <Guid> results = new List <Guid>(); foreach (var x in localOptions.Tags) { if (!x.StartsWith("#")) { Printer.PrintMessage("#e#Error:## tag {0} doesn't start with #b#\\###!", x); return(false); } string search = x.Substring(1); if (localOptions.Fuzzy) { localOptions.IgnoreCase = true; search = $"%{search}%"; } IEnumerable <Guid> getTags = Workspace.FindTags(search, localOptions.IgnoreCase).Select(y => y.Version); if (!localOptions.All || first) { results = results.Concat(getTags).Distinct().ToList(); } else { results = results.Intersect(getTags).ToList(); } first = false; } Printer.PrintMessage("Matched {0} versions.", results.Count); foreach (var x in results) { Objects.Version ver = Workspace.GetVersion(x); if (ver != null) { Printer.PrintMessage(" - #b#{0}## on #c#{1}## ##[#s#{4}##] #q#by {2} at {3}", ver.ID, Workspace.GetBranch(ver.Branch).Name, ver.Author, ver.Timestamp.ToLocalTime(), string.Join(" ", Workspace.GetTagsForVersion(ver.ID).Select(t => "\\#" + t).ToArray())); } else { Printer.PrintError(" - {0} wasn't found", x); } } return(true); }
public PushHeadHook(Area ws, string username, Objects.Branch branch, Objects.Version newHead, Objects.Version oldHead, List <Objects.Version> consumedVersions) : base(ws, username) { m_Branch = branch; m_NewHead = newHead; m_OldHead = oldHead; m_AdditionalVersions = new Lazy <List <Objects.Version> >(() => { return(consumedVersions.Distinct().ToList()); }); m_Modifications = new Lazy <List <KeyValuePair <Objects.AlterationType, string> > >(() => { Dictionary <string, string> oldRecords = new Dictionary <string, string>(); HashSet <string> newRecords = new HashSet <string>(); if (oldHead != null) { foreach (var rec in ws.GetRecords(ws.GetVersion(oldHead.ID))) { oldRecords.Add(rec.CanonicalName, rec.Fingerprint); } } List <KeyValuePair <Objects.AlterationType, string> > results = new List <KeyValuePair <Objects.AlterationType, string> >(); if (newHead != null) { foreach (var rec in ws.GetRecords(ws.GetVersion(newHead.ID))) { string oldfp; if (oldRecords.TryGetValue(rec.CanonicalName, out oldfp)) { if (oldfp != rec.Fingerprint) { results.Add(new KeyValuePair <Objects.AlterationType, string>(Objects.AlterationType.Update, rec.CanonicalName)); } } else { results.Add(new KeyValuePair <Objects.AlterationType, string>(Objects.AlterationType.Add, rec.CanonicalName)); } newRecords.Add(rec.CanonicalName); } } foreach (var x in oldRecords) { if (!newRecords.Contains(x.Key)) { results.Add(new KeyValuePair <Objects.AlterationType, string>(Objects.AlterationType.Delete, x.Key)); } } return(results); }); }
protected override bool RunInternal(object options) { SetAnnotationVerbOptions localOptions = options as SetAnnotationVerbOptions; Objects.Version ver = Workspace.GetPartialVersion(localOptions.Version); if (ver == null) { Printer.PrintMessage("#e#Error:## can't find version #b#\"{0}\"## to assign annotation to.", localOptions.Version); return(false); } Objects.Annotation annotation = Workspace.GetAnnotation(ver.ID, localOptions.Key, false); if (annotation != null && localOptions.NoOverwrite) { Printer.PrintMessage("Annotation already exists. Overwriting is currently disabled."); return(false); } if (!localOptions.Precise) { annotation = Workspace.GetSimilarAnnotation(ver.ID, localOptions.Key); if (annotation != null) { Printer.PrintMessage("A similar annotation (with key #b#\"{0}\"##) exists. Delete this annotation or enable #b#--precise## mode to continue.", annotation.Key); return(false); } } if (string.IsNullOrEmpty(localOptions.Filename)) { if (localOptions.StringData == null || localOptions.StringData.Count == 0) { Printer.PrintMessage("#e#Error:## Data for annotation is empty."); return(false); } return(Workspace.SetAnnotation(ver.ID, localOptions.Key, string.Join(" ", localOptions.StringData.ToArray()))); } else { System.IO.FileInfo info = new System.IO.FileInfo(localOptions.Filename); if (!info.Exists) { Printer.PrintMessage("#e#Error:## Payload file #b#\"{0}\"## does not exist.", info.FullName); return(false); } using (var s = info.OpenRead()) return(Workspace.SetAnnotation(ver.ID, localOptions.Key, Utilities.FileClassifier.Classify(info) == Utilities.FileEncoding.Binary, s)); } }
protected override bool RunInternal(object options) { DiffVersionsVerbOptions localOptions = options as DiffVersionsVerbOptions; Printer.EnableDiagnostics = localOptions.Verbose; Objects.Version baseVersion = null; Objects.Version compareVersion = null; if (localOptions.Versions.Count == 0) { Printer.PrintError("Must specify a version or branch to compare to"); return(false); } else if (localOptions.Versions.Count == 1) { if (Workspace.HasStagedModifications) { Printer.PrintError("Cannot compare current workspace while there are staged modifications"); return(false); } baseVersion = Workspace.Version; compareVersion = GetVersionByName(localOptions.Versions[0]); } else if (localOptions.Versions.Count == 2) { baseVersion = GetVersionByName(localOptions.Versions[0]); compareVersion = GetVersionByName(localOptions.Versions[1]); } else { Printer.PrintError("Too many versions specified"); return(false); } if (baseVersion == null || compareVersion == null) { return(false); } CompareVersions(baseVersion, compareVersion, localOptions); return(true); }
public void CompareVersions(Objects.Version baseVersion, Objects.Version compareVersion, DiffVersionsVerbOptions localOptions) { var baseRecords = Workspace.GetRecords(baseVersion); var compareRecords = Workspace.GetRecords(compareVersion); // List additions var added = new HashSet <Objects.Record>(compareRecords, RecordPathComparer.Instance); added.ExceptWith(baseRecords); Report("Add", added.ToList()); // List deletions var deleted = new HashSet <Objects.Record>(baseRecords, RecordPathComparer.Instance); deleted.ExceptWith(compareRecords); Report("Delete", deleted.ToList()); // Check for modifications var compareLookup = new Dictionary <string, Objects.Record>(); foreach (var record in compareRecords) { compareLookup[record.CanonicalName] = record; } var modified = new List <Objects.Record>(); foreach (var baseRecord in baseRecords) { Objects.Record compareRecord; if (!compareLookup.TryGetValue(baseRecord.CanonicalName, out compareRecord)) { continue; } if (compareRecord.Fingerprint != baseRecord.Fingerprint) { modified.Add(compareRecord); } } Report("Modify", modified); }
public bool Run(System.IO.DirectoryInfo workingDirectory, object options) { RebaseVerbOptions localOptions = options as RebaseVerbOptions; Printer.EnableDiagnostics = localOptions.Verbose; Area ws = Area.Load(workingDirectory); if (ws == null) { return(false); } if (string.IsNullOrEmpty(localOptions.Message)) { Printer.PrintError("#e#Error: Rebase requires commit message."); return(false); } if (localOptions.Collapse) { // Step 1: get the rebase target node Objects.Version currentVersion = ws.Version; Objects.Version parentVersion = ws.GetPartialVersion(localOptions.Target); if (parentVersion == null) { Printer.PrintError("#e#Error: Can't identify parent version for rebase with name #b#\"{0}\"#e#.", localOptions.Target); return(false); } if (parentVersion.ID == currentVersion.ID) { Printer.PrintError("#e#Error: Rebase parent can't be the current version."); return(false); } return(ws.RebaseCollapse(currentVersion, parentVersion, localOptions.Message)); } else { Printer.PrintError("#e#Error: rebase only works when collapsing operations."); return(false); } return(true); }
public bool Run(System.IO.DirectoryInfo workingDirectory, object options) { MergeVerbOptions localOptions = options as MergeVerbOptions; Printer.EnableDiagnostics = localOptions.Verbose; Area ws = Area.Load(workingDirectory); if (ws == null) { return(false); } Objects.Version forceParent = null; if (!string.IsNullOrEmpty(localOptions.ParentVersion)) { forceParent = ws.GetPartialVersion(localOptions.ParentVersion); } Area.MergeSpecialOptions opt = new Area.MergeSpecialOptions() { AllowRecursiveMerge = !localOptions.Simple, IgnoreMergeParents = localOptions.IgnoreMergeAncestry, Reintegrate = localOptions.Reintegrate, MetadataOnly = localOptions.Metadata, OverrideDisallowedMerges = localOptions.IgnoreDisallowed, IgnoreAttribChanges = localOptions.IgnoreAttribChanges, ForceParentVersion = forceParent, ResolutionStrategy = localOptions.Mine ? Area.MergeSpecialOptions.ResolutionSystem.Mine : (localOptions.Theirs ? Area.MergeSpecialOptions.ResolutionSystem.Theirs : Area.MergeSpecialOptions.ResolutionSystem.Normal) }; if (localOptions.Target.Count == 0) { Printer.PrintMessage("#x#Error:## No targets to merge from!"); } foreach (var x in localOptions.Target) { ws.Merge(x, false, opt); } return(true); }
private void FormatLog(Tuple <Objects.Version, int> vt, IEnumerable <KeyValuePair <bool, ResolvedAlteration> > filteralt, LogVerbOptions localOptions) { Objects.Version v = vt.Item1; if (m_LoggedVersions == null) { m_LoggedVersions = new HashSet <Guid>(); } m_LoggedVersions.Add(v.ID); Objects.Branch branch = null; if (!m_Branches.TryGetValue(v.Branch, out branch)) { branch = Workspace.GetBranch(v.Branch); m_Branches[v.Branch] = branch; } if (localOptions.Xml) { Printer.PrintMessage($" <version id='{v.ID}' parent='{v.Parent}' branch='{v.Branch}' timestamp='{v.Timestamp.ToString("o")}' author='{XmlAttr(v.Author)}' published='{v.Published}'>"); Printer.PrintMessage($" <message>{XmlText(v.Message)}</message>"); foreach (var y in Workspace.GetMergeInfo(v.ID)) { var mergeParent = Workspace.GetVersion(y.SourceVersion); Printer.PrintMessage($" <merge type='{y.Type.ToString().ToLower()}' version='{mergeParent.ID}' branch='{mergeParent.Branch}' />"); } if (localOptions.Detail == LogVerbOptions.DetailMode.Full) { foreach (var y in GetAlterations(v)) { string operationName = y.Alteration.Type.ToString().ToLower(); if (y.Alteration.Type == Objects.AlterationType.Copy || y.Alteration.Type == Objects.AlterationType.Move) { Objects.Record prior = Workspace.GetRecord(y.Alteration.PriorRecord.Value); Objects.Record next = Workspace.GetRecord(y.Alteration.NewRecord.Value); bool edited = (!next.IsDirectory && prior.DataIdentifier != next.DataIdentifier); Printer.PrintMessage($" <alteration type='{operationName}' path='{XmlAttr(next.CanonicalName)}' frompath='{XmlAttr(prior.CanonicalName)}' edited='{edited}' />"); } else { Printer.PrintMessage($" <alteration type='{operationName}' path='{y.Record.CanonicalName}' />"); } } } Printer.PrintMessage(" </version>"); } else if (localOptions.Jrunting) { // list of heads var heads = Workspace.GetHeads(v.ID); bool isHead = false; string headString = ""; foreach (var y in heads) { isHead = true; if (headString.Length != 0) { headString = headString + ", "; } headString += Workspace.GetBranch(y.Branch).Name; } // message up to first newline string message = v.Message; if (message == null) { message = string.Empty; } message = message.Replace("\r\n", "\n"); var idx = message.IndexOf('\n'); if (idx == -1) { idx = message.Length; } message = message.Substring(0, idx); string mergemarker = ""; if (Workspace.GetMergeInfo(v.ID).Count() > 0) { var m = Workspace.GetMergeInfo(v.ID).First(); var heads2 = Workspace.GetHeads(m.SourceVersion); if (heads2.Count > 0) { if (isHead) { mergemarker = " <- " + Workspace.GetBranch(heads2.First().Branch).Name; } else { mergemarker = "M: " + Workspace.GetBranch(heads2.First().Branch).Name; } } } var date = new DateTime(v.Timestamp.Ticks, DateTimeKind.Utc).ToShortDateString(); string pattern = "* #U#{0}## - "; if (isHead) { pattern += "#Y#({4}{5})## "; } else if (mergemarker.Length > 0) { pattern += "#Y#({5})## "; } pattern += "{1} "; var tagList = Workspace.GetTagsForVersion(v.ID); if (tagList.Count > 0) { pattern += "#I#[" + string.Join(" ", tagList.Select(x => "\\#" + x).ToArray()) + "]## "; } pattern += "#g#({2}, {3})##"; Printer.PrintMessage(pattern, v.ShortName, message, v.Author, date, headString, mergemarker); } else if (localOptions.Concise) { if (vt.Item2 != 0 && localOptions.Indent) { Printer.Prefix = " "; } var heads = Workspace.GetHeads(v.ID); bool isHead = false; foreach (var y in heads) { if (y.Branch == branch.ID) { isHead = true; break; } } string message = v.Message; if (message == null) { message = string.Empty; } string tipmarker = " "; if (v.ID == m_Tip.ID) { tipmarker = "#w#*##"; } string mergemarker = " "; if (Workspace.GetMergeInfo(v.ID).FirstOrDefault() != null) { mergemarker = "#s#M##"; } var tagList = Workspace.GetTagsForVersion(v.ID); string tags = ""; if (tagList.Count > 0) { tags = "#s#" + string.Join(" ", tagList.Select(x => "\\#" + x).ToArray()) + "## "; } Printer.PrintMessage($"{tipmarker}#c#{v.ShortName}:##{mergemarker}({v.Revision}/{(isHead ? "#i#" : "#b#")}{branch.Name}##)" + $"{message.Replace("\r\n", " ").Replace('\n', ' ')} {tags}" + $"#q#({v.Author} {new DateTime(v.Timestamp.Ticks, DateTimeKind.Utc).ToShortDateString()})##"); Printer.Prefix = ""; } else { Printer.PrintMessage(""); if (vt.Item2 != 0 && localOptions.Indent) { Printer.Prefix = "| "; } string tipmarker = ""; if (v.ID == m_Tip.ID) { tipmarker = " #w#*<current>##"; } Printer.PrintMessage("({0}) #c#{1}## on branch #b#{2}##{3}", v.Revision, v.ID, branch.Name, tipmarker); var mergeInfo = Workspace.GetMergeInfo(v.ID); foreach (var y in mergeInfo) { var mergeParent = Workspace.GetVersion(y.SourceVersion); Objects.Branch mergeBranch = null; if (!m_Branches.TryGetValue(mergeParent.Branch, out mergeBranch)) { mergeBranch = Workspace.GetBranch(mergeParent.Branch); m_Branches[mergeParent.Branch] = mergeBranch; } Printer.PrintMessage(" <- Merged from #s#{0}## on branch #b#{1}##", mergeParent.ID, mergeBranch.Name); } var heads = Workspace.GetHeads(v.ID); foreach (var y in heads) { Objects.Branch headBranch = null; if (!m_Branches.TryGetValue(y.Branch, out headBranch)) { headBranch = Workspace.GetBranch(y.Branch); m_Branches[y.Branch] = headBranch; } string branchFlags = string.Empty; if (branch.Terminus.HasValue) { branchFlags = " #e#(deleted)##"; } Printer.PrintMessage(" ++ #i#Head## of branch #b#{0}## (#b#\"{1}\"##){2}", headBranch.ID, headBranch.Name, branchFlags); } if (branch.Terminus == v.ID) { Printer.PrintMessage(" ++ #i#Terminus## of #e#deleted branch## #b#{0}## (#b#\"{1}\"##)", branch.ID, branch.Name); } Printer.PrintMessage("#b#Author:## {0} #q# {1} ##", v.Author, v.Timestamp.ToLocalTime()); var tagList = Workspace.GetTagsForVersion(v.ID); if (tagList.Count > 0) { Printer.PrintMessage(" #s#" + string.Join(" ", tagList.Select(x => "\\#" + x).ToArray()) + "##"); } Printer.PrintMessage(""); Printer.PushIndent(); Printer.PrintMessage("{0}", string.IsNullOrWhiteSpace(v.Message) ? "<none>" : Printer.Escape(v.Message)); Printer.PopIndent(); if (localOptions.Detail == LogVerbOptions.DetailMode.Detailed || localOptions.Detail == LogVerbOptions.DetailMode.Full) { var alterations = localOptions.Detail == LogVerbOptions.DetailMode.Detailed ? filteralt.Select(z => z.Value) : GetAlterations(v); if (localOptions.Detail == LogVerbOptions.DetailMode.Full) { Printer.PrintMessage(""); Printer.PrintMessage("#b#Alterations:##"); foreach (var y in alterations.OrderBy(z => z.Alteration.Type)) { if (y.Alteration.Type == Objects.AlterationType.Move || y.Alteration.Type == Objects.AlterationType.Copy) { string operationName = y.Alteration.Type.ToString().ToLower(); Objects.Record prior = Workspace.GetRecord(y.Alteration.PriorRecord.Value); Objects.Record next = Workspace.GetRecord(y.Alteration.NewRecord.Value); bool isUpdate = false; if (y.Alteration.Type == Objects.AlterationType.Move && !next.IsDirectory && prior.DataIdentifier != next.DataIdentifier) { isUpdate = true; operationName = "refactor"; } Printer.PrintMessage("#{2}#({0})## {1}\n <- #q#{3}##", operationName, y.Record.CanonicalName, GetAlterationFormat(y.Alteration.Type), prior.CanonicalName); if (localOptions.Diff && isUpdate) { InlineDiff(prior, next); } } else { Printer.PrintMessage("#{2}#({0})## {1}", y.Alteration.Type.ToString().ToLower(), y.Record.CanonicalName, GetAlterationFormat(y.Alteration.Type)); if (localOptions.Diff && y.Alteration.Type == Objects.AlterationType.Update) { InlineDiff(Workspace.GetRecord(y.Alteration.PriorRecord.Value), Workspace.GetRecord(y.Alteration.NewRecord.Value)); } } } } else { int[] alterationCounts = new int[5]; foreach (var y in alterations) { alterationCounts[(int)y.Alteration.Type]++; } bool first = true; string formatData = ""; for (int i = 0; i < alterationCounts.Length; i++) { if (alterationCounts[i] != 0) { if (!first) { formatData += ", "; } else { formatData += " "; } first = false; formatData += string.Format("#{2}#{0}s: {1}##", ((Objects.AlterationType)i).ToString(), alterationCounts[i], GetAlterationFormat((Objects.AlterationType)i)); } } if (formatData.Length > 0) { Printer.PrintMessage(""); Printer.PrintMessage("#b#Alterations:##"); Printer.PrintMessage(formatData); } } } else if (FilterOptions.Objects.Count != 0) { Printer.PrintMessage(""); Printer.PrintMessage("#b#Alterations:##"); List <KeyValuePair <string, ResolvedAlteration> > altList = new List <KeyValuePair <string, ResolvedAlteration> >(); foreach (var y in GetAlterations(v)) { string recName = y.Record.CanonicalName; altList.Add(new KeyValuePair <string, ResolvedAlteration>(recName, y)); } if (localOptions.Diff) { var records = FilterObjects(altList) .SelectMany(x => new[] { x.Value.Alteration.PriorRecord, x.Value.Alteration.NewRecord }) .Where(x => x.HasValue) .Select(x => Workspace.GetRecord(x.Value)); Workspace.GetMissingObjects(records, null); } foreach (var y in FilterObjects(altList).Select(x => x.Value)) { if (y.Alteration.Type == Objects.AlterationType.Move || y.Alteration.Type == Objects.AlterationType.Copy) { string operationName = y.Alteration.Type.ToString().ToLower(); Objects.Record prior = Workspace.GetRecord(y.Alteration.PriorRecord.Value); Objects.Record next = Workspace.GetRecord(y.Alteration.NewRecord.Value); bool isUpdate = false; if (y.Alteration.Type == Objects.AlterationType.Move && !next.IsDirectory && prior.DataIdentifier != next.DataIdentifier) { isUpdate = true; operationName = "refactor"; } Printer.PrintMessage("#{2}#({0})## {1}\n <- #q#{3}##", operationName, y.Record.CanonicalName, GetAlterationFormat(y.Alteration.Type), prior.CanonicalName); if (localOptions.Diff && isUpdate) { InlineDiff(prior, next); } } else { Printer.PrintMessage("#{2}#({0})## {1}", y.Alteration.Type.ToString().ToLower(), y.Record.CanonicalName, GetAlterationFormat(y.Alteration.Type)); if (localOptions.Diff && y.Alteration.Type == Objects.AlterationType.Update) { InlineDiff(Workspace.GetRecord(y.Alteration.PriorRecord.Value), Workspace.GetRecord(y.Alteration.NewRecord.Value)); } } } } Printer.Prefix = ""; // Same-branch merge revisions. This only sort-of respects the limit :( //foreach (var y in mergeInfo) //{ // var mergeParent = Workspace.GetVersion(y.SourceVersion); // if (mergeParent.Branch == v.Branch) // { // Printer.PushIndent(); // Printer.PrintMessage("---- Merged versions ----"); // List<Objects.Version> mergedVersions = new List<Objects.Version>(); // var p = mergeParent; // do // { // mergedVersions.Add(p); // if (p.Parent.HasValue && !m_LoggedVersions.Contains(p.Parent.Value)) // p = Workspace.GetVersion(p.Parent.Value); // else // p = null; // } while (p != null); // foreach (var a in ApplyHistoryFilter(mergedVersions, localOptions)) // FormatLog(a.Item1, a.Item2, localOptions); // Printer.PrintMessage("-------------------------"); // Printer.PopIndent(); // } //} } }
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; }
IEnumerable <ResolvedAlteration> GetAlterations(Objects.Version v) { return(Workspace.GetAlterations(v).Select(x => new ResolvedAlteration(x, Workspace))); }
protected override bool RunInternal(object options) { ListAnnotationVerbOptions localOptions = options as ListAnnotationVerbOptions; List <Objects.Annotation> annotations = new List <Objects.Annotation>(); Objects.Version ver = Workspace.GetPartialVersion(localOptions.Version); if (ver == null) { Printer.PrintMessage("#e#Error:## can't find version #b#\"{0}\"## to retrieve annotation list.", localOptions.Version); return(false); } if (string.IsNullOrEmpty(localOptions.Key)) { annotations.AddRange(Workspace.GetAnnotationsForVersion(ver.ID, !localOptions.Deleted)); } else { annotations.AddRange(Workspace.GetAllAnnotations(ver.ID, localOptions.Key, localOptions.IgnoreCase)); } if (annotations.Count == 0) { Printer.PrintMessage("No annotations matching query."); } else { List <Objects.Annotation> filterList = new List <Objects.Annotation>(); HashSet <string> key = new HashSet <string>(); foreach (var x in annotations) { if (x.Active == false) { if (localOptions.Deleted) { continue; } } else { if (!localOptions.All) { if (key.Contains(x.Key)) { continue; } key.Add(x.Key); } } filterList.Add(x); } annotations = filterList; Printer.PrintMessage("Found #b#{0}## annotations.", annotations.Count); for (int i = 0; i < annotations.Count; i++) { var x = annotations[i]; string suffix = ""; if (x.Active == false) { suffix = "#e#(deleted)##"; } else { if (Workspace.GetAnnotation(x.Version, x.Key, false).ID == x.ID) { suffix = "#s#(tip)##"; } } suffix += string.Format(" #q#({0})##", Versionr.Utilities.Misc.FormatSizeFriendly(Workspace.GetAnnotationPayloadSize(x))); if (!Workspace.HasAnnotationData(x)) { suffix += " #w#(missing data)##"; } Printer.PrintMessage(" #b#{1}## on version #b#{2}## {5}\n by #b#{3}## on {4} #q#(ID: {6})##", i, x.Key, x.Version, x.Author, x.Timestamp.ToLocalTime(), suffix, x.ID); } } return(true); }
protected override bool RunInternal(object options) { GetAnnotationVerbOptions localOptions = options as GetAnnotationVerbOptions; Objects.Annotation annotation = null; if (string.IsNullOrEmpty(localOptions.Key)) { if (!localOptions.Plain) { Printer.PrintMessage("#e#Error:## an annotation key must be specified."); } return(false); } if (!string.IsNullOrEmpty(localOptions.Version)) { Objects.Version ver = Workspace.GetPartialVersion(localOptions.Version); if (ver == null) { if (!localOptions.Plain) { Printer.PrintMessage("#e#Error:## can't find version #b#\"{0}\"## to retrieve annotation.", localOptions.Version); } return(false); } annotation = Workspace.GetAnnotation(ver.ID, localOptions.Key, localOptions.IgnoreCase); if (annotation == null) { if (localOptions.Recursive) { if (!localOptions.Plain) { Printer.PrintMessage("#w#Warning:## no annotation matching that key for the current version, searching history."); } var history = Workspace.GetLogicalHistory(ver, false, true, true); foreach (var v in history) { if (!localOptions.Plain) { Printer.PrintMessage("Checking version #b#{0}##.", v.ID); } annotation = Workspace.GetAnnotation(ver.ID, localOptions.Key, localOptions.IgnoreCase); if (annotation != null) { break; } } if (annotation == null) { if (!localOptions.Plain) { Printer.PrintMessage("#e#Error:## no annotation matching that key."); } return(false); } } else { if (!localOptions.Plain) { Printer.PrintMessage("#e#Error:## no annotation matching that key for the specified version."); } return(false); } } } else { var annotations = Workspace.GetPartialAnnotation(localOptions.Key); if (annotations.Count == 0) { if (!localOptions.Plain) { Printer.PrintMessage("#e#Error:## no annotation matching that ID."); } return(false); } else if (annotations.Count > 1) { if (!localOptions.Plain) { Printer.PrintMessage("#e#Error:## found #b#{0}## multiple matching annotations:", annotations.Count); for (int i = 0; i < annotations.Count; i++) { var x = annotations[i]; string suffix = ""; if (x.Active == false) { suffix = "#e#(deleted)##"; } else { if (Workspace.GetAnnotation(x.Version, x.Key, false).ID == x.ID) { suffix = "#s#(tip)##"; } } suffix += string.Format(" #q#{0}##", Workspace.GetAnnotationPayloadSize(x)); Printer.PrintMessage(" [{0}]: #b#{1}## on version #b#{2}## {5}\n by #b#{3}## on {4} #q#(ID: {6})##", i, x.Key, x.Version, x.Author, x.Timestamp.ToLocalTime(), suffix, x.ID); } } return(false); } else { annotation = annotations[0]; } } if (!localOptions.Plain) { Printer.PrintMessage("Version #b#{0}## - annotation #b#{1}## #q#({2})##", annotation.Version, annotation.Key, annotation.ID); Printer.PrintMessage("Added by #b#{0}## on {1}", annotation.Author, annotation.Timestamp.ToLocalTime()); Printer.PrintMessage(""); } if (annotation.Active == false) { if (!localOptions.Plain) { Printer.PrintMessage("#e#Annotation has been deleted.##"); } return(false); } if (!localOptions.Plain && annotation.Flags.HasFlag(Objects.AnnotationFlags.Binary) && string.IsNullOrEmpty(localOptions.Filename)) { Printer.PrintMessage("#q#[Annotation contents is a binary blob.]##"); } else { if (string.IsNullOrEmpty(localOptions.Filename)) { Printer.PrintMessage(Printer.Escape(Workspace.GetAnnotationAsString(annotation))); } else { using (System.IO.Stream s = Workspace.GetAnnotationStream(annotation)) using (System.IO.FileStream fs = System.IO.File.Open(localOptions.Filename, System.IO.FileMode.Create)) s.CopyTo(fs); if (!localOptions.Plain) { Printer.PrintMessage("Wrote annotation contents to file #b#{0}##.", localOptions.Filename); } } } return(true); }
public bool Run(System.IO.DirectoryInfo workingDirectory, object options) { MergeInfoVerbOptions localOptions = options as MergeInfoVerbOptions; Printer.EnableDiagnostics = localOptions.Verbose; Area ws = Area.Load(workingDirectory); if (ws == null) { return(false); } foreach (var x in localOptions.Target) { Objects.Version v = ws.GetPartialVersion(x); if (v != null) { Printer.PrintMessage("Merge information for version #c#{0}##.", v.ID); var mergeInfos = ws.GetMergeList(v.ID); HashSet <Guid> directMerges = new HashSet <Guid>(); foreach (var m in mergeInfos) { if (m == null) { Printer.PrintMessage(" - Merged into #w#unknown version##"); } else { Objects.Branch b = ws.GetBranch(m.Branch); directMerges.Add(b.ID); Printer.PrintMessage(" - Merged into #b#{0}## on branch #b#\"{1}\"## ({2})", m.ShortName, b.Name, b.ShortID); } } string deleteMarker = " #e#[deleted]##"; Printer.PrintMessage("Branch relationships:"); foreach (var b in ws.GetBranches(localOptions.Deleted)) { HashSet <Guid> inputMerges = new HashSet <Guid>(); HashSet <Guid> visitedMerges = new HashSet <Guid>(); string result = "#w#unrelated"; int relationshipCode = 0; foreach (var h in ws.GetBranchHeads(b)) { var headVersion = ws.GetVersion(h.Version); if (relationshipCode < 4 && headVersion.ID == v.ID) { relationshipCode = 4; result = "#s#a branch head"; } else if (relationshipCode < 3 && ws.GetHistory(headVersion).Any(z => z.ID == v.ID)) { relationshipCode = 3; result = "#s#a direct parent"; } else if (relationshipCode < 2 && directMerges.Contains(b.ID)) { relationshipCode = 2; result = "#s#a merge parent"; } else if (relationshipCode < 1 && ws.GetParentGraph(headVersion, false).ContainsKey(v.ID)) { relationshipCode = 1; result = "#c#an indirect ancestor"; } } Printer.PrintMessage(" - #b#{0}## ({1}){3}: version is {2}##.", b.Name, b.ShortID, result, b.Terminus.HasValue ? deleteMarker : string.Empty); } } else { Printer.PrintError("#e#Can't locate version with ID #b#\"{0}\"#e#.", x); } } return(true); }
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 || x.Code == StatusCode.Conflict)) { if (localOptions.Recorded && x.Staged == false) { continue; } if (x.Code == StatusCode.Conflict) { Printer.PrintMessage("Object: #b#{0}## is #w#conflicted##.", x.CanonicalName); } 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 || localOptions.ExternalNonBlocking) { tempFiles.Add(tmp); bool nonblocking = Workspace.Directives.NonBlockingDiff.HasValue && Workspace.Directives.NonBlockingDiff.Value; nonblocking |= localOptions.ExternalNonBlocking; var t = GetTaskFactory(options).StartNew(() => { var diffResult = Utilities.DiffTool.Diff(tmp, x.Name + "-base", System.IO.Path.Combine(Workspace.RootDirectory.FullName, 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)), !localOptions.KeepTabs, Workspace.GetLocalCanonicalName(x.VersionControlRecord)); } finally { new System.IO.FileInfo(tmp).IsReadOnly = false; 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) { if (localOptions.Recorded && x.Staged == false) { continue; } Objects.Record otherRecord = null; if (recordMap.TryGetValue(x.CanonicalName, out otherRecord) && !otherRecord.IsDirectory) { if (x.VersionControlRecord != null && x.VersionControlRecord.DataIdentifier == otherRecord.DataIdentifier) { continue; } if (x.FilesystemEntry != null && otherRecord.Fingerprint == x.FilesystemEntry.Hash && otherRecord.Size == x.FilesystemEntry.Length) { 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 || localOptions.ExternalNonBlocking) { tempFiles.Add(tmp); bool nonblocking = Workspace.Directives.NonBlockingDiff.HasValue && Workspace.Directives.NonBlockingDiff.Value; nonblocking |= localOptions.ExternalNonBlocking; var t = GetTaskFactory(options).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)), !localOptions.KeepTabs, 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 || localOptions.ExternalNonBlocking) { bool nonblocking = Workspace.Directives.NonBlockingDiff.HasValue && Workspace.Directives.NonBlockingDiff.Value; nonblocking |= localOptions.ExternalNonBlocking; tempFiles.Add(tmpVersion); tempFiles.Add(tmpParent); var t = GetTaskFactory(options).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, !localOptions.KeepTabs, rec.CanonicalName); } 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); }
protected override bool RunInternal(IRemoteClient client, RemoteCommandVerbOptions options) { AheadVerbOptions localOptions = options as AheadVerbOptions; Info.DisplayInfo(client.Workspace); Objects.Branch desiredBranch = client.Workspace.CurrentBranch; if (!string.IsNullOrEmpty(localOptions.Branch)) { bool multiple; desiredBranch = client.Workspace.GetBranchByPartialName(localOptions.Branch, out multiple); if (desiredBranch == null) { Printer.PrintError("#e#Error:## Local branch #b#`{0}`## not found.", localOptions.Branch); return(false); } } var branches = client.ListBranches(); if (branches == null) { Printer.PrintError("#e#Error:## Server does not support branch list operation."); return(false); } foreach (var x in branches.Item1) { if (x.ID != desiredBranch.ID && !localOptions.AllBranches) { continue; } var localBranch = client.Workspace.GetBranch(x.ID); if (localOptions.AllBranches && localBranch == null && !localOptions.ShowUninteresting) { continue; } if (x.Terminus.HasValue && (!localOptions.AllBranches || localOptions.IncludeDeleted)) { bool present = client.Workspace.GetVersion(x.Terminus.Value) != null; Objects.Version terminus = null; branches.Item3.TryGetValue(x.Terminus.Value, out terminus); string presentMarker = present ? "" : " #w#(behind)##"; if (present && localBranch != null) { if (localBranch.Terminus.Value != x.Terminus.Value) { presentMarker += " #w#(ahead)##"; } else { if (localOptions.AllBranches && !localOptions.ShowUninteresting) { continue; } presentMarker += " #s#(up-to-date)##"; } } if (localBranch != null && !localBranch.Terminus.HasValue) { presentMarker += " #w#(not locally deleted)##"; } if (localBranch == null) { presentMarker += " #w#(not synchronized)##"; } string branchMarker = localOptions.AllBranches ? "#b#" + x.Name + "##" : ""; if (terminus == null) { Printer.PrintMessage("Remote - #e#(deleted)## {2} - Last version: #e#(unknown)## #b#{0}##{1}", x.Terminus.Value, presentMarker, branchMarker); } else { Printer.PrintMessage("Remote - #e#(deleted)## {4} - Last version: #b#{0}##{3}, #q#{2} {1}##", terminus.ShortName, terminus.Timestamp.ToLocalTime(), terminus.Author, presentMarker, branchMarker); } } foreach (var z in branches.Item2.Where(y => y.Key == x.ID)) { bool present = client.Workspace.GetVersion(z.Value) != null; string presentMarker = present ? "" : " #w#(behind)##"; if (present && localBranch != null) { var localHeads = client.Workspace.GetBranchHeads(localBranch); if (localHeads.Count == 1 && localHeads[0].Version != z.Value) { presentMarker += " #w#(ahead)##"; } else { if (localOptions.AllBranches && !localOptions.ShowUninteresting) { continue; } presentMarker += " #s#(up-to-date)##"; } } if (localBranch != null && localBranch.Terminus.HasValue) { presentMarker += " #e#(locally deleted)##"; } if (localBranch == null) { presentMarker += " #w#(not synchronized)##"; } string branchMarker = localOptions.AllBranches ? "#b#" + x.Name + "##" : ""; var head = branches.Item3[z.Value]; Printer.PrintMessage("Remote - #s#(active)## {4} - Version: #b#{0}##{3}, #q#{2} {1}##", head.ShortName, head.Timestamp.ToLocalTime(), head.Author, presentMarker, branchMarker); } } return(true); }
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; } if (localOptions.ShowAutoMerges) { localOptions.ShowMerges = true; } if (localOptions.FollowBranches || localOptions.ShowMerges) { if (!localOptions.Logical) { Printer.PrintError("#e#Error:## Following branches and specifically enabling display or merges are only valid options when showing the #b#--logical## history."); return(false); } } 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); } } bool versionAutoSelected = false; bool lastResortVersionSelection = false; List <Objects.Head> targetHeadObjects = null; if (localOptions.Limit == -1) { localOptions.Limit = (version == null || targetedBranch) ? 10 : 1; } if (version == null) { versionAutoSelected = true; targetHeadObjects = ws.GetBranchHeads(ws.CurrentBranch); if (targetHeadObjects.Count == 1) { version = ws.GetVersion(targetHeadObjects[0].Version); } else { var guid = ws.Version.ID; foreach (var head in targetHeadObjects) { if (head.Version == guid) { version = ws.Version; break; } } if (version == null) { foreach (var head in targetHeadObjects) { var temphistory = ws.GetHistory(ws.GetVersion(head.Version), null); foreach (var h in temphistory) { if (h.ID == guid) { version = ws.GetVersion(head.Version); break; } } } } if (version == null) { lastResortVersionSelection = true; version = ws.Version; } } } int?nullableLimit = localOptions.Limit; if (nullableLimit.Value <= 0) { nullableLimit = null; } if (localOptions.Xml) { Printer.PrintMessage("<?xml version='1.0'?>"); Printer.PrintMessage($"<vsrlog>"); var branch = ws.GetBranch(version.Branch); Printer.PrintMessage($" <branch id='{branch.ID}' name='{XmlAttr(branch.Name)}'>"); foreach (var head in ws.GetBranchHeads(branch)) { Printer.PrintMessage($" <head version='{head.Version}' />"); } Printer.PrintMessage(" </branch>"); } var history = (localOptions.Logical ? ws.GetLogicalHistorySequenced(version, localOptions.FollowBranches, localOptions.ShowMerges, localOptions.ShowAutoMerges, nullableLimit) : ws.GetHistory(version, nullableLimit).Select(x => new Tuple <Objects.Version, int>(x, 0))).AsEnumerable(); m_Tip = Workspace.Version; Objects.Version last = null; m_Branches = new Dictionary <Guid, Objects.Branch>(); bool anything = false; ws.BeginDatabaseTransaction(); foreach (var x in ApplyHistoryFilter(history, localOptions)) { last = x.Item1.Item1; FormatLog(x.Item1, x.Item2, localOptions); anything = true; } ws.CommitDatabaseTransaction(); if (localOptions.Xml) { Printer.PrintMessage("</vsrlog>"); } else { if (!localOptions.Jrunting) { if (last != null && last.ID != m_Tip.ID) { var branch = Workspace.CurrentBranch; var heads = Workspace.GetBranchHeads(branch); bool isHead = heads.Any(x => x.Version == m_Tip.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); } } if (!anything) { if (!nullableLimit.HasValue || nullableLimit.Value <= 0) { Printer.PrintMessage("\nNo versions matched your history/filter query (searched #b#all## revisions)."); } else { Printer.PrintMessage("\nNo versions matched your history/filter query (searched #b#{0}## revisions).\n\nTry setting #b#--limit## to a larger value (or #b#0## for all revisions).", nullableLimit.Value); } } } if (versionAutoSelected) { if (targetHeadObjects.Count > 1) { Printer.WriteLineMessage("\n #w#Warning:## Target branch has multiple heads."); Printer.WriteLineMessage("\n Heads of #b#\"{0}\"##:", ws.CurrentBranch.Name); foreach (var x in targetHeadObjects) { var v = Workspace.GetVersion(x.Version); Printer.WriteLineMessage(" #b#{0}##: {1} by {2}", v.ShortName, v.Timestamp.ToLocalTime(), v.Author); } } } } return(true); }
public PreCommitHook(Area ws, string username, Objects.Branch branch, Objects.Version version, string message, List <KeyValuePair <AlterationType, string> > modifications) : base(ws, username, branch, version) { m_Modifications = modifications; m_Message = message; }
public PostCommitHook(Area ws, string username, Objects.Branch branch, Objects.Version version, Objects.Version old, List <KeyValuePair <AlterationType, string> > modifications) : base(ws, username, branch, version, old) { m_Modifications = modifications; }
protected override bool RunInternal(object options) { DeleteAnnotationVerbOptions localOptions = options as DeleteAnnotationVerbOptions; Objects.Annotation annotation = null; if (string.IsNullOrEmpty(localOptions.Key)) { if (!localOptions.Plain) { Printer.PrintMessage("#e#Error:## an annotation key must be specified."); } return(false); } if (!string.IsNullOrEmpty(localOptions.Version)) { Objects.Version ver = Workspace.GetPartialVersion(localOptions.Version); if (ver == null) { if (!localOptions.Plain) { Printer.PrintMessage("#e#Error:## can't find version #b#\"{0}\"## to remove annotation.", localOptions.Version); } return(false); } annotation = Workspace.GetAnnotation(ver.ID, localOptions.Key, localOptions.IgnoreCase); if (annotation == null) { if (!localOptions.Plain) { Printer.PrintMessage("#e#Error:## no annotation matching that key for the specified version."); } return(false); } } else { var annotations = Workspace.GetPartialAnnotation(localOptions.Key); if (annotations.Count == 0) { if (!localOptions.Plain) { Printer.PrintMessage("#e#Error:## no annotation matching that ID."); } return(false); } else if (annotations.Count > 1) { if (!localOptions.Plain) { Printer.PrintMessage("#e#Error:## found #b#{0}## multiple matching annotations:", annotations.Count); for (int i = 0; i < annotations.Count; i++) { var x = annotations[i]; string suffix = ""; if (x.Active == false) { suffix = "#e#(deleted)##"; } else { if (Workspace.GetAnnotation(x.Version, x.Key, false).ID == x.ID) { suffix = "#s#(tip)##"; } } suffix += string.Format(" #q#{0}##", Workspace.GetAnnotationPayloadSize(x)); Printer.PrintMessage(" [{0}]: #b#{1}## on version #b#{2}## {5}\n by #b#{3}## on {4} #q#(ID: {6})##", i, x.Key, x.Version, x.Author, x.Timestamp.ToLocalTime(), suffix, x.ID); } } return(false); } else { annotation = annotations[0]; } } if (annotation.Active != false) { Workspace.DeleteAnnotation(annotation); Printer.PrintMessage("Deleted."); return(true); } return(false); }
protected override bool RunInternal(IRemoteClient client, RemoteCommandVerbOptions options) { PullVerbOptions localOptions = options as PullVerbOptions; bool objects = true; if (localOptions.PullAll) { objects = false; } if (localOptions.List) { var branches = client.ListBranches(); if (branches == null) { return(false); } Printer.PrintMessage("Displaying remote branches:"); foreach (var x in branches.Item1) { if (!localOptions.Deleted && x.Terminus.HasValue) { continue; } string tipmarker = ""; if (x.ID == client.Workspace.CurrentBranch.ID) { tipmarker = " #w#*<current>##"; } Printer.PrintMessage("#b#{1}## - #c#{0}##{2}", x.ID, x.Name, tipmarker); string heading = string.Empty; var localBranch = client.Workspace.GetBranch(x.ID); if (x.Terminus.HasValue) { Objects.Version terminus = null; bool present = client.Workspace.GetVersion(x.Terminus.Value) != null; string presentMarker = present ? "" : " #w#(behind)##"; if (!branches.Item3.TryGetValue(x.Terminus.Value, out terminus)) { Printer.PrintMessage(" #e#(deleted)## - #w#(no data)##"); continue; } if (present && localBranch != null) { if (localBranch.Terminus.Value != x.Terminus.Value) { presentMarker += " #w#(ahead)##"; } } if (localBranch != null && !localBranch.Terminus.HasValue) { presentMarker += " #w#(not locally deleted)##"; } if (localBranch == null) { presentMarker += " #w#(not synchronized)##"; } Printer.PrintMessage(" #e#(deleted)## - Last version: #b#{0}##{3}, #q#{2} {1}##", terminus.ShortName, terminus.Timestamp.ToLocalTime(), terminus.Author, presentMarker); } foreach (var z in branches.Item2.Where(y => y.Key == x.ID)) { bool present = client.Workspace.GetVersion(z.Value) != null; string presentMarker = present ? "" : " #w#(behind)##"; if (present && localBranch != null) { var localHeads = client.Workspace.GetBranchHeads(localBranch); if (localHeads.Count == 1 && localHeads[0].Version != z.Value) { presentMarker += " #w#(ahead)##"; } } if (localBranch != null && localBranch.Terminus.HasValue) { presentMarker += " #e#(locally deleted)##"; } if (localBranch == null) { presentMarker += " #w#(not synchronized)##"; } var head = branches.Item3[z.Value]; Printer.PrintMessage(" #s#(head)## - Version: #b#{0}##{3}, #q#{2} {1}##", head.ShortName, head.Timestamp.ToLocalTime(), head.Author, presentMarker); } } return(true); } if (!client.Pull(localOptions.PullObjects.HasValue ? localOptions.PullObjects.Value : objects, localOptions.RemoteBranch, localOptions.PullAll, localOptions.AcceptDeletes)) { return(false); } if (localOptions.Update) { client.Workspace.Update(new Area.MergeSpecialOptions()); } return(true); }