mirror of
https://gerrit.googlesource.com/git-repo
synced 2025-07-02 20:17:19 +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
|
"""Command which defaults to output in a pager, as its
|
||||||
display tends to be larger than one screen full.
|
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.
|
"""Failed to parse the manifest file.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
class ManifestInvalidRevisionError(Exception):
|
||||||
|
"""The revision value in a project is incorrect.
|
||||||
|
"""
|
||||||
|
|
||||||
class EditorError(Exception):
|
class EditorError(Exception):
|
||||||
"""Unspecified error from the user's text editor.
|
"""Unspecified error from the user's text editor.
|
||||||
"""
|
"""
|
||||||
|
24
main.py
24
main.py
@ -27,8 +27,11 @@ import os
|
|||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from command import InteractiveCommand, PagedCommand
|
from command import InteractiveCommand
|
||||||
|
from command import MirrorSafeCommand
|
||||||
|
from command import PagedCommand
|
||||||
from editor import Editor
|
from editor import Editor
|
||||||
|
from error import ManifestInvalidRevisionError
|
||||||
from error import NoSuchProjectError
|
from error import NoSuchProjectError
|
||||||
from error import RepoChangedException
|
from error import RepoChangedException
|
||||||
from manifest import Manifest
|
from manifest import Manifest
|
||||||
@ -45,6 +48,9 @@ global_options.add_option('-p', '--paginate',
|
|||||||
global_options.add_option('--no-pager',
|
global_options.add_option('--no-pager',
|
||||||
dest='no_pager', action='store_true',
|
dest='no_pager', action='store_true',
|
||||||
help='disable the pager')
|
help='disable the pager')
|
||||||
|
global_options.add_option('--version',
|
||||||
|
dest='show_version', action='store_true',
|
||||||
|
help='display this version of repo')
|
||||||
|
|
||||||
class _Repo(object):
|
class _Repo(object):
|
||||||
def __init__(self, repodir):
|
def __init__(self, repodir):
|
||||||
@ -68,6 +74,13 @@ class _Repo(object):
|
|||||||
argv = []
|
argv = []
|
||||||
gopts, gargs = global_options.parse_args(glob)
|
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:
|
try:
|
||||||
cmd = self.commands[name]
|
cmd = self.commands[name]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
@ -80,6 +93,12 @@ class _Repo(object):
|
|||||||
cmd.manifest = Manifest(cmd.repodir)
|
cmd.manifest = Manifest(cmd.repodir)
|
||||||
Editor.globalConfig = cmd.manifest.globalConfig
|
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):
|
if not gopts.no_pager and not isinstance(cmd, InteractiveCommand):
|
||||||
config = cmd.manifest.globalConfig
|
config = cmd.manifest.globalConfig
|
||||||
if gopts.pager:
|
if gopts.pager:
|
||||||
@ -94,6 +113,9 @@ class _Repo(object):
|
|||||||
copts, cargs = cmd.OptionParser.parse_args(argv)
|
copts, cargs = cmd.OptionParser.parse_args(argv)
|
||||||
try:
|
try:
|
||||||
cmd.Execute(copts, cargs)
|
cmd.Execute(copts, cargs)
|
||||||
|
except ManifestInvalidRevisionError, e:
|
||||||
|
print >>sys.stderr, 'error: %s' % str(e)
|
||||||
|
sys.exit(1)
|
||||||
except NoSuchProjectError, e:
|
except NoSuchProjectError, e:
|
||||||
if e.name:
|
if e.name:
|
||||||
print >>sys.stderr, 'error: project %s not found' % e.name
|
print >>sys.stderr, 'error: project %s not found' % e.name
|
||||||
|
61
project.py
61
project.py
@ -25,6 +25,7 @@ from color import Coloring
|
|||||||
from git_command import GitCommand
|
from git_command import GitCommand
|
||||||
from git_config import GitConfig, IsId
|
from git_config import GitConfig, IsId
|
||||||
from error import GitError, ImportError, UploadError
|
from error import GitError, ImportError, UploadError
|
||||||
|
from error import ManifestInvalidRevisionError
|
||||||
from remote import Remote
|
from remote import Remote
|
||||||
|
|
||||||
HEAD = 'HEAD'
|
HEAD = 'HEAD'
|
||||||
@ -357,7 +358,7 @@ class Project(object):
|
|||||||
else: f_status = '-'
|
else: f_status = '-'
|
||||||
|
|
||||||
if i and i.src_path:
|
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)
|
i.src_path, p, i.level)
|
||||||
else:
|
else:
|
||||||
line = ' %s%s\t%s' % (i_status, f_status, p)
|
line = ' %s%s\t%s' % (i_status, f_status, p)
|
||||||
@ -528,7 +529,6 @@ class Project(object):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
if self.worktree:
|
if self.worktree:
|
||||||
self._RepairAndroidImportErrors()
|
|
||||||
self._InitMRef()
|
self._InitMRef()
|
||||||
else:
|
else:
|
||||||
self._InitMirrorHead()
|
self._InitMirrorHead()
|
||||||
@ -545,30 +545,6 @@ class Project(object):
|
|||||||
for file in self.copyfiles:
|
for file in self.copyfiles:
|
||||||
file._Copy()
|
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):
|
def Sync_LocalHalf(self):
|
||||||
"""Perform only the local IO portion of the sync process.
|
"""Perform only the local IO portion of the sync process.
|
||||||
Network access is not required.
|
Network access is not required.
|
||||||
@ -582,6 +558,12 @@ class Project(object):
|
|||||||
|
|
||||||
rem = self.GetRemote(self.remote.name)
|
rem = self.GetRemote(self.remote.name)
|
||||||
rev = rem.ToLocal(self.revision)
|
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
|
branch = self.CurrentBranch
|
||||||
|
|
||||||
if branch is None:
|
if branch is None:
|
||||||
@ -770,7 +752,8 @@ class Project(object):
|
|||||||
"""
|
"""
|
||||||
cb = self.CurrentBranch
|
cb = self.CurrentBranch
|
||||||
kill = []
|
kill = []
|
||||||
for name in self._allrefs.keys():
|
left = self._allrefs
|
||||||
|
for name in left.keys():
|
||||||
if name.startswith(R_HEADS):
|
if name.startswith(R_HEADS):
|
||||||
name = name[len(R_HEADS):]
|
name = name[len(R_HEADS):]
|
||||||
if cb is None or name != cb:
|
if cb is None or name != cb:
|
||||||
@ -783,14 +766,12 @@ class Project(object):
|
|||||||
self.work_git.DetachHead(HEAD)
|
self.work_git.DetachHead(HEAD)
|
||||||
kill.append(cb)
|
kill.append(cb)
|
||||||
|
|
||||||
deleted = set()
|
|
||||||
if kill:
|
if kill:
|
||||||
try:
|
try:
|
||||||
old = self.bare_git.GetHead()
|
old = self.bare_git.GetHead()
|
||||||
except GitError:
|
except GitError:
|
||||||
old = 'refs/heads/please_never_use_this_as_a_branch_name'
|
old = 'refs/heads/please_never_use_this_as_a_branch_name'
|
||||||
|
|
||||||
rm_re = re.compile(r"^Deleted branch (.*)\.$")
|
|
||||||
try:
|
try:
|
||||||
self.bare_git.DetachHead(rev)
|
self.bare_git.DetachHead(rev)
|
||||||
|
|
||||||
@ -802,22 +783,20 @@ class Project(object):
|
|||||||
b.Wait()
|
b.Wait()
|
||||||
finally:
|
finally:
|
||||||
self.bare_git.SetHead(old)
|
self.bare_git.SetHead(old)
|
||||||
|
left = self._allrefs
|
||||||
|
|
||||||
for line in b.stdout.split("\n"):
|
for branch in kill:
|
||||||
m = rm_re.match(line)
|
if (R_HEADS + branch) not in left:
|
||||||
if m:
|
self.CleanPublishedCache()
|
||||||
deleted.add(m.group(1))
|
break
|
||||||
|
|
||||||
if deleted:
|
|
||||||
self.CleanPublishedCache()
|
|
||||||
|
|
||||||
if cb and cb not in kill:
|
if cb and cb not in kill:
|
||||||
kill.append(cb)
|
kill.append(cb)
|
||||||
kill.sort()
|
kill.sort()
|
||||||
|
|
||||||
kept = []
|
kept = []
|
||||||
for branch in kill:
|
for branch in kill:
|
||||||
if branch not in deleted:
|
if (R_HEADS + branch) in left:
|
||||||
branch = self.GetBranch(branch)
|
branch = self.GetBranch(branch)
|
||||||
base = branch.LocalMerge
|
base = branch.LocalMerge
|
||||||
if not base:
|
if not base:
|
||||||
@ -872,7 +851,11 @@ class Project(object):
|
|||||||
if not os.path.exists(self.gitdir):
|
if not os.path.exists(self.gitdir):
|
||||||
os.makedirs(self.gitdir)
|
os.makedirs(self.gitdir)
|
||||||
self.bare_git.init()
|
self.bare_git.init()
|
||||||
self.config.SetString('core.bare', None)
|
|
||||||
|
if self.manifest.IsMirror:
|
||||||
|
self.config.SetString('core.bare', 'true')
|
||||||
|
else:
|
||||||
|
self.config.SetString('core.bare', None)
|
||||||
|
|
||||||
hooks = self._gitdir_path('hooks')
|
hooks = self._gitdir_path('hooks')
|
||||||
try:
|
try:
|
||||||
|
@ -17,9 +17,9 @@ import re
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import subprocess
|
import subprocess
|
||||||
from command import Command
|
from command import Command, MirrorSafeCommand
|
||||||
|
|
||||||
class Forall(Command):
|
class Forall(Command, MirrorSafeCommand):
|
||||||
common = False
|
common = False
|
||||||
helpSummary = "Run a shell command in each project"
|
helpSummary = "Run a shell command in each project"
|
||||||
helpUsage = """
|
helpUsage = """
|
||||||
@ -30,10 +30,22 @@ Executes the same shell command in each project.
|
|||||||
|
|
||||||
Environment
|
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_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
|
shell positional arguments ($1, $2, .., $#) are set to any arguments
|
||||||
following <command>.
|
following <command>.
|
||||||
|
|
||||||
@ -66,13 +78,26 @@ not redirected.
|
|||||||
cmd.append(cmd[0])
|
cmd.append(cmd[0])
|
||||||
cmd.extend(opt.command[1:])
|
cmd.extend(opt.command[1:])
|
||||||
|
|
||||||
|
mirror = self.manifest.IsMirror
|
||||||
rc = 0
|
rc = 0
|
||||||
for project in self.GetProjects(args):
|
for project in self.GetProjects(args):
|
||||||
env = dict(os.environ.iteritems())
|
env = dict(os.environ.iteritems())
|
||||||
env['REPO_PROJECT'] = project.name
|
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,
|
p = subprocess.Popen(cmd,
|
||||||
cwd = project.worktree,
|
cwd = cwd,
|
||||||
shell = shell,
|
shell = shell,
|
||||||
env = env)
|
env = env)
|
||||||
r = p.wait()
|
r = p.wait()
|
||||||
|
@ -17,9 +17,9 @@ import sys
|
|||||||
from formatter import AbstractFormatter, DumbWriter
|
from formatter import AbstractFormatter, DumbWriter
|
||||||
|
|
||||||
from color import Coloring
|
from color import Coloring
|
||||||
from command import PagedCommand
|
from command import PagedCommand, MirrorSafeCommand
|
||||||
|
|
||||||
class Help(PagedCommand):
|
class Help(PagedCommand, MirrorSafeCommand):
|
||||||
common = False
|
common = False
|
||||||
helpSummary = "Display detailed help on a command"
|
helpSummary = "Display detailed help on a command"
|
||||||
helpUsage = """
|
helpUsage = """
|
||||||
|
@ -17,12 +17,12 @@ import os
|
|||||||
import sys
|
import sys
|
||||||
|
|
||||||
from color import Coloring
|
from color import Coloring
|
||||||
from command import InteractiveCommand
|
from command import InteractiveCommand, MirrorSafeCommand
|
||||||
from error import ManifestParseError
|
from error import ManifestParseError
|
||||||
from remote import Remote
|
from remote import Remote
|
||||||
from git_command import git, MIN_GIT_VERSION
|
from git_command import git, MIN_GIT_VERSION
|
||||||
|
|
||||||
class Init(InteractiveCommand):
|
class Init(InteractiveCommand, MirrorSafeCommand):
|
||||||
common = True
|
common = True
|
||||||
helpSummary = "Initialize repo in the current directory"
|
helpSummary = "Initialize repo in the current directory"
|
||||||
helpUsage = """
|
helpUsage = """
|
||||||
|
@ -19,11 +19,11 @@ import subprocess
|
|||||||
import sys
|
import sys
|
||||||
|
|
||||||
from git_command import GIT
|
from git_command import GIT
|
||||||
from command import Command
|
from command import Command, MirrorSafeCommand
|
||||||
from error import RepoChangedException, GitError
|
from error import RepoChangedException, GitError
|
||||||
from project import R_HEADS
|
from project import R_HEADS
|
||||||
|
|
||||||
class Sync(Command):
|
class Sync(Command, MirrorSafeCommand):
|
||||||
common = True
|
common = True
|
||||||
helpSummary = "Update working tree to the latest revision"
|
helpSummary = "Update working tree to the latest revision"
|
||||||
helpUsage = """
|
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