launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #19290
Re: [Merge] lp:~cjwatson/turnip/merge-prerequisite into lp:turnip
Review: Approve code
Diff comments:
> === modified file 'turnip/api/store.py'
> --- turnip/api/store.py 2015-08-28 11:55:50 +0000
> +++ turnip/api/store.py 2015-08-28 14:39:09 +0000
> @@ -297,28 +300,55 @@
> sha1_source, context_lines)
>
>
> +def _add_conflicted_files(repo, index):
> + """Add flattened versions of conflicted files in an index.
> +
> + Any conflicted files will be merged using
> + `pygit2.Repository.merge_file_from_index` (thereby including conflict
> + markers); the resulting files will be added to the index and the
> + conflicts deleted.
> +
> + :param repo: a `pygit2.Repository`.
> + :param index: a `pygit2.Index` to modify.
> + :return: a set of files that contain conflicts.
> + """
> + conflicts = set()
> + if index.conflicts is not None:
> + for conflict in list(index.conflicts):
> + path = [entry for entry in conflict
> + if entry is not None][0].path
> + conflicts.add(path)
> + merged_file = repo.merge_file_from_index(*conflict)
> + blob_oid = repo.create_blob(merged_file)
> + index.add(IndexEntry(path, blob_oid, GIT_FILEMODE_BLOB))
Should this be GIT_FILEMODE_BLOB_EXECUTABLE in some cases?
> + del index.conflicts[path]
> + return conflicts
> +
> +
> def get_merge_diff(repo_store, repo_name, sha1_base,
> - sha1_head, context_lines=3):
> + sha1_head, context_lines=3, sha1_prerequisite=None):
> """Get diff of common ancestor and source diff.
>
> :param sha1_base: target sha1 for merge.
> :param sha1_head: source sha1 for merge.
> :param context_lines: num unchanged lines that define a hunk boundary.
> + :param sha1_prerequisite: if not None, sha1 of prerequisite commit to
> + merge into `sha1_target` before computing diff to `sha1_source`.
> """
> - with open_repo(repo_store, repo_name) as repo:
> + with open_repo(
> + repo_store, repo_name,
> + force_ephemeral=(sha1_prerequisite is not None)) as repo:
> + if sha1_prerequisite is not None:
> + prerequisite_index = repo.merge_commits(
> + sha1_base, sha1_prerequisite)
> + _add_conflicted_files(repo, prerequisite_index)
> + from_tree = repo[prerequisite_index.write_tree(repo=repo)]
> + else:
> + from_tree = repo[sha1_base].tree
> merged_index = repo.merge_commits(sha1_base, sha1_head)
> - conflicts = set()
> - if merged_index.conflicts is not None:
> - for conflict in list(merged_index.conflicts):
> - path = [entry for entry in conflict
> - if entry is not None][0].path
> - conflicts.add(path)
> - merged_file = repo.merge_file_from_index(*conflict)
> - blob_oid = repo.create_blob(merged_file)
> - merged_index.add(IndexEntry(path, blob_oid, GIT_FILEMODE_BLOB))
> - del merged_index.conflicts[path]
> + conflicts = _add_conflicted_files(repo, merged_index)
> patch = merged_index.diff_to_tree(
> - repo[sha1_base].tree, context_lines=context_lines).patch
> + from_tree, context_lines=context_lines).patch
> if patch is None:
> patch = u''
> shas = [sha1_base, sha1_head]
--
https://code.launchpad.net/~cjwatson/turnip/merge-prerequisite/+merge/269512
Your team Launchpad code reviewers is subscribed to branch lp:turnip.
References