Changeset 1195 in tailor
- Timestamp:
- 06/29/06 01:25:02 (7 years ago)
- Hash name:
- 20060628232502-130f5-9fddd5dda8c17309c7837d5307fbbe24b112c9de
- Files:
-
- 2 edited
-
README (modified) (1 diff)
-
vcpx/repository/git.py (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
README
r1184 r1195 665 665 ``subdir`` different from ``.``. [#]_ 666 666 667 git 668 %%% 667 git target 668 %%%%%%%%%% 669 669 670 670 parent-repo : string 671 Relative path to a git directory to use as a parent. This is useful 672 to import repository branches. If this parameter is empty, the 673 branch has no parent (default behaviour). 671 Relative path to a git directory to use as a parent. This is one 672 way to import branches into a git repository, which creates a new 673 git repository borrowing ancestry from the parent-repo. It is quite 674 a simple way, and thus believed to be quite robust, but spreads 675 branches across several git repositories. If this parameter is 676 not set, and ``repository`` is not set either, the branch has no 677 parent. 678 679 The alternative is to specify a ``repository`` parameter, to contain 680 all git branches. The .git directory in the working copy for each 681 branch will then only contain the ``.git/index`` file. 682 683 branch : string 684 The name of the branch to which to commit. It is only used in 685 single-repository mode (using ``repository``, see above). The 686 default is to use the "master" branch. 674 687 675 688 branchpoint : string -
vcpx/repository/git.py
r1194 r1195 4 4 # :Autore: Todd Mokros <tmokros@tmokros.net> 5 5 # Brendan Cully <brendan@kublai.com> 6 # Yann Dirson <ydirson@altern.org> 6 7 # :Licenza: GNU General Public License 7 8 # … … 15 16 from vcpx.repository import Repository 16 17 from vcpx.shwrap import ExternalCommand, PIPE 18 from vcpx.config import ConfigurationError 17 19 from vcpx.source import UpdatableSourceWorkingDir, GetUpstreamChangesetsFailure 18 20 from vcpx.source import ChangesetApplicationFailure … … 30 32 self.PARENT_REPO = project.config.get(self.name, 'parent-repo') 31 33 self.BRANCHPOINT = project.config.get(self.name, 'branchpoint', 'HEAD') 32 34 self.BRANCHNAME = project.config.get(self.name, 'branch') 35 if self.BRANCHNAME: 36 self.BRANCHNAME = 'refs/heads/' + self.BRANCHNAME 37 38 if self.repository and self.PARENT_REPO: 39 self.log.critical('Cannot make sense of both "repository" and "parent-repo" parameters') 40 raise ConfigurationError ('Must specify only one of "repository" and "parent-repo"') 41 42 if self.BRANCHNAME and not self.repository: 43 self.log.critical('Cannot make sense of "branch" if "repository" is not set') 44 raise ConfigurationError ('Missing "repository" to make use o "branch"') 45 46 self.env = {} 47 48 if self.repository: 49 self.storagedir = self.repository 50 self.env['GIT_DIR'] = self.storagedir 51 self.env['GIT_INDEX_FILE'] = self.METADIR + '/index' 52 else: 53 self.storagedir = self.METADIR 54 55 class GitExternalCommand(ExternalCommand): 56 def __init__(self, repo, command=None, cwd=None): 57 """ 58 Initialize an ExternalCommand instance tied to a GitRepository 59 from which it inherits a set of environment variables to use 60 fo each execute(). 61 """ 62 63 self.repo = repo 64 return ExternalCommand.__init__(self, command, cwd) 65 66 def execute(self, *args, **kwargs): 67 """Execute the command, with controlled environment.""" 68 69 if not kwargs.has_key('env'): 70 kwargs['env'] = {} 71 72 kwargs['env'].update(self.repo.env) 73 74 return ExternalCommand.execute(self, *args, **kwargs) 33 75 34 76 class GitWorkingDir(UpdatableSourceWorkingDir, SynchronizableTargetWorkingDir): 35 77 36 78 def _tryCommand(self, cmd, exception=Exception, pipe=True): 37 c = ExternalCommand(command = self.repository.command(*cmd), cwd = self.basedir) 79 c = GitExternalCommand(self.repository, 80 command = self.repository.command(*cmd), cwd = self.basedir) 38 81 if pipe: 39 82 output = c.execute(stdout=PIPE)[0] … … 241 284 treeid = self._tryCommand(['write-tree'])[0] 242 285 243 # find the parent commit if any 244 c = ExternalCommand(cwd=self.basedir, 245 command=self.repository.command('rev-parse', 'HEAD')) 286 # in single-repository mode, only update the relevant branch 287 if self.repository.BRANCHNAME: 288 refname = self.repository.BRANCHNAME 289 else: 290 refname = 'HEAD' 291 292 # find the previous commit on the branch if any 293 c = GitExternalCommand(self.repository, cwd=self.basedir, 294 command=self.repository.command('rev-parse', refname)) 246 295 (out, err) = c.execute(stdout=PIPE, stderr=PIPE) 247 296 if c.exit_status: … … 267 316 else: 268 317 cmd = self.repository.command('commit-tree', treeid) 269 c = ExternalCommand(cwd=self.basedir, command=cmd)318 c = GitExternalCommand(self.repository, cwd=self.basedir, command=cmd) 270 319 271 320 logmessage = encode('\n'.join(logmessage)) … … 286 335 else: 287 336 commitid=out.read().split('\n')[0] 337 288 338 if parent: 289 self._tryCommand(['update-ref', 'HEAD', commitid, parent])339 self._tryCommand(['update-ref', refname, commitid, parent]) 290 340 else: 291 self._tryCommand(['update-ref', 'HEAD', commitid])341 self._tryCommand(['update-ref', refname, commitid]) 292 342 293 343 def _tag(self, tag): 294 344 # Allow a new tag to overwrite an older one with -f 295 345 cmd = self.repository.command("tag", "-f", tag) 296 c = ExternalCommand(cwd=self.basedir, command=cmd)346 c = GitExternalCommand(self.repository, cwd=self.basedir, command=cmd) 297 347 c.execute() 298 348 … … 350 400 """ 351 401 352 from os import renames 402 from os import renames, mkdir 353 403 from os.path import join, exists 354 404 355 405 if not exists(join(self.basedir, self.repository.METADIR)): 356 if not self.repository.PARENT_REPO: 357 cmd = self.repository.command("init-db") 358 init = ExternalCommand(cwd=self.basedir, command=cmd) 359 init.execute() 360 if init.exit_status: 361 raise TargetInitializationFailure( 362 "%s returned status %s" % (str(init), init.exit_status)) 363 else: 406 if self.repository.PARENT_REPO: 364 407 cmd = self.repository.command("clone", "--shared", "-n", 365 408 self.repository.PARENT_REPO, 'tmp') 366 clone = ExternalCommand(cwd=self.basedir, command=cmd)409 clone = GitExternalCommand(self.repository, cwd=self.basedir, command=cmd) 367 410 clone.execute() 368 411 if clone.exit_status: … … 374 417 375 418 cmd = self.repository.command("reset", "--soft", self.repository.BRANCHPOINT) 376 reset = ExternalCommand(cwd=self.basedir, command=cmd)419 reset = GitExternalCommand(self.repository, cwd=self.basedir, command=cmd) 377 420 reset.execute() 378 421 if reset.exit_status: … … 380 423 "%s returned status %s" % (str(reset), reset.exit_status)) 381 424 425 elif self.repository.repository and self.repository.BRANCHNAME: 426 # ...and exists(self.repository.storagedir) ? 427 428 # initialization of a new branch in single-repository mode 429 mkdir(join(self.basedir, self.repository.METADIR)) 430 431 bp = self._tryCommand(['rev-parse', self.repository.BRANCHPOINT])[0] 432 self._tryCommand(['read-tree', bp]) 433 self._tryCommand(['update-ref', self.repository.BRANCHNAME, bp]) 434 #self._tryCommand(['checkout-index']) 435 436 else: 437 self._tryCommand(['init-db']) 438 if self.repository.repository: 439 # in this mode, the db is not stored in working dir, so we 440 # have to create .git ourselves 441 mkdir(join(self.basedir, self.repository.METADIR)) 382 442 383 443 def _prepareWorkingDirectory(self, source_repo): … … 390 450 from vcpx.dualwd import IGNORED_METADIRS 391 451 392 infodir = join(self.basedir, self.repository.METADIR, 'info') 452 # create info/excludes in storagedir 453 infodir = join(self.basedir, self.repository.storagedir, 'info') 393 454 if not exists(infodir): 394 455 mkdir(infodir)
Note: See TracChangeset
for help on using the changeset viewer.
