mirror of
https://gerrit.googlesource.com/git-repo
synced 2025-06-30 20:17:08 +00:00
Compare commits
10 Commits
Author | SHA1 | Date | |
---|---|---|---|
2816d4f387 | |||
44469464d2 | |||
c95583bf4f | |||
6a5644d392 | |||
fe08675956 | |||
be0e8ac232 | |||
47c1a63a07 | |||
559b846b17 | |||
7c6c64d463 | |||
3778f9d47e |
@ -114,3 +114,8 @@ class PagedCommand(Command):
|
||||
"""Command which defaults to output in a pager, as its
|
||||
display tends to be larger than one screen full.
|
||||
"""
|
||||
|
||||
class MirrorSafeCommand(object):
|
||||
"""Command permits itself to run within a mirror,
|
||||
and does not require a working directory.
|
||||
"""
|
||||
|
4
error.py
4
error.py
@ -17,6 +17,10 @@ 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.
|
||||
"""
|
||||
|
24
main.py
24
main.py
@ -27,8 +27,11 @@ import os
|
||||
import re
|
||||
import sys
|
||||
|
||||
from command import InteractiveCommand, PagedCommand
|
||||
from command import InteractiveCommand
|
||||
from command import MirrorSafeCommand
|
||||
from command import PagedCommand
|
||||
from editor import Editor
|
||||
from error import ManifestInvalidRevisionError
|
||||
from error import NoSuchProjectError
|
||||
from error import RepoChangedException
|
||||
from manifest import Manifest
|
||||
@ -45,6 +48,9 @@ global_options.add_option('-p', '--paginate',
|
||||
global_options.add_option('--no-pager',
|
||||
dest='no_pager', action='store_true',
|
||||
help='disable the pager')
|
||||
global_options.add_option('--version',
|
||||
dest='show_version', action='store_true',
|
||||
help='display this version of repo')
|
||||
|
||||
class _Repo(object):
|
||||
def __init__(self, repodir):
|
||||
@ -68,6 +74,13 @@ class _Repo(object):
|
||||
argv = []
|
||||
gopts, gargs = global_options.parse_args(glob)
|
||||
|
||||
if gopts.show_version:
|
||||
if name == 'help':
|
||||
name = 'version'
|
||||
else:
|
||||
print >>sys.stderr, 'fatal: invalid usage of --version'
|
||||
sys.exit(1)
|
||||
|
||||
try:
|
||||
cmd = self.commands[name]
|
||||
except KeyError:
|
||||
@ -80,6 +93,12 @@ class _Repo(object):
|
||||
cmd.manifest = Manifest(cmd.repodir)
|
||||
Editor.globalConfig = cmd.manifest.globalConfig
|
||||
|
||||
if not isinstance(cmd, MirrorSafeCommand) and cmd.manifest.IsMirror:
|
||||
print >>sys.stderr, \
|
||||
"fatal: '%s' requires a working directory"\
|
||||
% name
|
||||
sys.exit(1)
|
||||
|
||||
if not gopts.no_pager and not isinstance(cmd, InteractiveCommand):
|
||||
config = cmd.manifest.globalConfig
|
||||
if gopts.pager:
|
||||
@ -94,6 +113,9 @@ class _Repo(object):
|
||||
copts, cargs = cmd.OptionParser.parse_args(argv)
|
||||
try:
|
||||
cmd.Execute(copts, cargs)
|
||||
except ManifestInvalidRevisionError, e:
|
||||
print >>sys.stderr, 'error: %s' % str(e)
|
||||
sys.exit(1)
|
||||
except NoSuchProjectError, e:
|
||||
if e.name:
|
||||
print >>sys.stderr, 'error: project %s not found' % e.name
|
||||
|
55
project.py
55
project.py
@ -25,6 +25,7 @@ from color import Coloring
|
||||
from git_command import GitCommand
|
||||
from git_config import GitConfig, IsId
|
||||
from error import GitError, ImportError, UploadError
|
||||
from error import ManifestInvalidRevisionError
|
||||
from remote import Remote
|
||||
|
||||
HEAD = 'HEAD'
|
||||
@ -357,7 +358,7 @@ class Project(object):
|
||||
else: f_status = '-'
|
||||
|
||||
if i and i.src_path:
|
||||
line = ' %s%s\t%s => (%s%%)' % (i_status, f_status,
|
||||
line = ' %s%s\t%s => %s (%s%%)' % (i_status, f_status,
|
||||
i.src_path, p, i.level)
|
||||
else:
|
||||
line = ' %s%s\t%s' % (i_status, f_status, p)
|
||||
@ -528,7 +529,6 @@ class Project(object):
|
||||
return False
|
||||
|
||||
if self.worktree:
|
||||
self._RepairAndroidImportErrors()
|
||||
self._InitMRef()
|
||||
else:
|
||||
self._InitMirrorHead()
|
||||
@ -545,30 +545,6 @@ class Project(object):
|
||||
for file in self.copyfiles:
|
||||
file._Copy()
|
||||
|
||||
def _RepairAndroidImportErrors(self):
|
||||
if self.name in ['platform/external/iptables',
|
||||
'platform/external/libpcap',
|
||||
'platform/external/tcpdump',
|
||||
'platform/external/webkit',
|
||||
'platform/system/wlan/ti']:
|
||||
# I hate myself for doing this...
|
||||
#
|
||||
# In the initial Android 1.0 release these projects were
|
||||
# shipped, some users got them, and then the history had
|
||||
# to be rewritten to correct problems with their imports.
|
||||
# The 'android-1.0' tag may still be pointing at the old
|
||||
# history, so we need to drop the tag and fetch it again.
|
||||
#
|
||||
try:
|
||||
remote = self.GetRemote(self.remote.name)
|
||||
relname = remote.ToLocal(R_HEADS + 'release-1.0')
|
||||
tagname = R_TAGS + 'android-1.0'
|
||||
if self._revlist(not_rev(relname), tagname):
|
||||
cmd = ['fetch', remote.name, '+%s:%s' % (tagname, tagname)]
|
||||
GitCommand(self, cmd, bare = True).Wait()
|
||||
except GitError:
|
||||
pass
|
||||
|
||||
def Sync_LocalHalf(self):
|
||||
"""Perform only the local IO portion of the sync process.
|
||||
Network access is not required.
|
||||
@ -582,6 +558,12 @@ class Project(object):
|
||||
|
||||
rem = self.GetRemote(self.remote.name)
|
||||
rev = rem.ToLocal(self.revision)
|
||||
try:
|
||||
self.bare_git.rev_parse('--verify', '%s^0' % rev)
|
||||
except GitError:
|
||||
raise ManifestInvalidRevisionError(
|
||||
'revision %s in %s not found' % (self.revision, self.name))
|
||||
|
||||
branch = self.CurrentBranch
|
||||
|
||||
if branch is None:
|
||||
@ -770,7 +752,8 @@ class Project(object):
|
||||
"""
|
||||
cb = self.CurrentBranch
|
||||
kill = []
|
||||
for name in self._allrefs.keys():
|
||||
left = self._allrefs
|
||||
for name in left.keys():
|
||||
if name.startswith(R_HEADS):
|
||||
name = name[len(R_HEADS):]
|
||||
if cb is None or name != cb:
|
||||
@ -783,14 +766,12 @@ class Project(object):
|
||||
self.work_git.DetachHead(HEAD)
|
||||
kill.append(cb)
|
||||
|
||||
deleted = set()
|
||||
if kill:
|
||||
try:
|
||||
old = self.bare_git.GetHead()
|
||||
except GitError:
|
||||
old = 'refs/heads/please_never_use_this_as_a_branch_name'
|
||||
|
||||
rm_re = re.compile(r"^Deleted branch (.*)\.$")
|
||||
try:
|
||||
self.bare_git.DetachHead(rev)
|
||||
|
||||
@ -802,14 +783,12 @@ class Project(object):
|
||||
b.Wait()
|
||||
finally:
|
||||
self.bare_git.SetHead(old)
|
||||
left = self._allrefs
|
||||
|
||||
for line in b.stdout.split("\n"):
|
||||
m = rm_re.match(line)
|
||||
if m:
|
||||
deleted.add(m.group(1))
|
||||
|
||||
if deleted:
|
||||
for branch in kill:
|
||||
if (R_HEADS + branch) not in left:
|
||||
self.CleanPublishedCache()
|
||||
break
|
||||
|
||||
if cb and cb not in kill:
|
||||
kill.append(cb)
|
||||
@ -817,7 +796,7 @@ class Project(object):
|
||||
|
||||
kept = []
|
||||
for branch in kill:
|
||||
if branch not in deleted:
|
||||
if (R_HEADS + branch) in left:
|
||||
branch = self.GetBranch(branch)
|
||||
base = branch.LocalMerge
|
||||
if not base:
|
||||
@ -872,6 +851,10 @@ class Project(object):
|
||||
if not os.path.exists(self.gitdir):
|
||||
os.makedirs(self.gitdir)
|
||||
self.bare_git.init()
|
||||
|
||||
if self.manifest.IsMirror:
|
||||
self.config.SetString('core.bare', 'true')
|
||||
else:
|
||||
self.config.SetString('core.bare', None)
|
||||
|
||||
hooks = self._gitdir_path('hooks')
|
||||
|
@ -17,9 +17,9 @@ import re
|
||||
import os
|
||||
import sys
|
||||
import subprocess
|
||||
from command import Command
|
||||
from command import Command, MirrorSafeCommand
|
||||
|
||||
class Forall(Command):
|
||||
class Forall(Command, MirrorSafeCommand):
|
||||
common = False
|
||||
helpSummary = "Run a shell command in each project"
|
||||
helpUsage = """
|
||||
@ -30,10 +30,22 @@ Executes the same shell command in each project.
|
||||
|
||||
Environment
|
||||
-----------
|
||||
pwd is the project's working directory.
|
||||
pwd is the project's working directory. If the current client is
|
||||
a mirror client, then pwd is the Git repository.
|
||||
|
||||
REPO_PROJECT is set to the unique name of the project.
|
||||
|
||||
REPO_PATH is the path relative the the root of the client.
|
||||
|
||||
REPO_REMOTE is the name of the remote system from the manifest.
|
||||
|
||||
REPO_LREV is the name of the revision from the manifest, translated
|
||||
to a local tracking branch. If you need to pass the manifest
|
||||
revision to a locally executed git command, use REPO_LREV.
|
||||
|
||||
REPO_RREV is the name of the revision from the manifest, exactly
|
||||
as written in the manifest.
|
||||
|
||||
shell positional arguments ($1, $2, .., $#) are set to any arguments
|
||||
following <command>.
|
||||
|
||||
@ -66,13 +78,26 @@ not redirected.
|
||||
cmd.append(cmd[0])
|
||||
cmd.extend(opt.command[1:])
|
||||
|
||||
mirror = self.manifest.IsMirror
|
||||
rc = 0
|
||||
for project in self.GetProjects(args):
|
||||
env = dict(os.environ.iteritems())
|
||||
env['REPO_PROJECT'] = project.name
|
||||
env['REPO_PATH'] = project.relpath
|
||||
env['REPO_REMOTE'] = project.remote.name
|
||||
env['REPO_LREV'] = project\
|
||||
.GetRemote(project.remote.name)\
|
||||
.ToLocal(project.revision)
|
||||
env['REPO_RREV'] = project.revision
|
||||
|
||||
if mirror:
|
||||
env['GIT_DIR'] = project.gitdir
|
||||
cwd = project.gitdir
|
||||
else:
|
||||
cwd = project.worktree
|
||||
|
||||
p = subprocess.Popen(cmd,
|
||||
cwd = project.worktree,
|
||||
cwd = cwd,
|
||||
shell = shell,
|
||||
env = env)
|
||||
r = p.wait()
|
||||
|
@ -17,9 +17,9 @@ import sys
|
||||
from formatter import AbstractFormatter, DumbWriter
|
||||
|
||||
from color import Coloring
|
||||
from command import PagedCommand
|
||||
from command import PagedCommand, MirrorSafeCommand
|
||||
|
||||
class Help(PagedCommand):
|
||||
class Help(PagedCommand, MirrorSafeCommand):
|
||||
common = False
|
||||
helpSummary = "Display detailed help on a command"
|
||||
helpUsage = """
|
||||
|
@ -17,12 +17,12 @@ import os
|
||||
import sys
|
||||
|
||||
from color import Coloring
|
||||
from command import InteractiveCommand
|
||||
from command import InteractiveCommand, MirrorSafeCommand
|
||||
from error import ManifestParseError
|
||||
from remote import Remote
|
||||
from git_command import git, MIN_GIT_VERSION
|
||||
|
||||
class Init(InteractiveCommand):
|
||||
class Init(InteractiveCommand, MirrorSafeCommand):
|
||||
common = True
|
||||
helpSummary = "Initialize repo in the current directory"
|
||||
helpUsage = """
|
||||
|
@ -19,11 +19,11 @@ import subprocess
|
||||
import sys
|
||||
|
||||
from git_command import GIT
|
||||
from command import Command
|
||||
from command import Command, MirrorSafeCommand
|
||||
from error import RepoChangedException, GitError
|
||||
from project import R_HEADS
|
||||
|
||||
class Sync(Command):
|
||||
class Sync(Command, MirrorSafeCommand):
|
||||
common = True
|
||||
helpSummary = "Update working tree to the latest revision"
|
||||
helpUsage = """
|
||||
|
35
subcmds/version.py
Normal file
35
subcmds/version.py
Normal file
@ -0,0 +1,35 @@
|
||||
#
|
||||
# Copyright (C) 2009 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.
|
||||
|
||||
import sys
|
||||
from command import Command, MirrorSafeCommand
|
||||
from git_command import git
|
||||
from project import HEAD
|
||||
|
||||
class Version(Command, MirrorSafeCommand):
|
||||
common = False
|
||||
helpSummary = "Display the version of repo"
|
||||
helpUsage = """
|
||||
%prog
|
||||
"""
|
||||
|
||||
def Execute(self, opt, args):
|
||||
rp = self.manifest.repoProject
|
||||
rem = rp.GetRemote(rp.remote.name)
|
||||
|
||||
print 'repo version %s' % rp.work_git.describe(HEAD)
|
||||
print ' (from %s)' % rem.url
|
||||
print git.version().strip()
|
||||
print 'Python %s' % sys.version
|
Reference in New Issue
Block a user