Skip to content

Commit

Permalink
base: Make --update more intuitive
Browse files Browse the repository at this point in the history
Fix #45.
  • Loading branch information
avdgrinten committed Nov 8, 2024
1 parent 3d1679b commit 7f8e853
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
9 changes: 8 additions & 1 deletion xbstrap/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ def handle_plan_args(cfg, plan, args):
plan.reset = xbstrap.base.ResetMode.RESET
if args.hard_reset:
plan.reset = xbstrap.base.ResetMode.HARD_RESET
if args.restrict_updates:
plan.restrict_updates = True
if args.only_wanted:
plan.only_wanted = True
if args.keep_going:
Expand Down Expand Up @@ -212,7 +214,7 @@ def handle_plan_args(cfg, plan, args):
"-u", "--update", action="store_true", help="check for package updates"
)
handle_plan_args.parser.add_argument(
"--recursive", action="store_true", help="when updating: also update requirements"
"--recursive", action="store_true", help="recursively run build steps that are out of date"
)
handle_plan_args.parser.add_argument(
"--paranoid",
Expand All @@ -229,6 +231,11 @@ def handle_plan_args(cfg, plan, args):
action="store_true",
help="clean and reset repository state; risks loss of local changes and commits!",
)
handle_plan_args.parser.add_argument(
"--restrict-updates",
action="store_true",
help="restrict updates to packages that are explicitly wanted on the command line",
)
handle_plan_args.parser.add_argument(
"--only-wanted",
action="store_true",
Expand Down
28 changes: 15 additions & 13 deletions xbstrap/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3318,6 +3318,7 @@ def __init__(self, cfg):
self.explain = False
self.check = False
self.update = False
self.restrict_updates = False
self.recursive = False
self.paranoid = False
self.wanted = set()
Expand Down Expand Up @@ -3657,32 +3658,33 @@ def activate(root_key):
dep_item = self._items[dep_pair]
dep_item.build_span = True

# Activate updatable items.
if self.update:

def is_outdated(item, dep_item):
ts = item.timestamp
dep_ts = dep_item.timestamp
if ts is None or dep_ts is None:
return False
return dep_ts > ts
def is_outdated(item, dep_item):
ts = item.timestamp
dep_ts = dep_item.timestamp
if ts is None or dep_ts is None:
return False
return dep_ts > ts

# Handle --update and --recursive.
if self.update or self.recursive:
for item in self._order:
# Unless we're doing a recursive update, we only follow check items
# that are reachable by build edges.
if not self.recursive and not item.build_span:
if self.restrict_updates and not item.build_span:
continue

# Both --update and --recursive activate missing/updatable items.
if item.is_missing or item.is_updatable:
activate(item.key)

# Activate items if their dependencies were activated.
# Both --update and --recursive activate on outdated build edges.
for dep_pair in item.build_edges:
dep_item = self._items[dep_pair]
if dep_item.active:
activate(item.key)
elif is_outdated(item, dep_item):
item.outdated = True
activate(item.key)

# Only --recursive activates on outdated requirements.
if self.recursive:
for dep_pair in item.require_edges:
dep_item = self._items[dep_pair]
Expand Down

0 comments on commit 7f8e853

Please sign in to comment.