Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add option for first-parent VCS flag (for publish/gh-pages only) #751

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions asv/commands/publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,18 @@ def setup_arguments(cls, subparsers):
'--html-dir', '-o', default=None, help=(
"Optional output directory. Default is 'html_dir' "
"from asv config"))
parser.add_argument(
"--first-parent", action="store_true", default=True, dest="first_parent",
help="""Use git's --first-parent or hg's --follow-first options for associating
commits with branches. Each commit will be assigned to the first branch that
it occurred on, not to any later branches that may have that commit merged in.""")
parser.add_argument(
"--no-first-parent", action="store_false", dest="first_parent",
help="""Do not use git's --first-parent or hg's --follow-first options for
associating commits with branches. Use this if you have merged older feature
branches into your main branch, and you want to show all the old commits in the
context of the new branch. If you have commits that are not appearing in a
plot of your main branch, try this.""")

parser.set_defaults(func=cls.run_from_args)

Expand All @@ -75,7 +87,8 @@ def setup_arguments(cls, subparsers):
def run_from_conf_args(cls, conf, args):
if args.html_dir is not None:
conf.html_dir = args.html_dir
return cls.run(conf=conf, range_spec=args.range, pull=not args.no_pull)
return cls.run(conf=conf, range_spec=args.range, pull=not args.no_pull,
first_parent=args.first_parent)

@staticmethod
def iter_results(conf, repo, range_spec=None):
Expand All @@ -91,7 +104,7 @@ def iter_results(conf, repo, range_spec=None):
yield result

@classmethod
def run(cls, conf, range_spec=None, pull=True):
def run(cls, conf, range_spec=None, pull=True, first_parent=True):
params = {}
graphs = GraphSet()
machines = {}
Expand Down Expand Up @@ -160,7 +173,7 @@ def copy_ignore(src, names):
revision_to_date = dict((r, hash_to_date[h]) for h, r in six.iteritems(revisions))

branches = dict(
(branch, repo.get_branch_commits(branch))
(branch, repo.get_branch_commits(branch, first_parent=first_parent))
for branch in conf.branches)

log.step()
Expand Down
11 changes: 7 additions & 4 deletions asv/plugins/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,10 @@ def get_date(self, hash):
['rev-list', '-n', '1', '--format=%at', hash],
valid_return_codes=(0, 1), dots=False).strip().split()[-1]) * 1000

def get_hashes_from_range(self, range_spec):
args = ['rev-list', '--first-parent']
def get_hashes_from_range(self, range_spec, first_parent=True):
args = ['rev-list']
if first_parent:
args.append('--first-parent')
if range_spec != "":
args += range_spec.split()
output = self._run_git(args, valid_return_codes=(0, 1), dots=False)
Expand Down Expand Up @@ -172,11 +174,12 @@ def get_tags(self):
def get_date_from_name(self, name):
return self.get_date(name + "^{commit}")

def get_branch_commits(self, branch):
return self.get_hashes_from_range(self.get_branch_name(branch))
def get_branch_commits(self, branch, first_parent=True):
return self.get_hashes_from_range(self.get_branch_name(branch), first_parent=first_parent)

def get_revisions(self, commits):
revisions = {}

for i, commit in enumerate(self._run_git([
"rev-list", "--all", "--date-order", "--reverse",
]).splitlines()):
Expand Down
19 changes: 16 additions & 3 deletions asv/plugins/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,34 @@ def setup_arguments(cls, subparsers):
"--rewrite", action="store_true",
help=("Rewrite gh-pages branch to contain only a single commit, "
"instead of adding a new commit"))
parser.add_argument(
"--first-parent", action="store_true", default=True, dest="first_parent",
help="""Use git's --first-parent or hg's --follow-first options for associating
commits with branches. Each commit will be assigned to the first branch that
it occurred on, not to any later branches that may have that commit merged in.""")
parser.add_argument(
"--no-first-parent", action="store_false", dest="first_parent",
help="""Do not use git's --first-parent or hg's --follow-first options for
associating commits with branches. Use this if you have merged older feature
branches into your main branch, and you want to show all the old commits in the
context of the new branch. If you have commits that are not appearing in a
plot of your main branch, try this.""")

parser.set_defaults(func=cls.run_from_args)

return parser

@classmethod
def run_from_conf_args(cls, conf, args):
return cls.run(conf=conf, no_push=args.no_push, rewrite=args.rewrite)
return cls.run(conf=conf, no_push=args.no_push, rewrite=args.rewrite,
first_parent=args.first_parent)

@classmethod
def run(cls, conf, no_push, rewrite):
def run(cls, conf, no_push, rewrite, first_parent=True):
git = util.which('git')

# Publish
Publish.run(conf)
Publish.run(conf, first_parent=first_parent)

cwd = os.path.abspath(os.getcwd())

Expand Down
4 changes: 2 additions & 2 deletions asv/plugins/mercurial.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,9 @@ def get_tags(self):
def get_date_from_name(self, name):
return self.get_date(name)

def get_branch_commits(self, branch):
def get_branch_commits(self, branch, first_parent=True):
return self.get_hashes_from_range("ancestors({0})".format(self.get_branch_name(branch)),
followfirst=True)
followfirst=first_parent)

def get_revisions(self, commits):
revisions = {}
Expand Down
8 changes: 4 additions & 4 deletions asv/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,22 +161,22 @@ def get_date_from_name(self, name):
"""
raise NotImplementedError()

def get_branch_commits(self, branch):
def get_branch_commits(self, branch, first_parent=True):
"""
Returns the ordered list (last commit first) of all commits in
`branch` following first parent in case of merge
"""
raise NotImplementedError()

def get_new_branch_commits(self, branches, existing):
def get_new_branch_commits(self, branches, existing, first_parent=True):
"""
Return a set of new commits on `branches` that are successors of all
`existing` commits
"""
new = set()
new_commits = []
for branch in branches:
for commit in self.get_branch_commits(branch):
for commit in self.get_branch_commits(branch, first_parent=first_parent):
if commit in existing:
break
if commit not in new:
Expand Down Expand Up @@ -242,7 +242,7 @@ def pull(self):
def get_branch_commits(self, branch):
self._raise_error()

def get_new_branch_commits(self, branches, existing):
def get_new_branch_commits(self, branches, existing, first_parent=True):
self._raise_error()


Expand Down