Ejemplo n.º 1
0
        private static void appendOneRecord(ObjectId oldId, ObjectId newId, PersonIdent ident, String msg, Repository db, String refName)
        {
            if (ident == null)
                ident = new PersonIdent(db);
            else
                ident = new PersonIdent(ident);

            StringBuilder r = new StringBuilder();
            r.Append(ObjectId.ToString(oldId));
            r.Append(' ');
            r.Append(ObjectId.ToString(newId));
            r.Append(' ');
            r.Append(ident.ToExternalString());
            r.Append('\t');
            r.Append(msg);
            r.Append('\n');

            byte[] rec = Constants.encode(r.ToString());
            var logdir = new DirectoryInfo(db.Directory + "/" + Constants.LOGS);
            var reflog = new DirectoryInfo(logdir + "/" + refName);
            var refdir = reflog.Parent;

            refdir.Create();
            if (!refdir.Exists)
                throw new IOException("Cannot create directory " + refdir);

            using (var @out = new FileStream(reflog.FullName, System.IO.FileMode.OpenOrCreate, FileAccess.Write))
            {
                try
                {
                    @out.Write(rec, 0, rec.Length);
                }
                finally
                {
                    @out.Close();
                }
            }
        }
Ejemplo n.º 2
0
            public Entry(byte[] raw, int pos)
            {
                oldId = ObjectId.FromString(raw, pos);
                pos += Constants.OBJECT_ID_LENGTH*2;
                if (raw[pos++] != ' ')
                    throw new ArgumentException("Raw log message does not parse as log entry");
                newId = ObjectId.FromString(raw, pos);
                pos += Constants.OBJECT_ID_LENGTH * 2;
                if (raw[pos++] != ' ')
                    throw new ArgumentException("Raw log message does not parse as log entry");
                who = RawParseUtils.parsePersonIdentOnly(raw, pos);
                int p0 = RawParseUtils.next(raw, pos, (byte)'\t');

                if (p0 == -1)
                    throw new ArgumentException("Raw log message does not parse as log entry");

                int p1 = RawParseUtils.nextLF(raw, p0);
                if (p1 == -1)
                    throw new ArgumentException("Raw log message does not parse as log entry");

                comment = RawParseUtils.decode(raw, p0, p1 - 1);
            }
Ejemplo n.º 3
0
 private static string BuildReflogString(Repository repo, ObjectId oldCommit, ObjectId commit, string message)
 {
     PersonIdent me = new PersonIdent(repo);
     string initial = "";
     if (oldCommit == null)
     {
         oldCommit = ObjectId.ZeroId;
         initial = " (initial)";
     }
     string s = oldCommit.ToString() + " " + commit.ToString() + " "
             + me.ToExternalString() + "\t" + message + initial;
     return s;
 }
Ejemplo n.º 4
0
        private void Decode()
        {
            if (raw == null) return;

            using (var reader = new StreamReader(new MemoryStream(raw)))
            {
                string n = reader.ReadLine();
                if (n == null || !n.StartsWith("tree "))
                {
                    throw new CorruptObjectException(CommitId, "no tree");
                }
                while ((n = reader.ReadLine()) != null && n.StartsWith("parent "))
                {
                    // empty body
                }
                if (n == null || !n.StartsWith("author "))
                {
                    throw new CorruptObjectException(CommitId, "no author");
                }
                string rawAuthor = n.Substring("author ".Length);
                n = reader.ReadLine();
                if (n == null || !n.StartsWith("committer "))
                {
                    throw new CorruptObjectException(CommitId, "no committer");
                }
                string rawCommitter = n.Substring("committer ".Length);
                n = reader.ReadLine();

                if (n != null && n.StartsWith("encoding"))
                    Encoding = Encoding.GetEncoding(n.Substring("encoding ".Length));
                else if (n == null || !n.Equals(""))
                    throw new CorruptObjectException(CommitId, "malformed header:" + n);



#warning This does not currently support custom encodings
                //byte[] readBuf = new byte[br.available()]; // in-memory stream so this is all bytes left
                //br.Read(readBuf);
                //int msgstart = readBuf.Length != 0 ? (readBuf[0] == '\n' ? 1 : 0) : 0;

                if (Encoding != null)
                {
                    // TODO: this isn't reliable so we need to guess the encoding from the actual content
                    throw new NotSupportedException("Custom Encoding is not currently supported.");
                    //author = new PersonIdent(new string(this.Encoding.GetBytes(rawAuthor), this.Encoding));
                    //committer = new PersonIdent(new string(rawCommitter.getBytes(), encoding.name()));
                    //message = new string(readBuf, msgstart, readBuf.Length - msgstart, encoding.name());
                }
                else
                {
                    // TODO: use config setting / platform / ascii / iso-latin
                    author = new PersonIdent(rawAuthor);
                    committer = new PersonIdent(rawCommitter);
                    //message = new string(readBuf, msgstart, readBuf.Length - msgstart);
                    message = reader.ReadToEnd();
                }
            }


            raw = null;


        }
Ejemplo n.º 5
0
 public PersonIdent(PersonIdent pi, DateTimeOffset when)
 {
     this.Name = pi.Name;
     this.EmailAddress = pi.EmailAddress;
     this.when_time = when;
 }
Ejemplo n.º 6
0
 public PersonIdent(PersonIdent pi)
     : this(pi.Name, pi.EmailAddress)
 {
 }
Ejemplo n.º 7
0
 public PersonIdent(PersonIdent pi, long git_time, int offset_in_minutes)
 {
     this.Name = pi.Name;
     this.EmailAddress = pi.EmailAddress;
     this.when_time = git_time.GitTimeToDateTimeOffset((long)offset_in_minutes);
 }
Ejemplo n.º 8
0
        private static void AppendOneRecord(ObjectId oldId, ObjectId newId, PersonIdent ident, string msg, Repository db, string refName)
        {
            ident = ident == null ? new PersonIdent(db) : new PersonIdent(ident);

            var r = new StringBuilder();
            r.Append(ObjectId.ToString(oldId));
            r.Append(' ');
            r.Append(ObjectId.ToString(newId));
            r.Append(' ');
            r.Append(ident.ToExternalString());
            r.Append('\t');
            r.Append(msg);
            r.Append('\n');

            byte[] rec = Constants.encode(r.ToString());
            var logdir = new DirectoryInfo(Path.Combine(db.Directory.FullName, Constants.LOGS));
            var reflog = new DirectoryInfo(Path.Combine(logdir.FullName, refName));

            var refdir = reflog.Parent;

            if (!refdir.Exists && !refdir.Mkdirs())
            {
                throw new IOException("Cannot create directory " + refdir);
            }

            using (var @out = new FileStream(reflog.FullName, System.IO.FileMode.Append, FileAccess.Write))
            {
                @out.Write(rec, 0, rec.Length);
            }
        }
Ejemplo n.º 9
0
 public PersonIdent(PersonIdent pi, DateTime when)
     : this(pi.Name, pi.EmailAddress, when.ToUnixTime() * 1000, pi.tzOffset)
 {
 }
Ejemplo n.º 10
0
 public PersonIdent(PersonIdent pi, DateTime when, TimeZoneInfo tz)
     : this(pi.Name, pi.EmailAddress, when, tz)
 {
 }
Ejemplo n.º 11
0
 public PersonIdent(PersonIdent pi, long git_time, int offset_in_minutes)
     : this(pi.Name, pi.EmailAddress, git_time, offset_in_minutes)
 {
 }
Ejemplo n.º 12
0
        private void decode()
        {
            // FIXME: handle I/O errors
            if (raw == null) return;

            using (var br = new StreamReader(new MemoryStream(raw)))
            {
                string n = br.ReadLine();
                if (n == null || !n.StartsWith("object "))
                {
                    throw new CorruptObjectException(TagId, "no object");
                }
                Id = ObjectId.FromString(n.Substring(7));
                n = br.ReadLine();
                if (n == null || !n.StartsWith("type "))
                {
                    throw new CorruptObjectException(TagId, "no type");
                }
                TagType = n.Substring("type ".Length);
                n = br.ReadLine();

                if (n == null || !n.StartsWith("tag "))
                {
                    throw new CorruptObjectException(TagId, "no tag name");
                }
                TagName = n.Substring("tag ".Length);
                n = br.ReadLine();

                // We should see a "tagger" header here, but some repos have tags
                // without it.
                if (n == null)
                    throw new CorruptObjectException(TagId, "no tagger header");

                if (n.Length > 0)
                    if (n.StartsWith("tagger "))
                        Tagger = new PersonIdent(n.Substring("tagger ".Length));
                    else
                        throw new CorruptObjectException(TagId, "no tagger/bad header");

                // Message should start with an empty line, but
                StringBuilder tempMessage = new StringBuilder();
                char[] readBuf = new char[2048];
                int readLen;
                int readIndex = 0;
                while ((readLen = br.Read(readBuf, readIndex, readBuf.Length)) > 0)
                {
                    //readIndex += readLen;
                    tempMessage.Append(readBuf, 0, readLen);
                }
                message = tempMessage.ToString();
                if (message.StartsWith("\n"))
                    message = message.Substring(1);
            }

            raw = null;
        }