Skip to content

Commit

Permalink
Merge lp:brz/3.1.
Browse files Browse the repository at this point in the history
  • Loading branch information
jelmer authored and breezy-bot committed Mar 22, 2021
2 parents 65ef779 + 12e5adc commit 139e115
Show file tree
Hide file tree
Showing 27 changed files with 319 additions and 93 deletions.
12 changes: 12 additions & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Security Policy

## Supported Versions

| Version | Supported |
| -------- | ------------------ |
| 3.1.x | :white_check_mark: |
| 3.0.x | :x: |

## Reporting a Vulnerability

Please report security issues by e-mail to [email protected].
4 changes: 2 additions & 2 deletions breezy/builtins.py
Original file line number Diff line number Diff line change
Expand Up @@ -4584,7 +4584,7 @@ def _do_preview(self, merger):

def _do_merge(self, merger, change_reporter, allow_pending, verified):
merger.change_reporter = change_reporter
conflict_count = merger.do_merge()
conflict_count = len(merger.do_merge())
if allow_pending:
merger.set_pending()
if verified == 'failed':
Expand Down Expand Up @@ -4842,7 +4842,7 @@ def run(self, file_list=None, merge_type=None, show_base=False,
conflicts = merger.do_merge()
finally:
tree.set_parent_ids(parents)
if conflicts > 0:
if len(conflicts) > 0:
return 1
else:
return 0
Expand Down
6 changes: 3 additions & 3 deletions breezy/bzr/workingtree.py
Original file line number Diff line number Diff line change
Expand Up @@ -1932,7 +1932,7 @@ def _update_tree(self, old_tip=None, change_reporter=None, revision=None,
# local work is unreferenced and will appear to have been lost.
#
with self.lock_tree_write():
nb_conflicts = 0
nb_conflicts = []
try:
last_rev = self.get_parent_ids()[0]
except IndexError:
Expand All @@ -1953,7 +1953,7 @@ def _update_tree(self, old_tip=None, change_reporter=None, revision=None,
show_base=show_base)
if nb_conflicts:
self.add_parent_tree((old_tip, other_tree))
return nb_conflicts
return len(nb_conflicts)

if last_rev != _mod_revision.ensure_null(revision):
# the working tree is up to date with the branch
Expand Down Expand Up @@ -1995,7 +1995,7 @@ def _update_tree(self, old_tip=None, change_reporter=None, revision=None,
(old_tip, self.branch.repository.revision_tree(old_tip)))
self.set_parent_trees(parent_trees)
last_rev = parent_trees[0][0]
return nb_conflicts
return len(nb_conflicts)


class WorkingTreeFormatMetaDir(bzrdir.BzrFormat, WorkingTreeFormat):
Expand Down
27 changes: 20 additions & 7 deletions breezy/git/branch.py
Original file line number Diff line number Diff line change
Expand Up @@ -1450,13 +1450,26 @@ def fetch(self, stop_revision=None, fetch_tags=None, lossy=False,
for k, v in self.source.tags.get_tag_dict().items():
ret.append((None, v))
ret.append((None, stop_revision))
try:
revidmap = self.interrepo.fetch_revs(ret, lossy=lossy, limit=limit)
except NoPushSupport:
raise errors.NoRoundtrippingSupport(self.source, self.target)
return _mod_repository.FetchResult(revidmap={
old_revid: new_revid
for (old_revid, (new_sha, new_revid)) in revidmap.items()})
if getattr(self.interrepo, 'fetch_revs', None):
try:
revidmap = self.interrepo.fetch_revs(ret, lossy=lossy, limit=limit)
except NoPushSupport:
raise errors.NoRoundtrippingSupport(self.source, self.target)
return _mod_repository.FetchResult(revidmap={
old_revid: new_revid
for (old_revid, (new_sha, new_revid)) in revidmap.items()})
else:
def determine_wants(refs):
wants = []
for git_sha, revid in ret:
if git_sha is None:
git_sha, mapping = self.target.lookup_bzr_revision_id(revid)
wants.append(git_sha)
return wants

self.interrepo.fetch_objects(
determine_wants, lossy=lossy, limit=limit)
return _mod_repository.FetchResult()

def pull(self, overwrite=False, stop_revision=None, local=False,
possible_transports=None, run_hooks=True, _stop_revno=None,
Expand Down
4 changes: 2 additions & 2 deletions breezy/git/interrepo.py
Original file line number Diff line number Diff line change
Expand Up @@ -801,9 +801,9 @@ def fetch_refs(self, update_refs, lossy=False, overwrite=False):
def git_update_refs(old_refs):
ret = {}
self.old_refs = {
k: (v, None) for (k, v) in viewitems(old_refs)}
k: (v, None) for (k, v) in old_refs.items()}
new_refs = update_refs(self.old_refs)
for name, (gitid, revid) in viewitems(new_refs):
for name, (gitid, revid) in new_refs.items():
if gitid is None:
gitid = self.source_store._lookup_revision_sha1(revid)
if not overwrite:
Expand Down
2 changes: 2 additions & 0 deletions breezy/git/mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,9 +411,11 @@ def decode_using_encoding(rev, commit, encoding):
rev.properties[u'author'] = commit.author.decode(encoding)
rev.message, rev.git_metadata = self._decode_commit_message(
rev, commit.message, encoding)

if commit.encoding is not None:
rev.properties[u'git-explicit-encoding'] = commit.encoding.decode(
'ascii')
if commit.encoding is not None and commit.encoding != b'false':
decode_using_encoding(rev, commit, commit.encoding.decode('ascii'))
else:
for encoding in ('utf-8', 'latin1'):
Expand Down
2 changes: 1 addition & 1 deletion breezy/git/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -630,8 +630,8 @@ def get_changed_refs(remote_refs):
except errors.NoSuchRevision:
raise errors.NoRoundtrippingSupport(
source, self.open_branch(name=name, nascent_ok=True))
old_sha = remote_refs.get(actual_refname)
if not overwrite:
old_sha = remote_refs.get(actual_refname)
if remote_divergence(old_sha, new_sha, source_store):
raise DivergedBranches(
source, self.open_branch(name, nascent_ok=True))
Expand Down
20 changes: 20 additions & 0 deletions breezy/git/tests/test_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,26 @@ def test_explicit_encoding(self):
self.assertEqual("iso8859-1", rev.properties[u"git-explicit-encoding"])
self.assertTrue(u"git-implicit-encoding" not in rev.properties)

def test_explicit_encoding_false(self):
c = Commit()
c.tree = b"cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
c.message = b"Some message"
c.committer = b"Committer"
c.commit_time = 4
c.author_time = 5
c.commit_timezone = 60 * 5
c.author_timezone = 60 * 3
c.author = u"Authér".encode("utf-8")
c.encoding = b"false"
mapping = BzrGitMappingv1()
rev, roundtrip_revid, verifiers = mapping.import_commit(
c, mapping.revision_id_foreign_to_bzr)
self.assertEqual(None, roundtrip_revid)
self.assertEqual({}, verifiers)
self.assertEqual(u"Authér", rev.properties[u'author'])
self.assertEqual("false", rev.properties[u"git-explicit-encoding"])
self.assertTrue(u"git-implicit-encoding" not in rev.properties)

def test_implicit_encoding_fallback(self):
c = Commit()
c.tree = b"cc9462f7f8263ef5adfbeff2fb936bb36b504cba"
Expand Down
15 changes: 14 additions & 1 deletion breezy/git/tests/test_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import os

from ...transform import ROOT_PARENT, conflict_pass, resolve_conflicts
from ...transform import ROOT_PARENT, conflict_pass, resolve_conflicts, revert
from . import TestCaseWithTransport


Expand All @@ -39,3 +39,16 @@ def test_directory_exists(self):
self.assertEqual([], list(conflicts))
tt.apply()
self.assertEqual(set(['name1', 'name2']), set(os.listdir('dir')))

def test_revert_does_not_remove(self):
tree = self.make_branch_and_tree('.', format='git')
tt = tree.transform()
dir1 = tt.new_directory('dir', ROOT_PARENT)
tid = tt.new_file('name1', dir1, [b'content1'])
tt.version_file(tid)
tt.apply()
tree.commit('start')
with open('dir/name1', 'wb') as f:
f.write(b'new content2')
revert(tree, tree.basis_tree())
self.assertEqual([], list(tree.iter_changes(tree.basis_tree())))
2 changes: 1 addition & 1 deletion breezy/git/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -1440,7 +1440,7 @@ def _generate_index_changes(self):
changes = {}
changed_ids = set()
for id_set in [self._new_name, self._new_parent,
self._new_executability]:
self._new_executability, self._new_contents]:
changed_ids.update(id_set)
for id_set in [self._new_name, self._new_parent]:
removed_id.update(id_set)
Expand Down
6 changes: 3 additions & 3 deletions breezy/git/workingtree.py
Original file line number Diff line number Diff line change
Expand Up @@ -1518,7 +1518,7 @@ def _update_tree(self, old_tip=None, change_reporter=None, revision=None,
#
with self.lock_tree_write():
from .. import merge
nb_conflicts = 0
nb_conflicts = []
try:
last_rev = self.get_parent_ids()[0]
except IndexError:
Expand All @@ -1539,7 +1539,7 @@ def _update_tree(self, old_tip=None, change_reporter=None, revision=None,
show_base=show_base)
if nb_conflicts:
self.add_parent_tree((old_tip, other_tree))
return nb_conflicts
return len(nb_conflicts)

if last_rev != _mod_revision.ensure_null(revision):
to_tree = self.branch.repository.revision_tree(revision)
Expand Down Expand Up @@ -1572,7 +1572,7 @@ def _update_tree(self, old_tip=None, change_reporter=None, revision=None,
(old_tip, self.branch.repository.revision_tree(old_tip)))
self.set_parent_trees(parent_trees)
last_rev = parent_trees[0][0]
return nb_conflicts
return len(nb_conflicts)


class GitWorkingTreeFormat(workingtree.WorkingTreeFormat):
Expand Down
2 changes: 1 addition & 1 deletion breezy/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ def do_merge(self):
trace.note(gettext("%d conflicts encountered.")
% len(merge.cooked_conflicts))

return len(merge.cooked_conflicts)
return merge.cooked_conflicts


class _InventoryNoneEntry(object):
Expand Down
20 changes: 17 additions & 3 deletions breezy/plugins/github/hoster.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ def get_push_url(self, branch):
repo = self._get_repo(owner, project)
return github_url_to_bzr_url(repo['ssh_url'], branch_name)

def get_derived_branch(self, base_branch, name, project=None, owner=None):
def get_derived_branch(self, base_branch, name, project=None, owner=None, preferred_schemes=None):
base_owner, base_project, base_branch_name = parse_github_branch_url(base_branch)
base_repo = self._get_repo(base_owner, base_project)
if owner is None:
Expand All @@ -465,10 +465,24 @@ def get_derived_branch(self, base_branch, name, project=None, owner=None):
project = base_repo['name']
try:
remote_repo = self._get_repo(owner, project)
full_url = github_url_to_bzr_url(remote_repo['ssh_url'], name)
return _mod_branch.Branch.open(full_url)
except NoSuchProject:
raise errors.NotBranchError('%s/%s/%s' % (WEB_GITHUB_URL, owner, project))
if preferred_schemes is None:
preferred_schemes = ['git+ssh']
for scheme in preferred_schemes:
if scheme == 'git+ssh':
github_url = remote_repo['ssh_url']
break
if scheme == 'https':
github_url = remote_repo['clone_url']
break
if scheme == 'git':
github_url = remote_repo['git_url']
break
else:
raise AssertionError
full_url = github_url_to_bzr_url(github_url, name)
return _mod_branch.Branch.open(full_url)

def get_proposer(self, source_branch, target_branch):
return GitHubMergeProposalBuilder(self, source_branch, target_branch)
Expand Down
Loading

0 comments on commit 139e115

Please sign in to comment.