mirror of
https://gerrit.googlesource.com/git-repo
synced 2026-01-12 09:30:28 +00:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
edadb25c02 | ||
|
|
96edb9b573 |
39
project.py
39
project.py
@@ -21,6 +21,7 @@ import random
|
||||
import re
|
||||
import shutil
|
||||
import stat
|
||||
import string
|
||||
import subprocess
|
||||
import sys
|
||||
import tarfile
|
||||
@@ -266,6 +267,7 @@ class ReviewableBranch:
|
||||
dest_branch=None,
|
||||
validate_certs=True,
|
||||
push_options=None,
|
||||
patchset_description=None,
|
||||
):
|
||||
self.project.UploadForReview(
|
||||
branch=self.name,
|
||||
@@ -281,6 +283,7 @@ class ReviewableBranch:
|
||||
dest_branch=dest_branch,
|
||||
validate_certs=validate_certs,
|
||||
push_options=push_options,
|
||||
patchset_description=patchset_description,
|
||||
)
|
||||
|
||||
def GetPublishedRefs(self):
|
||||
@@ -1089,6 +1092,7 @@ class Project:
|
||||
dest_branch=None,
|
||||
validate_certs=True,
|
||||
push_options=None,
|
||||
patchset_description=None,
|
||||
):
|
||||
"""Uploads the named branch for code review."""
|
||||
if branch is None:
|
||||
@@ -1171,6 +1175,10 @@ class Project:
|
||||
opts += ["wip"]
|
||||
if ready:
|
||||
opts += ["ready"]
|
||||
if patchset_description:
|
||||
opts += [
|
||||
f"m={self._encode_patchset_description(patchset_description)}"
|
||||
]
|
||||
if opts:
|
||||
ref_spec = ref_spec + "%" + ",".join(opts)
|
||||
cmd.append(ref_spec)
|
||||
@@ -1183,6 +1191,30 @@ class Project:
|
||||
R_PUB + branch.name, R_HEADS + branch.name, message=msg
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def _encode_patchset_description(original):
|
||||
"""Applies percent-encoding for strings sent as patchset description.
|
||||
|
||||
The encoding used is based on but stricter than URL encoding (Section
|
||||
2.1 of RFC 3986). The only non-escaped characters are alphanumerics, and
|
||||
'SPACE' (U+0020) can be represented as 'LOW LINE' (U+005F) or
|
||||
'PLUS SIGN' (U+002B).
|
||||
|
||||
For more information, see the Gerrit docs here:
|
||||
https://gerrit-review.googlesource.com/Documentation/user-upload.html#patch_set_description
|
||||
"""
|
||||
SAFE = {ord(x) for x in string.ascii_letters + string.digits}
|
||||
|
||||
def _enc(b):
|
||||
if b in SAFE:
|
||||
return chr(b)
|
||||
elif b == ord(" "):
|
||||
return "_"
|
||||
else:
|
||||
return f"%{b:02x}"
|
||||
|
||||
return "".join(_enc(x) for x in original.encode("utf-8"))
|
||||
|
||||
def _ExtractArchive(self, tarpath, path=None):
|
||||
"""Extract the given tar on its current location
|
||||
|
||||
@@ -1483,6 +1515,7 @@ class Project:
|
||||
self,
|
||||
syncbuf,
|
||||
force_sync=False,
|
||||
force_checkout=False,
|
||||
submodules=False,
|
||||
errors=None,
|
||||
verbose=False,
|
||||
@@ -1570,7 +1603,7 @@ class Project:
|
||||
syncbuf.info(self, "discarding %d commits", len(lost))
|
||||
|
||||
try:
|
||||
self._Checkout(revid, quiet=True)
|
||||
self._Checkout(revid, force_checkout=force_checkout, quiet=True)
|
||||
if submodules:
|
||||
self._SyncSubmodules(quiet=True)
|
||||
except GitError as e:
|
||||
@@ -2825,10 +2858,12 @@ class Project:
|
||||
except OSError:
|
||||
return False
|
||||
|
||||
def _Checkout(self, rev, quiet=False):
|
||||
def _Checkout(self, rev, force_checkout=False, quiet=False):
|
||||
cmd = ["checkout"]
|
||||
if quiet:
|
||||
cmd.append("-q")
|
||||
if force_checkout:
|
||||
cmd.append("-f")
|
||||
cmd.append(rev)
|
||||
cmd.append("--")
|
||||
if GitCommand(self, cmd).Wait() != 0:
|
||||
|
||||
@@ -278,6 +278,11 @@ directories if they have previously been linked to a different
|
||||
object directory. WARNING: This may cause data to be lost since
|
||||
refs may be removed when overwriting.
|
||||
|
||||
The --force-checkout option can be used to force git to switch revs even if the
|
||||
index or the working tree differs from HEAD, and if there are untracked files.
|
||||
WARNING: This may cause data to be lost since uncommitted changes may be
|
||||
removed.
|
||||
|
||||
The --force-remove-dirty option can be used to remove previously used
|
||||
projects with uncommitted changes. WARNING: This may cause data to be
|
||||
lost since uncommitted changes may be removed with projects that no longer
|
||||
@@ -375,6 +380,14 @@ later is required to fix a server side protocol bug.
|
||||
"point to a different object directory. WARNING: this "
|
||||
"may cause loss of data",
|
||||
)
|
||||
p.add_option(
|
||||
"--force-checkout",
|
||||
dest="force_checkout",
|
||||
action="store_true",
|
||||
help="force checkout even if it results in throwing away "
|
||||
"uncommitted modifications. "
|
||||
"WARNING: this may cause loss of data",
|
||||
)
|
||||
p.add_option(
|
||||
"--force-remove-dirty",
|
||||
dest="force_remove_dirty",
|
||||
@@ -991,12 +1004,17 @@ later is required to fix a server side protocol bug.
|
||||
|
||||
return _FetchMainResult(all_projects)
|
||||
|
||||
def _CheckoutOne(self, detach_head, force_sync, verbose, project):
|
||||
def _CheckoutOne(
|
||||
self, detach_head, force_sync, force_checkout, verbose, project
|
||||
):
|
||||
"""Checkout work tree for one project
|
||||
|
||||
Args:
|
||||
detach_head: Whether to leave a detached HEAD.
|
||||
force_sync: Force checking out of the repo.
|
||||
force_sync: Force checking out of .git directory (e.g. overwrite
|
||||
existing git directory that was previously linked to a different
|
||||
object directory).
|
||||
force_checkout: Force checking out of the repo content.
|
||||
verbose: Whether to show verbose messages.
|
||||
project: Project object for the project to checkout.
|
||||
|
||||
@@ -1011,7 +1029,11 @@ later is required to fix a server side protocol bug.
|
||||
errors = []
|
||||
try:
|
||||
project.Sync_LocalHalf(
|
||||
syncbuf, force_sync=force_sync, errors=errors, verbose=verbose
|
||||
syncbuf,
|
||||
force_sync=force_sync,
|
||||
force_checkout=force_checkout,
|
||||
errors=errors,
|
||||
verbose=verbose,
|
||||
)
|
||||
success = syncbuf.Finish()
|
||||
except GitError as e:
|
||||
@@ -1082,6 +1104,7 @@ later is required to fix a server side protocol bug.
|
||||
self._CheckoutOne,
|
||||
opt.detach_head,
|
||||
opt.force_sync,
|
||||
opt.force_checkout,
|
||||
opt.verbose,
|
||||
),
|
||||
projects,
|
||||
|
||||
@@ -244,6 +244,11 @@ Gerrit Code Review: https://www.gerritcodereview.com/
|
||||
default=[],
|
||||
help="add a label when uploading",
|
||||
)
|
||||
p.add_option(
|
||||
"--pd",
|
||||
"--patchset-description",
|
||||
help="description for patchset",
|
||||
)
|
||||
p.add_option(
|
||||
"--re",
|
||||
"--reviewers",
|
||||
@@ -655,6 +660,7 @@ Gerrit Code Review: https://www.gerritcodereview.com/
|
||||
dest_branch=destination,
|
||||
validate_certs=opt.validate_certs,
|
||||
push_options=opt.push_options,
|
||||
patchset_description=opt.patchset_description,
|
||||
)
|
||||
|
||||
branch.uploaded = True
|
||||
|
||||
@@ -107,6 +107,16 @@ class ReviewableBranchTests(unittest.TestCase):
|
||||
self.assertTrue(rb.date)
|
||||
|
||||
|
||||
class ProjectTests(unittest.TestCase):
|
||||
"""Check Project behavior."""
|
||||
|
||||
def test_encode_patchset_description(self):
|
||||
self.assertEqual(
|
||||
project.Project._encode_patchset_description("abcd00!! +"),
|
||||
"abcd00%21%21_%2b",
|
||||
)
|
||||
|
||||
|
||||
class CopyLinkTestCase(unittest.TestCase):
|
||||
"""TestCase for stub repo client checkouts.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user