MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / parse_branch_ref

Function parse_branch_ref

tensorflow/tools/git/gen_git_source.py:37–62  ·  view source on GitHub ↗

Given a filename of a .git/HEAD file return ref path. In particular, if git is in detached head state, this will return None. If git is in attached head, it will return the branch reference. E.g. if on 'master', the HEAD will contain 'ref: refs/heads/master' so 'refs/heads/master' will be

(filename)

Source from the content-addressed store, hash-verified

35
36
37def parse_branch_ref(filename):
38 """Given a filename of a .git/HEAD file return ref path.
39
40 In particular, if git is in detached head state, this will
41 return None. If git is in attached head, it will return
42 the branch reference. E.g. if on 'master', the HEAD will
43 contain 'ref: refs/heads/master' so 'refs/heads/master'
44 will be returned.
45
46 Example: parse_branch_ref(".git/HEAD")
47 Args:
48 filename: file to treat as a git HEAD file
49 Returns:
50 None if detached head, otherwise ref subpath
51 Raises:
52 RuntimeError: if the HEAD file is unparseable.
53 """
54
55 data = open(filename).read().strip()
56 items = data.split(" ")
57 if len(items) == 1:
58 return None
59 elif len(items) == 2 and items[0] == "ref:":
60 return items[1].strip()
61 else:
62 raise RuntimeError("Git directory has unparseable HEAD")
63
64
65def configure(src_base_path, gen_path, debug=False):

Callers 2

configureFunction · 0.85
generateFunction · 0.85

Calls 3

stripMethod · 0.80
readMethod · 0.45
splitMethod · 0.45

Tested by

no test coverage detected