コード例 #1
0
 ///	<summary> * The constructor from object identifier
 ///	</summary>
 ///	<param name="base">the base configuration file </param>
 ///	<param name="r">the repository</param>
 /// <param name="objectid">the object identifier</param>
 /// <exception cref="IOException">
 /// the blob cannot be read from the repository. </exception>
 /// <exception cref="ConfigInvalidException">
 /// the blob is not a valid configuration format.
 /// </exception> 
 public BlobBasedConfig(Config @base, Repository r, ObjectId objectid)
     : base(@base)
 {
     ObjectLoader loader = r.OpenBlob(objectid);
     if (loader == null)
     {
         throw new IOException("Blob not found: " + objectid);
     }
     fromText(RawParseUtils.decode(loader.Bytes));
 }
コード例 #2
0
ファイル: Codec.cs プロジェクト: HackerBaloo/GitSharp
        public static ObjectType DecodeTypeString(ObjectId id, byte[] typeString, byte endMark, ref int offset)
        {
            try
            {
                switch (typeString[offset])
                {
                    case (byte)'b':
                        if (typeString[offset + 1] != (byte)'l' ||
                        typeString[offset + 2] != (byte)'o' ||
                        typeString[offset + 3] != (byte)'b' ||
                        typeString[offset + 4] != endMark) break;
                        offset += 5;
                        return ObjectType.Blob;

                    case (byte)'c':
                        if (typeString[offset + 1] != (byte)'o' || typeString[offset + 2] != (byte)'m' ||
                        typeString[offset + 3] != (byte)'m' || typeString[offset + 4] != (byte)'i' ||
                        typeString[offset + 5] != (byte)'t' || typeString[offset + 6] != endMark) break;
                        offset += 7;
                        return ObjectType.Commit;

                    case (byte)'t':
                        switch (typeString[offset + 1])
                        {
                            case (byte)'a':
                                if (typeString[offset + 2] != (byte)'g' || typeString[offset + 2] != endMark)
                                {
                                    throw new CorruptObjectException(id, "invalid type");
                                }
                                offset += 4;
                                return ObjectType.Tag;

                            case (byte)'r':
                                if (typeString[offset + 2] != (byte)'e' || typeString[offset + 3] != (byte)'e' || typeString[offset + 4] != endMark)
                                {
                                    throw new CorruptObjectException(id, "invalid type");
                                }
                                offset += 5;
                                return ObjectType.Tree;

                        }
                        break;
                }
            }
            catch (IndexOutOfRangeException)
            {
            }
            throw new CorruptObjectException(id, "invalid type");
        }
コード例 #3
0
ファイル: Tag.cs プロジェクト: gilran/GitSharp
 /**
  * Construct a Tag representing an existing with a known name referencing an known object.
  * This could be either a simple or annotated tag.
  *
  * @param db {@link Repository}
  * @param id target id.
  * @param refName tag name or null
  * @param raw data of an annotated tag.
  */
 public Tag(Repository db, ObjectId id, string refName, byte[] raw)
 {
     Repository = db;
     if (raw != null)
     {
         TagId = id;
         Id = ObjectId.FromString(raw, 7);
     }
     else
         Id = id;
     if (refName != null && refName.StartsWith("refs/tags/"))
         refName = refName.Substring(10);
     TagName = refName;
     this.raw = raw;
 }
コード例 #4
0
ファイル: RefLogWriter.cs プロジェクト: stephensong/GitSharp
        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();
                }
            }
        }
コード例 #5
0
ファイル: RefLogWriter.cs プロジェクト: ArildF/GitSharp
        /**
         * Writes reflog entry for ref specified by refName
         *
         * @param repo
         *            repository to use
         * @param oldCommit
         *            previous commit
         * @param commit
         *            new commit
         * @param message
         *            reflog message
         * @param refName
         *            full ref name
         */
        public static void WriteReflog(Repository repo, ObjectId oldCommit, ObjectId commit, string message, string refName)
        {
            string entry = BuildReflogString(repo, oldCommit, commit, message);

            DirectoryInfo directory = repo.Directory;

            FileInfo reflogfile = PathUtil.CombineFilePath(directory, "logs/" + refName);
            DirectoryInfo reflogdir = reflogfile.Directory;
            if (!reflogdir.Exists)
            {
                try
                {
                    reflogdir.Create();
                }
                catch (Exception)
                {
                    throw new IOException("Cannot create directory " + reflogdir);
                }
            }
            StreamWriter writer = new StreamWriter(reflogfile.OpenWrite());
            writer.WriteLine(entry);
            writer.Close();
        }
コード例 #6
0
ファイル: Repository.cs プロジェクト: gilran/GitSharp
 /**
  * @param id
  *            SHA'1 of a tree
  * @return an {@link ObjectLoader} for accessing the data of a named tree
  * @
  */
 public ObjectLoader OpenTree(ObjectId id)
 {
     return OpenObject(id);
 }
コード例 #7
0
ファイル: Repository.cs プロジェクト: gilran/GitSharp
 /**
  * Access a Commit by SHA'1 id.
  * @param id
  * @return Commit or null
  * @ for I/O error or unexpected object type.
  */
 public Commit MapCommit(ObjectId id)
 {
     ObjectLoader or = OpenObject(id);
     if (or == null)
         return null;
     byte[] raw = or.getBytes();
     if (Constants.OBJ_COMMIT == or.getType())
         return new Commit(this, id, raw);
     throw new IncorrectObjectTypeException(id, ObjectType.Commit);
 }
コード例 #8
0
ファイル: Repository.cs プロジェクト: gilran/GitSharp
 public Commit OpenCommit(ObjectId id)
 {
     return MapCommit(id);
 }
コード例 #9
0
ファイル: Repository.cs プロジェクト: gilran/GitSharp
        //private void OpenObjectInAllPacks(AnyObjectId objectId, ICollection<PackedObjectLoader> resultLoaders, WindowCursor cursor)
        //{
        //    foreach (PackFile pack in _packs)
        //    {
        //        PackedObjectLoader loader = pack.Get(cursor, objectId);
        //        if (loader != null)
        //            resultLoaders.Add(loader);
        //    }
        //}


        /**
         * @param id
         *            SHA'1 of a blob
         * @return an {@link ObjectLoader} for accessing the data of a named blob
         * @
         */
        public ObjectLoader OpenBlob(ObjectId id)
        {
            return OpenObject(id);
        }
コード例 #10
0
ファイル: Repository.cs プロジェクト: gilran/GitSharp
 private Tree MakeTree(ObjectId id, byte[] raw)
 {
     return new Tree(this, id, raw);
 }
コード例 #11
0
 public DeltaRefPackedObjectLoader(PackFile pr, long dataOffset, long objectOffset, int deltaSz, ObjectId @base)
     : base(pr, dataOffset, objectOffset, deltaSz)
 {
     deltaBase = @base;
 }
コード例 #12
0
ファイル: RefLogWriter.cs プロジェクト: ArildF/GitSharp
 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;
 }
コード例 #13
0
ファイル: Repository.cs プロジェクト: gilran/GitSharp
 /**
  * Access a Tree by SHA'1 id.
  * @param id
  * @return Tree or null
  * @ for I/O error or unexpected object type.
  */
 public Tree MapTree(ObjectId id)
 {
     ObjectLoader or = OpenObject(id);
     if (or == null)
         return null;
     byte[] raw = or.getBytes();
     switch (((ObjectType)or.getType()))
     {
         case ObjectType.Tree:
             return new Tree(this, id, raw);
         case ObjectType.Commit:
             return MapTree(ObjectId.FromString(raw, 5));
     }
     throw new IncorrectObjectTypeException(id, ObjectType.Tree);
 }
コード例 #14
0
ファイル: RefDatabase.cs プロジェクト: Squelch/GitSharp
 internal void Stored(string origName, string name, ObjectId id, DateTime time)
 {
     lock (this)
     {
         _looseRefs[name] = new Ref(Ref.Storage.Loose, origName, name, id);
         _looseRefsMTime[name] = time;
         SetModified();
     }
     Repository.fireRefsMaybeChanged();
 }
コード例 #15
0
ファイル: RefDatabase.cs プロジェクト: Squelch/GitSharp
 public CachedRef(Storage st, string refName, ObjectId id, DateTime mtime)
     : base(st, refName, id)
 {
     LastModified = mtime;
 }
コード例 #16
0
ファイル: Repository.cs プロジェクト: drothmaler/GitSharp
        /// <summary>
        /// Access any type of Git object by id and
        /// </summary>
        /// <param name="id">SHA-1 of object to read</param>
        /// <param name="refName">optional, only relevant for simple tags</param>
        /// <returns>The Git object if found or null</returns>
        public object MapObject(ObjectId id, string refName)
        {
            ObjectLoader or = OpenObject(id);

            if (or == null)
            {
                return null;
            }

            byte[] raw = or.Bytes;
            switch ((ObjectType)(or.Type))
            {
                case ObjectType.Tree:
                    return MakeTree(id, raw);

                case ObjectType.Commit:
                    return MakeCommit(id, raw);

                case ObjectType.Tag:
                    return MakeTag(id, refName, raw);

                case ObjectType.Blob:
                    return raw;

                default:
                    throw new IncorrectObjectTypeException(id,
                        "COMMIT nor TREE nor BLOB nor TAG");
            }
        }
コード例 #17
0
ファイル: Commit.cs プロジェクト: gilran/GitSharp
 /**
  * Create a commit object with the specified id and data from and existing
  * commit object in a repository.
  *
  * @param db
  *            The repository to which this commit object belongs
  * @param id
  *            Commit id
  * @param raw
  *            Raw commit object data
  */
 public Commit(Repository db, ObjectId id, byte[] raw)
 {
     Repository = db;
     CommitId = id;
     treeId = ObjectId.FromString(raw, 5);
     ParentIds = new ObjectId[1];
     int np = 0;
     int rawPtr = 46;
     while (true)
     {
         if (raw[rawPtr] != 'p')
             break;
         switch (np)
         {
             case 0:
                 ParentIds[np++] = ObjectId.FromString(raw, rawPtr + 7);
                 break;
             case 1:
                 ParentIds = new[] { ParentIds[0], ObjectId.FromString(raw, rawPtr + 7) };
                 np++;
                 break;
             default:
                 if (ParentIds.Length <= np)
                 {
                     ObjectId[] old = ParentIds;
                     ParentIds = new ObjectId[ParentIds.Length + 32];
                     for (int i = 0; i < np; ++i)
                         ParentIds[i] = old[i];
                 }
                 ParentIds[np++] = ObjectId.FromString(raw, rawPtr + 7);
                 break;
         }
         rawPtr += 48;
     }
     if (np != ParentIds.Length)
     {
         ObjectId[] old = ParentIds;
         ParentIds = new ObjectId[np];
         for (int i = 0; i < np; ++i)
             ParentIds[i] = old[i];
     }
     else
         if (np == 0)
             ParentIds = new ObjectId[0];
     this.raw = raw;
 }
コード例 #18
0
ファイル: Commit.cs プロジェクト: gilran/GitSharp
 /**
  * Create a commit associated with these parents and associate it with a
  * repository.
  *
  * @param db
  *            The repository to which this commit object belongs
  * @param parentIds
  *            Id's of the parent(s)
  */
 public Commit(Repository db, ObjectId[] parentIds)
 {
     Repository = db;
     ParentIds = parentIds;
 }
コード例 #19
0
ファイル: Repository.cs プロジェクト: gilran/GitSharp
        /**
         * Access any type of Git object by id and
         *
         * @param id
         *            SHA-1 of object to read
         * @param refName optional, only relevant for simple tags
         * @return The Git object if found or null
         * @
         */
        public object MapObject(ObjectId id, string refName)
        {
            ObjectLoader or = OpenObject(id);
            byte[] raw = or.getBytes();
            switch ((ObjectType)(or.getType()))
            {
                case ObjectType.Tree:
                    return MakeTree(id, raw);
                case ObjectType.Commit:
                    return MakeCommit(id, raw);
                case ObjectType.Tag:
                    return MakeTag(id, refName, raw);
                case ObjectType.Blob:
                    return raw;
            }
            return null;

        }
コード例 #20
0
        public IncorrectObjectTypeException(ObjectId id, string type)
            : base(string.Format("object {0} is not a {1}.", id, type))
        {

        }
コード例 #21
0
ファイル: Repository.cs プロジェクト: gilran/GitSharp
 private object MakeCommit(ObjectId id, byte[] raw)
 {
     return new Commit(this, id, raw);
 }
コード例 #22
0
ファイル: LockFile.cs プロジェクト: ArildF/GitSharp
 public void Write(ObjectId id)
 {
     RequireLock();
     try
     {
         var b = new BinaryWriter(os);
         id.CopyTo(os);
         b.Write('\n');
         b.Flush();
         fLck.Release();
         b.Close();
         os = null;
     }
     catch (Exception)
     {
         Unlock();
         throw;
     }
 }
コード例 #23
0
ファイル: Repository.cs プロジェクト: gilran/GitSharp
 private Tag MakeTag(ObjectId id, string refName, byte[] raw)
 {
     return new Tag(this, id, refName, raw);
 }
コード例 #24
0
ファイル: Tree.cs プロジェクト: rzeng/GitSharp
 public Tree(Repository repo, ObjectId id, byte[] raw)
     : base(null, id, null)
 {
     _db = repo;
     ReadTree(raw);
 }
コード例 #25
0
ファイル: Repository.cs プロジェクト: gilran/GitSharp
 /**
  * Access a Tag by SHA'1 id
  * @param refName
  * @param id
  * @return Commit or null
  * @ for I/O error or unexpected object type.
  */
 public Tag MapTag(string refName, ObjectId id)
 {
     ObjectLoader or = OpenObject(id);
     if (or == null)
         return null;
     byte[] raw = or.getBytes();
     if (ObjectType.Tag == (ObjectType)or.getType())
         return new Tag(this, id, refName, raw);
     return new Tag(this, id, refName, null);
 }
コード例 #26
0
ファイル: Tree.cs プロジェクト: rzeng/GitSharp
 public Tree(Tree parent, ObjectId id, byte[] nameUTF8)
     : base(parent, id, nameUTF8)
 {
     _db = parent.Repository;
 }
コード例 #27
0
 public IncorrectObjectTypeException(ObjectId id, int type, Exception inner) : base(string.Format("object {0} is not a {1}.", id, (ObjectType)type), inner) { }
コード例 #28
0
ファイル: FileTreeEntry.cs プロジェクト: drothmaler/GitSharp
 public FileTreeEntry(Tree parent, ObjectId id, byte[] nameUTF8, bool execute)
     : base(parent,id, nameUTF8)
 {
     this.SetExecutable(execute);
 }
コード例 #29
0
ファイル: TreeEntry.cs プロジェクト: ArildF/GitSharp
 public TreeEntry(Tree myParent, ObjectId id, byte[] nameUTF8)
 {
     this.NameUTF8 = nameUTF8;
     this.Parent = myParent;
     this._id = id;
 }
コード例 #30
0
ファイル: ReflogReader.cs プロジェクト: rzeng/GitSharp
            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);
            }