user2181871
user2181871

Reputation:

seek the changes of a file

i wish detect lines changed of the defferent versions of a file in perforce my problem is that when i tried to get the different versions of the file i get always the last version how can i proceed to get the different versions

String password = "*****";
String ws_client = "****";

        Repository rep;
        P4Server ps = new P4Server(conStr, user, password, ws_client);
        Server server = new Server(new ServerAddress(conStr));
        rep = new Repository(server);
        rep.Connection.UserName = user;
        Options options = new Options();

        Console.WriteLine(options.ToString());
        Client c = new Client();

        options["Password"] = password;
        rep.Connection.Client = new Client();
        rep.Connection.Connect(options);
        rep.Connection.Login(password, options);
        Console.WriteLine(rep.ToString());

      string text1="";
        string text2="";
        P4Command cmd = new P4Command(ps);
        string[]cmdargs= new string[1];
        cmdargs[0] = "";
        Console.WriteLine(cmd.ToString());
        Console.WriteLine(ps.ToString());
        Console.WriteLine(server.ToString());

        // *********************************************************************

        #region mrigla2 using filehistory class

        FileSpec filespecs = new FileSpec(FileSpec.DepotSpec("//obms/Dot-NET/Main/FixDepthSource/SLC_FDS/clsFixEventsSource.vb").DepotPath, Revision.Head);
        Options opt = new Options();
       opt.Add("-m", "");


        IList<FileHistory> filehistories = new List<FileHistory>();
        filehistories = rep.GetFileHistory(new Options(), filespecs);
        if (filehistories != null)
        {
            foreach (FileHistory fh in filehistories)
            {

                string p = fh.DepotPath.Path;

                string dpath = "//obms/Dot-NET/Main/FixDepthSource/SLC_FDS/clsFixEventsSource.vb";
                if (p==dpath)
                {
                    Console.WriteLine("Client name:" + fh.ClientName);
                    Console.WriteLine("Description:" + fh.Description);
                    Console.WriteLine("username:" + fh.UserName);
                    Console.WriteLine("Date:" + fh.Date);

                    Console.WriteLine("changelist:" + fh.ChangelistId);
                    directoriesfile.Filedirectory fsd = Program.getpaths(p, ps); 
                    Console.BackgroundColor = ConsoleColor.Red;
                    Console.WriteLine("******************revision:" + fh.Revision+"**********************");
                    if (fh.Revision == 6)
                    {  text1 = System.IO.File.ReadAllText(fsd.localPath); }

                    if (fh.Revision == 5)
                    {text2 = System.IO.File.ReadAllText(fsd.localPath); }

                    Console.BackgroundColor = ConsoleColor.Black;
                    affichcontentFile(fsd.depotPath, ps, fsd.localPath);
                    Console.WriteLine("Action:" + fh.Action);
                }





            }


        }

Upvotes: 2

Views: 731

Answers (2)

user2181871
user2181871

Reputation:

FileSpec fso = new FileSpec(FileSpec.DepotSpec(fsd.depotPath).DepotPath, Revision.Head);

IList<FileSpec> fsos = new List<FileSpec>();
fsos.Add(fso);

Options opts = new Options();
opts.Add("-a", "");

IList<FileAnnotation> fas = rep.GetFileAnnotations(fsos, opts);

foreach (FileAnnotation fa in fas)
{
    Console.BackgroundColor = ConsoleColor.Yellow;
    lines5+= fa.Line;
    Console.BackgroundColor = ConsoleColor.Black;
}

Upvotes: 1

Bryan Pendleton
Bryan Pendleton

Reputation: 16359

To get the history of the contents of a file, use 'p4 annotate'.

To get the history of a file (but not its contents), use 'p4 filelog'.

To get the differences between two specified versions of a file, use 'p4 diff2'.

Putting together 'p4 filelog' (to figure out which versions correspond to which changes) and 'p4 diff2' (to compute the differences between two versions) will get you much useful information.

Or do what I do: don't do any of these things, and install P4V, and use 'Time Lapse View'. It's a beautiful visual tool that makes exploring a file's history simple.

Upvotes: 1

Related Questions