| @@ 997-1040 (lines=44) @@ | ||
| 994 | f = open(versionfile_abs, "r") |
|
| 995 | for line in f.readlines(): |
|
| 996 | if line.strip().startswith("git_refnames ="): |
|
| 997 | mo = re.search(r'=\s*"(.*)"', line) |
|
| 998 | if mo: |
|
| 999 | keywords["refnames"] = mo.group(1) |
|
| 1000 | if line.strip().startswith("git_full ="): |
|
| 1001 | mo = re.search(r'=\s*"(.*)"', line) |
|
| 1002 | if mo: |
|
| 1003 | keywords["full"] = mo.group(1) |
|
| 1004 | if line.strip().startswith("git_time ="): |
|
| 1005 | mo = re.search(r'=\s*"(.*)"', line) |
|
| 1006 | if mo: |
|
| 1007 | keywords["time"] = mo.group(1) |
|
| 1008 | f.close() |
|
| 1009 | except EnvironmentError: |
|
| 1010 | pass |
|
| 1011 | return keywords |
|
| 1012 | ||
| 1013 | ||
| 1014 | @register_vcs_handler("git", "keywords") |
|
| 1015 | def git_versions_from_keywords(keywords, tag_prefix, verbose): |
|
| 1016 | """Get version information from git keywords.""" |
|
| 1017 | if not keywords: |
|
| 1018 | raise NotThisMethod("no keywords at all, weird") |
|
| 1019 | refnames = keywords["refnames"].strip() |
|
| 1020 | if refnames.startswith("$Format"): |
|
| 1021 | if verbose: |
|
| 1022 | print("keywords are unexpanded, not using") |
|
| 1023 | raise NotThisMethod("unexpanded keywords, not a git-archive tarball") |
|
| 1024 | refs = set([r.strip() for r in refnames.strip("()").split(",")]) |
|
| 1025 | # starting in git-1.8.3, tags are listed as "tag: foo-1.0" instead of |
|
| 1026 | # just "foo-1.0". If we see a "tag: " prefix, prefer those. |
|
| 1027 | TAG = "tag: " |
|
| 1028 | tags = set([r[len(TAG):] for r in refs if r.startswith(TAG)]) |
|
| 1029 | if not tags: |
|
| 1030 | # Either we're using git < 1.8.3, or there really are no tags. We use |
|
| 1031 | # a heuristic: assume all version tags have a digit. The old git %d |
|
| 1032 | # expansion behaves like git log --decorate=short and strips out the |
|
| 1033 | # refs/heads/ and refs/tags/ prefixes that would let us distinguish |
|
| 1034 | # between branches and tags. By ignoring refnames without digits, we |
|
| 1035 | # filter out many common branch names like "release" and |
|
| 1036 | # "stabilization", as well as "HEAD" and "master". |
|
| 1037 | tags = set([r for r in refs if re.search(r'\d', r)]) |
|
| 1038 | if verbose: |
|
| 1039 | print("discarding '%s', no digits" % ",".join(refs-tags)) |
|
| 1040 | if verbose: |
|
| 1041 | print("likely tags: %s" % ",".join(sorted(tags))) |
|
| 1042 | for ref in sorted(tags): |
|
| 1043 | # sorting will prefer e.g. "2.0" over "2.0rc1" |
|
| @@ 145-188 (lines=44) @@ | ||
| 142 | mo = re.search(r'=\s*"(.*)"', line) |
|
| 143 | if mo: |
|
| 144 | keywords["time"] = mo.group(1) |
|
| 145 | f.close() |
|
| 146 | except EnvironmentError: |
|
| 147 | pass |
|
| 148 | return keywords |
|
| 149 | ||
| 150 | ||
| 151 | @register_vcs_handler("git", "keywords") |
|
| 152 | def git_versions_from_keywords(keywords, tag_prefix, verbose): |
|
| 153 | """Get version information from git keywords.""" |
|
| 154 | if not keywords: |
|
| 155 | raise NotThisMethod("no keywords at all, weird") |
|
| 156 | refnames = keywords["refnames"].strip() |
|
| 157 | if refnames.startswith("$Format"): |
|
| 158 | if verbose: |
|
| 159 | print("keywords are unexpanded, not using") |
|
| 160 | raise NotThisMethod("unexpanded keywords, not a git-archive tarball") |
|
| 161 | refs = set([r.strip() for r in refnames.strip("()").split(",")]) |
|
| 162 | # starting in git-1.8.3, tags are listed as "tag: foo-1.0" instead of |
|
| 163 | # just "foo-1.0". If we see a "tag: " prefix, prefer those. |
|
| 164 | TAG = "tag: " |
|
| 165 | tags = set([r[len(TAG):] for r in refs if r.startswith(TAG)]) |
|
| 166 | if not tags: |
|
| 167 | # Either we're using git < 1.8.3, or there really are no tags. We use |
|
| 168 | # a heuristic: assume all version tags have a digit. The old git %d |
|
| 169 | # expansion behaves like git log --decorate=short and strips out the |
|
| 170 | # refs/heads/ and refs/tags/ prefixes that would let us distinguish |
|
| 171 | # between branches and tags. By ignoring refnames without digits, we |
|
| 172 | # filter out many common branch names like "release" and |
|
| 173 | # "stabilization", as well as "HEAD" and "master". |
|
| 174 | tags = set([r for r in refs if re.search(r'\d', r)]) |
|
| 175 | if verbose: |
|
| 176 | print("discarding '%s', no digits" % ",".join(refs-tags)) |
|
| 177 | if verbose: |
|
| 178 | print("likely tags: %s" % ",".join(sorted(tags))) |
|
| 179 | for ref in sorted(tags): |
|
| 180 | # sorting will prefer e.g. "2.0" over "2.0rc1" |
|
| 181 | if ref.startswith(tag_prefix): |
|
| 182 | r = ref[len(tag_prefix):] |
|
| 183 | if verbose: |
|
| 184 | print("picking %s" % r) |
|
| 185 | return {"version": r, |
|
| 186 | "full-revisionid": keywords["full"].strip(), |
|
| 187 | "dirty": False, "error": None, |
|
| 188 | "time": keywords["time"].strip()} |
|
| 189 | # no suitable tags, so version is "0+unknown", but full hex is still there |
|
| 190 | if verbose: |
|
| 191 | print("no suitable tags, using unknown + full revision id") |
|