Ejemplo n.º 1
0
 protected HgNodeID GetRevlogEntryDataNodeID(HgRevlogEntryData revlogEntryData)
 {
     return GetRevlogEntryDataNodeID(
         revlogEntryData.Entry.FirstParentRevisionNodeID,
         revlogEntryData.Entry.SecondParentRevisionNodeID,
         revlogEntryData.Data);
 }
 public HgChangeset ReadChangeset(HgRevlogEntryData revlogEntryData)
 {
     try
     {
         return ReadChangesetInternal(revlogEntryData);
     }
     catch(Exception e)
     {
         throw;
     }
 }
        private HgChangeset ReadChangesetInternal(HgRevlogEntryData revlogEntryData)
        {
            var filesStart = revlogEntryData.Data.IndexOfNth((byte)'\n', 3);
            var filesEnd = revlogEntryData.Data.IndexOf((byte)'\n', (byte)'\n');

            var headerString = hgEncoder.DecodeAsUtf8(revlogEntryData.Data, 0, filesStart);
            
            var filesString = 
                filesStart == filesEnd ? 
                    "" :
                    hgEncoder.DecodeAsLocal(
                        revlogEntryData.Data, 
                        filesStart + 1, // The \n 
                        filesEnd - filesStart - 1);
            
            var commentString = hgEncoder.DecodeAsUtf8(
                revlogEntryData.Data, 
                filesEnd + 2, // These \n\n bytes 
                revlogEntryData.Data.Length - filesEnd - 2);

            var header = headerString.Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);

            var manifestNodeID = new HgNodeID(header[0]);
            var committedBy = HgAuthor.Parse(header[1]);

            var timeParts = header[2].Split(' ');
            var time = int.Parse(timeParts[0]);
            var timeZone = int.Parse(timeParts[1]);

            var branchData = header[2].SubstringAfterNth(" ", 1).Or("branch:default");

            var b = branchData.Split('\0').Select(s => new { key = s.Split(':')[0], value = s.Split(':')[1] }).ToDictionary(s => s.key, s => s.value).DefaultableWith(v => "");
            var branchName = new HgBranch(b["branch"].Or("default"), b["close"] == "1");
            var sourceNodeID = new HgNodeID(b["source"].Or(HgNodeID.Null.Long));
            
            var dateTime = DateTime.SpecifyKind(new DateTime(1970, 1, 1).AddSeconds(time).AddSeconds(-1 * timeZone), DateTimeKind.Local);
            var committedAt = new DateTimeOffset(dateTime);

            var files = filesString.Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);
            
            var metadata = GetRevlogEntryMetadata(revlogEntryData.Entry);

            return new HgChangeset(metadata, manifestNodeID, committedBy, committedAt, branchName, sourceNodeID, files, commentString);
        }
        private HgRevlogEntryData GetRevlogEntryData(HgRevlogEntryData revlogEntryData)
        {
            var data = revlogEntryData.Data;

            HgFileCopyInfo.ExtractFileCopyInfo(ref data);

            //
            // Apparently, entries in standins end with \n, so we explicitly limit to 40 bytes
            HgNodeID nodeID;
            if(HgNodeID.TryParse(Encoding.ASCII.GetString(data, 0, 40), out nodeID))
            {
                var lfPath = Path.Combine(storeBasePath, @"..\largefiles", nodeID.Long);
                if(File.Exists(lfPath))
                {
                    data = File.ReadAllBytes(lfPath);
                    revlogEntryData = new HgRevlogEntryData(revlogEntryData.Entry, data);
                } // if
            } // if

            return revlogEntryData;
        }
Ejemplo n.º 5
0
        public HgManifestEntry ReadManifestEntry(HgRevlogEntryData revlogEntryData)
        {
            var data = revlogEntryData.Data;
            var lines = data.Split((byte)'\n');
            
            var files = new List<HgManifestFileEntry>(lines.Length);

            foreach(var line in lines)
            {
                var z = Array.IndexOf(data, (byte)0, line.Offset) - line.Offset;

                var path = hgEncoder.DecodeAsLocal(data, line.Offset, z);
                var nodeID = Encoding.ASCII.GetString(data, line.Offset + z + 1, line.Length - z - 2);
                if(nodeID.Length > 40)
                    nodeID = nodeID.Substring(0, 40);

                files.Add(new HgManifestFileEntry(GetManifestEntryPath(path), new HgNodeID(nodeID)));
            } // foreach

            return new HgManifestEntry(GetRevlogEntryMetadata(revlogEntryData.Entry), files);
        }