Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
swh-loader-git
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Antoine Lambert
swh-loader-git
Commits
9272e6df
Commit
9272e6df
authored
9 years ago
by
Antoine R. Dumont
Browse files
Options
Downloads
Patches
Plain Diff
Reference zack's tryouts
parent
7af22bf7
Branches
towards-put-all-objects
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
scratch/git_visit.py
+47
-0
47 additions, 0 deletions
scratch/git_visit.py
with
47 additions
and
0 deletions
scratch/git_visit.py
0 → 100644
+
47
−
0
View file @
9272e6df
# (* OCaml: non tail-recursive version *)
# let rec visit obj =
# if not (is_in_cache obj) then begin
# List.iter visit (get_parents obj);
# store_object obj
# end
# let _ = visit root_obj
# (* OCaml: (almost) tail-recursive version *)
# let visit obj =
# let rec aux visit_todo store_todo =
# match visit_todo with
# | [] -> store_todo
# | obj :: rest ->
# if not (is_in_cache obj) then
# let parents = get_parents obj in
# (* "@" is not tail-rec in OCaml (length of 1st arg.), but we don't
# care here, as equivalent operators might be tail-rec in other
# languages. To be tail-rec in OCaml we would need List.rev_append
# here, and to do reverse gymnastic elsewhere. *)
# aux (rest @ parents) (obj :: store_todo)
# in
# let objects_to_store = aux [obj] [] in
# List.iter store_object objects_to_store
# let _ = visit root_obj
from
collections
import
deque
def
visit
(
root_obj
,
cache
,
store
):
to_visit
=
deque
([
root_obj
])
# FIFO
to_store
=
deque
()
# LIFO
while
to_visit
:
# 1st pass: visit top-down, use cache, collect to_store
obj
=
to_visit
.
popleft
()
# extract from beginning (left)
if
obj
not
in
cache
:
to_visit
.
extend
(
obj
.
parents
)
# append to end (right)
to_store
.
append
(
obj
)
while
to_store
:
# 2nd pass: store objects bottom-up
obj
=
to_store
.
pop
()
store
.
add
(
obj
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment