public ConflictListItem(ConflictListView view, PendingChange change) : base(view) { if (change == null) throw new ArgumentNullException("change"); _change = change; RefreshText(view.Context); }
public override void OnExecute(CommandEventArgs e) { IPendingChangesManager pcm = e.GetService <IPendingChangesManager>(); PendingChange.RefreshContext rc = new PendingChange.RefreshContext(e.Context); Dictionary <string, PendingChange> selectedChanges = new Dictionary <string, PendingChange>(StringComparer.OrdinalIgnoreCase); List <SvnItem> resources = new List <SvnItem>(); foreach (SvnItem item in e.Selection.GetSelectedSvnItems(true)) { PendingChange pc; if (PendingChange.CreateIfPending(rc, item, out pc)) { if (!pc.IsNoChangeForPatching()) { selectedChanges.Add(pc.FullPath, pc); resources.Add(pc.SvnItem); } } } if (resources.Count == 0) { return; } using (PendingChangeSelector pcs = new PendingChangeSelector()) { pcs.Text = CommandStrings.CreatePatchTitle; pcs.PreserveWindowPlacement = true; pcs.LoadItems(resources); DialogResult dr = pcs.ShowDialog(e.Context); if (dr != DialogResult.OK) { return; } string fileName = GetFileName(e.Context.DialogOwner); if (string.IsNullOrEmpty(fileName)) { return; } PendingChangeCreatePatchArgs pca = new PendingChangeCreatePatchArgs(); pca.FileName = fileName; IAnkhSolutionSettings ss = e.GetService <IAnkhSolutionSettings>(); pca.RelativeToPath = ss.ProjectRoot; pca.AddUnversionedFiles = true; List <PendingChange> patchChanges = new List <PendingChange>(pcs.GetSelection()); e.GetService <IPendingChangeHandler>().CreatePatch(patchChanges, pca); } }
/// <summary> /// Generates the list view item. /// </summary> /// <param name="change">The change.</param> /// <returns></returns> /// <remarks>Documented by CFI, 2010-06-27</remarks> private ListViewItem GenerateListViewItem(PendingChange change) { Icon smallIcon = Win32.GetFileIcon(change.LocalItem, true); Icon largeIcon = Win32.GetFileIcon(change.LocalItem, false); if (smallIcon != null) { listViewFiles.SmallImageList.Images.Add(smallIcon); } if (largeIcon != null) { listViewFiles.LargeImageList.Images.Add(largeIcon); } ListViewItem item; if (smallIcon != null) { item = new ListViewItem(change.FileName, listViewFiles.LargeImageList.Images.Count - 1); } else { item = new ListViewItem(change.FileName); } string mode = ""; if (change.IsAdd) { mode += "add, "; } if (change.IsDelete) { mode += "delete, "; } if (change.IsEdit) { mode += "edit, "; } if (change.IsLock) { mode += "lock, "; } if (change.IsMerge) { mode += "merge, "; } if (change.IsRename) { mode += "rename, "; } mode = mode.TrimEnd(',', ' '); item.SubItems.Add(mode); item.SubItems.Add(Path.GetDirectoryName(change.LocalItem)); item.Tag = change; return(item); }
public static void ShowDialogFileFolderProperties(Workspace workspace, PendingChange pendingChange, PropertiesMode mode) { Assembly assembly = typeof(ConfigureWorkspaceGrid).Assembly; var dialogType = assembly.GetType("Microsoft.TeamFoundation.VersionControl.Controls.DialogFileFolderProperties"); dynamic dynamicDialog = ExposedObject.New(dialogType, TfsContext.VersionControlServer, workspace, pendingChange, mode); var d = (Form)dynamicDialog; d.ShowDialog(); }
/// <summary> /// Returns the full file path of the pending change file. /// </summary> /// <param name="pendingChange">The pending change file</param> /// <returns>The full file path of the given pending change</returns> private static string GetFullFilePath(PendingChange pendingChange) { return(pendingChange != null ? string.Format( CultureInfo.CurrentCulture, @"{0}/{1}", pendingChange.LocalOrServerFolder, pendingChange.FileName) : string.Empty); }
/// <summary> /// Returns the given pending change if it should be undone, otherwise null. /// </summary> private Task <PendingChange> ShouldUndoPendingChangeAsync(PendingChange pendingChange) { return(Task.Run(() => { if (pendingChange.IsAdd || pendingChange.IsDelete || pendingChange.IsLocalItemDelete || pendingChange.IsUndelete) { return null; } byte[] baseItemHashCode; try { using (var baseFileStream = pendingChange.DownloadBaseFile()) { using (var hashAlgorithem = new SHA1Cng()) { baseItemHashCode = hashAlgorithem.ComputeHash(baseFileStream); } } } catch (Exception ex) { const string ErrorMessageFormat = "Error occurred during computing hash for the base item of {0}: {1}"; LoggerUtilities.LogError(string.Format(CultureInfo.CurrentCulture, ErrorMessageFormat, pendingChange.ServerItem, ex.ToString())); return null; } byte[] localItemHashCode; try { using (var localFileStream = new FileStream(Path.GetFullPath(pendingChange.LocalItem), FileMode.Open, FileAccess.Read)) { using (var hashAlgorithem = new SHA1Cng()) { localItemHashCode = hashAlgorithem.ComputeHash(localFileStream); } } } catch (Exception ex) { const string ErrorMessageFormat = "Error occurred during computing hash for the local item of {0}: {1}"; LoggerUtilities.LogError(string.Format(CultureInfo.CurrentCulture, ErrorMessageFormat, pendingChange.ServerItem, ex.ToString())); return null; } return Enumerable.SequenceEqual(baseItemHashCode, localItemHashCode) ? pendingChange : null; })); }
private string GetRevision(PendingChange PendingChange) { if (PendingChange.Revision.HasValue) { return(PendingChange.Revision.ToString()); } else { return(""); } }
private static byte[] GetMD5HashValue(PendingChange change) { if (change.IsDelete || !File.Exists(change.LocalItem)) { return(change.UploadHashValue); } else { return(MD5.Create().ComputeHash(File.ReadAllBytes(change.LocalItem))); } }
private static DateTime GetLastChangeDate(PendingChange change) { if (change.IsDelete) { return(change.CreationDate); } else { return(File.GetLastWriteTime(change.LocalItem)); } }
public static Document ToDocument(this PendingChange change) { if (change == null) { throw new ArgumentNullException("change"); } var meta = change.Meta; if (meta == null) { return new Document { Id = change.Id, FilePath = change.DeletedFilePath } } ; DateTime?takenAt = null; double? lat = null; double? lon = null; if (meta.photo_info != null) { if (!String.IsNullOrEmpty(meta.photo_info.time_taken)) { takenAt = ToUtcDateTimeFromDropBoxTimeString(meta.photo_info.time_taken); } if (meta.photo_info.lat_long != null && meta.photo_info.lat_long.Length == 2) { lat = meta.photo_info.lat_long[0]; lon = meta.photo_info.lat_long[1]; } } return(new Document { Id = change.Id, // timestamps are chosen based on what's available CreatedAt = ToUtcDateTimeFromDropBoxTimeString(meta.client_mtime), ModifiedAt = ToUtcDateTimeFromDropBoxTimeString(meta.modified), FileSize = (ulong)meta.bytes, FilePath = meta.path, TakenAt = takenAt, Latitude = lat, Longitude = lon, Thumbnail = change.Thumbnail }); }
public ConflictListItem(ConflictListView view, PendingChange change) : base(view) { if (change == null) { throw new ArgumentNullException("change"); } _change = change; RefreshText(view.Context); }
private bool IsChildChanged(string path) { GitItem item = StatusCache[path]; if (item == null) { return(false); } return(PendingChange.IsPending(item)); }
PendingChangeItem ISelectionMapOwner <PendingChangeItem> .GetItemFromSelectionObject(object item) { PendingChange pc = (PendingChange)item; PendingChangeItem pci = null; if (pc != null && _wc != null) { _wc.TryGetValue(pc.FullPath, out pci); } return(pci); }
public PendingCommitItem(PendingCommitsView view, PendingChange change) : base(view) { if (change == null) throw new ArgumentNullException("change"); _change = change; Checked = true; RefreshText(view.Context); }
internal PendingChangeTreeNode(PendingChange pendingChange, bool useServerPath) { PendingChange = pendingChange; UseServerPath = useServerPath; if (PendingChange == null) { return; } ItemText = PendingChangesHelper.GetItemName(PendingChange, UseServerPath); ItemPath = PendingChangesHelper.GetItemPath(PendingChange, UseServerPath); ItemSubText = PendingChangesHelper.FormatDisplayChangeType(PendingChange, UseServerPath); IsDeleted = pendingChange.IsDelete; }
public PendingCommitItem(PendingCommitsView view, PendingChange change) : base(view) { if (change == null) throw new ArgumentNullException("change"); _change = change; //initially check only if this change does not belong to an "ignore" change list Checked = !change.IgnoreOnCommit; RefreshText(view.Context); }
public void CompareWithLatest(string item) { Workspace w = this.GetWorkspace(item); if (w != null) { PendingChange pc = w.GetPendingChanges(item).SingleOrDefault(); if (pc != null) { ClientHelperVSProxy.Instance.CompareWithLatestVersion(new[] { pc }); } } }
public static SourceControlFileState ToSourceControlFileState(this PendingChange source) { if (source.IsAdd) { return(SourceControlFileState.Added); } if (source.IsDelete) { return(SourceControlFileState.Deleted); } return(SourceControlFileState.Changed); }
public AdapterShelvesetChange(PendingChange pendingChange, string[] workspaceBranches) { _pendingChange = pendingChange; _workspaceBranches = workspaceBranches; foreach (string workspaceBranch in workspaceBranches) { if (_pendingChange.ServerItem.StartsWith(workspaceBranch + "/")) { _workspaceBranch = workspaceBranch; break; } } }
/// <summary> /// Update workspace with the latest version of specified item if item is not currently checked out. /// </summary> /// <param name="item">The path to the file to update.</param> /// <param name="recursive">Recurse to the last child.</param> /// <returns><c>false</c> if file is currently checked out.</returns> public static bool GetLatestVersion(string item, bool recursive = false) { var checkinChanges = Workspace.GetPendingChangesEnumerable(item, recursive ? RecursionType.Full : RecursionType.None); if (!PendingChange.IsIEnumerableEmpty(checkinChanges)) { //File is checked out. return(false); } var s = Workspace.Get(new string[] { item }, VersionSpec.Latest, recursive ? RecursionType.Full : RecursionType.None, GetOptions.Overwrite | GetOptions.GetAll); return(true); }
public override void OnUpdate(CommandUpdateEventArgs e) { bool recursive = (e.Command != AnkhCommand.CommitProjectFile); foreach (SvnItem i in e.Selection.GetSelectedSvnItems(recursive)) { if (PendingChange.IsPending(i)) { return; } } e.Enabled = false; }
/// <summary> /// Compares the contents of two given files. /// </summary> /// <param name="firstPendingChange">The first pending change file.</param> /// <param name="secondPendingChange">The second pending change file</param> /// <returns>True if the file contents are same. False otherwise.</returns> private static bool AreFilesInPendingChangesSame(PendingChange firstPendingChange, PendingChange secondPendingChange) { if (firstPendingChange != null && secondPendingChange != null && firstPendingChange.ChangeType != ChangeType.Delete && secondPendingChange.ChangeType != ChangeType.Delete) { string pendingChangeFileName = Path.GetTempFileName(); firstPendingChange.DownloadShelvedFile(pendingChangeFileName); string matchingFileName = Path.GetTempFileName(); secondPendingChange.DownloadShelvedFile(matchingFileName); return(FileCompare(pendingChangeFileName, matchingFileName)); } return(false); }
/// <summary> /// 'Pends' the add of a new folder and file and then checks it into the /// repository. /// </summary> /// <param name="workspace">Version control workspace to use when /// adding the folder and file.</param> /// <param name="newFilename">Full path to the file to add (the path /// of the folder will be derived from the file's path.</param> /// <exception cref="SecurityException">If the user doesn't have /// check-in permission for the specified <paramref name="workspace"/>.</exception> /// <exception cref="IOException">If there's a problem creating the file.</exception> /// <exception cref="VersionControlException">If </exception> private static void AddNewFile(Workspace workspace, String newFilename) { Debug.Assert(workspace != null); Debug.Assert(!String.IsNullOrEmpty(newFilename)); Debug.Assert(!File.Exists(newFilename)); if (!workspace.HasCheckInPermission) { throw new SecurityException( String.Format("{0} does not have check-in permission for workspace: {1}", workspace.VersionControlServer.AuthenticatedUser, workspace.DisplayName)); } try { // create the new file using (var streamWriter = new StreamWriter(newFilename)) { streamWriter.WriteLine("Revision 1"); } // Now pend the add of our new folder and file workspace.PendAdd(Path.GetDirectoryName(newFilename), true); // Show our pending changes var pendingAdds = new List <PendingChange>((IEnumerable <PendingChange>) workspace.GetPendingChanges()); pendingAdds.ForEach(delegate(PendingChange add) { Console.WriteLine("\t{1}: {0}", add.LocalItem, PendingChange.GetLocalizedStringForChangeType(add.ChangeType)); }); // Checkin the items we added int changesetForAdd = workspace.CheckIn(pendingAdds.ToArray(), "Initial check-in"); Console.WriteLine("Checked in changeset {0}", changesetForAdd); } catch (IOException ex) { Console.Error.WriteLine("Error writing {1}: {0}", ex.Message, newFilename); throw; } catch (VersionControlException ex) { Console.Error.WriteLine("Error adding file: {0}", ex.Message); throw; } }
/// <summary> /// Performs a check-out of the specified item. /// </summary> /// <param name="item">The path to the file to check out.</param> /// <param name="lockLevel">The lock level to apply to each file checked out.</param> /// <param name="recursive">Recurse to the last child.</param> /// <returns><c>false</c> if file was already checked out.</returns> public static bool CheckOut(string item, LockLevel lockLevel = LockLevel.Unchanged, bool recursive = false) { var checkinChanges = Workspace.GetPendingChangesEnumerable(item, recursive ? RecursionType.Full : RecursionType.None); if (!PendingChange.IsIEnumerableEmpty(checkinChanges)) { //File is already checked out. return(false); } Workspace.PendEdit(new string[] { item }, recursive ? RecursionType.Full : RecursionType.None, null, lockLevel, true, Microsoft.TeamFoundation.VersionControl.Common.PendChangesOptions.GetLatestOnCheckout); return(true); }
protected override void OnResolveItem(ResolveItemEventArgs e) { base.OnResolveItem(e); if (_listItems != null) { PendingChange pc = e.SelectionItem as PendingChange; PendingCommitItem pci; if (pc != null && this._listItems.TryGetValue(pc.FullPath, out pci)) { e.Item = pci; } } }
public PendingCommitItem(PendingCommitsView view, PendingChange change) : base(view) { if (change == null) { throw new ArgumentNullException("change"); } _change = change; //initially check only if this change does not belong to an "ignore" change list Checked = !change.IgnoreOnCommit; RefreshText(view.Context); }
private bool IsOurChange(PendingChange eachPending) { if (eachPending.IsLocalItemDelete) { return(eachPending.SourceServerItem.Equals(this.ServerPath, StringComparison.CurrentCultureIgnoreCase)); } else if (eachPending.IsRename) { return(eachPending.SourceServerItem.Equals(this.ServerPath, StringComparison.CurrentCultureIgnoreCase)); } else if (eachPending.LocalItem != null) { return(eachPending.ServerItem.Equals(this.ServerPath, StringComparison.CurrentCultureIgnoreCase)); } return(false); }
public ChangeType?GetChangeType() { PendingChange pendingChange = Workspace.GetPendingChange(Path); PendingChange = pendingChange; if (PendingChange != null) { return(PendingChange.ChangeType); } if (Workspace.VersionControlServer.ServerItemExists(Path, Microsoft.TeamFoundation.VersionControl.Client.ItemType.Any)) { return(ChangeType.None); } return(null); }
public void UploadFile(string workspaceName, string workspaceOwner, PendingChange change) { var fileContent = File.ReadAllBytes(change.LocalItem); var fileHash = Hash(fileContent); string contentType = uncompressedContentType; using (var memory = new MemoryStream(fileContent)) { byte[] buffer = new byte[ChunkSize]; int cnt; while((cnt = memory.Read(buffer, 0, ChunkSize)) > 0) { var range = GetRange(memory.Position - cnt, memory.Position, fileContent.Length); UploadPart(change.ServerItem, workspaceName, workspaceOwner, fileContent.Length, fileHash, range, contentType, buffer, cnt); } } }
public void Add(Guid guid, string time) { foreach (PendingChange change in pendingChanges) { // Exists in table if (change.punchId == guid) { change.Time = time; return; } } // Record doens't exist, add it PendingChange newChange = new PendingChange(); newChange.punchId = guid; newChange.Time = time; pendingChanges.Add(newChange); }
/// <summary> /// Convert the passed changeset to an array of modifcations. /// </summary> private Modification[] toModifcations(Changeset changeset) { List <Modification> modifications = new List <Modification>(); string userName = changeset.Committer; string comment = changeset.Comment; int changeNumber = changeset.ChangesetId; // In VSTS, the version of the file is the same as the changeset number it was checked in with. string version = Convert.ToString(changeNumber); DateTime modifedTime = this.TFS.TimeZone.ToLocalTime(changeset.CreationDate); foreach (Change change in changeset.Changes) { Modification modification = new Modification(); modification.UserName = userName; modification.Comment = comment; modification.ChangeNumber = changeNumber; modification.ModifiedTime = modifedTime; modification.Version = version; modification.Type = PendingChange.GetLocalizedStringForChangeType(change.ChangeType); // Populate fields from change item Item item = change.Item; if (item.ItemType == ItemType.File) { // split into foldername and filename int lastSlash = item.ServerItem.LastIndexOf('/'); modification.FileName = item.ServerItem.Substring(lastSlash + 1); // patch to the following line submitted by Ralf Kretzschmar. modification.FolderName = item.ServerItem.Substring(0, lastSlash); } else { // TODO - what should filename be if dir?? Empty string or null? modification.FileName = string.Empty; modification.FolderName = item.ServerItem; } Log.Debug(modification.ToString()); modifications.Add(modification); } return(modifications.ToArray()); }
// Displays change and path information from the ExtendedItem. static void DisplayExtendedItem(ExtendedItem item, Workspace workspace) { Console.Write(" "); // Indicate whether someone else has a pending change on this file or folder. The // ExtendedItem doesn't contain the list of users with pending changes on this file. // For that information, we'd need to call QueryPendingSets() in addition to // GetExtendedItems() and join the two together via the item ID. if (item.HasOtherPendingChange) { Console.Write("^ "); } // Show the lock information if someone has locked the file or folder. if (item.LockStatus != LockLevel.None) { Console.Write("[{0},{1}] ", PendingChange.GetLocalizedStringForLockLevel(item.LockStatus), item.LockOwner); } // If there is a change pending on the item in the current workspace, display it. if (item.ChangeType != ChangeType.None) { Console.Write("({0}) ", PendingChange.GetLocalizedStringForChangeType(item.ChangeType)); } // Display the local path. if (!item.IsInWorkspace) { // Get the mapping so that we can determine its local path or that it is cloaked. WorkingFolder wf = workspace.TryGetWorkingFolderForServerItem(item.TargetServerItem); // Let's skip cloaked items, since the user doesn't want them. if (!wf.IsCloaked) { Console.WriteLine(wf.LocalItem); } } else { Console.WriteLine(item.LocalItem); } }
protected internal bool IsFileFromPackages(PendingChange pendingChange) { if (pendingChange.ServerItem.ToLower().Contains("/packages/")) { return(true); } if (pendingChange.ServerItem.ToLower().Contains("/bower_components/")) { return(true); } if (pendingChange.ServerItem.ToLower().Contains("/vendor/")) { return(true); } return(false); }
/// <summary> /// Indicates whether a pending change is ignored. /// </summary> /// <param name="pendingChange">The pending change to test.</param> /// <returns><b>true</b> if the change is ignored, otherwise <b>false</b>.</returns> private bool IsChangeIgnored(PendingChange pendingChange) { var isAddSet = Utilities.IsFlagSet(this.Context.Settings.EvaluateOn, EvaluateOnType.Add); var isBranchSet = Utilities.IsFlagSet(this.Context.Settings.EvaluateOn, EvaluateOnType.Branch); var isEditSet = Utilities.IsFlagSet(this.Context.Settings.EvaluateOn, EvaluateOnType.Edit); var isMargeSet = Utilities.IsFlagSet(this.Context.Settings.EvaluateOn, EvaluateOnType.Merge); var isRenameSet = Utilities.IsFlagSet(this.Context.Settings.EvaluateOn, EvaluateOnType.Rename); if (pendingChange.IsAdd && isAddSet) { return(false); } return(pendingChange.IsBranch && !isBranchSet || pendingChange.IsEdit && !isEditSet || pendingChange.IsMerge && !isMargeSet || pendingChange.IsRename && !isRenameSet); }
/// <summary> /// Initializes a new instance of the <see cref="PendingChangeEventArgs"/> class. /// </summary> /// <param name="service">The service.</param> /// <param name="change">The change.</param> public PendingChangeEventArgs(IPendingChangesManager service, PendingChange change) { if (service == null) throw new ArgumentNullException("service"); _change = change; // change can be null _context = service; }
public changeItem(PendingChange change) { this.change = change; fileName = change.FileName; changeType = change.ChangeType.ToString(); folder = change.LocalOrServerFolder; selected = true; }
// public void ShelveFile(string workspaceName, string ownerName, PendingChange change) // { // UploadFile(workspaceName, ownerName, change); // } private void UploadFile(string workspaceName, string ownerName, PendingChange change) { var uploadService = this.Collection.GetService<UploadService>(); uploadService.UploadFile(workspaceName, ownerName, change); }
internal void UploadFile(Workspace workspace, PendingChange change) { if (change.ItemType != ItemType.File) return; if (change.ChangeType.HasFlag(ChangeType.Edit) || change.ChangeType.HasFlag(ChangeType.Add)) UploadFile(workspace.Name, workspace.OwnerName, change); }
private string GetRevision(PendingChange PendingChange) { if (PendingChange.Revision.HasValue) return PendingChange.Revision.ToString(); else return ""; }
/// <summary> /// Tries to get a matching file from the specified text /// </summary> /// <param name="text"></param> /// <param name="change"></param> /// <returns></returns> /// <remarks>Called from the log message editor in an attempt to provide a mouse over</remarks> public bool TryMatchFile(string text, out PendingChange change) { change = null; if (string.IsNullOrEmpty(text)) return false; lock (_toRefresh) { text = text.Replace(Path.DirectorySeparatorChar, '/'); foreach (PendingChange pc in _pendingChanges) { if (pc.RelativePath == text) { change = pc; return true; } } int liSlash = text.LastIndexOf('/'); if (liSlash > 0) { text = text.Substring(liSlash + 1); } foreach (PendingChange pc in _pendingChanges) { if (text == pc.Name || text == Path.GetFileNameWithoutExtension(pc.Name)) { change = pc; return true; } } return false; } }
internal PendingChangeEventArgs(Workspace workspace, PendingChange pendingChange) { this.workspace = workspace; this.pendingChange = pendingChange; }
private void Reload() { PendingChange.RefreshContext rc = new PendingChange.RefreshContext(Context); Dictionary<string, bool> checkedCache = new Dictionary<string, bool>(StringComparer.OrdinalIgnoreCase); foreach (PendingCommitItem pci in pendingList.Items) { checkedCache[pci.FullPath] = pci.Checked; } pendingList.ClearItems(); foreach (SvnItem i in _allItems) { if (_filter != null && !_filter(i)) continue; PendingChange pc = new PendingChange(rc, i); PendingCommitItem pci = new PendingCommitItem(pendingList, pc); bool chk; if (checkedCache.TryGetValue(i.FullPath, out chk)) pci.Checked = chk; else if (_checkedFilter != null && !_checkedFilter(i)) pci.Checked = false; pendingList.Items.Add(pci); } }
public bool ShowChange(PendingChange pc) { if (files.Contains(pc.FullPath)) return true; if (!_mapper.ContainsPath(pc.FullPath)) { foreach (string f in folders) { if (pc.IsBelowPath(f)) { // Path is not contained in any other project but below one of the project roots return true; } } } return false; }