Browse files

initial commit of obj-c bindings for libgit2

  • Loading branch information...
0 parents commit 0be12c9244e931ec8ca00dafbb43ec1855976444 @tclem tclem committed Mar 1, 2011
Showing with 11,376 additions and 0 deletions.
  1. +16 −0 .gitignore
  2. +33 −0 Classes/Categories/NSData+Base64.h
  3. +299 −0 Classes/Categories/NSData+Base64.m
  4. +33 −0 Classes/Categories/NSError+Git.h
  5. +178 −0 Classes/Categories/NSError+Git.m
  6. +17 −0 Classes/Categories/NSString+Git.h
  7. +25 −0 Classes/Categories/NSString+Git.m
  8. +21 −0 Classes/GTBlob.h
  9. +50 −0 Classes/GTBlob.m
  10. +28 −0 Classes/GTCommit.h
  11. +109 −0 Classes/GTCommit.m
  12. +31 −0 Classes/GTIndex.h
  13. +117 −0 Classes/GTIndex.m
  14. +34 −0 Classes/GTIndexEntry.h
  15. +154 −0 Classes/GTIndexEntry.m
  16. +17 −0 Classes/GTLib.h
  17. +36 −0 Classes/GTLib.m
  18. +35 −0 Classes/GTObject.h
  19. +138 −0 Classes/GTObject.m
  20. +22 −0 Classes/GTRawObject.h
  21. +52 −0 Classes/GTRawObject.m
  22. +41 −0 Classes/GTRepository.h
  23. +258 −0 Classes/GTRepository.m
  24. +25 −0 Classes/GTSignature.h
  25. +98 −0 Classes/GTSignature.m
  26. +25 −0 Classes/GTTag.h
  27. +68 −0 Classes/GTTag.m
  28. +24 −0 Classes/GTTree.h
  29. +86 −0 Classes/GTTree.m
  30. +24 −0 Classes/GTTreeEntry.h
  31. +70 −0 Classes/GTTreeEntry.m
  32. +26 −0 Classes/GTWalker.h
  33. +85 −0 Classes/GTWalker.m
  34. +2 −0 English.lproj/InfoPlist.strings
  35. +1 −0 Frameworks/GHUnit.framework/GHUnit
  36. +1 −0 Frameworks/GHUnit.framework/Headers
  37. +1 −0 Frameworks/GHUnit.framework/Resources
  38. BIN Frameworks/GHUnit.framework/Versions/A/GHUnit
  39. +47 −0 Frameworks/GHUnit.framework/Versions/A/Headers/BWSplitView.h
  40. +155 −0 Frameworks/GHUnit.framework/Versions/A/Headers/GHAsyncTestCase.h
  41. +50 −0 Frameworks/GHUnit.framework/Versions/A/Headers/GHMockNSHTTPURLResponse.h
  42. +173 −0 Frameworks/GHUnit.framework/Versions/A/Headers/GHMockNSURLConnection.h
  43. +132 −0 Frameworks/GHUnit.framework/Versions/A/Headers/GHNSInvocation+Utils.h
  44. +133 −0 Frameworks/GHUnit.framework/Versions/A/Headers/GHNSInvocationProxy.h
  45. +63 −0 Frameworks/GHUnit.framework/Versions/A/Headers/GHNSLocale+Mock.h
  46. +100 −0 Frameworks/GHUnit.framework/Versions/A/Headers/GHNSObject+Invocation.h
  47. +44 −0 Frameworks/GHUnit.framework/Versions/A/Headers/GHTest+JUnitXML.h
  48. +184 −0 Frameworks/GHUnit.framework/Versions/A/Headers/GHTest.h
  49. +23 −0 Frameworks/GHUnit.framework/Versions/A/Headers/GHTestApp.h
  50. +146 −0 Frameworks/GHUnit.framework/Versions/A/Headers/GHTestCase.h
  51. +42 −0 Frameworks/GHUnit.framework/Versions/A/Headers/GHTestGroup+JUnitXML.h
  52. +176 −0 Frameworks/GHUnit.framework/Versions/A/Headers/GHTestGroup.h
  53. +1,012 −0 Frameworks/GHUnit.framework/Versions/A/Headers/GHTestMacros.h
  54. +46 −0 Frameworks/GHUnit.framework/Versions/A/Headers/GHTestOperation.h
  55. +31 −0 Frameworks/GHUnit.framework/Versions/A/Headers/GHTestOutlineViewModel.h
  56. +162 −0 Frameworks/GHUnit.framework/Versions/A/Headers/GHTestRunner.h
  57. +118 −0 Frameworks/GHUnit.framework/Versions/A/Headers/GHTestSuite.h
  58. +103 −0 Frameworks/GHUnit.framework/Versions/A/Headers/GHTestViewController.h
  59. +167 −0 Frameworks/GHUnit.framework/Versions/A/Headers/GHTestViewModel.h
  60. +41 −0 Frameworks/GHUnit.framework/Versions/A/Headers/GHTestWindowController.h
  61. +148 −0 Frameworks/GHUnit.framework/Versions/A/Headers/GHTesting.h
  62. +40 −0 Frameworks/GHUnit.framework/Versions/A/Headers/GHUNSObject+Swizzle.h
  63. +590 −0 Frameworks/GHUnit.framework/Versions/A/Headers/GHUnit.h
  64. +105 −0 Frameworks/GHUnit.framework/Versions/A/Headers/GTMStackTrace.h
  65. +97 −0 Frameworks/GHUnit.framework/Versions/A/Headers/NSException+GHTestFailureExceptions.h
  66. +71 −0 Frameworks/GHUnit.framework/Versions/A/Headers/NSValue+GHValueFormatter.h
  67. BIN Frameworks/GHUnit.framework/Versions/A/Resources/English.lproj/InfoPlist.strings
  68. BIN Frameworks/GHUnit.framework/Versions/A/Resources/GHTestApp.nib
  69. BIN Frameworks/GHUnit.framework/Versions/A/Resources/GHTestView.nib
  70. BIN Frameworks/GHUnit.framework/Versions/A/Resources/GHTestWindow.nib
  71. +4 −0 Frameworks/GHUnit.framework/Versions/A/Resources/GHUnit-Debug.xcconfig
  72. +15 −0 Frameworks/GHUnit.framework/Versions/A/Resources/GHUnit.xcconfig
  73. BIN Frameworks/GHUnit.framework/Versions/A/Resources/GradientSplitViewDimpleBitmap.tif
  74. BIN Frameworks/GHUnit.framework/Versions/A/Resources/GradientSplitViewDimpleVector.pdf
  75. +22 −0 Frameworks/GHUnit.framework/Versions/A/Resources/Info.plist
  76. +1 −0 Frameworks/GHUnit.framework/Versions/Current
  77. +87 −0 GHUnitTestMain.m
  78. +28 −0 Info.plist
  79. +16 −0 Makefile
  80. +766 −0 ObjectiveGitFramework.xcodeproj/project.pbxproj
  81. +9 −0 ObjectiveGitFramework_Prefix.pch
  82. +14 −0 README.md
  83. +28 −0 Tests-Info.plist
  84. +47 −0 Tests/Contants.h
  85. +92 −0 Tests/GTBlobTest.m
  86. +122 −0 Tests/GTCommitTest.m
  87. +222 −0 Tests/GTIndexTest.m
  88. +36 −0 Tests/GTLibTest.m
  89. +86 −0 Tests/GTObjectTest.m
  90. +46 −0 Tests/GTRepositoryPackTest.m
  91. +138 −0 Tests/GTRepositoryTest.m
  92. +62 −0 Tests/GTTagTest.m
  93. +62 −0 Tests/GTTreeTest.m
  94. +167 −0 Tests/GTWalkerTest.m
  95. +44 −0 Tests/RunTests.sh
  96. +1 −0 Tests/fixtures/baseline/testrepo.git/HEAD
  97. +6 −0 Tests/fixtures/baseline/testrepo.git/config
  98. +1 −0 Tests/fixtures/baseline/testrepo.git/description
  99. BIN Tests/fixtures/baseline/testrepo.git/index
  100. +6 −0 Tests/fixtures/baseline/testrepo.git/info/exclude
  101. +3 −0 Tests/fixtures/baseline/testrepo.git/logs/HEAD
  102. +3 −0 Tests/fixtures/baseline/testrepo.git/logs/refs/heads/master
  103. BIN Tests/fixtures/baseline/testrepo.git/objects/04/7142d55581bfb3a703eec247e4fadd5666e789
  104. +2 −0 Tests/fixtures/baseline/testrepo.git/objects/08/ca5b320ed2111f62ec74158b52242757664516
  105. BIN Tests/fixtures/baseline/testrepo.git/objects/0c/37a5391bbff43c37f0d0371823a5509eed5b1d
  106. BIN Tests/fixtures/baseline/testrepo.git/objects/13/85f264afb75a56a5bec74243be9b367ba4ca08
  107. BIN Tests/fixtures/baseline/testrepo.git/objects/18/1037049a54a1eb5fab404658a3a250b44335d7
  108. BIN Tests/fixtures/baseline/testrepo.git/objects/18/10dff58d8a660512d4832e740f692884338ccd
  109. +2 −0 Tests/fixtures/baseline/testrepo.git/objects/23/c5964c265e17b12ce89320ec21b5015f033a66
  110. BIN Tests/fixtures/baseline/testrepo.git/objects/2c/8611f5dacf3c106cd90f4b71e40f87c64cfdab
  111. BIN Tests/fixtures/baseline/testrepo.git/objects/2d/2eff63372b08adf0a9eb84109ccf7d19e2f3a2
  112. BIN Tests/fixtures/baseline/testrepo.git/objects/31/b7680598f36b4e8d0948ddf13ee17d009e9a80
  113. +2 −0 Tests/fixtures/baseline/testrepo.git/objects/32/4d981d11440240df53e825b6eba0afddcb39fa
  114. +2 −0 Tests/fixtures/baseline/testrepo.git/objects/36/060c58702ed4c2a40832c51758d5344201d89a
  115. +2 −0 Tests/fixtures/baseline/testrepo.git/objects/36/a1a2e1ebed3bb4de53d2d0d3982dd724caa7de
  116. BIN Tests/fixtures/baseline/testrepo.git/objects/45/b983be36b73c0788dc9cbcb76cbb80fc7bb057
  117. BIN Tests/fixtures/baseline/testrepo.git/objects/46/bf0f2b6d602a0d0a8971216dfb81692bde5286
  118. +2 −0 Tests/fixtures/baseline/testrepo.git/objects/49/4a45810d66a43ff2ed747db6f13d7779436de5
  119. +2 −0 Tests/fixtures/baseline/testrepo.git/objects/4a/202b346bb0fb0db7eff3cffeb3c70babbd2045
  120. +2 −0 Tests/fixtures/baseline/testrepo.git/objects/4b/d7c21254336b430f3dcaca0bf27124edbfd979
  121. +3 −0 Tests/fixtures/baseline/testrepo.git/objects/58/2ab21929a82c7c1c10521f371fa011e41a6730
  122. +2 −0 Tests/fixtures/baseline/testrepo.git/objects/58/3cf9deb2f587481b3e88f700066764351c5a98
  123. +2 −0 Tests/fixtures/baseline/testrepo.git/objects/5b/5b025afb0b4c913b4c338a42934a3863bf3644
  124. BIN Tests/fixtures/baseline/testrepo.git/objects/61/9f9935957e010c419cb9d15621916ddfcc0b96
  125. BIN Tests/fixtures/baseline/testrepo.git/objects/63/b661110a0c7e53c5db0389de17f6aee08b21c3
  126. +2 −0 Tests/fixtures/baseline/testrepo.git/objects/6d/e3956f865eb06b3cf5707325df92f3526d9927
  127. BIN Tests/fixtures/baseline/testrepo.git/objects/75/057dd4114e74cca1d750d0aee1647c903cb60a
  128. BIN Tests/fixtures/baseline/testrepo.git/objects/81/4889a078c031f61ed08ab5fa863aea9314344d
  129. BIN Tests/fixtures/baseline/testrepo.git/objects/84/96071c1b46c854b31185ea97743be6a8774479
  130. +2 −0 Tests/fixtures/baseline/testrepo.git/objects/92/867bc5db73e8182a7bf7387dabda57efa9f0c8
  131. +3 −0 Tests/fixtures/baseline/testrepo.git/objects/9f/d738e8f7967c078dceed8190330fc8648ee56a
  132. +2 −0 Tests/fixtures/baseline/testrepo.git/objects/a3/5622ee2ca7c7cf68abdcad335588fbb8bca9ec
  133. +2 −0 Tests/fixtures/baseline/testrepo.git/objects/a4/a7dce85cf63874e984719f4fdd239f5145052f
  134. BIN Tests/fixtures/baseline/testrepo.git/objects/a7/1586c1dfe8a71c6cbf6c129f404c5642ff31bd
  135. BIN Tests/fixtures/baseline/testrepo.git/objects/a8/233120f6ad708f843d861ce2b7228ec4e3dec6
  136. +2 −0 Tests/fixtures/baseline/testrepo.git/objects/b5/fd0db2023fefaad6d654498b19da0452d6ed6f
  137. +2 −0 Tests/fixtures/baseline/testrepo.git/objects/b6/8f98fb09ce029c462ab6cb4b0a6bd388991008
  138. +2 −0 Tests/fixtures/baseline/testrepo.git/objects/b8/f63858750d58a047fb01de56600a848d148c5c
  139. +3 −0 Tests/fixtures/baseline/testrepo.git/objects/be/3563ae3f795b2b4353bcce3a527ad0a4f7f644
  140. +3 −0 Tests/fixtures/baseline/testrepo.git/objects/c4/7800c7266a2be04c571c04d5a6614691ea99bd
  141. BIN Tests/fixtures/baseline/testrepo.git/objects/c4/dc1555e4d4fa0e0c9c3fc46734c7c35b3ce90b
  142. +2 −0 Tests/fixtures/baseline/testrepo.git/objects/d5/8bc7e528c2ed684024ed09c0a866515cbaa93d
  143. +2 −0 Tests/fixtures/baseline/testrepo.git/objects/dc/e40996517d8183ba11d2d0de35c5513db7cd6b
  144. +2 −0 Tests/fixtures/baseline/testrepo.git/objects/e3/02ade1ce3d2729bbe053dd8f923b294336437e
  145. +2 −0 Tests/fixtures/baseline/testrepo.git/objects/e4/065ef1811aa1279362c275aab504b846067a9f
  146. BIN Tests/fixtures/baseline/testrepo.git/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391
  147. +3 −0 Tests/fixtures/baseline/testrepo.git/objects/e7/d45d5c5b1d3897cba0fb342df207b833b83d7c
  148. +3 −0 Tests/fixtures/baseline/testrepo.git/objects/eb/283b26b265cf3b3c509d32f47adddee83624a4
  149. +2 −0 Tests/fixtures/baseline/testrepo.git/objects/f0/a804583c8dd509d1a0e6fac899a85d31ac121e
  150. BIN Tests/fixtures/baseline/testrepo.git/objects/f3/4546500875044d9a2ae8804171897c81364721
  151. BIN Tests/fixtures/baseline/testrepo.git/objects/f6/0079018b664e4e79329a7ef9559c8d9e0378d1
  152. BIN Tests/fixtures/baseline/testrepo.git/objects/fa/49b077972391ad58037050f2a75f74e3671e92
  153. BIN Tests/fixtures/baseline/testrepo.git/objects/fd/093bff70906175335656e6ce6ae05783708765
  154. BIN Tests/fixtures/baseline/testrepo.git/objects/pack/pack-d7c6adf9f61318f041845b01440d09aa7a91e1b5.idx
  155. BIN Tests/fixtures/baseline/testrepo.git/objects/pack/pack-d7c6adf9f61318f041845b01440d09aa7a91e1b5.pack
  156. +2 −0 Tests/fixtures/baseline/testrepo.git/packed-refs
  157. +1 −0 Tests/fixtures/baseline/testrepo.git/refs/heads/master
  158. +1 −0 Tests/fixtures/baseline/testrepo.git/refs/tags/v0.9
  159. +1 −0 Tests/fixtures/baseline/testrepo.git/refs/tags/v1.0
  160. +1 −0 Tests/fixtures/testrepo.git/HEAD
  161. +6 −0 Tests/fixtures/testrepo.git/config
  162. +1 −0 Tests/fixtures/testrepo.git/description
  163. BIN Tests/fixtures/testrepo.git/index
  164. +6 −0 Tests/fixtures/testrepo.git/info/exclude
  165. +3 −0 Tests/fixtures/testrepo.git/logs/HEAD
  166. +3 −0 Tests/fixtures/testrepo.git/logs/refs/heads/master
  167. BIN Tests/fixtures/testrepo.git/objects/04/7142d55581bfb3a703eec247e4fadd5666e789
  168. +2 −0 Tests/fixtures/testrepo.git/objects/08/ca5b320ed2111f62ec74158b52242757664516
  169. BIN Tests/fixtures/testrepo.git/objects/0c/37a5391bbff43c37f0d0371823a5509eed5b1d
  170. BIN Tests/fixtures/testrepo.git/objects/13/85f264afb75a56a5bec74243be9b367ba4ca08
  171. BIN Tests/fixtures/testrepo.git/objects/18/1037049a54a1eb5fab404658a3a250b44335d7
  172. BIN Tests/fixtures/testrepo.git/objects/18/10dff58d8a660512d4832e740f692884338ccd
  173. +2 −0 Tests/fixtures/testrepo.git/objects/23/c5964c265e17b12ce89320ec21b5015f033a66
  174. BIN Tests/fixtures/testrepo.git/objects/2c/8611f5dacf3c106cd90f4b71e40f87c64cfdab
  175. BIN Tests/fixtures/testrepo.git/objects/2d/2eff63372b08adf0a9eb84109ccf7d19e2f3a2
  176. BIN Tests/fixtures/testrepo.git/objects/31/b7680598f36b4e8d0948ddf13ee17d009e9a80
  177. +2 −0 Tests/fixtures/testrepo.git/objects/32/4d981d11440240df53e825b6eba0afddcb39fa
  178. +2 −0 Tests/fixtures/testrepo.git/objects/36/060c58702ed4c2a40832c51758d5344201d89a
  179. +2 −0 Tests/fixtures/testrepo.git/objects/36/a1a2e1ebed3bb4de53d2d0d3982dd724caa7de
  180. BIN Tests/fixtures/testrepo.git/objects/45/b983be36b73c0788dc9cbcb76cbb80fc7bb057
  181. BIN Tests/fixtures/testrepo.git/objects/46/bf0f2b6d602a0d0a8971216dfb81692bde5286
  182. +2 −0 Tests/fixtures/testrepo.git/objects/49/4a45810d66a43ff2ed747db6f13d7779436de5
  183. +2 −0 Tests/fixtures/testrepo.git/objects/4a/202b346bb0fb0db7eff3cffeb3c70babbd2045
  184. +2 −0 Tests/fixtures/testrepo.git/objects/4b/d7c21254336b430f3dcaca0bf27124edbfd979
  185. +3 −0 Tests/fixtures/testrepo.git/objects/58/2ab21929a82c7c1c10521f371fa011e41a6730
  186. +2 −0 Tests/fixtures/testrepo.git/objects/58/3cf9deb2f587481b3e88f700066764351c5a98
  187. +2 −0 Tests/fixtures/testrepo.git/objects/5b/5b025afb0b4c913b4c338a42934a3863bf3644
  188. BIN Tests/fixtures/testrepo.git/objects/61/9f9935957e010c419cb9d15621916ddfcc0b96
  189. BIN Tests/fixtures/testrepo.git/objects/63/b661110a0c7e53c5db0389de17f6aee08b21c3
  190. +2 −0 Tests/fixtures/testrepo.git/objects/6d/e3956f865eb06b3cf5707325df92f3526d9927
  191. BIN Tests/fixtures/testrepo.git/objects/75/057dd4114e74cca1d750d0aee1647c903cb60a
  192. BIN Tests/fixtures/testrepo.git/objects/81/4889a078c031f61ed08ab5fa863aea9314344d
  193. BIN Tests/fixtures/testrepo.git/objects/84/96071c1b46c854b31185ea97743be6a8774479
  194. +2 −0 Tests/fixtures/testrepo.git/objects/92/867bc5db73e8182a7bf7387dabda57efa9f0c8
  195. +3 −0 Tests/fixtures/testrepo.git/objects/9f/d738e8f7967c078dceed8190330fc8648ee56a
  196. +2 −0 Tests/fixtures/testrepo.git/objects/a3/5622ee2ca7c7cf68abdcad335588fbb8bca9ec
  197. +2 −0 Tests/fixtures/testrepo.git/objects/a4/a7dce85cf63874e984719f4fdd239f5145052f
  198. BIN Tests/fixtures/testrepo.git/objects/a7/1586c1dfe8a71c6cbf6c129f404c5642ff31bd
  199. BIN Tests/fixtures/testrepo.git/objects/a8/233120f6ad708f843d861ce2b7228ec4e3dec6
  200. +2 −0 Tests/fixtures/testrepo.git/objects/b5/fd0db2023fefaad6d654498b19da0452d6ed6f
  201. +2 −0 Tests/fixtures/testrepo.git/objects/b6/8f98fb09ce029c462ab6cb4b0a6bd388991008
  202. +2 −0 Tests/fixtures/testrepo.git/objects/b8/f63858750d58a047fb01de56600a848d148c5c
  203. +3 −0 Tests/fixtures/testrepo.git/objects/be/3563ae3f795b2b4353bcce3a527ad0a4f7f644
  204. +3 −0 Tests/fixtures/testrepo.git/objects/c4/7800c7266a2be04c571c04d5a6614691ea99bd
  205. BIN Tests/fixtures/testrepo.git/objects/c4/dc1555e4d4fa0e0c9c3fc46734c7c35b3ce90b
  206. +2 −0 Tests/fixtures/testrepo.git/objects/d5/8bc7e528c2ed684024ed09c0a866515cbaa93d
  207. +2 −0 Tests/fixtures/testrepo.git/objects/dc/e40996517d8183ba11d2d0de35c5513db7cd6b
  208. +2 −0 Tests/fixtures/testrepo.git/objects/e3/02ade1ce3d2729bbe053dd8f923b294336437e
  209. +2 −0 Tests/fixtures/testrepo.git/objects/e4/065ef1811aa1279362c275aab504b846067a9f
  210. BIN Tests/fixtures/testrepo.git/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391
  211. +3 −0 Tests/fixtures/testrepo.git/objects/e7/d45d5c5b1d3897cba0fb342df207b833b83d7c
  212. +3 −0 Tests/fixtures/testrepo.git/objects/eb/283b26b265cf3b3c509d32f47adddee83624a4
  213. +2 −0 Tests/fixtures/testrepo.git/objects/f0/a804583c8dd509d1a0e6fac899a85d31ac121e
  214. BIN Tests/fixtures/testrepo.git/objects/f3/4546500875044d9a2ae8804171897c81364721
  215. BIN Tests/fixtures/testrepo.git/objects/f6/0079018b664e4e79329a7ef9559c8d9e0378d1
  216. BIN Tests/fixtures/testrepo.git/objects/fa/49b077972391ad58037050f2a75f74e3671e92
  217. BIN Tests/fixtures/testrepo.git/objects/fd/093bff70906175335656e6ce6ae05783708765
  218. BIN Tests/fixtures/testrepo.git/objects/pack/pack-d7c6adf9f61318f041845b01440d09aa7a91e1b5.idx
  219. BIN Tests/fixtures/testrepo.git/objects/pack/pack-d7c6adf9f61318f041845b01440d09aa7a91e1b5.pack
  220. +2 −0 Tests/fixtures/testrepo.git/packed-refs
  221. +1 −0 Tests/fixtures/testrepo.git/refs/heads/master
  222. +1 −0 Tests/fixtures/testrepo.git/refs/tags/v0.9
  223. +1 −0 Tests/fixtures/testrepo.git/refs/tags/v1.0
  224. +56 −0 libgit2/include/git2.h
  225. +128 −0 libgit2/include/git2/blob.h
  226. +184 −0 libgit2/include/git2/commit.h
  227. +160 −0 libgit2/include/git2/common.h
  228. +45 −0 libgit2/include/git2/errors.h
  229. +199 −0 libgit2/include/git2/index.h
  230. +146 −0 libgit2/include/git2/object.h
  231. +201 −0 libgit2/include/git2/odb.h
  232. +76 −0 libgit2/include/git2/odb_backend.h
  233. +137 −0 libgit2/include/git2/oid.h
  234. +176 −0 libgit2/include/git2/refs.h
  235. +239 −0 libgit2/include/git2/repository.h
  236. +136 −0 libgit2/include/git2/revwalk.h
  237. +70 −0 libgit2/include/git2/signature.h
  238. +145 −0 libgit2/include/git2/tag.h
  239. +80 −0 libgit2/include/git2/thread-utils.h
  240. +222 −0 libgit2/include/git2/tree.h
  241. +151 −0 libgit2/include/git2/types.h
  242. +58 −0 libgit2/include/git2/zlib.h
  243. BIN libgit2/lib/libgit2.a
16 .gitignore
@@ -0,0 +1,16 @@
+.DS_Store
+*.swp
+*~.nib
+
+build/*
+ObjectiveGitFramework/build/*
+
+*.pbxuser
+*.perspective
+*.perspectivev3
+
+*.mode1v3
+*.mode2v3
+
+project.xcworkspace
+*/xcuserdata/
33 Classes/Categories/NSData+Base64.h
@@ -0,0 +1,33 @@
+//
+// NSData+Base64.h
+// base64
+//
+// Created by Matt Gallagher on 2009/06/03.
+// Copyright 2009 Matt Gallagher. All rights reserved.
+//
+// Permission is given to use this source code file, free of charge, in any
+// project, commercial or otherwise, entirely at your risk, with the condition
+// that any redistribution (in part or whole) of source code must retain
+// this copyright and permission notice. Attribution in compiled projects is
+// appreciated but not required.
+//
+
+#import <Foundation/Foundation.h>
+
+void *NewBase64Decode(
+ const char *inputBuffer,
+ size_t length,
+ size_t *outputLength);
+
+char *NewBase64Encode(
+ const void *inputBuffer,
+ size_t length,
+ bool separateLines,
+ size_t *outputLength);
+
+@interface NSData (Base64)
+
++ (NSData *)dataFromBase64String:(NSString *)aString;
+- (NSString *)base64EncodedString;
+
+@end
299 Classes/Categories/NSData+Base64.m
@@ -0,0 +1,299 @@
+//
+// NSData+Base64.m
+// base64
+//
+// Created by Matt Gallagher on 2009/06/03.
+// Copyright 2009 Matt Gallagher. All rights reserved.
+//
+// Permission is given to use this source code file, free of charge, in any
+// project, commercial or otherwise, entirely at your risk, with the condition
+// that any redistribution (in part or whole) of source code must retain
+// this copyright and permission notice. Attribution in compiled projects is
+// appreciated but not required.
+//
+
+#import "NSData+Base64.h"
+
+//
+// Mapping from 6 bit pattern to ASCII character.
+//
+static unsigned char base64EncodeLookup[65] =
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+
+//
+// Definition for "masked-out" areas of the base64DecodeLookup mapping
+//
+#define xx 65
+
+//
+// Mapping from ASCII character to 6 bit pattern.
+//
+static unsigned char base64DecodeLookup[256] =
+{
+ xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx,
+ xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx,
+ xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, 62, xx, xx, xx, 63,
+ 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, xx, xx, xx, xx, xx, xx,
+ xx, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
+ 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, xx, xx, xx, xx, xx,
+ xx, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
+ 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, xx, xx, xx, xx, xx,
+ xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx,
+ xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx,
+ xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx,
+ xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx,
+ xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx,
+ xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx,
+ xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx,
+ xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx,
+};
+
+//
+// Fundamental sizes of the binary and base64 encode/decode units in bytes
+//
+#define BINARY_UNIT_SIZE 3
+#define BASE64_UNIT_SIZE 4
+
+//
+// NewBase64Decode
+//
+// Decodes the base64 ASCII string in the inputBuffer to a newly malloced
+// output buffer.
+//
+// inputBuffer - the source ASCII string for the decode
+// length - the length of the string or -1 (to specify strlen should be used)
+// outputLength - if not-NULL, on output will contain the decoded length
+//
+// returns the decoded buffer. Must be free'd by caller. Length is given by
+// outputLength.
+//
+void *NewBase64Decode(
+ const char *inputBuffer,
+ size_t length,
+ size_t *outputLength)
+{
+ if (length == -1)
+ {
+ length = strlen(inputBuffer);
+ }
+
+ size_t outputBufferSize =
+ ((length+BASE64_UNIT_SIZE-1) / BASE64_UNIT_SIZE) * BINARY_UNIT_SIZE;
+ unsigned char *outputBuffer = (unsigned char *)malloc(outputBufferSize);
+
+ size_t i = 0;
+ size_t j = 0;
+ while (i < length)
+ {
+ //
+ // Accumulate 4 valid characters (ignore everything else)
+ //
+ unsigned char accumulated[BASE64_UNIT_SIZE];
+ size_t accumulateIndex = 0;
+ while (i < length)
+ {
+ unsigned char decode = base64DecodeLookup[inputBuffer[i++]];
+ if (decode != xx)
+ {
+ accumulated[accumulateIndex] = decode;
+ accumulateIndex++;
+
+ if (accumulateIndex == BASE64_UNIT_SIZE)
+ {
+ break;
+ }
+ }
+ }
+
+ //
+ // Store the 6 bits from each of the 4 characters as 3 bytes
+ //
+ outputBuffer[j] = (accumulated[0] << 2) | (accumulated[1] >> 4);
+ outputBuffer[j + 1] = (accumulated[1] << 4) | (accumulated[2] >> 2);
+ outputBuffer[j + 2] = (accumulated[2] << 6) | accumulated[3];
+ j += accumulateIndex - 1;
+ }
+
+ if (outputLength)
+ {
+ *outputLength = j;
+ }
+ return outputBuffer;
+}
+
+//
+// NewBase64Decode
+//
+// Encodes the arbitrary data in the inputBuffer as base64 into a newly malloced
+// output buffer.
+//
+// inputBuffer - the source data for the encode
+// length - the length of the input in bytes
+// separateLines - if zero, no CR/LF characters will be added. Otherwise
+// a CR/LF pair will be added every 64 encoded chars.
+// outputLength - if not-NULL, on output will contain the encoded length
+// (not including terminating 0 char)
+//
+// returns the encoded buffer. Must be free'd by caller. Length is given by
+// outputLength.
+//
+char *NewBase64Encode(
+ const void *buffer,
+ size_t length,
+ bool separateLines,
+ size_t *outputLength)
+{
+ const unsigned char *inputBuffer = (const unsigned char *)buffer;
+
+ #define MAX_NUM_PADDING_CHARS 2
+ #define OUTPUT_LINE_LENGTH 64
+ #define INPUT_LINE_LENGTH ((OUTPUT_LINE_LENGTH / BASE64_UNIT_SIZE) * BINARY_UNIT_SIZE)
+ #define CR_LF_SIZE 2
+
+ //
+ // Byte accurate calculation of final buffer size
+ //
+ size_t outputBufferSize =
+ ((length / BINARY_UNIT_SIZE)
+ + ((length % BINARY_UNIT_SIZE) ? 1 : 0))
+ * BASE64_UNIT_SIZE;
+ if (separateLines)
+ {
+ outputBufferSize +=
+ (outputBufferSize / OUTPUT_LINE_LENGTH) * CR_LF_SIZE;
+ }
+
+ //
+ // Include space for a terminating zero
+ //
+ outputBufferSize += 1;
+
+ //
+ // Allocate the output buffer
+ //
+ char *outputBuffer = (char *)malloc(outputBufferSize);
+ if (!outputBuffer)
+ {
+ return NULL;
+ }
+
+ size_t i = 0;
+ size_t j = 0;
+ const size_t lineLength = separateLines ? INPUT_LINE_LENGTH : length;
+ size_t lineEnd = lineLength;
+
+ while (true)
+ {
+ if (lineEnd > length)
+ {
+ lineEnd = length;
+ }
+
+ for (; i + BINARY_UNIT_SIZE - 1 < lineEnd; i += BINARY_UNIT_SIZE)
+ {
+ //
+ // Inner loop: turn 48 bytes into 64 base64 characters
+ //
+ outputBuffer[j++] = base64EncodeLookup[(inputBuffer[i] & 0xFC) >> 2];
+ outputBuffer[j++] = base64EncodeLookup[((inputBuffer[i] & 0x03) << 4)
+ | ((inputBuffer[i + 1] & 0xF0) >> 4)];
+ outputBuffer[j++] = base64EncodeLookup[((inputBuffer[i + 1] & 0x0F) << 2)
+ | ((inputBuffer[i + 2] & 0xC0) >> 6)];
+ outputBuffer[j++] = base64EncodeLookup[inputBuffer[i + 2] & 0x3F];
+ }
+
+ if (lineEnd == length)
+ {
+ break;
+ }
+
+ //
+ // Add the newline
+ //
+ outputBuffer[j++] = '\r';
+ outputBuffer[j++] = '\n';
+ lineEnd += lineLength;
+ }
+
+ if (i + 1 < length)
+ {
+ //
+ // Handle the single '=' case
+ //
+ outputBuffer[j++] = base64EncodeLookup[(inputBuffer[i] & 0xFC) >> 2];
+ outputBuffer[j++] = base64EncodeLookup[((inputBuffer[i] & 0x03) << 4)
+ | ((inputBuffer[i + 1] & 0xF0) >> 4)];
+ outputBuffer[j++] = base64EncodeLookup[(inputBuffer[i + 1] & 0x0F) << 2];
+ outputBuffer[j++] = '=';
+ }
+ else if (i < length)
+ {
+ //
+ // Handle the double '=' case
+ //
+ outputBuffer[j++] = base64EncodeLookup[(inputBuffer[i] & 0xFC) >> 2];
+ outputBuffer[j++] = base64EncodeLookup[(inputBuffer[i] & 0x03) << 4];
+ outputBuffer[j++] = '=';
+ outputBuffer[j++] = '=';
+ }
+ outputBuffer[j] = 0;
+
+ //
+ // Set the output length and return the buffer
+ //
+ if (outputLength)
+ {
+ *outputLength = j;
+ }
+ return outputBuffer;
+}
+
+@implementation NSData (Base64)
+
+//
+// dataFromBase64String:
+//
+// Creates an NSData object containing the base64 decoded representation of
+// the base64 string 'aString'
+//
+// Parameters:
+// aString - the base64 string to decode
+//
+// returns the autoreleased NSData representation of the base64 string
+//
++ (NSData *)dataFromBase64String:(NSString *)aString
+{
+ NSData *data = [aString dataUsingEncoding:NSASCIIStringEncoding];
+ size_t outputLength;
+ void *outputBuffer = NewBase64Decode([data bytes], [data length], &outputLength);
+ NSData *result = [NSData dataWithBytes:outputBuffer length:outputLength];
+ free(outputBuffer);
+ return result;
+}
+
+//
+// base64EncodedString
+//
+// Creates an NSString object that contains the base 64 encoding of the
+// receiver's data. Lines are broken at 64 characters long.
+//
+// returns an autoreleased NSString being the base 64 representation of the
+// receiver.
+//
+- (NSString *)base64EncodedString
+{
+ size_t outputLength;
+ char *outputBuffer =
+ NewBase64Encode([self bytes], [self length], true, &outputLength);
+
+ NSString *result =
+ [[[NSString alloc]
+ initWithBytes:outputBuffer
+ length:outputLength
+ encoding:NSASCIIStringEncoding]
+ autorelease];
+ free(outputBuffer);
+ return result;
+}
+
+@end
33 Classes/Categories/NSError+Git.h
@@ -0,0 +1,33 @@
+//
+// NSError+Git.h
+// ObjectiveGitFramework
+//
+// Created by Timothy Clem on 2/17/11.
+// Copyright 2011 GitHub Inc. All rights reserved.
+//
+
+#import <Cocoa/Cocoa.h>
+
+
+@interface NSError (Git)
+
++ (NSError *)gitErrorForInitRepository: (int)code;
++ (NSError *)gitErrorForOpenRepository: (int)code;
++ (NSError *)gitErrorForInitRevWalker: (int)code;
++ (NSError *)gitErrorForInitRepoIndex: (int)code;
++ (NSError *)gitErrorForLookupSha: (int)code;
++ (NSError *)gitErrorForMkStr: (int)code;
++ (NSError *)gitErrorForAddTreeEntry: (int)code;
++ (NSError *)gitErrorForNewObject: (int)code;
++ (NSError *)gitErrorForWriteObject: (int)code;
++ (NSError *)gitErrorForRawRead: (int)code;
++ (NSError *)gitErrorForHashObject: (int)code;
++ (NSError *)gitErrorForWriteObjectToDb: (int)code;
++ (NSError *)gitErrorForTreeEntryToObject: (int)code;
++ (NSError *)gitErrorForInitIndex: (int)code;
++ (NSError *)gitErrorForReadIndex: (int)code;
++ (NSError *)gitErrorForIndexStageValue;
++ (NSError *)gitErrorForAddEntryToIndex: (int)code;
++ (NSError *)gitErrorForWriteIndex: (int)code;
+
+@end
178 Classes/Categories/NSError+Git.m
@@ -0,0 +1,178 @@
+//
+// NSError+Git.m
+// ObjectiveGitFramework
+//
+// Created by Timothy Clem on 2/17/11.
+// Copyright 2011 GitHub Inc. All rights reserved.
+//
+
+#import "NSError+Git.h"
+
+static NSString * const GTGitErrorDomain = @"GTGitErrorDomain";
+
+@implementation NSError (Git)
+
++ (NSError *)gitErrorForInitRepository: (int)code {
+
+ return [NSError errorWithDomain:GTGitErrorDomain
+ code:code
+ userInfo:
+ [NSDictionary dictionaryWithObject:@"Failed to init this repository"
+ forKey:NSLocalizedDescriptionKey]];
+}
+
++ (NSError *)gitErrorForOpenRepository: (int)code {
+
+ return [NSError errorWithDomain:GTGitErrorDomain
+ code:code
+ userInfo:
+ [NSDictionary dictionaryWithObject:@"Failed to open this repository"
+ forKey:NSLocalizedDescriptionKey]];
+}
+
++ (NSError *)gitErrorForInitRepoIndex: (int)code {
+
+ return [NSError errorWithDomain:GTGitErrorDomain
+ code:code
+ userInfo:
+ [NSDictionary dictionaryWithObject:@"Failed to get index for this repository"
+ forKey:NSLocalizedDescriptionKey]];
+}
+
++ (NSError *)gitErrorForInitRevWalker: (int)code {
+
+ return [NSError errorWithDomain:GTGitErrorDomain
+ code:code
+ userInfo:
+ [NSDictionary dictionaryWithObject:@"Failed to initialize rev walker"
+ forKey:NSLocalizedDescriptionKey]];
+}
+
++ (NSError *)gitErrorForLookupSha: (int)code {
+
+ return [NSError errorWithDomain:GTGitErrorDomain
+ code:code
+ userInfo:
+ [NSDictionary dictionaryWithObject:@"Failed to lookup sha"
+ forKey:NSLocalizedDescriptionKey]];
+}
+
++ (NSError *)gitErrorForMkStr: (int)code {
+
+ return [NSError errorWithDomain:GTGitErrorDomain
+ code:code
+ userInfo:
+ [NSDictionary dictionaryWithObject:@"Failed to create object id from sha"
+ forKey:NSLocalizedDescriptionKey]];
+}
+
++ (NSError *)gitErrorForAddTreeEntry: (int)code {
+
+ return [NSError errorWithDomain:GTGitErrorDomain
+ code:code
+ userInfo:
+ [NSDictionary dictionaryWithObject:@"Failed to add a new tree entry"
+ forKey:NSLocalizedDescriptionKey]];
+}
+
++ (NSError *)gitErrorForNewObject: (int)code {
+
+ return [NSError errorWithDomain:GTGitErrorDomain
+ code:code
+ userInfo:
+ [NSDictionary dictionaryWithObject:@"Failed to create new object"
+ forKey:NSLocalizedDescriptionKey]];
+}
+
++ (NSError *)gitErrorForWriteObject: (int)code {
+
+ return [NSError errorWithDomain:GTGitErrorDomain
+ code:code
+ userInfo:
+ [NSDictionary dictionaryWithObject:@"Failed to write object"
+ forKey:NSLocalizedDescriptionKey]];
+
+}
+
++ (NSError *)gitErrorForRawRead: (int)code {
+
+ return [NSError errorWithDomain:GTGitErrorDomain
+ code:code
+ userInfo:
+ [NSDictionary dictionaryWithObject:@"Failed to read raw object"
+ forKey:NSLocalizedDescriptionKey]];
+}
+
++ (NSError *)gitErrorForHashObject: (int)code {
+
+ return [NSError errorWithDomain:GTGitErrorDomain
+ code:code
+ userInfo:
+ [NSDictionary dictionaryWithObject:@"Failed to get hash for object"
+ forKey:NSLocalizedDescriptionKey]];
+}
+
++ (NSError *)gitErrorForWriteObjectToDb: (int)code {
+
+ return [NSError errorWithDomain:GTGitErrorDomain
+ code:code
+ userInfo:
+ [NSDictionary dictionaryWithObject:@"Failed to write object to database"
+ forKey:NSLocalizedDescriptionKey]];
+}
+
++ (NSError *)gitErrorForTreeEntryToObject: (int)code {
+
+ return [NSError errorWithDomain:GTGitErrorDomain
+ code:code
+ userInfo:
+ [NSDictionary dictionaryWithObject:@"Failed to get object for tree entry"
+ forKey:NSLocalizedDescriptionKey]];
+}
+
++ (NSError *)gitErrorForInitIndex: (int)code {
+
+ return [NSError errorWithDomain:GTGitErrorDomain
+ code:code
+ userInfo:
+ [NSDictionary dictionaryWithObject:@"Failed to initialize index"
+ forKey:NSLocalizedDescriptionKey]];
+}
+
++ (NSError *)gitErrorForReadIndex: (int)code {
+
+ return [NSError errorWithDomain:GTGitErrorDomain
+ code:code
+ userInfo:
+ [NSDictionary dictionaryWithObject:@"Failed to read index"
+ forKey:NSLocalizedDescriptionKey]];
+}
+
++ (NSError *)gitErrorForIndexStageValue {
+
+ return [NSError errorWithDomain:GTGitErrorDomain
+ code:-1
+ userInfo:
+ [NSDictionary dictionaryWithObject:@"Invalid index stage (must range from 0 to 3)"
+ forKey:NSLocalizedDescriptionKey]];
+}
+
++ (NSError *)gitErrorForAddEntryToIndex: (int)code {
+
+ return [NSError errorWithDomain:GTGitErrorDomain
+ code:code
+ userInfo:
+ [NSDictionary dictionaryWithObject:@"Failed to add entry to index"
+ forKey:NSLocalizedDescriptionKey]];
+}
+
++ (NSError *)gitErrorForWriteIndex: (int)code {
+
+ return [NSError errorWithDomain:GTGitErrorDomain
+ code:code
+ userInfo:
+ [NSDictionary dictionaryWithObject:@"Failed to write index"
+ forKey:NSLocalizedDescriptionKey]];
+}
+
+@end
17 Classes/Categories/NSString+Git.h
@@ -0,0 +1,17 @@
+//
+// NSString+Git.h
+// ObjectiveGitFramework
+//
+// Created by Timothy Clem on 2/18/11.
+// Copyright 2011 GitHub Inc. All rights reserved.
+//
+
+#import <Cocoa/Cocoa.h>
+
+
+@interface NSString (Git)
+
++ (const char*)utf8StringForString:(NSString *)str;
++ (NSString *)stringForUTF8String:(const char*)str;
+
+@end
25 Classes/Categories/NSString+Git.m
@@ -0,0 +1,25 @@
+//
+// NSString+Git.m
+// ObjectiveGitFramework
+//
+// Created by Timothy Clem on 2/18/11.
+// Copyright 2011 GitHub Inc. All rights reserved.
+//
+
+#import "NSString+Git.h"
+
+
+@implementation NSString (Git)
+
+
++ (const char*)utf8StringForString:(NSString *)str {
+
+ return [str cStringUsingEncoding:NSUTF8StringEncoding];
+}
+
++ (NSString *)stringForUTF8String:(const char*)str {
+
+ return [NSString stringWithCString:str encoding:NSUTF8StringEncoding];
+}
+
+@end
21 Classes/GTBlob.h
@@ -0,0 +1,21 @@
+//
+// GTBlob.h
+// ObjectiveGitFramework
+//
+// Created by Timothy Clem on 2/25/11.
+// Copyright 2011 GitHub Inc. All rights reserved.
+//
+
+#import <git2.h>
+#import "GTObject.h"
+
+@interface GTBlob : GTObject {
+
+}
+
+@property (nonatomic, assign, readonly) NSInteger size;
+@property (nonatomic, copy) NSString *content;
+
+- (id)initInRepo:(GTRepository *)theRepo error:(NSError **)error;
+
+@end
50 Classes/GTBlob.m
@@ -0,0 +1,50 @@
+//
+// GTBlob.m
+// ObjectiveGitFramework
+//
+// Created by Timothy Clem on 2/25/11.
+// Copyright 2011 GitHub Inc. All rights reserved.
+//
+
+#import "GTBlob.h"
+#import "NSString+Git.h"
+
+
+@implementation GTBlob
+
+@synthesize size;
+@synthesize content;
+
+- (id)initInRepo:(GTRepository *)theRepo error:(NSError **)error {
+
+ if(self = [super init]) {
+ self.repo = theRepo;
+ self.object = [GTObject getNewObjectInRepo:self.repo.repo type:GIT_OBJ_BLOB error:error];
+ if(self.object == nil)return nil;
+ }
+ return self;
+}
+
+- (git_blob *)blob {
+
+ return (git_blob *)self.object;
+}
+
+- (NSInteger)size {
+
+ return git_blob_rawsize(self.blob);
+}
+
+- (NSString *)content {
+
+ NSInteger s = [self size];
+ if(s == 0) return [NSString stringForUTF8String:""];
+
+ return [NSString stringForUTF8String:git_blob_rawcontent(self.blob)];
+}
+- (void)setContent:(NSString *)newContent {
+
+ git_blob_set_rawcontent(self.blob, [NSString utf8StringForString:newContent], [newContent length]);
+}
+
+@end
28 Classes/GTCommit.h
@@ -0,0 +1,28 @@
+//
+// GTCommit.h
+// ObjectiveGitFramework
+//
+// Created by Timothy Clem on 2/22/11.
+// Copyright 2011 GitHub Inc. All rights reserved.
+//
+
+#import <git2.h>
+#import "GTObject.h"
+
+@class GTSignature;
+@class GTTree;
+
+@interface GTCommit : GTObject {}
+
+@property (nonatomic, assign, readonly) git_commit *commit;
+@property (nonatomic, copy) NSString *message;
+@property (nonatomic, copy, readonly) NSString *messageShort;
+@property (nonatomic, retain, readonly) NSDate *time;
+@property (nonatomic, retain) GTSignature *author;
+@property (nonatomic, retain) GTSignature *commiter;
+@property (nonatomic, retain) GTTree *tree;
+@property (nonatomic, retain, readonly) NSArray *parents;
+
+- (id)initInRepo:(GTRepository *)theRepo error:(NSError **)error;
+
+@end
109 Classes/GTCommit.m
@@ -0,0 +1,109 @@
+//
+// GTCommit.m
+// ObjectiveGitFramework
+//
+// Created by Timothy Clem on 2/22/11.
+// Copyright 2011 GitHub Inc. All rights reserved.
+//
+
+#import "GTCommit.h"
+#import "GTSignature.h"
+#import "GTTree.h"
+#import "NSString+Git.h"
+#import "NSError+Git.h"
+
+@implementation GTCommit
+
+@synthesize commit;
+@synthesize message;
+@synthesize messageShort;
+@synthesize time;
+@synthesize author;
+@synthesize commiter;
+@synthesize tree;
+@synthesize parents;
+
+
+- (id)initInRepo:(GTRepository *)theRepo error:(NSError **)error {
+
+ if(self = [super init]) {
+ self.repo = theRepo;
+ self.object = [GTObject getNewObjectInRepo:self.repo.repo type:GIT_OBJ_COMMIT error:error];
+ if(self.object == nil)return nil;
+ }
+ return self;
+}
+
+- (git_commit *)commit {
+
+ return (git_commit *)self.object;
+}
+
+- (NSString *)message {
+
+ const char *s = git_commit_message(self.commit);
+ return [NSString stringForUTF8String:s];
+}
+- (void)setMessage:(NSString *)m {
+
+ git_commit_set_message(self.commit, [NSString utf8StringForString:m]);
+}
+
+- (NSString *)messageShort {
+
+ const char *s = git_commit_message_short(self.commit);
+ return [NSString stringForUTF8String:s];
+}
+
+- (NSDate *)time {
+
+ time_t t = git_commit_time(self.commit);
+ return [NSDate dateWithTimeIntervalSince1970:t];
+}
+
+- (GTSignature *)author {
+
+ const git_signature *s = git_commit_author(self.commit);
+ return [GTSignature signatureWithSignature:(git_signature *)s];
+}
+- (void)setAuthor:(GTSignature *)a {
+
+ git_commit_set_author(self.commit, a.signature);
+}
+
+- (GTSignature *)commiter {
+
+ const git_signature *s = git_commit_committer(self.commit);
+ return [GTSignature signatureWithSignature:(git_signature *)s];
+}
+- (void)setCommiter:(GTSignature *)c {
+
+ git_commit_set_committer(self.commit, c.signature);
+}
+
+- (GTTree *)tree {
+
+ const git_tree *t = git_commit_tree(self.commit);
+ return t ? (GTTree *)[GTObject objectInRepo:self.repo withObject:(git_object *)t] : nil;
+}
+- (void)setTree:(GTTree *)t {
+
+ git_commit_set_tree(self.commit, t.tree);
+}
+
+- (NSArray *)parents {
+
+ if(parents == nil){
+ NSMutableArray *rents = [[[NSMutableArray alloc] init] autorelease];
+
+ git_commit *parent;
+ for(int i=0; (parent = git_commit_parent(self.commit, i)) != NULL; i++) {
+ [rents addObject:(GTCommit *)[GTObject objectInRepo:self.repo withObject:(git_object *)parent]];
+ }
+
+ parents = [NSArray arrayWithArray:rents];
+ }
+ return parents;
+}
+
+@end
31 Classes/GTIndex.h
@@ -0,0 +1,31 @@
+//
+// GTIndex.h
+// ObjectiveGitFramework
+//
+// Created by Timothy Clem on 2/28/11.
+// Copyright 2011 GitHub Inc. All rights reserved.
+//
+
+#import <git2.h>
+
+@class GTIndexEntry;
+
+@interface GTIndex : NSObject {}
+
+@property (nonatomic, assign) git_index *index;
+@property (nonatomic, copy) NSURL *path;
+@property (nonatomic, assign) NSInteger entryCount;
+
++ (id)indexWithPath:(NSURL *)localFileUrl error:(NSError **)error;
+- (id)initWithPath:(NSURL *)localFileUrl error:(NSError **)error;
++ (id)indexWithIndex:(git_index *)theIndex;
+- (id)initWithGitIndex:(git_index *)theIndex;
+- (void)refreshAndReturnError:(NSError **)error;
+- (void)clear;
+- (GTIndexEntry *)getEntryAtIndex:(NSInteger)theIndex;
+- (GTIndexEntry *)getEntryWithName:(NSString *)name;
+- (void)addEntry:(GTIndexEntry *)entry error:(NSError **)error;
+- (void)addFile:(NSString *)file error:(NSError **)error;
+- (void)writeAndReturnError:(NSError **)error;
+
+@end
117 Classes/GTIndex.m
@@ -0,0 +1,117 @@
+//
+// GTIndex.m
+// ObjectiveGitFramework
+//
+// Created by Timothy Clem on 2/28/11.
+// Copyright 2011 GitHub Inc. All rights reserved.
+//
+
+#import "GTIndex.h"
+#import "GTIndexEntry.h"
+#import "NSString+Git.h"
+#import "NSError+Git.h"
+
+@implementation GTIndex
+
+@synthesize index;
+@synthesize path;
+@synthesize entryCount;
+
+#pragma mark -
+#pragma mark Initialization
+
++ (id)indexWithPath:(NSURL *)localFileUrl error:(NSError **)error {
+
+ return [[[GTIndex alloc] initWithPath:localFileUrl error:error] autorelease];
+}
+
+- (id)initWithPath:(NSURL *)localFileUrl error:(NSError **)error {
+
+ if(self = [super init]) {
+ self.path = localFileUrl;
+ git_index *i;
+ int gitError = git_index_open_bare(&i, [NSString utf8StringForString:[self.path path]]);
+ if(gitError != GIT_SUCCESS) {
+ if(error != NULL)
+ *error = [NSError gitErrorForInitIndex:gitError];
+ return nil;
+ }
+ self.index = i;
+ }
+ return self;
+}
+
++ (id)indexWithIndex:(git_index *)theIndex {
+
+ return [[[GTIndex alloc] initWithGitIndex:theIndex] autorelease];
+}
+
+- (id)initWithGitIndex:(git_index *)theIndex; {
+
+ if(self = [super init]){
+ self.index = theIndex;
+ }
+ return self;
+}
+
+#pragma mark -
+#pragma mark API
+
+- (NSInteger)entryCount {
+
+ return git_index_entrycount(self.index);
+}
+
+- (void)refreshAndReturnError:(NSError **)error {
+
+ int gitError = git_index_read(self.index);
+ if(gitError != GIT_SUCCESS) {
+ if(error != NULL)
+ *error = [NSError gitErrorForReadIndex:gitError];
+ }
+}
+
+- (void)clear {
+
+ git_index_clear(self.index);
+}
+
+- (GTIndexEntry *)getEntryAtIndex:(NSInteger)theIndex {
+
+ return [GTIndexEntry indexEntryWithEntry:git_index_get(self.index, theIndex)];
+}
+
+- (GTIndexEntry *)getEntryWithName:(NSString *)name {
+
+ int i = git_index_find(self.index, [NSString utf8StringForString:name]);
+ return [GTIndexEntry indexEntryWithEntry:git_index_get(self.index, i)];
+}
+
+- (void)addEntry:(GTIndexEntry *)entry error:(NSError **)error {
+
+ int gitError = git_index_insert(self.index, entry.entry);
+ if(gitError != GIT_SUCCESS){
+ if(error != NULL)
+ *error = [NSError gitErrorForAddEntryToIndex:gitError];
+ }
+}
+
+- (void)addFile:(NSString *)file error:(NSError **)error {
+
+ int gitError = git_index_add(self.index, [NSString utf8StringForString:file], 0);
+ if(gitError != GIT_SUCCESS){
+ if(error != NULL)
+ *error = [NSError gitErrorForAddEntryToIndex:gitError];
+ }
+}
+
+- (void)writeAndReturnError:(NSError **)error {
+
+ int gitError = git_index_write(self.index);
+ if(gitError != GIT_SUCCESS){
+ if(error != NULL)
+ *error = [NSError gitErrorForWriteIndex:gitError];
+ }
+}
+
+@end
34 Classes/GTIndexEntry.h
@@ -0,0 +1,34 @@
+//
+// GTIndexEntry.h
+// ObjectiveGitFramework
+//
+// Created by Timothy Clem on 2/28/11.
+// Copyright 2011 GitHub Inc. All rights reserved.
+//
+
+#import <git2.h>
+
+
+@interface GTIndexEntry : NSObject {
+
+}
+
+@property (nonatomic, assign) git_index_entry *entry;
+@property (nonatomic, copy) NSString *path;
+@property (nonatomic, copy) NSString *sha;
+@property (nonatomic, copy) NSDate *mTime;
+@property (nonatomic, copy) NSDate *cTime;
+@property (nonatomic, assign) long long fileSize;
+@property (nonatomic, assign) NSUInteger dev;
+@property (nonatomic, assign) NSUInteger ino;
+@property (nonatomic, assign) NSUInteger mode;
+@property (nonatomic, assign) NSUInteger uid;
+@property (nonatomic, assign) NSUInteger gid;
+@property (nonatomic, assign) NSUInteger flags;
+@property (nonatomic, assign) NSUInteger stage;
+@property (nonatomic, assign, readonly) BOOL isValid;
+
++ (id)indexEntryWithEntry:(git_index_entry *)theEntry;
+- (id)initWithEntry:(git_index_entry *)theEntry;
+
+@end
154 Classes/GTIndexEntry.m
@@ -0,0 +1,154 @@
+//
+// GTIndexEntry.m
+// ObjectiveGitFramework
+//
+// Created by Timothy Clem on 2/28/11.
+// Copyright 2011 GitHub Inc. All rights reserved.
+//
+
+#import "GTIndexEntry.h"
+#import "NSString+Git.h"
+#import "NSError+Git.h"
+
+@implementation GTIndexEntry
+
+@synthesize entry;
+@synthesize path;
+@synthesize sha;
+@synthesize mTime;
+@synthesize cTime;
+@synthesize fileSize;
+@synthesize dev;
+@synthesize ino;
+@synthesize mode;
+@synthesize uid;
+@synthesize gid;
+@synthesize flags;
+@synthesize stage;
+@synthesize isValid;
+
+
++ (id)indexEntryWithEntry:(git_index_entry *)theEntry {
+
+ return [[[GTIndexEntry alloc] initWithEntry:theEntry] autorelease];
+}
+
+- (id)initWithEntry:(git_index_entry *)theEntry {
+
+ if(self = [super init]) {
+ self.entry = theEntry;
+ }
+ return self;
+}
+
+- (id)init {
+
+ if(self = [super init]) {
+ self.entry = malloc(sizeof(git_index_entry));
+ memset(self.entry, 0x0, sizeof(git_index_entry));
+ }
+ return self;
+}
+
+- (NSString *)path {
+
+ if(self.entry->path == NULL)return nil;
+ return [NSString stringForUTF8String:self.entry->path];
+}
+- (void)setPath:(NSString *)thePath {
+
+ if(self.entry->path != NULL)
+ free(self.entry->path);
+
+ entry->path = (char *)[NSString utf8StringForString:thePath];
+}
+
+- (NSString *)sha {
+
+ char hex[41];
+ git_oid_fmt(hex, &entry->oid);
+ hex[40] = 0;
+ return [NSString stringForUTF8String:hex];
+}
+- (void)setSha:(NSString *)theSha{
+
+ git_oid_mkstr(&entry->oid, [NSString utf8StringForString:theSha]);
+// if(gitError != GIT_SUCCESS){
+// if(error != NULL)
+// *error = [NSError gitErrorForMkStr:gitError];
+// }
+}
+
+- (NSDate *)mTime {
+
+ double time = self.entry->mtime.seconds + (self.entry->mtime.nanoseconds/1000);
+ return [NSDate dateWithTimeIntervalSince1970:time];
+}
+- (void)setMTime:(NSDate *)time {
+
+ NSTimeInterval t = [time timeIntervalSince1970];
+ self.entry->mtime.seconds = (int)t;
+ self.entry->mtime.nanoseconds = 1000 * (t - (int)t);
+}
+
+- (NSDate *)cTime {
+
+ double time = self.entry->ctime.seconds + (self.entry->ctime.nanoseconds/1000);
+ return [NSDate dateWithTimeIntervalSince1970:time];
+}
+- (void)setCTime:(NSDate *)time {
+
+ NSTimeInterval t = [time timeIntervalSince1970];
+ self.entry->ctime.seconds = (int)t;
+ self.entry->ctime.nanoseconds = 1000 * (t - (int)t);
+}
+
+- (long long)fileSize { return self.entry->file_size; }
+- (void)setFileSize:(long long) size { self.entry->file_size = size; }
+
+- (NSUInteger)dev { return self.entry->dev; }
+- (void)setDev:(NSUInteger)theDev { self.entry->dev = theDev; }
+
+- (NSUInteger)ino { return self.entry->ino; }
+- (void)setIno:(NSUInteger)theIno { self.entry->ino = theIno; }
+
+- (NSUInteger)mode { return self.entry->mode; }
+- (void)setMode:(NSUInteger)theMode { self.entry->mode = theMode; }
+
+- (NSUInteger)uid { return self.entry->uid; }
+- (void)setUid:(NSUInteger)theUid { self.entry->uid = theUid; }
+
+- (NSUInteger)gid { return self.entry->gid; }
+- (void)setGid:(NSUInteger)theGid { self.entry->gid = theGid; }
+
+- (NSUInteger)flags {
+
+ return (self.entry->flags & 0xFFFF) | (self.entry->flags_extended << 16);
+}
+- (void)setFlags:(NSUInteger)theFlags {
+
+ self.entry->flags = (unsigned short)(theFlags & 0xFFFF);
+ self.entry->flags_extended = (unsigned short)((theFlags >> 16) & 0xFFFF);
+}
+
+- (BOOL)isValid {
+ return (self.flags & GIT_IDXENTRY_VALID) != 0;
+}
+
+- (NSUInteger)stage {
+
+ return (self.entry->flags & GIT_IDXENTRY_STAGEMASK) >> GIT_IDXENTRY_STAGESHIFT;
+}
+- (void)setStage:(NSUInteger)theStage {
+
+ if(theStage < 0 || theStage > 3){
+ return;
+// if(error != NULL)
+// *error = [NSError gitErrorForIndexStageValue];
+ }
+
+ self.entry->flags &= ~GIT_IDXENTRY_STAGEMASK;
+ self.entry->flags |= (theStage << GIT_IDXENTRY_STAGESHIFT);
+}
+
+@end
17 Classes/GTLib.h
@@ -0,0 +1,17 @@
+//
+// GTLib.h
+// ObjectiveGitFramework
+//
+// Created by Timothy Clem on 2/18/11.
+// Copyright 2011 GitHub Inc. All rights reserved.
+//
+
+
+@interface GTLib : NSObject {
+
+}
+
++ (NSData *)hexToRaw:(NSString *)hex;
++ (NSString *)rawToHex:(NSData *)raw;
+
+@end
36 Classes/GTLib.m
@@ -0,0 +1,36 @@
+//
+// GTLib.m
+// ObjectiveGitFramework
+//
+// Created by Timothy Clem on 2/18/11.
+// Copyright 2011 GitHub Inc. All rights reserved.
+//
+
+#import <git2.h>
+#import "GTLib.h"
+#import "NSString+Git.h"
+
+
+@implementation GTLib
+
++ (NSData *)hexToRaw:(NSString *)hex {
+
+ git_oid oid;
+ git_oid_mkstr(&oid, [NSString utf8StringForString:hex]);
+
+ return [NSData dataWithBytes:oid.id length:20];
+}
+
++ (NSString *)rawToHex:(NSData *)raw {
+
+ git_oid oid;
+ char hex[41];
+
+ git_oid_mkraw(&oid, [raw bytes]);
+ git_oid_fmt(hex, &oid);
+ hex[40] = 0;
+
+ return [NSString stringForUTF8String:hex];
+}
+
+@end
35 Classes/GTObject.h
@@ -0,0 +1,35 @@
+//
+// GTObject.h
+// ObjectiveGitFramework
+//
+// Created by Timothy Clem on 2/22/11.
+// Copyright 2011 GitHub Inc. All rights reserved.
+//
+
+#import <git2.h>
+#import "GTRepository.h"
+
+/*typedef enum {
+ Commit = 1,
+ Tree = 2,
+ Blob = 3,
+ Tag = 4
+} GTObjectType;*/
+
+@interface GTObject : NSObject {}
+
+@property (nonatomic, copy, readonly) NSString *type;
+@property (nonatomic, copy, readonly) NSString *sha;
+@property (nonatomic, assign) git_object *object;
+@property (nonatomic, retain) GTRepository *repo;
+
++ (git_object *)getNewObjectInRepo:(git_repository *)r type:(git_otype)theType error:(NSError **)error;
++ (git_object *)getNewObjectInRepo:(git_repository *)r sha:(NSString *)sha type:(git_otype)theType error:(NSError **)error;
+
++ (id)objectInRepo:(GTRepository *)theRepo withObject:(git_object *)theObject;
+- (id)initInRepo:(GTRepository *)theRepo withObject:(git_object *)theObject;
+- (NSString *)writeAndReturnError:(NSError **)error;
+- (GTRawObject *)readRawAndReturnError:(NSError **)error;
+
+@end
+
138 Classes/GTObject.m
@@ -0,0 +1,138 @@
+//
+// GTObject.m
+// ObjectiveGitFramework
+//
+// Created by Timothy Clem on 2/22/11.
+// Copyright 2011 GitHub Inc. All rights reserved.
+//
+
+#import "GTObject.h"
+#import "GTCommit.h"
+#import "GTRawObject.h"
+#import "NSError+Git.h"
+#import "NSString+Git.h"
+
+static NSString * const GTCommitClassName = @"GTCommit";
+static NSString * const GTTreeClassName = @"GTTree";
+static NSString * const GTBlobClassName = @"GTBlob";
+static NSString * const GTObjectClassName = @"GTObject";
+static NSString * const GTTagClassName = @"GTTag";
+
+@implementation GTObject
+
+@synthesize type;
+@synthesize sha;
+
+@synthesize object;
+@synthesize repo;
+
++ (id)objectInRepo:(GTRepository *)theRepo withObject:(git_object *)theObject {
+
+ NSString *klass;
+ git_otype t = git_object_type(theObject);
+ switch (t) {
+ case GIT_OBJ_COMMIT:
+ klass = GTCommitClassName;
+ break;
+ case GIT_OBJ_TREE:
+ klass = GTTreeClassName;
+ break;
+ case GIT_OBJ_BLOB:
+ klass = GTBlobClassName;
+ break;
+ case GIT_OBJ_TAG:
+ klass = GTTagClassName;
+ break;
+ default:
+ klass = GTObjectClassName;
+ break;
+ }
+
+ return [[[NSClassFromString(klass) alloc] initInRepo:theRepo withObject:theObject] autorelease];
+}
+
+- (id)initInRepo:(GTRepository *)theRepo withObject:(git_object *)theObject {
+
+ if(self = [super init]){
+ self.repo = theRepo;
+ self.object = theObject;
+ }
+ return self;
+}
+
++ (git_object *)getNewObjectInRepo:(git_repository *)r type:(git_otype)theType error:(NSError **)error {
+
+ git_object *obj;
+ int gitError = git_repository_newobject(&obj, r, theType);
+ if(gitError != GIT_SUCCESS) {
+ if(error != NULL)
+ *error = [NSError gitErrorForNewObject:gitError];
+ return nil;
+ }
+ return obj;
+}
+
++ (git_object *)getNewObjectInRepo:(git_repository *)r sha:(NSString *)sha type:(git_otype)theType error:(NSError **)error {
+
+ git_object *obj = NULL;
+ git_oid oid;
+ git_oid_mkstr(&oid, [NSString utf8StringForString:sha]);
+ int gitError = git_repository_lookup(&obj, r, &oid, theType);
+ if(gitError != GIT_SUCCESS){
+ if(error != NULL)
+ *error = [NSError gitErrorForLookupSha:gitError];
+ return nil;
+ }
+ NSAssert(obj, @"Failed to lookup git_object from repo");
+ return obj;
+}
+
+- (NSString *)type {
+
+ return [NSString stringForUTF8String:git_object_type2string(git_object_type(self.object))];
+}
+
+- (NSString *)sha {
+
+ char hex[41];
+ git_oid_fmt(hex, git_object_id(self.object));
+ hex[40] = 0;
+ return [NSString stringForUTF8String:hex];
+}
+
+- (NSString *)writeAndReturnError:(NSError **)error {
+
+ int gitError = git_object_write(self.object);
+ if(gitError != GIT_SUCCESS){
+ if(error != NULL)
+ *error = [NSError gitErrorForWriteObject:gitError];
+ return nil;
+ }
+ return self.sha;
+}
+
+- (GTRawObject *)readRawAndReturnError:(NSError **)error {
+
+ return [self.repo rawRead:git_object_id(self.object) error:error];
+}
+
+- (NSUInteger)hash {
+ return [self.sha hash];
+}
+
+- (BOOL)isEqual:(id)otherObject {
+ if(![otherObject isKindOfClass:[GTObject class]]) return NO;
+
+ return 0 == git_oid_cmp(git_object_id(self.object), git_object_id(((GTObject *)otherObject).object)) ? YES : NO;
+}
+
+// Do NOT call git_object_free()
+// The object is owned by the repo and will be
+// garbage collected when the repo is freed
+/*- (void)finalize {
+
+ git_object_free(object);
+ [super finalize];
+}*/
+
+@end
22 Classes/GTRawObject.h
@@ -0,0 +1,22 @@
+//
+// GTRawObject.h
+// ObjectiveGitFramework
+//
+// Created by Timothy Clem on 2/24/11.
+// Copyright 2011 GitHub Inc. All rights reserved.
+//
+
+#import <git2.h>
+
+@interface GTRawObject : NSObject {}
+
+@property (nonatomic, assign) git_otype type;
+@property (nonatomic, copy) NSData *data;
+
++ (id)rawObjectWithType:(git_otype)theType data:(NSData *)theData;
++ (id)rawObjectWithType:(git_otype)theType string:(NSString *)string;
+- (id)initWithType:(git_otype)theType data:(NSData *)theData;
+- (id)initWithType:(git_otype)theType string:(NSString *)string;
+- (NSString *)dataAsUTF8String;
+
+@end
52 Classes/GTRawObject.m
@@ -0,0 +1,52 @@
+//
+// GTRawObject.m
+// ObjectiveGitFramework
+//
+// Created by Timothy Clem on 2/24/11.
+// Copyright 2011 GitHub Inc. All rights reserved.
+//
+
+#import "GTRawObject.h"
+#import "NSString+Git.h"
+
+@implementation GTRawObject
+
+@synthesize type;
+@synthesize data;
+
++ (id)rawObjectWithType:(git_otype)theType data:(NSData *)theData {
+
+ return [[[GTRawObject alloc] initWithType:theType data:theData] autorelease];
+}
+
++ (id)rawObjectWithType:(git_otype)theType string:(NSString *)string {
+
+ return [[[GTRawObject alloc] initWithType:theType string:string] autorelease];
+}
+
+- (id)initWithType:(git_otype)theType data:(NSData *)theData {
+
+ if(self = [super init]) {
+ self.type = theType;
+ self.data = theData;
+ }
+ return self;
+}
+
+- (id)initWithType:(git_otype)theType string:(NSString *)string {
+
+ if(self = [super init]) {
+ self.type = theType;
+ self.data = [string dataUsingEncoding:NSUTF8StringEncoding];
+ }
+ return self;
+}
+
+- (NSString *)dataAsUTF8String {
+
+ if(!self.data) return nil;
+
+ return [NSString stringWithUTF8String:[data bytes]];
+}
+
+@end
41 Classes/GTRepository.h
@@ -0,0 +1,41 @@
+//
+// GTRepository.h
+// ObjectiveGitFramework
+//
+// Created by Timothy Clem on 2/17/11.
+// Copyright 2011 GitHub Inc. All rights reserved.
+//
+
+#import <git2.h>
+
+@class GTWalker;
+@class GTObject;
+@class GTRawObject;
+@class GTCommit;
+@class GTIndex;
+
+@interface GTRepository : NSObject {}
+
+@property (nonatomic, assign) git_repository *repo;
+@property (nonatomic, retain) NSURL *fileUrl;
+@property (nonatomic, retain) GTWalker *walker;
+@property (nonatomic, retain) GTIndex *index;
+
++ (id)repoByOpeningRepositoryInDirectory:(NSURL *)localFileUrl error:(NSError **)error;
++ (id)repoByCreatingRepositoryInDirectory:(NSURL *)localFileUrl error:(NSError **)error;
+- (id)initByOpeningRepositoryInDirectory:(NSURL *)localFileUrl error:(NSError **)error;
+- (id)initByCreatingRepositoryInDirectory:(NSURL *)localFileUrl error:(NSError **)error;
+
++ (NSString *)hash:(GTRawObject *)rawObj error:(NSError **)error;
+
+- (GTObject *)lookup:(NSString *)sha error:(NSError **)error;
+- (BOOL)exists:(NSString *)sha;
+- (BOOL)hasObject:(NSString *)sha;
+- (GTRawObject *)rawRead:(const git_oid *)oid error:(NSError **)error;
+- (GTRawObject *)read:(NSString *)sha error:(NSError **)error;
+- (NSString *)write:(GTRawObject *)rawObj error:(NSError **)error;
+- (void)walk:(NSString *)sha sorting:(unsigned int)sortMode error:(NSError **)error block:(void (^)(GTCommit *commit))block;
+- (void)walk:(NSString *)sha error:(NSError **)error block:(void (^)(GTCommit *commit))block;
+- (void)setupIndexAndReturnError:(NSError **)error;
+
+@end
258 Classes/GTRepository.m
@@ -0,0 +1,258 @@
+//
+// GTRepository.m
+// ObjectiveGitFramework
+//
+// Created by Timothy Clem on 2/17/11.
+// Copyright 2011 GitHub Inc. All rights reserved.
+//
+
+#import "GTRepository.h"
+#import "GTWalker.h"
+#import "GTObject.h"
+#import "GTCommit.h"
+#import "GTRawObject.h"
+#import "NSError+Git.h"
+#import "NSString+Git.h"
+#import "GTIndex.h"
+
+@interface GTRepository ()
+@end
+
+
+@implementation GTRepository
+
+@synthesize repo;
+@synthesize fileUrl;
+@synthesize walker;
+@synthesize index;
+
++ (id)repoByOpeningRepositoryInDirectory:(NSURL *)localFileUrl error:(NSError **)error {
+ return [[[GTRepository alloc]initByOpeningRepositoryInDirectory:localFileUrl error:error] autorelease];
+}
+
++ (id)repoByCreatingRepositoryInDirectory:(NSURL *)localFileUrl error:(NSError **)error {
+ return [[[GTRepository alloc]initByCreatingRepositoryInDirectory:localFileUrl error:error] autorelease];
+}
+
+- (id)initByOpeningRepositoryInDirectory:(NSURL *)localFileUrl error:(NSError **)error {
+
+ if(self = [super init]){
+
+ self.fileUrl = localFileUrl;
+
+ GTLog("Opening repository in directory: %@", localFileUrl);
+
+ const char *path;
+ if([[localFileUrl path] hasSuffix:@".git"]) {
+ path = [NSString utf8StringForString:[localFileUrl path]];
+ } else {
+ path = [NSString utf8StringForString:[NSString stringWithFormat:@"%@/.git", [localFileUrl path]]];
+ }
+
+ git_repository *r;
+ int gitError = git_repository_open(&r, path);
+ if(gitError != GIT_SUCCESS) {
+ if(error != NULL)
+ *error = [NSError gitErrorForOpenRepository:gitError];
+ return nil;
+ }
+ self.repo = r;
+
+ self.walker = [[[GTWalker alloc] initWithRepository:self error:error] autorelease];
+ if(self.walker == nil) return nil;
+ }
+ return self;
+}
+
+- (id)initByCreatingRepositoryInDirectory:(NSURL *)localFileUrl error:(NSError **)error {
+
+ if(self = [super init]){
+
+ self.fileUrl = localFileUrl;
+
+ GTLog("Creating repository in directory: %@", localFileUrl);
+
+ git_repository *r;
+ const char * path = [NSString utf8StringForString:[localFileUrl path]];
+ int gitError = git_repository_init(&r, path, 0);
+ if(gitError != GIT_SUCCESS) {
+ if(error != NULL)
+ *error = [NSError gitErrorForInitRepository:gitError];
+ return nil;
+ }
+ self.repo = r;
+
+ self.walker = [[[GTWalker alloc] initWithRepository:self error:error] autorelease];
+ if(self.walker == nil) return nil;
+ }
+ return self;
+}
+
+#pragma mark -
+#pragma mark API
+
++ (void)mapRawObject:(GTRawObject *)rawObj toObject:(git_rawobj *)obj {
+
+ obj->type = rawObj.type;
+ obj->len = 0;
+ obj->data = NULL;
+ if (rawObj.data != nil) {
+ obj->len = [rawObj.data length];
+ obj->data = malloc(obj->len);
+ memcpy(obj->data, [rawObj.data bytes], obj->len);
+ }
+}
+
++ (NSString *)shaForOid:(git_oid)oid {
+
+ char hex[41];
+ git_oid_fmt(hex, &oid);
+ hex[40] = 0;
+ return [NSString stringWithCString:hex encoding:NSUTF8StringEncoding];
+}
+
++ (NSString *)hash:(GTRawObject *)rawObj error:(NSError **)error {
+
+ git_rawobj obj;
+ git_oid oid;
+
+ [GTRepository mapRawObject:rawObj toObject:&obj];
+
+ int gitError = git_rawobj_hash(&oid, &obj);
+ if(gitError != GIT_SUCCESS){
+ if (error != NULL)
+ *error = [NSError gitErrorForHashObject:gitError];
+ return nil;
+ }
+
+ return [GTRepository shaForOid:oid];
+}
+
+#pragma mark -
+#pragma mark Properties
+
+- (GTObject *)lookup:(NSString *)sha error:(NSError **)error {
+
+ git_otype type = GIT_OBJ_ANY;
+ git_oid oid;
+ git_object *obj;
+
+ git_oid_mkstr(&oid, [NSString utf8StringForString:sha]);
+ int gitError = git_repository_lookup(&obj, self.repo, &oid, type);
+ if(gitError != GIT_SUCCESS){
+ if(error != NULL)
+ *error = [NSError gitErrorForLookupSha:gitError];
+ return nil;
+ }
+
+ return [GTObject objectInRepo:self withObject:obj];
+}
+- (BOOL)exists:(NSString *)sha {
+ return [self hasObject:sha];
+}
+- (BOOL)hasObject:(NSString *)sha {
+
+ git_odb *odb;
+ git_oid oid;
+
+ odb = git_repository_database(self.repo);
+ git_oid_mkstr(&oid, [NSString utf8StringForString:sha]);
+
+ return git_odb_exists(odb, &oid) ? YES : NO;
+}
+
+- (GTRawObject *)newRawObject:(const git_rawobj *)obj {
+
+ return [[GTRawObject rawObjectWithType:obj->type data:[NSData dataWithBytes:obj->data length:obj->len]] autorelease];
+}
+
+- (GTRawObject *)rawRead:(const git_oid *)oid error:(NSError **)error {
+
+ git_odb *odb;
+ git_rawobj obj;
+
+ odb = git_repository_database(self.repo);
+ int gitError = git_odb_read(&obj, odb, oid);
+ if(gitError != GIT_SUCCESS) {
+ if(error != NULL)
+ *error = [NSError gitErrorForRawRead:gitError];
+ return nil;
+ }
+
+ GTRawObject *rawObj = [self newRawObject:&obj];
+ git_rawobj_close(&obj);
+
+ return rawObj;
+}
+
+- (GTRawObject *)read:(NSString *)sha error:(NSError **)error {
+
+ git_oid oid;
+ int gitError = git_oid_mkstr(&oid, [NSString utf8StringForString:sha]);
+ if(gitError != GIT_SUCCESS) {
+ if (error != NULL)
+ *error = [NSError gitErrorForMkStr:gitError];
+ return nil;
+ }
+ return [self rawRead:&oid error:error];
+}
+
+- (NSString *)write:(GTRawObject *)rawObj error:(NSError **)error {
+
+ git_odb *odb;
+ git_rawobj obj;
+ git_oid oid;
+
+ odb = git_repository_database(self.repo);
+
+ [GTRepository mapRawObject:rawObj toObject:&obj];
+ int gitError = git_odb_write(&oid, odb, &obj);
+ git_rawobj_close(&obj);
+ if(gitError != GIT_SUCCESS) {
+ if(error != NULL)
+ *error = [NSError gitErrorForWriteObjectToDb:gitError];
+ return nil;
+ }
+
+ return [GTRepository shaForOid:oid];
+}
+
+- (void)walk:(NSString *)sha sorting:(unsigned int)sortMode error:(NSError **)error block:(void (^)(GTCommit *commit))block {
+
+ if(block == nil)return;
+
+ [self.walker sorting:sortMode];
+ [self.walker push:sha error:error];
+
+ GTCommit *commit = nil;
+ while((commit = [self.walker next]) != nil){
+ block(commit);
+ }
+}
+
+- (void)walk:(NSString *)sha error:(NSError **)error block:(void (^)(GTCommit *commit))block {
+
+ [self walk:sha sorting:GIT_SORT_TIME error:error block:block];
+}
+
+- (void)setupIndexAndReturnError:(NSError **)error {
+
+ git_index *i;
+ int gitError = git_repository_index(&i, self.repo);
+ if(gitError != GIT_SUCCESS) {
+ if(error != NULL)
+ *error = [NSError gitErrorForInitRepoIndex:gitError];
+ }
+ else {
+ self.index = [[GTIndex indexWithIndex:i] autorelease];
+ }
+}
+
+- (void)finalize {
+
+ // TODO: Gotta figure out all this memory management crap
+ //git_repository_free(repo);
+ [super finalize];
+}
+
+@end
25 Classes/GTSignature.h
@@ -0,0 +1,25 @@
+//
+// GTSignature.h
+// ObjectiveGitFramework
+//
+// Created by Timothy Clem on 2/22/11.
+// Copyright 2011 GitHub Inc. All rights reserved.
+//
+
+#import <git2.h>
+#import "GTObject.h"
+
+@interface GTSignature : NSObject {}
+
+@property (nonatomic, assign) git_signature *signature;
+
+@property (nonatomic, copy) NSString *name;
+@property (nonatomic, copy) NSString *email;
+@property (nonatomic, retain) NSDate *time;
+
++ (id)signatureWithSignature:(git_signature *)theSignature;
+- (id)initWithSignature:(git_signature *)theSignature;
++ (id)signatureWithName:(NSString *)theName email:(NSString *)theEmail time:(NSDate *)theTime;
+- (id)initWithName:(NSString *)theName email:(NSString *)theEmail time:(NSDate *)theTime;
+
+@end
98 Classes/GTSignature.m
@@ -0,0 +1,98 @@
+//
+// GTSignature.m
+// ObjectiveGitFramework
+//
+// Created by Timothy Clem on 2/22/11.
+// Copyright 2011 GitHub Inc. All rights reserved.
+//
+
+#import "GTSignature.h"
+#import "NSString+Git.h"
+
+@implementation GTSignature
+
+@synthesize signature;
+@synthesize name;
+@synthesize email;
+@synthesize time;
+
++ (id)signatureWithSignature:(git_signature *)theSignature {
+ return [[[GTSignature alloc] initWithSignature:theSignature] autorelease];
+}
+
+- (id)initWithSignature:(git_signature *)theSignature {
+
+ if(self = [self init]) {
+ self.signature = theSignature;
+ }
+ return self;
+}
+
++ (id)signatureWithName:(NSString *)theName email:(NSString *)theEmail time:(NSDate *)theTime {
+ return [[[GTSignature alloc] initWithName:theName email:theEmail time:theTime] autorelease];
+}
+- (id)initWithName:(NSString *)theName email:(NSString *)theEmail time:(NSDate *)theTime {
+
+ if(self = [super init]) {
+ self.signature = git_signature_new(
+ [NSString utf8StringForString:theName],
+ [NSString utf8StringForString:theEmail],
+ [theTime timeIntervalSince1970],
+ 0);
+ // tclem todo: figure out offset for NSDate
+ }
+ return self;
+}
+
+- (NSString *)name {
+
+ return [NSString stringForUTF8String:self.signature->name];
+}
+- (void)setName:(NSString *)n {
+
+ free(self.signature->name);
+ self.signature->name = strdup([n cStringUsingEncoding:NSUTF8StringEncoding]);
+}
+
+- (NSString *)email {
+
+ return [NSString stringForUTF8String:self.signature->email];
+}
+- (void)setEmail:(NSString *)e {
+
+ free(self.signature->email);
+ self.signature->email = strdup([e cStringUsingEncoding:NSUTF8StringEncoding]);
+}
+
+- (NSDate *)time {
+
+ return [NSDate dateWithTimeIntervalSince1970:self.signature->when.time];
+}
+- (void)setTime:(NSDate *)d {
+
+ self.signature->when.time = [d timeIntervalSince1970];
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"\
+ \n\t %@ \
+ \n\t name = %@ \
+ \n\t email = %@ \
+ \n\t time = %@ \
+ ",
+ NSStringFromClass([self class]),
+ self.name,
+ self.email,
+ self.time
+ ];
+}
+
+
+- (void)finalize {
+
+ git_signature_free(signature);
+ [super finalize];
+}
+
+
+@end
25 Classes/GTTag.h
@@ -0,0 +1,25 @@
+//
+// GTTag.h
+// ObjectiveGitFramework
+//
+// Created by Timothy Clem on 2/28/11.
+// Copyright 2011 GitHub Inc. All rights reserved.
+//
+
+#import <git2.h>
+#import "GTObject.h"
+
+@class GTSignature;
+
+@interface GTTag : GTObject {
+
+}
+
+@property (nonatomic, assign) git_tag *tag;
+@property (nonatomic, copy) NSString *message;
+@property (nonatomic, copy) NSString *name;
+@property (nonatomic, retain) GTObject *target;
+@property (nonatomic, copy) NSString *targetType;
+@property (nonatomic, retain) GTSignature *tagger;
+
+@end
68 Classes/GTTag.m
@@