Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
R
repo
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
YongjieWang
repo
Commits
13508fdb
Commit
13508fdb
authored
Nov 17, 2015
by
Matthias Putz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update: google git-repo v1.12.32
parent
12c1beb7
Show whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
328 additions
and
69 deletions
+328
-69
command.py
command.py
+6
-1
manifest-format.txt
docs/manifest-format.txt
+26
-1
gitc_utils.py
gitc_utils.py
+69
-22
main.py
main.py
+7
-2
manifest_xml.py
manifest_xml.py
+2
-1
repo
repo
+35
-6
gitc_delete.py
subcmds/gitc_delete.py
+55
-0
gitc_init.py
subcmds/gitc_init.py
+17
-17
help.py
subcmds/help.py
+6
-2
start.py
subcmds/start.py
+5
-5
sync.py
subcmds/sync.py
+24
-12
gitc_config
tests/fixtures/gitc_config
+1
-0
test_wrapper.py
tests/test_wrapper.py
+75
-0
No files found.
command.py
View file @
13508fdb
...
...
@@ -231,7 +231,12 @@ class MirrorSafeCommand(object):
and does not require a working directory.
"""
class
RequiresGitc
Command
(
object
):
class
GitcAvailable
Command
(
object
):
"""Command that requires GITC to be available, but does
not require the local client to be a GITC client.
"""
class
GitcClientCommand
(
object
):
"""Command that requires the local client to be a GITC
client.
"""
docs/manifest-format.txt
View file @
13508fdb
...
...
@@ -50,7 +50,9 @@ following DTD:
<!ATTLIST url CDATA #REQUIRED>
<!ELEMENT project (annotation*,
project*)>
project*,
copyfile?,
linkfile?)>
<!ATTLIST project name CDATA #REQUIRED>
<!ATTLIST project path CDATA #IMPLIED>
<!ATTLIST project remote IDREF #IMPLIED>
...
...
@@ -68,6 +70,14 @@ following DTD:
<!ATTLIST annotation value CDATA #REQUIRED>
<!ATTLIST annotation keep CDATA "true">
<!ELEMENT copyfile (EMPTY)>
<!ATTLIST src value CDATA #REQUIRED>
<!ATTLIST dest value CDATA #REQUIRED>
<!ELEMENT linkfile (EMPTY)>
<!ATTLIST src value CDATA #REQUIRED>
<!ATTLIST dest value CDATA #REQUIRED>
<!ELEMENT extend-project>
<!ATTLIST extend-project name CDATA #REQUIRED>
<!ATTLIST extend-project path CDATA #IMPLIED>
...
...
@@ -285,6 +295,21 @@ prefixed with REPO__. In addition, there is an optional attribute
"false". This attribute determines whether or not the annotation will
be kept when exported with the manifest subcommand.
Element copyfile
----------------
Zero or more copyfile elements may be specified as children of a
project element. Each element describes a src-dest pair of files;
the "src" file will be copied to the "dest" place during 'repo sync'
command.
"src" is project relative, "dest" is relative to the top of the tree.
Element linkfile
----------------
It's just like copyfile and runs at the same time as copyfile but
instead of copying it creates a symlink.
Element remove-project
----------------------
...
...
gitc_utils.py
View file @
13508fdb
...
...
@@ -15,6 +15,8 @@
from
__future__
import
print_function
import
os
import
platform
import
re
import
sys
import
time
...
...
@@ -22,24 +24,13 @@ import git_command
import
git_config
import
wrapper
GITC_FS_ROOT_DIR
=
'/gitc/manifest-rw/'
NUM_BATCH_RETRIEVE_REVISIONID
=
300
def
get_gitc_manifest_dir
():
return
wrapper
.
Wrapper
()
.
get_gitc_manifest_dir
()
def
parse_clientdir
(
gitc_fs_path
):
"""Parse a path in the GITC FS and return its client name.
@param gitc_fs_path: A subdirectory path within the GITC_FS_ROOT_DIR.
@returns: The GITC client name
"""
if
(
gitc_fs_path
==
GITC_FS_ROOT_DIR
or
not
gitc_fs_path
.
startswith
(
GITC_FS_ROOT_DIR
)):
return
None
return
gitc_fs_path
.
split
(
GITC_FS_ROOT_DIR
)[
1
]
.
split
(
'/'
)[
0
]
return
wrapper
.
Wrapper
()
.
gitc_parse_clientdir
(
gitc_fs_path
)
def
_set_project_revisions
(
projects
):
"""Sets the revisionExpr for a list of projects.
...
...
@@ -65,26 +56,82 @@ def _set_project_revisions(projects):
sys
.
exit
(
1
)
proj
.
revisionExpr
=
gitcmd
.
stdout
.
split
(
'
\t
'
)[
0
]
def
generate_gitc_manifest
(
client_dir
,
manifest
,
projects
=
None
):
def
_manifest_groups
(
manifest
):
"""Returns the manifest group string that should be synced
This is the same logic used by Command.GetProjects(), which is used during
repo sync
@param manifest: The XmlManifest object
"""
mp
=
manifest
.
manifestProject
groups
=
mp
.
config
.
GetString
(
'manifest.groups'
)
if
not
groups
:
groups
=
'default,platform-'
+
platform
.
system
()
.
lower
()
return
groups
def
generate_gitc_manifest
(
gitc_manifest
,
manifest
,
paths
=
None
):
"""Generate a manifest for shafsd to use for this GITC client.
@param client_dir: GITC client directory to install the .manifest file in.
@param manifest: XmlManifest object representing the repo manifest.
@param projects: List of projects we want to update, this must be a sublist
of manifest.projects to work properly. If not provided,
manifest.projects is used.
@param gitc_manifest: Current gitc manifest, or None if there isn't one yet.
@param manifest: A GitcManifest object loaded with the current repo manifest.
@param paths: List of project paths we want to update.
"""
print
(
'Generating GITC Manifest by fetching revision SHAs for each '
'project.'
)
if
projects
is
None
:
projects
=
manifest
.
projects
if
paths
is
None
:
paths
=
manifest
.
paths
.
keys
()
groups
=
[
x
for
x
in
re
.
split
(
r'[,\s]+'
,
_manifest_groups
(
manifest
))
if
x
]
# Convert the paths to projects, and filter them to the matched groups.
projects
=
[
manifest
.
paths
[
p
]
for
p
in
paths
]
projects
=
[
p
for
p
in
projects
if
p
.
MatchesGroups
(
groups
)]
if
gitc_manifest
is
not
None
:
for
path
,
proj
in
manifest
.
paths
.
iteritems
():
if
not
proj
.
MatchesGroups
(
groups
):
continue
if
not
proj
.
upstream
and
not
git_config
.
IsId
(
proj
.
revisionExpr
):
proj
.
upstream
=
proj
.
revisionExpr
if
not
path
in
gitc_manifest
.
paths
:
# Any new projects need their first revision, even if we weren't asked
# for them.
projects
.
append
(
proj
)
elif
not
path
in
paths
:
# And copy revisions from the previous manifest if we're not updating
# them now.
gitc_proj
=
gitc_manifest
.
paths
[
path
]
if
gitc_proj
.
old_revision
:
proj
.
revisionExpr
=
None
proj
.
old_revision
=
gitc_proj
.
old_revision
else
:
proj
.
revisionExpr
=
gitc_proj
.
revisionExpr
index
=
0
while
index
<
len
(
projects
):
_set_project_revisions
(
projects
[
index
:(
index
+
NUM_BATCH_RETRIEVE_REVISIONID
)])
index
+=
NUM_BATCH_RETRIEVE_REVISIONID
if
gitc_manifest
is
not
None
:
for
path
,
proj
in
gitc_manifest
.
paths
.
iteritems
():
if
proj
.
old_revision
and
path
in
paths
:
# If we updated a project that has been started, keep the old-revision
# updated.
repo_proj
=
manifest
.
paths
[
path
]
repo_proj
.
old_revision
=
repo_proj
.
revisionExpr
repo_proj
.
revisionExpr
=
None
# Convert URLs from relative to absolute.
for
name
,
remote
in
manifest
.
remotes
.
iteritems
():
remote
.
fetchUrl
=
remote
.
resolvedFetchUrl
# Save the manifest.
save_manifest
(
manifest
,
client_dir
=
client_dir
)
save_manifest
(
manifest
)
def
save_manifest
(
manifest
,
client_dir
=
None
):
"""Save the manifest file in the client_dir.
...
...
@@ -95,7 +142,7 @@ def save_manifest(manifest, client_dir=None):
if
not
client_dir
:
client_dir
=
manifest
.
gitc_client_dir
with
open
(
os
.
path
.
join
(
client_dir
,
'.manifest'
),
'w'
)
as
f
:
manifest
.
Save
(
f
)
manifest
.
Save
(
f
,
groups
=
_manifest_groups
(
manifest
)
)
# TODO(sbasi/jorg): Come up with a solution to remove the sleep below.
# Give the GITC filesystem time to register the manifest changes.
time
.
sleep
(
3
)
main.py
View file @
13508fdb
...
...
@@ -44,7 +44,7 @@ from git_command import git, GitCommand
from
git_config
import
init_ssh
,
close_ssh
from
command
import
InteractiveCommand
from
command
import
MirrorSafeCommand
from
command
import
RequiresGitc
Command
from
command
import
GitcAvailableCommand
,
GitcClient
Command
from
subcmds.version
import
Version
from
editor
import
Editor
from
error
import
DownloadError
...
...
@@ -146,11 +146,16 @@ class _Repo(object):
file
=
sys
.
stderr
)
return
1
if
isinstance
(
cmd
,
RequiresGitc
Command
)
and
not
gitc_utils
.
get_gitc_manifest_dir
():
if
isinstance
(
cmd
,
GitcAvailable
Command
)
and
not
gitc_utils
.
get_gitc_manifest_dir
():
print
(
"fatal: '
%
s' requires GITC to be available"
%
name
,
file
=
sys
.
stderr
)
return
1
if
isinstance
(
cmd
,
GitcClientCommand
)
and
not
gitc_client_name
:
print
(
"fatal: '
%
s' requires a GITC client"
%
name
,
file
=
sys
.
stderr
)
return
1
try
:
copts
,
cargs
=
cmd
.
OptionParser
.
parse_args
(
argv
)
copts
=
cmd
.
ReadEnvironmentOptions
(
copts
)
...
...
manifest_xml.py
View file @
13508fdb
...
...
@@ -169,11 +169,12 @@ class XmlManifest(object):
def
_ParseGroups
(
self
,
groups
):
return
[
x
for
x
in
re
.
split
(
r'[,\s]+'
,
groups
)
if
x
]
def
Save
(
self
,
fd
,
peg_rev
=
False
,
peg_rev_upstream
=
True
):
def
Save
(
self
,
fd
,
peg_rev
=
False
,
peg_rev_upstream
=
True
,
groups
=
None
):
"""Write the current manifest out to the given file descriptor.
"""
mp
=
self
.
manifestProject
if
groups
is
None
:
groups
=
mp
.
config
.
GetString
(
'manifest.groups'
)
if
groups
:
groups
=
self
.
_ParseGroups
(
groups
)
...
...
repo
View file @
13508fdb
...
...
@@ -21,7 +21,7 @@ REPO_REV = 'stable'
# limitations under the License.
# increment this whenever we make important changes to this script
VERSION
=
(
1
,
2
1
)
VERSION
=
(
1
,
2
2
)
# increment this if the MAINTAINER_KEYS block is modified
KEYRING_VERSION
=
(
1
,
2
)
...
...
@@ -68,6 +68,7 @@ S_manifests = 'manifests' # special manifest repository
REPO_MAIN
=
S_repo
+
'/main.py'
# main script
MIN_PYTHON_VERSION
=
(
2
,
6
)
# minimum supported python version
GITC_CONFIG_FILE
=
'/gitc/.config'
GITC_FS_ROOT_DIR
=
'/gitc/manifest-rw/'
import
errno
...
...
@@ -180,7 +181,7 @@ def _GitcInitOptions(init_optparse):
help
=
'Optional manifest file to use for this GITC client.'
)
g
.
add_option
(
'-c'
,
'--gitc-client'
,
dest
=
'gitc_client'
,
help
=
'The name
for the new gitc_client instance
.'
)
help
=
'The name
of the gitc_client instance to create or modify
.'
)
_gitc_manifest_dir
=
None
def
get_gitc_manifest_dir
():
...
...
@@ -197,6 +198,28 @@ def get_gitc_manifest_dir():
pass
return
_gitc_manifest_dir
def
gitc_parse_clientdir
(
gitc_fs_path
):
"""Parse a path in the GITC FS and return its client name.
@param gitc_fs_path: A subdirectory path within the GITC_FS_ROOT_DIR.
@returns: The GITC client name
"""
if
gitc_fs_path
==
GITC_FS_ROOT_DIR
:
return
None
if
not
gitc_fs_path
.
startswith
(
GITC_FS_ROOT_DIR
):
manifest_dir
=
get_gitc_manifest_dir
()
if
manifest_dir
==
''
:
return
None
if
manifest_dir
[
-
1
]
!=
'/'
:
manifest_dir
+=
'/'
if
gitc_fs_path
==
manifest_dir
:
return
None
if
not
gitc_fs_path
.
startswith
(
manifest_dir
):
return
None
return
gitc_fs_path
.
split
(
manifest_dir
)[
1
]
.
split
(
'/'
)[
0
]
return
gitc_fs_path
.
split
(
GITC_FS_ROOT_DIR
)[
1
]
.
split
(
'/'
)[
0
]
class
CloneFailure
(
Exception
):
"""Indicate the remote clone of repo itself failed.
"""
...
...
@@ -235,10 +258,13 @@ def _Init(args, gitc_init=False):
_print
(
'fatal: GITC filesystem is not available. Exiting...'
,
file
=
sys
.
stderr
)
sys
.
exit
(
1
)
if
not
opt
.
gitc_client
:
gitc_client
=
opt
.
gitc_client
if
not
gitc_client
:
gitc_client
=
gitc_parse_clientdir
(
os
.
getcwd
())
if
not
gitc_client
:
_print
(
'fatal: GITC client (-c) is required.'
,
file
=
sys
.
stderr
)
sys
.
exit
(
1
)
client_dir
=
os
.
path
.
join
(
gitc_manifest_dir
,
opt
.
gitc_client
)
client_dir
=
os
.
path
.
join
(
gitc_manifest_dir
,
gitc_client
)
if
not
os
.
path
.
exists
(
client_dir
):
os
.
makedirs
(
client_dir
)
os
.
chdir
(
client_dir
)
...
...
@@ -526,7 +552,6 @@ def _Clone(url, local, quiet):
'+refs/heads/*:refs/remotes/origin/*'
)
if
_DownloadBundle
(
url
,
local
,
quiet
):
_ImportBundle
(
local
)
else
:
_Fetch
(
url
,
local
,
'origin'
,
quiet
)
...
...
@@ -732,9 +757,13 @@ def _SetDefaultsTo(gitdir):
def
main
(
orig_args
):
repo_main
,
rel_repo_dir
=
_FindRepo
()
cmd
,
opt
,
args
=
_ParseArguments
(
orig_args
)
repo_main
,
rel_repo_dir
=
None
,
None
# Don't use the local repo copy, make sure to switch to the gitc client first.
if
cmd
!=
'gitc-init'
:
repo_main
,
rel_repo_dir
=
_FindRepo
()
wrapper_path
=
os
.
path
.
abspath
(
__file__
)
my_main
,
my_git
=
_RunSelf
(
wrapper_path
)
...
...
subcmds/gitc_delete.py
0 → 100644
View file @
13508fdb
#
# Copyright (C) 2015 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.
from
__future__
import
print_function
import
os
import
shutil
import
sys
from
command
import
Command
,
GitcClientCommand
import
gitc_utils
from
pyversion
import
is_python3
if
not
is_python3
():
# pylint:disable=W0622
input
=
raw_input
# pylint:enable=W0622
class
GitcDelete
(
Command
,
GitcClientCommand
):
common
=
True
visible_everywhere
=
False
helpSummary
=
"Delete a GITC Client."
helpUsage
=
"""
%
prog
"""
helpDescription
=
"""
This subcommand deletes the current GITC client, deleting the GITC manifest
and all locally downloaded sources.
"""
def
_Options
(
self
,
p
):
p
.
add_option
(
'-f'
,
'--force'
,
dest
=
'force'
,
action
=
'store_true'
,
help
=
'Force the deletion (no prompt).'
)
def
Execute
(
self
,
opt
,
args
):
if
not
opt
.
force
:
prompt
=
(
'This will delete GITC client:
%
s
\n
Are you sure? (yes/no) '
%
self
.
gitc_manifest
.
gitc_client_name
)
response
=
input
(
prompt
)
.
lower
()
if
not
response
==
'yes'
:
print
(
'Response was not "yes"
\n
Exiting...'
)
sys
.
exit
(
1
)
shutil
.
rmtree
(
self
.
gitc_manifest
.
gitc_client_dir
)
subcmds/gitc_init.py
View file @
13508fdb
...
...
@@ -18,11 +18,13 @@ import os
import
sys
import
gitc_utils
from
command
import
RequiresGitcCommand
from
command
import
GitcAvailableCommand
from
manifest_xml
import
GitcManifest
from
subcmds
import
init
import
wrapper
class
GitcInit
(
init
.
Init
,
RequiresGitc
Command
):
class
GitcInit
(
init
.
Init
,
GitcAvailable
Command
):
common
=
True
helpSummary
=
"Initialize a GITC Client."
helpUsage
=
"""
...
...
@@ -34,7 +36,7 @@ with the GITC file system.
This command will setup the client directory, initialize repo, just
like repo init does, and then downloads the manifest collection
and installs i
n
in the .repo/directory of the GITC client.
and installs i
t
in the .repo/directory of the GITC client.
Once this is done, a GITC manifest is generated by pulling the HEAD
SHA for each project and generates the properly formatted XML file
...
...
@@ -54,29 +56,27 @@ use for this GITC client.
help
=
'Optional manifest file to use for this GITC client.'
)
g
.
add_option
(
'-c'
,
'--gitc-client'
,
dest
=
'gitc_client'
,
help
=
'The name
for the new gitc_client instance
.'
)
help
=
'The name
of the gitc_client instance to create or modify
.'
)
def
Execute
(
self
,
opt
,
args
):
if
not
opt
.
gitc_client
:
print
(
'fatal: gitc client (-c) is required'
,
file
=
sys
.
stderr
)
gitc_client
=
gitc_utils
.
parse_clientdir
(
os
.
getcwd
())
if
not
gitc_client
or
(
opt
.
gitc_client
and
gitc_client
!=
opt
.
gitc_client
):
print
(
'fatal: Please update your repo command. See go/gitc for instructions.'
,
file
=
sys
.
stderr
)
sys
.
exit
(
1
)
self
.
client_dir
=
os
.
path
.
join
(
gitc_utils
.
get_gitc_manifest_dir
(),
opt
.
gitc_client
)
if
not
os
.
path
.
exists
(
gitc_utils
.
get_gitc_manifest_dir
()):
os
.
makedirs
(
gitc_utils
.
get_gitc_manifest_dir
())
if
not
os
.
path
.
exists
(
self
.
client_dir
):
os
.
mkdir
(
self
.
client_dir
)
gitc_client
)
super
(
GitcInit
,
self
)
.
Execute
(
opt
,
args
)
for
name
,
remote
in
self
.
manifest
.
remotes
.
iteritems
():
remote
.
fetchUrl
=
remote
.
resolvedFetchUrl
manifest_file
=
self
.
manifest
.
manifestFile
if
opt
.
manifest_file
:
if
not
os
.
path
.
exists
(
opt
.
manifest_file
):
print
(
'fatal: Specified manifest file
%
s does not exist.'
%
opt
.
manifest_file
)
sys
.
exit
(
1
)
self
.
manifest
.
Override
(
opt
.
manifest_file
)
gitc_utils
.
generate_gitc_manifest
(
self
.
client_dir
,
self
.
manifest
)
manifest_file
=
opt
.
manifest_file
manifest
=
GitcManifest
(
self
.
repodir
,
gitc_client
)
manifest
.
Override
(
manifest_file
)
gitc_utils
.
generate_gitc_manifest
(
None
,
manifest
)
print
(
'Please run `cd
%
s` to view your GITC client.'
%
os
.
path
.
join
(
gitc_utils
.
GITC_FS_ROOT_DIR
,
opt
.
gitc_client
))
os
.
path
.
join
(
wrapper
.
Wrapper
()
.
GITC_FS_ROOT_DIR
,
gitc_client
))
subcmds/help.py
View file @
13508fdb
...
...
@@ -19,7 +19,7 @@ import sys
from
formatter
import
AbstractFormatter
,
DumbWriter
from
color
import
Coloring
from
command
import
PagedCommand
,
MirrorSafeCommand
,
RequiresGitc
Command
from
command
import
PagedCommand
,
MirrorSafeCommand
,
GitcAvailableCommand
,
GitcClient
Command
import
gitc_utils
class
Help
(
PagedCommand
,
MirrorSafeCommand
):
...
...
@@ -57,8 +57,12 @@ Displays detailed usage information about a command.
print
(
'The most commonly used repo commands are:'
)
def
gitc_supported
(
cmd
):
if
not
isinstance
(
cmd
,
RequiresGitc
Command
):
if
not
isinstance
(
cmd
,
GitcAvailableCommand
)
and
not
isinstance
(
cmd
,
GitcClient
Command
):
return
True
if
self
.
manifest
.
isGitcClient
:
return
True
if
isinstance
(
cmd
,
GitcClientCommand
):
return
False
if
gitc_utils
.
get_gitc_manifest_dir
():
return
True
return
False
...
...
subcmds/start.py
View file @
13508fdb
...
...
@@ -57,7 +57,6 @@ revision specified in the manifest.
print
(
"error: at least one project must be specified"
,
file
=
sys
.
stderr
)
sys
.
exit
(
1
)
proj_name_to_gitc_proj_dict
=
{}
if
self
.
gitc_manifest
:
all_projects
=
self
.
GetProjects
(
projects
,
manifest
=
self
.
gitc_manifest
,
missing_ok
=
True
)
...
...
@@ -67,7 +66,6 @@ revision specified in the manifest.
else
:
project
.
already_synced
=
False
project
.
old_revision
=
project
.
revisionExpr
proj_name_to_gitc_proj_dict
[
project
.
name
]
=
project
project
.
revisionExpr
=
None
# Save the GITC manifest.
gitc_utils
.
save_manifest
(
self
.
gitc_manifest
)
...
...
@@ -77,9 +75,10 @@ revision specified in the manifest.
pm
=
Progress
(
'Starting
%
s'
%
nb
,
len
(
all_projects
))
for
project
in
all_projects
:
pm
.
update
()
if
self
.
gitc_manifest
:
gitc_project
=
proj_name_to_gitc_proj_dict
[
project
.
name
]
# Sync projects that have
already
been opened.
gitc_project
=
self
.
gitc_manifest
.
paths
[
project
.
relpath
]
# Sync projects that have
not
been opened.
if
not
gitc_project
.
already_synced
:
proj_localdir
=
os
.
path
.
join
(
self
.
gitc_manifest
.
gitc_client_dir
,
project
.
relpath
)
...
...
@@ -89,7 +88,7 @@ revision specified in the manifest.
project
.
Sync_NetworkHalf
()
sync_buf
=
SyncBuffer
(
self
.
manifest
.
manifestProject
.
config
)
project
.
Sync_LocalHalf
(
sync_buf
)
project
.
revision
Expr
=
gitc_project
.
old_revision
project
.
revision
Id
=
gitc_project
.
old_revision
# If the current revision is a specific SHA1 then we can't push back
# to it; so substitute with dest_branch if defined, or with manifest
...
...
@@ -100,6 +99,7 @@ revision specified in the manifest.
branch_merge
=
project
.
dest_branch
else
:
branch_merge
=
self
.
manifest
.
default
.
revisionExpr
if
not
project
.
StartBranch
(
nb
,
branch_merge
=
branch_merge
):
err
.
append
(
project
)
pm
.
end
()
...
...
subcmds/sync.py
View file @
13508fdb
...
...
@@ -75,6 +75,7 @@ from error import RepoChangedException, GitError, ManifestParseError
from
project
import
SyncBuffer
from
progress
import
Progress
from
wrapper
import
Wrapper
from
manifest_xml
import
GitcManifest
_ONE_DAY_S
=
24
*
60
*
60
...
...
@@ -670,32 +671,39 @@ later is required to fix a server side protocol bug.
if
opt
.
jobs
is
None
:
self
.
jobs
=
self
.
manifest
.
default
.
sync_j
# TODO (sbasi) - Add support for manifest changes, aka projects
# have been added or deleted from the manifest.
if
self
.
gitc_manifest
:
gitc_manifest_projects
=
self
.
GetProjects
(
args
,
manifest
=
self
.
gitc_manifest
,
missing_ok
=
True
)
gitc_projects
=
[]
opened_projects
=
[]
for
project
in
gitc_manifest_projects
:
if
not
project
.
old_revision
:
gitc_projects
.
append
(
project
)
if
project
.
relpath
in
self
.
gitc_manifest
.
paths
and
\
self
.
gitc_manifest
.
paths
[
project
.
relpath
]
.
old_revision
:
opened_projects
.
append
(
project
.
relpath
)
else
:
opened_projects
.
append
(
project
)
gitc_projects
.
append
(
project
.
relpath
)
if
gitc_projects
and
not
opt
.
local_only
:
if
not
args
:
gitc_projects
=
None
if
gitc_projects
!=
[]
and
not
opt
.
local_only
:
print
(
'Updating GITC client:
%
s'
%
self
.
gitc_manifest
.
gitc_client_name
)
gitc_utils
.
generate_gitc_manifest
(
self
.
gitc_manifest
.
gitc_client_dir
,
self
.
gitc_manifest
,
manifest
=
GitcManifest
(
self
.
repodir
,
self
.
gitc_manifest
.
gitc_client_name
)
if
manifest_name
:
manifest
.
Override
(
manifest_name
)
else
:
manifest
.
Override
(
self
.
manifest
.
manifestFile
)
gitc_utils
.
generate_gitc_manifest
(
self
.
gitc_manifest
,
manifest
,
gitc_projects
)
print
(
'GITC client successfully synced.'
)
# The opened projects need to be synced as normal, therefore we
# generate a new args list to represent the opened projects.
args
=
[]
for
proj
in
opened_projects
:
args
.
append
(
os
.
path
.
relpath
(
proj
.
worktree
,
os
.
getcwd
()))
# TODO: make this more reliable -- if there's a project name/path overlap,
# this may choose the wrong project.
args
=
[
os
.
path
.
relpath
(
self
.
manifest
.
paths
[
p
]
.
worktree
,
os
.
getcwd
())
for
p
in
opened_projects
]
if
not
args
:
return
all_projects
=
self
.
GetProjects
(
args
,
...
...
@@ -908,6 +916,7 @@ class PersistentTransport(xmlrpc.client.Transport):
# stripping those prefixes away.
if
cookiefile
:
tmpcookiefile
=
tempfile
.
NamedTemporaryFile
()
tmpcookiefile
.
write
(
"# HTTP Cookie File"
)
try
:
with
open
(
cookiefile
)
as
f
:
for
line
in
f
:
...
...
@@ -917,7 +926,10 @@ class PersistentTransport(xmlrpc.client.Transport):
tmpcookiefile
.
flush
()
cookiejar
=
cookielib
.
MozillaCookieJar
(
tmpcookiefile
.
name
)
try
:
cookiejar
.
load
()
except
cookielib
.
LoadError
:
cookiejar
=
cookielib
.
CookieJar
()
finally
:
tmpcookiefile
.
close
()
else
:
...
...
tests/fixtures/gitc_config
0 → 100644
View file @
13508fdb
gitc_dir=/test/usr/local/google/gitc
tests/test_wrapper.py
0 → 100644
View file @
13508fdb
#
# Copyright (C) 2015 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
os
import
unittest
import
wrapper
def
fixture
(
*
paths
):
"""Return a path relative to tests/fixtures.
"""
return
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
'fixtures'
,
*
paths
)
class
RepoWrapperUnitTest
(
unittest
.
TestCase
):
"""Tests helper functions in the repo wrapper
"""
def
setUp
(
self
):
"""Load the wrapper module every time
"""
wrapper
.
_wrapper_module
=
None
self
.
wrapper
=
wrapper
.
Wrapper
()
def
test_get_gitc_manifest_dir_no_gitc
(
self
):
"""
Test reading a missing gitc config file
"""
self
.
wrapper
.
GITC_CONFIG_FILE
=
fixture
(
'missing_gitc_config'
)
val
=
self
.
wrapper
.
get_gitc_manifest_dir
()
self
.
assertEqual
(
val
,
''
)
def
test_get_gitc_manifest_dir
(
self
):
"""
Test reading the gitc config file and parsing the directory
"""
self
.
wrapper
.
GITC_CONFIG_FILE
=
fixture
(
'gitc_config'
)
val
=
self
.
wrapper
.
get_gitc_manifest_dir
()
self
.
assertEqual
(
val
,
'/test/usr/local/google/gitc'
)
def
test_gitc_parse_clientdir_no_gitc
(
self
):
"""
Test parsing the gitc clientdir without gitc running
"""
self
.
wrapper
.
GITC_CONFIG_FILE
=
fixture
(
'missing_gitc_config'
)
self
.
assertEqual
(
self
.
wrapper
.
gitc_parse_clientdir
(
'/something'
),
None
)
self
.
assertEqual
(
self
.
wrapper
.
gitc_parse_clientdir
(
'/gitc/manifest-rw/test'
),
'test'
)
def
test_gitc_parse_clientdir
(
self
):
"""
Test parsing the gitc clientdir
"""
self
.
wrapper
.
GITC_CONFIG_FILE
=
fixture
(
'gitc_config'
)
self
.
assertEqual
(
self
.
wrapper
.
gitc_parse_clientdir
(
'/something'
),
None
)
self
.
assertEqual
(
self
.
wrapper
.
gitc_parse_clientdir
(
'/gitc/manifest-rw/test'
),
'test'
)
self
.
assertEqual
(
self
.
wrapper
.
gitc_parse_clientdir
(
'/gitc/manifest-rw/test/'
),
'test'
)
self
.
assertEqual
(
self
.
wrapper
.
gitc_parse_clientdir
(
'/gitc/manifest-rw/test/extra'
),
'test'
)
self
.
assertEqual
(
self
.
wrapper
.
gitc_parse_clientdir
(
'/test/usr/local/google/gitc/test'
),
'test'
)
self
.
assertEqual
(
self
.
wrapper
.
gitc_parse_clientdir
(
'/test/usr/local/google/gitc/test/'
),
'test'
)
self
.
assertEqual
(
self
.
wrapper
.
gitc_parse_clientdir
(
'/test/usr/local/google/gitc/test/extra'
),
'test'
)
self
.
assertEqual
(
self
.
wrapper
.
gitc_parse_clientdir
(
'/gitc/manifest-rw/'
),
None
)
self
.
assertEqual
(
self
.
wrapper
.
gitc_parse_clientdir
(
'/test/usr/local/google/gitc/'
),
None
)
if
__name__
==
'__main__'
:
unittest
.
main
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment