Ejemplo n.º 1
0
        public IEnumerable <HunkRangeInfo> GetDiffFor(ITextDocument textDocument, ITextSnapshot snapshot)
        {
            if (!CanGetDiff(textDocument.FilePath))
            {
                yield break;
            }

            var depotPath = GetPerforcePath(textDocument.FilePath, _connection.Client.Name);

            IList <FileDiff> target = null;

            try
            {
                // get diff using p4 diff
                GetDepotFileDiffsCmdOptions opts = new GetDepotFileDiffsCmdOptions(GetDepotFileDiffsCmdFlags.Unified, 0, 0, "", "", "");
                IList <FileSpec>            fsl  = new List <FileSpec>();
                FileSpec fs = new FileSpec(new DepotPath(depotPath));
                fsl.Add(fs);
                target = _repository.GetFileDiffs(fsl, opts);
                if (target == null)
                {
                    yield break;
                }
            }
            catch (P4Exception)
            {
                DisconnectImpl();
                yield break;
            }

            // TODO: implement comparison with yellow changes not "file on disk" vs "file in depot" but "file in RAM in VS" vs "file in depot"
            //var content = GetCompleteContent(textDocument, snapshot);
            //if (content == null) yield break;

            // TODO: after debugging remove the second and the third arguments from c'tor and next code, are they useless?
            var uniDiffParser  = new UnifiedFormatDiffParser(target[0].Diff, 0, false);
            var hunkRangeInfos = uniDiffParser.Parse();

            foreach (var hunkRangeInfo in hunkRangeInfos)
            {
                yield return(hunkRangeInfo);
            }
        }
Ejemplo n.º 2
0
        static IList <FileDiffs> GetFileDiffs(Repository rep, IList <Changelist> changelists, GetDepotFileDiffsCmdFlags flags = GetDepotFileDiffsCmdFlags.None)
        {
            List <FileDiffs> fileDiffs = new List <FileDiffs>(changelists.Count);

            foreach (Changelist cl in changelists)
            {
                foreach (FileMetaData f in cl.Files)
                {
                    FileSpec oldRev = new FileSpec(f.DepotPath, new Revision(f.HeadRev - 1));
                    FileSpec newRev = new FileSpec(f.DepotPath, new Revision(f.HeadRev));

                    GetDepotFileDiffsCmdOptions opts = new GetDepotFileDiffsCmdOptions(flags, 0, 0, null, null, null);
                    IList <DepotFileDiff>       diff = rep.GetDepotFileDiffs(oldRev.ToEscapedString(), newRev.ToEscapedString(), opts);

                    FileDiffs diffs = new FileDiffs(newRev.ToEscapedString(), cl.OwnerName, cl.Id, diff);
                    fileDiffs.Add(diffs);
                }
            }

            return(fileDiffs);
        }