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