public static IList <Changelist> GetCommits(Repository repo, string filePath, int count) { IList <Changelist> Changes = new List <Changelist>(); // first check cache var items = changelistCache; var lookup = items.ToLookup(kvp => kvp.Key, kvp => kvp.Value); foreach (Changelist change in lookup[filePath]) { Changes.Add(change); } if (Changes.Count > 0) { return(Changes); } try { ChangesCmdOptions opts = new ChangesCmdOptions(ChangesCmdFlags.FullDescription, null, 5, ChangeListStatus.Submitted, null); Changes = repo.GetChangelists(opts, new FileSpec(null, null, new LocalPath(filePath), null)); foreach (Changelist change in Changes) { changelistCache.Add(new KeyValuePair <string, Changelist>(filePath, change)); } } catch (Exception ex) { System.Windows.Forms.MessageBox.Show(ex.Message); } return(Changes); }
public int GetCurrentChangeList(Client client) { var opt = new ChangesCmdOptions(ChangesCmdFlags.None, client.Name, 1, ChangeListStatus.Submitted, this.Username); var ret = this.Repository.GetChangelists(opt); return(ret?.Count == 1 ? ret[0].Id : 0); }
public static Changelist GetLastCommit(Repository repo, string filePath) { IList <Changelist> Changes = new List <Changelist>(); // first check cache var items = changelistCache; var lookup = items.ToLookup(kvp => kvp.Key, kvp => kvp.Value); foreach (Changelist change in lookup[filePath]) { Changes.Add(change); } if (Changes.Count < 1) { try { ChangesCmdOptions opts = new ChangesCmdOptions(ChangesCmdFlags.FullDescription, null, 5, ChangeListStatus.Submitted, null); Changes = repo.GetChangelists(opts, new FileSpec(null, null, new LocalPath(GetSanitisedPath(filePath)), null)); } catch (P4Exception ex) { if (!(ex.ErrorCode == P4ClientError.MsgDb_NotUnderRoot)) { System.Windows.Forms.MessageBox.Show(ex.Message); } } } if (Changes == null || Changes.Count < 1) { return(null); } foreach (Changelist change in Changes) { var matches = from val in changelistCache where val.Key == filePath select val.Value as Changelist; Changelist c = matches.FirstOrDefault(ch => ch.Id == change.Id); if (c == null) { changelistCache.Add(new KeyValuePair <string, Changelist>(filePath, change)); } } return(Changes[0]); }
/// <summary> /// </summary> /// <returns></returns> public DateTime GetSyncTime() { if (ClientName == string.Empty) { return(DateTime.MinValue); } if (SyncTimeRequesting == false) { SyncTimeRequesting = true; ulong Current = TimeUtils.Ticks; ulong Elapsed = Current - LastRequestedSyncTime; if (Elapsed > SYNC_TIME_RECHECK_INTERVAL) { QueueAndAwaitCommand( Repo => { try { Logger.Log(LogLevel.Info, LogCategory.Scm, "Requesting sync time of perforce workspace: {0}", ClientName); ChangesCmdOptions Options = new ChangesCmdOptions(ChangesCmdFlags.IncludeTime, null, 1, ChangeListStatus.Submitted, null); FileSpec FilePath = new FileSpec(new DepotPath("//..."), VersionSpec.Have); IList <Changelist> Changes = Repo.GetChangelists(Options, FilePath); if (Changes.Count > 0) { SyncTime = Changes[0].ModifiedDate; Logger.Log(LogLevel.Info, LogCategory.Scm, "Workspace '{0}' last have changeset has timestamp {1}", ClientName, SyncTime.ToString()); } } finally { SyncTimeRequesting = false; } } ); } LastRequestedSyncTime = Current; } return(SyncTime); }
static IList <Changelist> GetNewChangelists(Repository rep, int maxItems = 5, string clientName = "", string userName = "") { string p4path = Environment.GetEnvironmentVariable("P4PATH"); ChangesCmdOptions options = new ChangesCmdOptions(ChangesCmdFlags.FullDescription | ChangesCmdFlags.IncludeTime, clientName, maxItems, ChangeListStatus.Submitted, userName); PathSpec path = new DepotPath(p4path); FileSpec depotFile = new FileSpec(path, null); IList <Changelist> recentChanges = rep.GetChangelists(options, depotFile); string[] recentIds = new string[maxItems]; int it = 0; foreach (var c in recentChanges) { recentIds[it] = c.Id.ToString(); ++it; } string idFilePath = "RecentIds.txt"; List <string> unsyncedIds = new List <string>(5); if (System.IO.File.Exists(idFilePath)) { string[] recentIdsFile = System.IO.File.ReadAllLines(idFilePath); int equalIndex = recentIds.Length; for (int i = 0; i < recentIds.Length; ++i) { for (int j = 0; j < recentIdsFile.Length; ++j) { if (Convert.ToInt32(recentIds[j]) > Convert.ToInt32(recentIdsFile[i])) { continue; } else if (Convert.ToInt32(recentIds[j]) == Convert.ToInt32(recentIdsFile[i])) { equalIndex = j; break; } else { Console.WriteLine("WARNING: Equal not found, changes possibly missed > Consider increasing maxItems"); } } if (equalIndex < recentIds.Length) { break; } } for (int i = 0; i < equalIndex; ++i) { unsyncedIds.Add(recentIds[i]); } } else { unsyncedIds.AddRange(recentIds); } List <Changelist> unsyncedLists = new List <Changelist>(unsyncedIds.Count); if (unsyncedIds.Count > 0) { System.IO.File.WriteAllLines(idFilePath, unsyncedIds); foreach (string id in unsyncedIds) { Changelist cl = rep.GetChangelist(Convert.ToInt32(id)); unsyncedLists.Add(cl); } unsyncedLists.Sort((x, y) => x.Id.CompareTo(y.Id)); } return(unsyncedLists); }
///A test for GetChangelistsjob097882 ///</summary> public void GetChangelistsTestjob097882(bool unicode) { string uri = "localhost:6666"; string user = "******"; string pass = string.Empty; string ws_client = "admin_space"; Process p4d = Utilities.DeployP4TestServer(TestDir, 13, unicode); Server server = new Server(new ServerAddress(uri)); try { Repository rep = new Repository(server); using (Connection con = rep.Connection) { con.UserName = user; con.Client = new Client(); con.Client.Name = ws_client; bool connected = con.Connect(null); Assert.IsTrue(connected); Assert.AreEqual(con.Status, ConnectionStatus.Connected); ChangesCmdOptions opts = new ChangesCmdOptions(ChangesCmdFlags.None, null, 0, ChangeListStatus.Submitted, null); FileSpec fs = new FileSpec(); fs.DepotPath = new DepotPath("//depot/..."); //// Creates and initializes a CultureInfo. This is to create //// a date with - as the seperator CultureInfo myCI = new CultureInfo("en-US", false); //// Clones myCI and modifies the DTFI and NFI instances associated with the clone. CultureInfo myCIclone = (CultureInfo)myCI.Clone(); myCIclone.DateTimeFormat.DateSeparator = "-"; System.Threading.Thread.CurrentThread.CurrentCulture = myCIclone; DateTime dts = new DateTime(2011, 5, 23, 1, 19, 17); DateTime dte = new DateTime(2011, 5, 25, 1, 19, 17); // confirm that the dates have dashes as seperators Assert.IsTrue(dts.ToString().Contains("5-23-2011")); Assert.IsTrue(dte.ToString().Contains("5-25-2011")); DateTimeVersion start = new DateTimeVersion(dts); DateTimeVersion end = new DateTimeVersion(dte); fs.Version = new VersionRange(start, end); IList <Changelist> changes = rep.GetChangelists(opts, fs); Assert.AreEqual(changes.Count, 4); } } finally { Utilities.RemoveTestServer(p4d, TestDir); } }
///A test for GetChangelistsjob094473 ///</summary> public void GetChangelistsTestjob094473(bool unicode) { string uri = "localhost:6666"; string user = "******"; string pass = string.Empty; string ws_client = "admin_space"; Process p4d = Utilities.DeployP4TestServer(TestDir, 13, unicode); Server server = new Server(new ServerAddress(uri)); try { Repository rep = new Repository(server); using (Connection con = rep.Connection) { con.UserName = user; con.Client = new Client(); con.Client.Name = ws_client; bool connected = con.Connect(null); Assert.IsTrue(connected); Assert.AreEqual(con.Status, ConnectionStatus.Connected); ChangesCmdOptions opts = new ChangesCmdOptions(ChangesCmdFlags.None, null, 0, ChangeListStatus.Submitted, null); IList <Changelist> changes = rep.GetChangelists(opts, null); // ascii 122 unicode 126 Assert.IsNotNull(changes); if (unicode) { Assert.AreEqual(126, changes.Count); } else { Assert.AreEqual(122, changes.Count); } // only get changes @ or above 100 opts = new ChangesCmdOptions(ChangesCmdFlags.None, null, 0, ChangeListStatus.Submitted, null, 100); // ascii 39 (151->100) unicode 51 (150->100) changes = rep.GetChangelists(opts, null); Assert.IsNotNull(changes); if (unicode) { Assert.AreEqual(51, changes.Count); Assert.AreEqual(150, changes[0].Id); } else { Assert.AreEqual(39, changes.Count); Assert.AreEqual(151, changes[0].Id); } // only get changes @ or above 100 and reverse the order opts = new ChangesCmdOptions(ChangesCmdFlags.ReverseOrder, null, 0, ChangeListStatus.Submitted, null, 100); // ascii 39 (100->151) unicode 51 (100->150) changes = rep.GetChangelists(opts, null); Assert.IsNotNull(changes); if (unicode) { Assert.AreEqual(51, changes.Count); Assert.AreEqual(100, changes[0].Id); } else { Assert.AreEqual(39, changes.Count); Assert.AreEqual(100, changes[0].Id); } } } finally { Utilities.RemoveTestServer(p4d, TestDir); } }