Example #1
0
        public void OtherOpenUserClientsTest()
        {
            DepotPath                   movedfile            = new DepotPath("//depot/main/movedfile");
            bool                        ismapped             = true;
            bool                        shelved              = true;
            FileAction                  headaction           = new FileAction();
            int                         headchange           = 0;
            int                         headrev              = 0;
            FileType                    headtype             = null;
            DateTime                    headtime             = new DateTime();
            DateTime                    headmodtime          = new DateTime();
            int                         movedrev             = 0;
            int                         haverev              = 0;
            string                      desc                 = "";
            string                      digest               = "";
            int                         filesize             = 0;
            FileAction                  action               = FileAction.Abandoned;
            FileType                    type                 = null;
            string                      actionowner          = "";
            int                         change               = 0;
            bool                        resolved             = true;
            bool                        unresolved           = true;
            bool                        reresolvable         = true;
            int                         otheropen            = -1;
            List <string>               otheropenuserclients = new List <string>();
            string                      Open1                = "user1@client1";
            string                      Open2                = "user2@client2";
            bool                        otherlock            = true;
            List <string>               otherlockuserclients = null;
            List <FileAction>           otheractions         = null;
            List <int>                  otherchanges         = null;
            bool                        ourlock              = true;
            List <FileResolveAction>    resolverecords       = null;
            Dictionary <String, Object> attributes           = null;
            Dictionary <String, Object> attributedigests     = null;

            FileMetaData target = new FileMetaData
                                      (movedfile, ismapped, shelved,
                                      headaction, headchange, headrev, headtype,
                                      headtime, headmodtime, movedrev, haverev,
                                      desc, digest, filesize, action, type,
                                      actionowner, change, resolved, unresolved,
                                      reresolvable, otheropen, otheropenuserclients,
                                      otherlock, otherlockuserclients, otheractions,
                                      otherchanges, ourlock, resolverecords, attributes,
                                      attributedigests, null, null, null, -1, null
                                      );

            List <string> expected = otheropenuserclients;

            target.OtherOpenUserClients.Add(Open1);
            target.OtherOpenUserClients.Add(Open2);
            Assert.AreEqual(Open1, target.OtherOpenUserClients[0]);
            Assert.AreEqual(Open2, target.OtherOpenUserClients[1]);
            IList <string> actual;

            target.OtherOpenUserClients = expected;
            actual = target.OtherOpenUserClients;
            Assert.AreEqual(expected, actual);
        }
        internal static void CopyFile(Repository p4Repo, string copyToLocation, string sourceFile)
        {
            GetFileContentsCmdOptions fileContentsOptions = new GetFileContentsCmdOptions(GetFileContentsCmdFlags.Suppress, copyToLocation);
            var depotObj = new DepotPath(sourceFile);

            p4Repo.GetFileContents(fileContentsOptions, new FileSpec(depotObj, null));
        }
Example #3
0
        public void EqualsTest()
        {
            PathSpec left      = new DepotPath("//depot/main/test.txt");
            PathSpec rightpos  = new DepotPath("//depot/main/test.txt");
            PathSpec rightneg1 = new DepotPath("//depot/main/empty.bmp");
            PathSpec rightneg2 = new ClientPath("//depot/main/test/txt");
            PathSpec rightnull = null;

            Assert.IsTrue(left.Equals(rightpos));
            Assert.IsFalse(left.Equals(rightneg1));
            Assert.IsFalse(left.Equals(rightneg2));
            Assert.IsFalse(left.Equals(rightnull));

            left      = new ClientPath("//user_workspace/main/test.txt");
            rightpos  = new ClientPath("//user_workspace/main/test.txt");
            rightneg1 = new ClientPath("//user_workspace/main/empty.bmp");
            rightneg2 = new DepotPath("//user_workspace/main/test.txt");
            rightnull = null;

            Assert.IsTrue(left.Equals(rightpos));
            Assert.IsFalse(left.Equals(rightneg1));
            Assert.IsFalse(left.Equals(rightneg2));
            Assert.IsFalse(left.Equals(rightnull));

            left      = new LocalPath(@"C:\workspace_root\test.txt");
            rightpos  = new LocalPath(@"C:\workspace_root\test.txt");
            rightneg1 = new LocalPath(@"C:\workspace_root\empty.bmp");
            rightneg2 = new DepotPath(@"C:\workspace_root\test.txt");
            rightnull = null;

            Assert.IsTrue(left.Equals(rightpos));
            Assert.IsFalse(left.Equals(rightneg1));
            Assert.IsFalse(left.Equals(rightneg2));
            Assert.IsFalse(left.Equals(rightnull));
        }
Example #4
0
        public void ToEscapedStringTest()
        {
            string    expected = "0";
            DepotPath dp       = new DepotPath(expected);
            FileSpec  target   = new FileSpec(dp);
            string    actual;

            actual = target.ToEscapedString();
            Assert.AreEqual(expected, actual);
        }
Example #5
0
        public void MovedFileTest()
        {
            DepotPath expected = new DepotPath("//depot/main/file2");

            setTarget();
            Assert.AreEqual(target.MovedFile, new DepotPath("//depot/main/movedfile"));
            target.MovedFile = expected;
            DepotPath actual = target.MovedFile;

            Assert.AreEqual(expected, actual);
        }
Example #6
0
        public void ToStringTest2()
        {
            Type      pathType = typeof(DepotPath);        // TODO: Initialize to an appropriate value
            string    expected = "0";
            DepotPath dp       = new DepotPath(expected);
            FileSpec  target   = new FileSpec(dp);
            string    actual;

            actual = target.ToString(pathType);
            Assert.AreEqual(expected, actual);
        }
Example #7
0
        public void VersionTest()
        {
            DepotPath   path     = new DepotPath("c:\foobarversion");
            VersionSpec version  = new VersionRange(new LabelNameVersion("my_label"), new LabelNameVersion("my_old_label"));
            FileSpec    target   = new FileSpec(path, version);
            DepotPath   expected = path;           //
            PathSpec    actual;

            target.DepotPath = expected;
            actual           = target.DepotPath;
            Assert.AreEqual(expected, actual);
        }
Example #8
0
        public void ParentTest()
        {
            PathSpec expected = new DepotPath("//Wrong/main");

            setTarget();
            Assert.AreEqual(target.Parent, new DepotPath("//projectX/main"));
            target.Parent = expected;
            PathSpec actual;

            actual = target.Parent;
            Assert.AreEqual(expected, actual);
        }
Example #9
0
        public void ToEscapedPathsTest()
        {
            string expected0 = "0";

            FileSpec[] list = new FileSpec[1];
            list[0] = new DepotPath(expected0);
            string[] expected = new string[1];
            expected[0] = expected0;

            string[] actual;
            actual = FileSpec.ToEscapedPaths(list);
            Assert.AreEqual(expected[0], actual[0]);
        }
Example #10
0
        public void FileConstructorTest()
        {
            DepotPath  path       = new DepotPath("//depot/main/photo.jpg");
            Revision   rev        = new Revision(4);
            int        change     = 4444;
            FileAction action     = FileAction.Branch;
            FileType   type       = new FileType("binary");
            DateTime   submittime = new DateTime(2011, 04, 15);
            File       target     = new File(path, null, rev, null, change, action, type, submittime, null, null);
            File       expected   = new File();

            expected.DepotPath = new DepotPath("//depot/main/photo.jpg");
            Assert.AreEqual(expected.DepotPath, target.DepotPath);
        }
Example #11
0
        public void ParseFilesCmdTaggedDataTest()
        {
            DepotPath  path       = new DepotPath("//depot/main/photo.jpg");
            Revision   rev        = new Revision(4);
            Revision   hasrev     = new Revision(3);
            int        change     = 4444;
            FileAction action     = FileAction.Branch;
            FileType   type       = new FileType("binary");
            DateTime   submittime = new DateTime(2011, 04, 15);
            File       expected   = new File(path, null, rev, hasrev, change, action, type, submittime, null, null);

            TaggedObject obj = new TaggedObject();

            File actual = new File();

            actual.ParseFilesCmdTaggedData(obj); // no data but shouldn't throw

            obj["depotFile"] = "//depot/main/photo.jpg";
            obj["rev"]       = "4";
            obj["haveRev"]   = "3";
            obj["change"]    = "4444";
            obj["action"]    = action.ToString();
            obj["type"]      = type.ToString();
            DateTime t      = new DateTime(2011, 4, 15, 0, 0, 0, 0);
            DateTime utBase = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
            TimeSpan utDiff = t - utBase;
            long     ut     = (long)utDiff.TotalSeconds;

            obj["time"] = ut.ToString();

            actual.ParseFilesCmdTaggedData(obj); // no data but shouldn't throw

            Assert.AreEqual(expected.DepotPath, actual.DepotPath);
            Assert.AreEqual(expected.Version, actual.Version);
            Assert.AreEqual(expected.HaveRev, actual.HaveRev);
            Assert.AreEqual(expected.ChangeId, actual.ChangeId);
            Assert.AreEqual(expected.Action, actual.Action);
            Assert.AreEqual(expected.Type, actual.Type);
            Assert.AreEqual(expected.SubmitTime, actual.SubmitTime);
        }
Example #12
0
        public void DepotPathTest()
        {
            int        revision     = 0;                // TODO: Initialize to an appropriate value
            int        changelistid = 0;                // TODO: Initialize to an appropriate value
            FileAction action       = new FileAction(); // TODO: Initialize to an appropriate value
            DateTime   date         = new DateTime();   // TODO: Initialize to an appropriate value
            string     username     = string.Empty;     // TODO: Initialize to an appropriate value
            FileType   filetype     = null;             // TODO: Initialize to an appropriate value
            string     description  = string.Empty;     // TODO: Initialize to an appropriate value
            string     digest       = string.Empty;
            int        filesize     = 0;
            PathSpec   depotpath    = new DepotPath("//...");
            string     clientname   = string.Empty;                                                                                                                                       // TODO: Initialize to an appropriate value
            List <RevisionIntegrationSummary> integrationsummaries = null;                                                                                                                // TODO: Initialize to an appropriate value
            FileHistory target   = new FileHistory(revision, changelistid, action, date, username, filetype, description, digest, filesize, depotpath, clientname, integrationsummaries); // TODO: Initialize to an appropriate value
            PathSpec    expected = depotpath;
            PathSpec    actual;

            target.DepotPath = expected;
            actual           = target.DepotPath;
            Assert.AreEqual(expected, actual);
        }
Example #13
0
        private IList <Changelist> GetChangesAfter(int previous, int current)
        {
            if (current <= previous)
            {
                return(null);
            }

            string depotPath = mSolutionPath.Text;

            if (mSolutionPath.Text.EndsWith(".sln"))
            {
                depotPath = mSolutionPath.Text.Substring(0, mSolutionPath.Text.LastIndexOf('/'));
            }

            FileSpec fs   = new DepotPath(depotPath);
            Options  opts = new Options();

            opts["-m"] = (current - previous).ToString();
            IList <Changelist> changes = rep.GetChangelists(opts, fs);

            return(changes);
        }
        /// <summary>
        /// Get the FileSpec for a depot file given a changelist
        /// </summary>
        /// <param name="depotFileName">The file name in current depot location</param>
        /// <param name="changelist">The language file's changelist to be used to find an older version of the int file</param>
        /// <param name="checkForRenameMove">Check if the file has changed names due to a move/rename</param>
        /// <returns>FileSpec which may have a different depotfilename than that passed into function if the file has been moved since changelist</returns>
        private FileSpec GetIntFileSpecForFileChangelist(string depotFileName, int changelist, bool checkForRenameMove)
        {
            if (!CheckConnect())
            {
                return null;
            }

            if (checkForRenameMove)
            {
                PathSpec HistoryPathSpec = new DepotPath(depotFileName) as PathSpec;

                FileSpec[] HistoryFiles = new FileSpec[1];
                HistoryFiles[0] = new FileSpec(HistoryPathSpec, VersionSpec.Head);

                Options Opts = new Options();
                Opts.Add("-i", "");
                IList<FileHistory> History = P4Repository.GetFileHistory(Opts, HistoryFiles);

                // walk through history until we find the first changelist older than the specified changelist
                foreach (FileHistory Item in History)
                {
                    if (Item.ChangelistId > changelist)
                    {
                        continue;
                    }

                    // use the depot filename at this revision
                    HistoryPathSpec = Item.DepotPath;
                    break;
                }

                return new FileSpec(HistoryPathSpec, new ChangelistIdVersion(changelist));
            }
            else
            {
                return new FileSpec(new DepotPath(depotFileName) as PathSpec, new ChangelistIdVersion(changelist));
            }
        }
Example #15
0
        private IList<Changelist> GetChangesAfter(int previous, int current)
        {
            if (current <= previous)
                return null;

            string depotPath = mSolutionPath.Text;
            if (mSolutionPath.Text.EndsWith(".sln"))
            {
                depotPath = mSolutionPath.Text.Substring(0, mSolutionPath.Text.LastIndexOf('/'));
            }

            FileSpec fs = new DepotPath(depotPath);
            Options opts = new Options();
            opts["-m"] = (current - previous).ToString();
            IList<Changelist> changes = rep.GetChangelists(opts, fs);

            return changes;
        }
Example #16
0
        public void ResolveRecordsTest()
        {
            DepotPath                movedfile            = new DepotPath("//depot/main/movedfile");
            bool                     ismapped             = true;
            bool                     shelved              = true;
            FileAction               headaction           = new FileAction();
            int                      headchange           = 0;
            int                      headrev              = 0;
            FileType                 headtype             = null;
            DateTime                 headtime             = new DateTime();
            DateTime                 headmodtime          = new DateTime();
            int                      movedrev             = 0;
            int                      haverev              = 0;
            string                   desc                 = "";
            string                   digest               = "";
            int                      filesize             = 0;
            FileAction               action               = FileAction.Abandoned;
            FileType                 type                 = null;
            string                   actionowner          = "";
            int                      change               = 0;
            bool                     resolved             = true;
            bool                     unresolved           = true;
            bool                     reresolvable         = true;
            int                      otheropen            = -1;
            List <string>            otheropenuserclients = null;
            bool                     otherlock            = true;
            List <string>            otherlockuserclients = null;
            List <FileAction>        otheractions         = null;
            List <int>               otherchanges         = null;
            bool                     ourlock              = true;
            List <FileResolveAction> resolverecords       = new List <FileResolveAction>();

            FileResolveAction Rec1 = new FileResolveAction
                                         (ResolveAction.Ignored, new FileSpec(new DepotPath("main/file1"), new Revision(1)),
                                         new FileSpec(new DepotPath("dev/file1"), new Revision(1)), 24, 48);

            FileResolveAction Rec2 = new FileResolveAction
                                         (ResolveAction.CopyFrom, new FileSpec(new DepotPath("rel1/file3"), new Revision(3)),
                                         new FileSpec(new DepotPath("main/file3"), new Revision(2)), 24, 48);

            Dictionary <String, Object> attributes       = null;
            Dictionary <String, Object> attributedigests = null;

            FileMetaData target = new FileMetaData
                                      (movedfile, ismapped, shelved,
                                      headaction, headchange, headrev, headtype,
                                      headtime, headmodtime, movedrev, haverev,
                                      desc, digest, filesize, action, type,
                                      actionowner, change, resolved, unresolved,
                                      reresolvable, otheropen, otheropenuserclients,
                                      otherlock, otherlockuserclients, otheractions,
                                      otherchanges, ourlock, resolverecords, attributes,
                                      attributedigests, null, null, null, -1, null
                                      );
            List <FileResolveAction> expected = resolverecords;

            target.ResolveRecords.Add(Rec1);
            target.ResolveRecords.Add(Rec2);
            Assert.AreEqual(Rec1, target.ResolveRecords[0]);
            Assert.AreEqual(Rec2, target.ResolveRecords[1]);
            IList <FileResolveAction> actual;

            target.ResolveRecords = expected;
            actual = target.ResolveRecords;
            Assert.AreEqual(expected, actual);
        }
Example #17
0
        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);
        }