Exemplo n.º 1
0
		public Object Get (SHA1 key)
		{
			if (cache == null)
				cache = new Dictionary<SHA1,Object>();
			
			if (cache.ContainsKey (key))
				return cache[key];
			
			if (ObjectExist (key)) {
				cache.Add (key, RetrieveObject (key));
			} else {
				throw new ArgumentException (String.Format ("The specified key {0} does not exist", key.ToHexString ()));
			}
			
			return cache[key];
		}
Exemplo n.º 2
0
		public static void ViewCompressedFile (string filePath)
		{
			FileStream fs = File.Open (filePath, FileMode.OpenOrCreate, FileAccess.ReadWrite);
			
			byte[] bytes = new byte[(int) fs.Length];
			
			fs.Read (bytes, 0, (int) fs.Length);
			
			byte[] content = ObjectStore.Decompress (bytes);
			
			SHA1 id = new SHA1 (content, true);
			
			Console.WriteLine ("ID: {0}", id.ToHexString ());
			Console.WriteLine ("Path {0}", filePath);
			
			Console.WriteLine ("Length: " + content.Length);
			
			foreach (char c in content) {
				if (c == '\n') {
					Console.WriteLine ("\\n");
					continue;
				}
				if (c == '\0')
					Console.Write ("[NULL]");
				Console.Write (c);
			}
		}
Exemplo n.º 3
0
		public static void CheckoutTest (string hash, string objStorePath)
		{
			ObjectStore store = new ObjectStore (objStorePath);
			
			SHA1 id = new SHA1 (SHA1.FromHexString (hash), false);
			
			Console.WriteLine ("Hash: " + hash);
			Console.WriteLine ("Id:   " + id.ToHexString ());
			
			Console.WriteLine ("hash created");
			
			Tree tree = (Tree) store.Get (id);
			
			Console.WriteLine ("tree created No. entries: " + tree.Entries.Length);
			
			store.Checkout (Environment.CurrentDirectory, tree);
			
			Console.WriteLine ("Checkout done WIIIII!!!");
		}
Exemplo n.º 4
0
		public static void ReadGitTree ()
		{
			FileStream fs = new FileStream ("c45099a4cd4ba61a32e1c61d987b73dc3b6146b9", FileMode.Open);
			Console.WriteLine ("SHA1 = c45099a4cd4ba61a32e1c61d987b73dc3b6146b9");
			
			BinaryReader br = new BinaryReader (fs);
			int len = (int)fs.Length;
			
			byte[] content = br.ReadBytes (len);
			
			Console.WriteLine ("First 2 bytes: {0} {1}", (int)content[0], (int)content[1]);
			Console.WriteLine ("Last 4 bytes: {0}{1}{2}{3}", (int)content[len - 4], (int)content[len - 3], 
			                   (int)content[len - 2], (int)content[len - 1]);
			
			byte[] deflated = Mono.Git.Core.ObjectStore.Decompress (content);
			
			int pos = 0;
			
			Console.Write ("header: ");
			
			for (; deflated[pos] != '\0'; pos++) {
				Console.Write ((char) deflated[pos]);
			}
			
			if (deflated[pos] == '\0') {
				Console.WriteLine ("[null]");
				pos++;
			}
			
			Console.WriteLine ("Content: ");
			
			byte[] deflatedNoHeader = new byte [deflated.Length - pos];
			
			Array.Copy (deflated, pos, deflatedNoHeader, 0, deflatedNoHeader.Length);
			
			pos = 0;
			int count = 0;
			
//			for (; pos < deflatedNoHeader.Length; pos++) {
//				if (deflatedNoHeader [pos] == '\0') {
//					count = 0;
//					Console.Write ("[#{0} null]", pos);
//					pos += 21;
//					if (pos > deflatedNoHeader.Length)
//						break;
//					byte[] bytes = new byte[20];
//					Array.Copy (deflatedNoHeader, pos, bytes, 0, 20);
//					SHA1 id = new SHA1 (bytes, true);
//					
//					Console.Write (id.ToHexString ());
//					continue;
//				}
//				if (deflatedNoHeader [pos] == '1' && deflatedNoHeader [pos + 1] == '0' && deflatedNoHeader [pos + 2] == '0') {
//					Console.Write ("\n#{0} count: {1}", pos, count);
//				}
//				Console.Write ((char) deflatedNoHeader [pos]);
//			}
			
			for (; pos < deflatedNoHeader.Length; pos++) {
				if (deflatedNoHeader [pos] == '\0') {
					break;
				}
				Console.Write ((char) deflatedNoHeader [pos]);
			}
			
			pos += 1;
			
			byte[] bytes = new byte[20];
			Array.Copy (deflatedNoHeader, pos, bytes, 0, 20);
			
			SHA1 id = new SHA1 (bytes, false);
			
			Console.WriteLine (" " + id.ToHexString ());
			
//			foreach (byte b in deflatedNoHeader) {
//				if (b == '\0')
//					Console.Write ("[null]");
//				Console.Write ((char) b);
//			}
		}
Exemplo n.º 5
0
		public Object (Type type, byte[] content)
		{
			// FIXME: ok, if we got a 0 length content(a blob), what we can do?
			if (content.Length == 0 || content == null)
				return;
			
			byte[] header = CreateObjectHeader (type, content.Length.ToString ());
			this.content = new byte[header.Length + content.Length];
			
			// filling the content
			Array.Copy (header, 0, this.content, 0, header.Length); // Copying the header first
			Array.Copy (content, 0, this.content, header.Length, content.Length); // then the data
			
			Console.WriteLine ("Length: " + this.content.Length);
			foreach (char c in this.content) {
				if (c == '\n') {
					Console.WriteLine ("\\n");
					continue;
				}
				if (c == '\0')
					Console.Write ("[NULL]");
				Console.Write (c);
			}
			
			// initializing the id with the content
			id = new SHA1 (this.content, true);
			
			Console.WriteLine ("ID: " + id.ToHexString ());
		}
Exemplo n.º 6
0
		/// <summary>
		/// Create a object first parent... e.g. f4/47d5573b70cf042d036bfa62f55cdefccd9909
		/// f4 is the parent we create in this method
		/// </summary>
		/// <param name="id">
		/// A <see cref="SHA1"/>
		/// </param>
		private void CreateObjectParent (SHA1 id)
		{
			string fullPath = null;
			
			if (!path.EndsWith ("/"))
				fullPath = path + "/" + id.ToHexString (0, 1);
			else
				fullPath = path + id.ToHexString (0, 1);
			
			if (!Directory.Exists (fullPath))
				Directory.CreateDirectory (fullPath);
		}