Permalink
Browse files

Clean up parts of borrowed code that are no longer necessary

  • Loading branch information...
1 parent 132d8b8 commit 6c009997c18e7f5aa0892910c4c89b2448c75cda @toddlipcon toddlipcon committed Jul 1, 2009
Showing with 54 additions and 189 deletions.
  1. +48 −30 crepo.py
  2. +0 −72 error.py
  3. +5 −85 git_command.py
  4. +1 −2 git_repo.py
View
@@ -10,8 +10,12 @@
from git_command import GitCommand
from git_repo import GitRepo
+LOADED_MANIFEST = None
def load_manifest():
- return manifest.load_manifest("manifest.json")
+ global LOADED_MANIFEST
+ if not LOADED_MANIFEST:
+ LOADED_MANIFEST = manifest.load_manifest("manifest.json")
+ return LOADED_MANIFEST
def help(args):
"""Shows help"""
@@ -32,48 +36,62 @@ def init(args):
man = load_manifest()
for (name, project) in man.projects.iteritems():
- logging.warn("Initializing project: %s" % name)
- clone_remote = man.remotes[project.from_remote]
- clone_url = clone_remote.fetch % name
- p = GitCommand(None, ["clone", "-o", project.from_remote, "-n", clone_url, project.dir])
- p.Wait()
-
- repo = GitRepo(workdir_for_project(project))
- if repo.command(["show-ref", "-q", "HEAD"]) != 0:
- # There is no HEAD (maybe origin/master doesnt exist) so check out the tracking
- # branch
- repo.check_command(["checkout", "--track", "-b", project.tracking_branch,
- project.remote_refspec])
- else:
- repo.check_command(["checkout"])
-
+ init_project(name, project)
ensure_remotes([])
fetch([])
checkout_branches([])
+
+
+def init_project(name, project):
+ man = load_manifest()
+ logging.warn("Initializing project: %s" % name)
+ clone_remote = man.remotes[project.from_remote]
+ clone_url = clone_remote.fetch % name
+ p = GitCommand(["clone", "-o", project.from_remote, "-n", clone_url, project.dir])
+ p.Wait()
+
+ repo = GitRepo(workdir_for_project(project))
+ if repo.command(["show-ref", "-q", "HEAD"]) != 0:
+ # There is no HEAD (maybe origin/master doesnt exist) so check out the tracking
+ # branch
+ repo.check_command(["checkout", "--track", "-b", project.tracking_branch,
+ project.remote_refspec])
+ else:
+ repo.check_command(["checkout"])
+
+
def ensure_remotes(args):
"""Ensure that remotes are set up"""
man = load_manifest()
for (proj_name, project) in man.projects.iteritems():
- repo = GitRepo(workdir_for_project(project))
- for remote_name in project.remotes:
- remote = man.remotes[remote_name]
- new_url = remote.fetch % proj_name
-
- p = repo.command_process(["config", "--get", "remote.%s.url" % remote_name],
- capture_stdout=True)
- if p.Wait() == 0:
- cur_url = p.stdout.strip()
- if cur_url != new_url:
- repo.check_command(["config", "--replace-all", "remote.%s.url" % remote_name, new_url])
- else:
- repo.check_command(["remote", "add", remote_name, new_url])
+ ensure_remotes_project(proj_name, project)
+
+
+def ensure_remotes_project(proj_name, project):
+ man = load_manifest()
+ repo = GitRepo(workdir_for_project(project))
+ for remote_name in project.remotes:
+ remote = man.remotes[remote_name]
+ new_url = remote.fetch % proj_name
+
+ p = repo.command_process(["config", "--get", "remote.%s.url" % remote_name],
+ capture_stdout=True)
+ if p.Wait() == 0:
+ cur_url = p.stdout.strip()
+ if cur_url != new_url:
+ repo.check_command(["config", "--replace-all", "remote.%s.url" % remote_name, new_url])
+ else:
+ repo.check_command(["remote", "add", remote_name, new_url])
def ensure_tracking_branches(args):
"""Ensures that the tracking branches are set up"""
man = load_manifest()
for (name, project) in man.projects.iteritems():
- repo = GitRepo(workdir_for_project(project))
+ wd = workdir_for_project(project)
+ if not os.path.exists(wd):
+ init_project(name, project)
+ repo = GitRepo(wd)
branch_missing = repo.command(
["rev-parse", "--verify", "-q", project.refspec],
capture_stdout=True)
View
@@ -1,72 +0,0 @@
-#
-# Copyright (C) 2008 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-class ManifestParseError(Exception):
- """Failed to parse the manifest file.
- """
-
-class ManifestInvalidRevisionError(Exception):
- """The revision value in a project is incorrect.
- """
-
-class EditorError(Exception):
- """Unspecified error from the user's text editor.
- """
-
-class GitError(Exception):
- """Unspecified internal error from git.
- """
- def __init__(self, command):
- self.command = command
-
- def __str__(self):
- return self.command
-
-class ImportError(Exception):
- """An import from a non-Git format cannot be performed.
- """
- def __init__(self, reason):
- self.reason = reason
-
- def __str__(self):
- return self.reason
-
-class UploadError(Exception):
- """A bundle upload to Gerrit did not succeed.
- """
- def __init__(self, reason):
- self.reason = reason
-
- def __str__(self):
- return self.reason
-
-class NoSuchProjectError(Exception):
- """A specified project does not exist in the work tree.
- """
- def __init__(self, name=None):
- self.name = name
-
- def __str__(self):
- if self.Name is None:
- return 'in current directory'
- return self.name
-
-class RepoChangedException(Exception):
- """Thrown if 'repo sync' results in repo updating its internal
- repo or manifest repositories. In this special case we must
- use exec to re-execute repo with the new code and manifest.
- """
- def __init__(self, extra_args=[]):
- self.extra_args = extra_args
View
@@ -14,72 +14,23 @@
# limitations under the License.
import os
-import sys
import subprocess
-import tempfile
-from error import GitError
from trace import REPO_TRACE, IsTrace, Trace
GIT = 'git'
MIN_GIT_VERSION = (1, 5, 4)
GIT_DIR = 'GIT_DIR'
+
LAST_GITDIR = None
LAST_CWD = None
-_ssh_proxy_path = None
-_ssh_sock_path = None
-
-def _ssh_sock(create=True):
- global _ssh_sock_path
- if _ssh_sock_path is None:
- if not create:
- return None
- dir = '/tmp'
- if not os.path.exists(dir):
- dir = tempfile.gettempdir()
- _ssh_sock_path = os.path.join(
- tempfile.mkdtemp('', 'ssh-', dir),
- 'master-%r@%h:%p')
- return _ssh_sock_path
-
-def _ssh_proxy():
- global _ssh_proxy_path
- if _ssh_proxy_path is None:
- _ssh_proxy_path = os.path.join(
- os.path.dirname(__file__),
- 'git_ssh')
- return _ssh_proxy_path
-
-
-class _GitCall(object):
- def version(self):
- p = GitCommand(None, ['--version'], capture_stdout=True)
- if p.Wait() == 0:
- return p.stdout
- return None
-
- def __getattr__(self, name):
- name = name.replace('_','-')
- def fun(*cmdv):
- command = [name]
- command.extend(cmdv)
- return GitCommand(None, command).Wait() == 0
- return fun
-git = _GitCall()
-
class GitCommand(object):
def __init__(self,
- project,
cmdv,
- bare = False,
- provide_stdin = False,
capture_stdout = False,
capture_stderr = False,
- disable_editor = False,
- ssh_proxy = False,
- cwd = None,
- gitdir = None):
+ cwd = None):
env = dict(os.environ)
for e in [REPO_TRACE,
@@ -92,39 +43,11 @@ def __init__(self,
if e in env:
del env[e]
- if disable_editor:
- env['GIT_EDITOR'] = ':'
- if ssh_proxy:
- env['REPO_SSH_SOCK'] = _ssh_sock()
- env['GIT_SSH'] = _ssh_proxy()
-
- if project:
- if not cwd:
- cwd = project.worktree
- if not gitdir:
- gitdir = project.gitdir
-
command = [GIT]
- if bare:
- if gitdir:
- env[GIT_DIR] = gitdir
- cwd = None
command.extend(cmdv)
- if provide_stdin:
- stdin = subprocess.PIPE
- else:
- stdin = None
-
- if capture_stdout:
- stdout = subprocess.PIPE
- else:
- stdout = None
-
- if capture_stderr:
- stderr = subprocess.PIPE
- else:
- stderr = None
+ stdout = subprocess.PIPE if capture_stdout else None
+ stderr = subprocess.PIPE if capture_stderr else None
if IsTrace():
global LAST_CWD
@@ -146,8 +69,6 @@ def __init__(self,
dbg += ': '
dbg += ' '.join(command)
- if stdin == subprocess.PIPE:
- dbg += ' 0<|'
if stdout == subprocess.PIPE:
dbg += ' 1>|'
if stderr == subprocess.PIPE:
@@ -158,11 +79,10 @@ def __init__(self,
p = subprocess.Popen(command,
cwd = cwd,
env = env,
- stdin = stdin,
stdout = stdout,
stderr = stderr)
except Exception, e:
- raise GitError('%s: %s' % (command[1], e))
+ raise Exception('%s: %s' % (command[1], e))
self.process = p
self.stdin = p.stdin
View
@@ -30,8 +30,7 @@ def check_command(self, cmdv, capture_stdout=False):
return p.stdout
def command_process(self, cmdv, **kwargs):
- p = GitCommand(project=None,
- cwd=self.path,
+ p = GitCommand(cwd=self.path,
cmdv=cmdv,
**kwargs)
return p

0 comments on commit 6c00999

Please sign in to comment.