Commit 0b9e693a authored by jochen@chromium.org's avatar jochen@chromium.org

Add option --local allowing for merging changes into a local working copy.

BUG=none
TEST=none

Review URL: http://codereview.chromium.org/651022

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@39603 0039d316-1c4b-4281-b951-d872f2087c98
parent 8bf2731d
...@@ -24,6 +24,10 @@ Valid parameters: ...@@ -24,6 +24,10 @@ Valid parameters:
--merge <revision> --branch <branch_num> --merge <revision> --branch <branch_num>
Example: %(app)s --merge 12345 --branch 187 Example: %(app)s --merge 12345 --branch 187
[Merge from trunk to local copy]
--merge <revision> --local
Example: %(app)s --merge 12345 --local
[Merge from branch to branch] [Merge from branch to branch]
--merge <revision> --sbranch <branch_num> --branch <branch_num> --merge <revision> --sbranch <branch_num> --branch <branch_num>
Example: %(app)s --merge 12345 --sbranch 248 --branch 249 Example: %(app)s --merge 12345 --sbranch 248 --branch 249
...@@ -96,6 +100,19 @@ def getSVNInfo(url, revision): ...@@ -96,6 +100,19 @@ def getSVNInfo(url, revision):
return info return info
def isSVNDirty():
command = 'svn status'
svn_status = subprocess.Popen(command,
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE).stdout.readlines()
for line in svn_status:
match = re.search(r"^[^X?]", line)
if match:
return True
return False
def getAuthor(url, revision): def getAuthor(url, revision):
info = getSVNInfo(url, revision) info = getSVNInfo(url, revision)
if (info.has_key("Last Changed Author")): if (info.has_key("Last Changed Author")):
...@@ -116,6 +133,16 @@ def isSVNDirectory(url, revision): ...@@ -116,6 +133,16 @@ def isSVNDirectory(url, revision):
return True return True
return False return False
def inCheckoutRoot(path):
info = getSVNInfo(path, "HEAD")
if (not info.has_key("Repository Root")):
return False
repo_root = info["Repository Root"];
info = getSVNInfo(os.path.dirname(os.path.abspath(path)), "HEAD")
if (info.get("Repository Root", None) != repo_root):
return True
return False
def getRevisionLog(url, revision): def getRevisionLog(url, revision):
"""Takes an svn url and gets the associated revision.""" """Takes an svn url and gets the associated revision."""
command = 'svn log ' + url + " -r"+str(revision) command = 'svn log ' + url + " -r"+str(revision)
...@@ -442,26 +469,37 @@ def main(options, args): ...@@ -442,26 +469,37 @@ def main(options, args):
working = options.workdir or DEFAULT_WORKING working = options.workdir or DEFAULT_WORKING
if options.local:
working = os.getcwd()
if not inCheckoutRoot(working):
print "'%s' appears not to be the root of a working copy" % working
sys.exit(1)
if isSVNDirty():
print "Working copy contains uncommitted files"
sys.exit(1)
command = 'svn log ' + url + " -r "+str(revision) + " -v" command = 'svn log ' + url + " -r "+str(revision) + " -v"
os.system(command) os.system(command)
if not (options.revertbot or prompt("Is this the correct revision?")): if not (options.revertbot or prompt("Is this the correct revision?")):
sys.exit(0) sys.exit(0)
if (os.path.exists(working)): if (os.path.exists(working)) and not options.local:
if not (options.revertbot or SKIP_CHECK_WORKING or if not (options.revertbot or SKIP_CHECK_WORKING or
prompt("Working directory: '%s' already exists, clobber?" % working)): prompt("Working directory: '%s' already exists, clobber?" % working)):
sys.exit(0) sys.exit(0)
deltree(working) deltree(working)
os.makedirs(working) if not options.local:
os.chdir(working) os.makedirs(working)
os.chdir(working)
if options.merge: if options.merge:
action = "Merge" action = "Merge"
branch_url = BRANCH_URL.replace("$branch", options.branch) if not options.local:
# Checkout everything but stuff that got added into a new dir branch_url = BRANCH_URL.replace("$branch", options.branch)
checkoutRevision(url, revision, branch_url) # Checkout everything but stuff that got added into a new dir
checkoutRevision(url, revision, branch_url)
# Merge everything that changed # Merge everything that changed
mergeRevision(url, revision) mergeRevision(url, revision)
# "Export" files that were added from the source and add them to branch # "Export" files that were added from the source and add them to branch
...@@ -498,6 +536,10 @@ def main(options, args): ...@@ -498,6 +536,10 @@ def main(options, args):
change_cmd += ' --silent' change_cmd += ' --silent'
runGcl(change_cmd) runGcl(change_cmd)
os.unlink(filename) os.unlink(filename)
if options.local:
sys.exit(0)
print author print author
print revision print revision
print ("gcl upload " + str(revision) + print ("gcl upload " + str(revision) +
...@@ -532,6 +574,8 @@ if __name__ == "__main__": ...@@ -532,6 +574,8 @@ if __name__ == "__main__":
help='Revision to merge from trunk to branch') help='Revision to merge from trunk to branch')
option_parser.add_option('-b', '--branch', option_parser.add_option('-b', '--branch',
help='Branch to revert or merge from') help='Branch to revert or merge from')
option_parser.add_option('-l', '--local', action='store_true',
help='Local working copy to merge to')
option_parser.add_option('-s', '--sbranch', option_parser.add_option('-s', '--sbranch',
help='Source branch for merge') help='Source branch for merge')
option_parser.add_option('-r', '--revert', type="int", option_parser.add_option('-r', '--revert', type="int",
...@@ -551,8 +595,12 @@ if __name__ == "__main__": ...@@ -551,8 +595,12 @@ if __name__ == "__main__":
option_parser.error("You need at least --merge or --revert") option_parser.error("You need at least --merge or --revert")
sys.exit(1) sys.exit(1)
if options.merge and not options.branch: if options.merge and not options.branch and not options.local:
option_parser.error("--merge requires a --branch") option_parser.error("--merge requires either --branch or --local")
sys.exit(1)
if options.local and (options.revert or options.branch):
option_parser.error("--local cannot be used with --revert or --branch")
sys.exit(1) sys.exit(1)
sys.exit(main(options, args)) sys.exit(main(options, args))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment