-
Notifications
You must be signed in to change notification settings - Fork 20
/
find-object-filenames
executable file
·60 lines (52 loc) · 1.99 KB
/
find-object-filenames
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env python
#
# Find all ref,filename pairs pointing to target file object
#
# Copyright 2017 Colin Walters <[email protected]>
# Licensed under the new-BSD license (http://www.opensource.org/licenses/bsd-license.php)
import gi
gi.require_version('OSTree', '1.0')
import sys,os,argparse
from gi.repository import GLib, Gio, OSTree
def fatal(msg):
print >>sys.stderr, msg
sys.exit(1)
parser = argparse.ArgumentParser()
parser.add_argument("--repo", help="Repo",
action='store', required=True)
parser.add_argument("--object", '-o', help="Object",
action='store', required=True)
parser.add_argument("--rev", '-e', help="Find starting from rev",
action='store')
args = parser.parse_args()
repopath = args.repo
obj = getattr(args, 'object')
r = OSTree.Repo.new(Gio.File.new_for_path(repopath))
r.open(None)
def find_object_recurse(findstate, d, obj, cancellable):
e = d.enumerate_children('standard::name,standard::type', 0, cancellable)
while True:
try:
[_,info,child] = e.iterate(cancellable)
except GLib.Error as e:
sys.stderr.write("Processing: {} => {} : {}".format(findstate[0], findstate[1], child.get_path()))
raise e
if info is None:
break
if info.get_file_type() == Gio.FileType.DIRECTORY:
find_object_recurse(findstate, child, obj, cancellable)
else:
if child.get_checksum() == obj:
print("{} => {} : {}".format(findstate[0], findstate[1], child.get_path()))
cancellable = None
if not args.rev:
[_,refs] = r.list_refs(None, None)
print("Searching {} refs for {}".format(len(refs), obj))
for ref in refs:
[_,root,rev] = r.read_commit(ref, None)
findstate = (ref, rev,)
find_object_recurse(findstate, root, obj, cancellable)
else:
[_,root,rev] = r.read_commit(args.rev, None)
findstate = (args.rev, rev,)
find_object_recurse(findstate, root, obj, cancellable)