Skip to content

Commit

Permalink
git-check-rebase: add --rows-filter experimental argument
Browse files Browse the repository at this point in the history
Signed-off-by: Vladimir Sementsov-Ogievskiy <[email protected]>
  • Loading branch information
Vladimir Sementsov-Ogievskiy committed Jul 12, 2023
1 parent 828c6cc commit f85efac
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 10 deletions.
8 changes: 7 additions & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ Options

.. option:: --rows-hide-level {show_all,hide_equal,hide_checked}

How much rows to show:
DEPRECATED: use --rows-filter instead!

How many rows to show:

show_all
the default, show all rows
Expand All @@ -101,6 +103,10 @@ Options
hide_checked
hide rows where commits are equal (green) or checked (yellow)

.. option:: --rows-filter ROWS_FILTER

A python expression (to be evaluated by ``eval()``, so be careful!). If result of the expression is evaluated as ``True`` the row is shown, otherwise hidden. In the expression you may use names of columns and any attribute of Row object, like methods ``all_equal()`` or ``all_ok()``. So ``--rows-hide-level hide_equal`` equals ``--rows-filter 'not all_equal()'`` and ``--rows-hide-level hide_checked`` equals ``--rows-filter 'not all_ok()'``.

.. option:: --interactive

For not-equal commits start an interactive comparison. For each pair of matching but not equeal commits **vim** is called with two patches opened to compare. In vim you may:
Expand Down
9 changes: 7 additions & 2 deletions git-check-rebase
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,15 @@ def print_legend(viewer, ranges, html):
class GitCheckRebase:
def __init__(self, range_defs, meta_path, html, issue_tracker,
porting_issues, legend,
columns, rows_hide_level, interactive, color,
columns, rows_hide_level, rows_filter, interactive, color,
ign_commit_messages):
self.range_defs = range_defs
self.issue_tracker = issue_tracker
self.porting_issues = \
porting_issues.split(',') if porting_issues else []
self.legend = legend
self.rows_hide_level = rows_hide_level
self.rows_filter = rows_filter
self.interactive = interactive
self.ign_commit_messages = ign_commit_messages
self.ranges = [] # see parse_range_defs
Expand Down Expand Up @@ -206,7 +207,8 @@ You may use it with next run, specifying option --meta {self.meta.fname}""")

out = self.tab.to_list(columns=self.columns,
headers=self.headers,
rows_hide_level=self.rows_hide_level)
rows_hide_level=self.rows_hide_level,
rows_filter=self.rows_filter)

if self.html:
print("""<!DOCTYPE html>
Expand Down Expand Up @@ -248,6 +250,8 @@ Then, corresponding issue keys are used to fill "new" column if exist''')
choices=[x.name.lower() for x in RowsHideLevel],
help='which rows to hide in table: "show_all" is default. ',
default=RowsHideLevel.SHOW_ALL.name.lower())
p.add_argument('--rows-filter',
help='which rows to show. experimental feature')
p.add_argument('--interactive',
help='do interactive comparison of not-equal commits. '
'For each commit to compare, vimdiff is started as a '
Expand All @@ -274,6 +278,7 @@ Then, corresponding issue keys are used to fill "new" column if exist''')
porting_issues=args.porting_issues,
legend=args.legend, columns=args.columns,
rows_hide_level=rows_hide_lvl,
rows_filter=args.rows_filter,
interactive=args.interactive,
color=args.color,
ign_commit_messages=args.ignore_commit_messages)
Expand Down
33 changes: 26 additions & 7 deletions git_check_rebase/compare_ranges.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,25 @@ def to_list(self, columns: List[Column],
line.append(default[c])
return line

def all_ok(self) -> bool:
return all(c is not None and c.comp != CompRes.NONE
for c in self.commits)

def all_equal(self) -> bool:
return all(c is not None and
c.comp in (CompRes.BASE, CompRes.EQUAL)
for c in self.commits)

def match_filter(self, expr: str) -> bool:
if not expr:
return True
commits = self.get_commits()
env = {a: getattr(self, a) for a in dir(self) if a[0] != '_'}
for i, r in enumerate(self.ranges):
if r.name.isidentifier():
env[r.name] = commits[i]
return eval(expr, env)


class RowsHideLevel(Enum):
SHOW_ALL = 1
Expand Down Expand Up @@ -330,8 +349,8 @@ def add_porting_issues(self, issue_tracker, porting_issues):
def to_list(self, columns: List[Column],
fmt: str = 'colored',
headers: bool = True,
rows_hide_level: RowsHideLevel = RowsHideLevel.SHOW_ALL) \
-> VTable:
rows_hide_level: RowsHideLevel = RowsHideLevel.SHOW_ALL,
rows_filter: str = '') -> VTable:

out: VTable = []
line: VTableRow
Expand All @@ -346,14 +365,14 @@ def to_list(self, columns: List[Column],
index_len = len(str(len(self.rows)))

for row_ind, row in enumerate(self.rows):
if not row.match_filter(rows_filter):
continue

if rows_hide_level.value >= RowsHideLevel.HIDE_CHECKED.value and \
all(c is not None and c.comp != CompRes.NONE for
c in row.commits):
row.all_ok():
continue
if rows_hide_level.value >= RowsHideLevel.HIDE_EQUAL.value and \
all(c is not None and
c.comp in (CompRes.BASE, CompRes.EQUAL) for
c in row.commits):
row.all_equal():
continue

line = row.to_list(columns, {
Expand Down

0 comments on commit f85efac

Please sign in to comment.