Guest User

Untitled

a guest
May 5th, 2018
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.39 KB | None | 0 0
  1. comparing with ../sumatra_hg
  2. searching for changes
  3. changeset: 75:9b5eb05b435b
  4. user: Michele Mattioni <mattioni@ebi.ac.uk>
  5. date: Mon Mar 29 11:14:21 2010 +0100
  6. summary: Initial work to support git repositories.
  7.  
  8. diff -r 5ff03559f848 -r 9b5eb05b435b src/versioncontrol/_git.py
  9. --- /dev/null Thu Jan 01 00:00:00 1970 +0000
  10. +++ b/src/versioncontrol/_git.py Mon Mar 29 11:14:21 2010 +0100
  11. @@ -0,0 +1,113 @@
  12. +"""
  13. +Defines the Sumatra version control interface for Git.
  14. +Based (heavily) on the Mercurial class
  15. +
  16. +Classes
  17. +-------
  18. +
  19. +GitWorkingCopy
  20. +GitRepository
  21. +
  22. +Functions
  23. +---------
  24. +
  25. +may_have_working_copy() - determine whether a .git subdirectory exists at a given
  26. + path
  27. +get_working_copy() - return a GitWorkingCopy object for a given path
  28. +get_repository() - return a GitRepository object for a given URL.
  29. +"""
  30. +
  31. +#from mercurial import hg, ui, patch
  32. +
  33. +import git
  34. +import os
  35. +import binascii
  36. +
  37. +from base import Repository, WorkingCopy
  38. +
  39. +
  40. +def may_have_working_copy(path=None):
  41. + path = path or os.getcwd()
  42. + if git.cmd.is_git_dir(path):
  43. + #return os.path.exists(os.path.join(path, ".git"))
  44. + return path
  45. +
  46. +def get_working_copy(path=None):
  47. + return GitWorkingCopy(path)
  48. +
  49. +def get_repository(url):
  50. + return GitRepository(url)
  51. +
  52. +
  53. +class GitWorkingCopy(WorkingCopy):
  54. +
  55. + def __init__(self, path=None):
  56. + self.path = path or os.getcwd()
  57. + self.repository = GitRepository(self.path)
  58. + self.repository.working_copy = self
  59. +
  60. + def current_version(self):# TODO Check
  61. + if hasattr(self.repository._repository, 'workingctx'): # handle different versions of Mercurial
  62. + ctx = self.repository._repository.workingctx().parents()[0]
  63. + else:
  64. + ctx = self.repository._repository.parents()[0]
  65. + return binascii.hexlify(ctx.node()[:6])
  66. +
  67. + def use_version(self, version):
  68. + assert not self.has_changed()
  69. + hg.clean(self.repository._repository, version)
  70. +
  71. + def use_latest_version(self):
  72. + # any changes to the working copy are retained/merged in
  73. + hg.update(self.repository._repository, 'tip')
  74. +
  75. + def status(self):
  76. + modified, added, removed, deleted, unknown, ignored, clean = self.repository._repository.status() #unknown=True)
  77. + return {'modified': modified, 'removed': removed,
  78. + 'deleted': deleted, 'unknown': unknown}
  79. +
  80. + def has_changed(self):
  81. + status = self.status()
  82. + changed = False
  83. + for st in 'modified', 'removed', 'deleted':
  84. + if status[st]:
  85. + changed = True
  86. + break
  87. + return changed
  88. +
  89. + def diff(self):
  90. + """Difference between working copy and repository."""
  91. + opts = patch.mdiff.diffopts(nodates=True)
  92. + diff = patch.diff(self.repository._repository, opts=opts)
  93. + return "".join(diff)
  94. +
  95. +class GitRepository(Repository):
  96. +
  97. + def __init__(self, url):
  98. + Repository.__init__(self, url)
  99. + self._repository = git.Repo(url)
  100. + self.working_copy = None
  101. +
  102. + def checkout(self, path="."):
  103. + """Clone a repository."""
  104. + path = os.path.abspath(path)
  105. + if self.url == path:
  106. + # update
  107. + hg.update(self._repository, None)
  108. +
  109. + else:
  110. + # can't clone into an existing directory, so we create
  111. + # an empty repository and then do a pull and update
  112. + local_repos = hg.repository(self._ui, path, create=True)
  113. + local_repos.pull(self._repository)
  114. + hg.update(local_repos, None)
  115. + self.working_copy = MercurialWorkingCopy()
  116. +
  117. + def __getstate__(self):
  118. + """For pickling"""
  119. + return {'url': self.url, 'wc': self.working_copy}
  120. +
  121. + def __setstate__(self, state):
  122. + """For unpickling"""
  123. + self.__init__(state['url'])
  124. + self.working_copy = state['wc']
  125.  
  126. changeset: 76:069d943fb2b4
  127. user: Michele Mattioni <mattioni@ebi.ac.uk>
  128. date: Mon Mar 29 17:08:36 2010 +0100
  129. summary: Implemented some fo the methods for git. Some methods were not clear, added a TODO comment with relative questions
  130.  
  131. diff -r 9b5eb05b435b -r 069d943fb2b4 src/versioncontrol/_git.py
  132. --- a/src/versioncontrol/_git.py Mon Mar 29 11:14:21 2010 +0100
  133. +++ b/src/versioncontrol/_git.py Mon Mar 29 17:08:36 2010 +0100
  134. @@ -17,20 +17,16 @@
  135. get_repository() - return a GitRepository object for a given URL.
  136. """
  137.  
  138. -#from mercurial import hg, ui, patch
  139. -
  140. import git
  141. import os
  142. -import binascii
  143.  
  144. from base import Repository, WorkingCopy
  145.  
  146.  
  147. def may_have_working_copy(path=None):
  148. path = path or os.getcwd()
  149. - if git.cmd.is_git_dir(path):
  150. - #return os.path.exists(os.path.join(path, ".git"))
  151. - return path
  152. + if git.cmd.is_git_dir(path, ".git"):
  153. + return os.path.exists(os.path.join(path, ".git"))
  154.  
  155. def get_working_copy(path=None):
  156. return GitWorkingCopy(path)
  157. @@ -46,40 +42,37 @@
  158. self.repository = GitRepository(self.path)
  159. self.repository.working_copy = self
  160.  
  161. - def current_version(self):# TODO Check
  162. - if hasattr(self.repository._repository, 'workingctx'): # handle different versions of Mercurial
  163. - ctx = self.repository._repository.workingctx().parents()[0]
  164. - else:
  165. - ctx = self.repository._repository.parents()[0]
  166. - return binascii.hexlify(ctx.node()[:6])
  167. + def current_version(self):
  168. + head = self.repository._repository.commits()[0]
  169. + return head.id
  170.  
  171. def use_version(self, version):
  172. - assert not self.has_changed()
  173. - hg.clean(self.repository._repository, version)
  174. + pass
  175. + # TODO:
  176. + # What exactly should happen here?
  177.  
  178. def use_latest_version(self):
  179. - # any changes to the working copy are retained/merged in
  180. - hg.update(self.repository._repository, 'tip')
  181. -
  182. + pass
  183. + # TODO:
  184. + # Shall we use the last version available from the repo?
  185. +
  186. def status(self):
  187. - modified, added, removed, deleted, unknown, ignored, clean = self.repository._repository.status() #unknown=True)
  188. - return {'modified': modified, 'removed': removed,
  189. - 'deleted': deleted, 'unknown': unknown}
  190. + # We don't need to use this.
  191. + pass
  192.  
  193. def has_changed(self):
  194. - status = self.status()
  195. changed = False
  196. - for st in 'modified', 'removed', 'deleted':
  197. - if status[st]:
  198. - changed = True
  199. - break
  200. + if self.repository._repository.is_dirty():
  201. + changed = True
  202. return changed
  203.  
  204. def diff(self):
  205. """Difference between working copy and repository."""
  206. - opts = patch.mdiff.diffopts(nodates=True)
  207. - diff = patch.diff(self.repository._repository, opts=opts)
  208. - return "".join(diff)
  209. +# opts = patch.mdiff.diffopts(nodates=True)
  210. +# diff = patch.diff(self.repository._repository, opts=opts)
  211. +# return "".join(diff)
  212. + pass
  213. + # TODO: This can be done, need to check a bit more.
  214.  
  215. class GitRepository(Repository):
  216.  
  217. @@ -90,18 +83,23 @@
  218.  
  219. def checkout(self, path="."):
  220. """Clone a repository."""
  221. - path = os.path.abspath(path)
  222. - if self.url == path:
  223. - # update
  224. - hg.update(self._repository, None)
  225. -
  226. - else:
  227. - # can't clone into an existing directory, so we create
  228. - # an empty repository and then do a pull and update
  229. - local_repos = hg.repository(self._ui, path, create=True)
  230. - local_repos.pull(self._repository)
  231. - hg.update(local_repos, None)
  232. - self.working_copy = MercurialWorkingCopy()
  233. +
  234. + pass
  235. + # TODO: We need to checkout the last commit?
  236. + # Or we need to clone the last commit somewhere (light branch?)
  237. +
  238. +# path = os.path.abspath(path)
  239. +# if self.url == path:
  240. +# # update
  241. +# hg.update(self._repository, None)
  242. +#
  243. +# else:
  244. +# # can't clone into an existing directory, so we create
  245. +# # an empty repository and then do a pull and update
  246. +# local_repos = hg.repository(self._ui, path, create=True)
  247. +# local_repos.pull(self._repository)
  248. +# hg.update(local_repos, None)
  249. +# self.working_copy = MercurialWorkingCopy()
  250.  
  251. def __getstate__(self):
  252. """For pickling"""
  253.  
  254. changeset: 77:2e06e43917db
  255. user: Michele Mattioni <mattioni@ebi.ac.uk>
  256. date: Mon Mar 29 17:49:45 2010 +0100
  257. summary: Fixed the dir checking in the path, added git to the supported vcs in the init
  258.  
  259. diff -r 069d943fb2b4 -r 2e06e43917db src/versioncontrol/__init__.py
  260. --- a/src/versioncontrol/__init__.py Mon Mar 29 17:08:36 2010 +0100
  261. +++ b/src/versioncontrol/__init__.py Mon Mar 29 17:49:45 2010 +0100
  262. @@ -11,7 +11,7 @@
  263. base - defines the base WorkingCopy and Repository classes
  264. _mercurial - defines MercurialWorkingCopy and MercurialRepository classes
  265. _subversion - defines SubversionWorkingCopy and SubversionRepository classes
  266. -
  267. +_git - defines GitWorkingCopy and GitRepository classes
  268. Exceptions
  269. ----------
  270.  
  271. @@ -38,7 +38,7 @@
  272.  
  273. vcs_list = []
  274.  
  275. -for vcs in ['mercurial', 'subversion']:
  276. +for vcs in ['mercurial', 'subversion', 'git']:
  277. try:
  278. __import__('sumatra.versioncontrol._%s' % vcs)
  279. vcs_list.append(sys.modules['sumatra.versioncontrol._%s' % vcs])
  280. diff -r 069d943fb2b4 -r 2e06e43917db src/versioncontrol/_git.py
  281. --- a/src/versioncontrol/_git.py Mon Mar 29 17:08:36 2010 +0100
  282. +++ b/src/versioncontrol/_git.py Mon Mar 29 17:49:45 2010 +0100
  283. @@ -25,7 +25,7 @@
  284.  
  285. def may_have_working_copy(path=None):
  286. path = path or os.getcwd()
  287. - if git.cmd.is_git_dir(path, ".git"):
  288. + if git.cmd.is_git_dir(os.path.join(path, ".git")):
  289. return os.path.exists(os.path.join(path, ".git"))
  290.  
  291. def get_working_copy(path=None):
  292.  
  293. changeset: 92:719a23068010
  294. parent: 77:2e06e43917db
  295. user: Michele Mattioni <mattioni@ebi.ac.uk>
  296. date: Thu Apr 01 10:54:38 2010 +0100
  297. summary: Fixed the diff method for git
  298.  
  299. diff -r 2e06e43917db -r 719a23068010 src/versioncontrol/_git.py
  300. --- a/src/versioncontrol/_git.py Mon Mar 29 17:49:45 2010 +0100
  301. +++ b/src/versioncontrol/_git.py Thu Apr 01 10:54:38 2010 +0100
  302. @@ -68,11 +68,8 @@
  303.  
  304. def diff(self):
  305. """Difference between working copy and repository."""
  306. -# opts = patch.mdiff.diffopts(nodates=True)
  307. -# diff = patch.diff(self.repository._repository, opts=opts)
  308. -# return "".join(diff)
  309. - pass
  310. - # TODO: This can be done, need to check a bit more.
  311. + return self.repository._repository.commit_diff('HEAD')
  312. +
  313.  
  314. class GitRepository(Repository):
  315.  
  316.  
  317. changeset: 97:12681cd09a30
  318. user: Michele Mattioni <mattioni@ebi.ac.uk>
  319. date: Tue Apr 06 13:15:17 2010 +0100
  320. summary: Implemented the checkout methos. Remote cloning of the repo still on the TODO.
  321.  
  322. diff -r 3a9067f68eb9 -r 12681cd09a30 src/versioncontrol/_git.py
  323. --- a/src/versioncontrol/_git.py Fri Apr 02 14:04:12 2010 +0200
  324. +++ b/src/versioncontrol/_git.py Tue Apr 06 13:15:17 2010 +0100
  325. @@ -50,16 +50,14 @@
  326. return head.id
  327.  
  328. def use_version(self, version):
  329. - pass
  330. - # TODO:
  331. - # this command should move the tree to some older
  332. - # revision (if I have understood git terminology correctly)
  333. - # this is perhaps equivalent to the git checkout command?
  334. + if not git.cmd.is_dirty():
  335. + g = git.Git(self.path)
  336. + g.checkout(version)
  337.  
  338. def use_latest_version(self):
  339. - pass
  340. - # TODO:
  341. - # use the last version available from the repo
  342. + if not git.cmd.is_dirty():
  343. + g = git.Git(self.path)
  344. + g.checkout('HEAD')
  345.  
  346. def status(self):
  347. # We don't need to use this.
  348. @@ -104,4 +102,4 @@
  349. def __setstate__(self, state):
  350. """For unpickling"""
  351. self.__init__(state['url'])
  352. - self.working_copy = state['wc']
  353. + self.working_copy = state['wc']
  354. \ No newline at end of file
  355.  
  356. changeset: 98:ea5697ab2c86
  357. tag: tip
  358. user: Michele Mattioni <mattioni@ebi.ac.uk>
  359. date: Tue Apr 06 16:48:07 2010 +0100
  360. summary: Implemented the checkout method and ran for the first time with a git repo. It seems to work.
  361.  
  362. diff -r 12681cd09a30 -r ea5697ab2c86 src/versioncontrol/_git.py
  363. --- a/src/versioncontrol/_git.py Tue Apr 06 13:15:17 2010 +0100
  364. +++ b/src/versioncontrol/_git.py Tue Apr 06 16:48:07 2010 +0100
  365. @@ -55,7 +55,7 @@
  366. g.checkout(version)
  367.  
  368. def use_latest_version(self):
  369. - if not git.cmd.is_dirty():
  370. + if not self.repository._repository.is_dirty:
  371. g = git.Git(self.path)
  372. g.checkout('HEAD')
  373.  
  374. @@ -68,7 +68,7 @@
  375.  
  376. def diff(self):
  377. """Difference between working copy and repository."""
  378. - return self.repository._repository.commit_diff('HEAD')
  379. + return self._repository.commit_diff('HEAD')
  380.  
  381.  
  382. class GitRepository(Repository):
  383. @@ -76,11 +76,12 @@
  384. def __init__(self, url):
  385. Repository.__init__(self, url)
  386. self.working_copy = None
  387. + self.checkout(url)
  388.  
  389. def checkout(self, path="."):
  390. """Clone a repository."""
  391. path = os.path.abspath(path)
  392. - g = git.Git()
  393. + g = git.Git(path)
  394. if self.url == path:
  395. # already have a repository in the working directory
  396. pass
Add Comment
Please, Sign In to add comment