| @@ 973-1025 (lines=53) @@ | ||
| 970 | return keywords |
|
| 971 | ||
| 972 | ||
| 973 | @register_vcs_handler("git", "keywords") |
|
| 974 | def git_versions_from_keywords(keywords, tag_prefix, verbose): |
|
| 975 | """Get version information from git keywords.""" |
|
| 976 | if not keywords: |
|
| 977 | raise NotThisMethod("no keywords at all, weird") |
|
| 978 | date = keywords.get("date") |
|
| 979 | if date is not None: |
|
| 980 | # git-2.2.0 added "%cI", which expands to an ISO-8601 -compliant |
|
| 981 | # datestamp. However we prefer "%ci" (which expands to an "ISO-8601 |
|
| 982 | # -like" string, which we must then edit to make compliant), because |
|
| 983 | # it's been around since git-1.5.3, and it's too difficult to |
|
| 984 | # discover which version we're using, or to work around using an |
|
| 985 | # older one. |
|
| 986 | date = date.strip().replace(" ", "T", 1).replace(" ", "", 1) |
|
| 987 | refnames = keywords["refnames"].strip() |
|
| 988 | if refnames.startswith("$Format"): |
|
| 989 | if verbose: |
|
| 990 | print("keywords are unexpanded, not using") |
|
| 991 | raise NotThisMethod("unexpanded keywords, not a git-archive tarball") |
|
| 992 | refs = set([r.strip() for r in refnames.strip("()").split(",")]) |
|
| 993 | # starting in git-1.8.3, tags are listed as "tag: foo-1.0" instead of |
|
| 994 | # just "foo-1.0". If we see a "tag: " prefix, prefer those. |
|
| 995 | TAG = "tag: " |
|
| 996 | tags = set([r[len(TAG):] for r in refs if r.startswith(TAG)]) |
|
| 997 | if not tags: |
|
| 998 | # Either we're using git < 1.8.3, or there really are no tags. We use |
|
| 999 | # a heuristic: assume all version tags have a digit. The old git %d |
|
| 1000 | # expansion behaves like git log --decorate=short and strips out the |
|
| 1001 | # refs/heads/ and refs/tags/ prefixes that would let us distinguish |
|
| 1002 | # between branches and tags. By ignoring refnames without digits, we |
|
| 1003 | # filter out many common branch names like "release" and |
|
| 1004 | # "stabilization", as well as "HEAD" and "master". |
|
| 1005 | tags = set([r for r in refs if re.search(r'\d', r)]) |
|
| 1006 | if verbose: |
|
| 1007 | print("discarding '%s', no digits" % ",".join(refs - tags)) |
|
| 1008 | if verbose: |
|
| 1009 | print("likely tags: %s" % ",".join(sorted(tags))) |
|
| 1010 | for ref in sorted(tags): |
|
| 1011 | # sorting will prefer e.g. "2.0" over "2.0rc1" |
|
| 1012 | if ref.startswith(tag_prefix): |
|
| 1013 | r = ref[len(tag_prefix):] |
|
| 1014 | if verbose: |
|
| 1015 | print("picking %s" % r) |
|
| 1016 | return {"version": r, |
|
| 1017 | "full-revisionid": keywords["full"].strip(), |
|
| 1018 | "dirty": False, "error": None, |
|
| 1019 | "date": date} |
|
| 1020 | # no suitable tags, so version is "0+unknown", but full hex is still there |
|
| 1021 | if verbose: |
|
| 1022 | print("no suitable tags, using unknown + full revision id") |
|
| 1023 | return {"version": "0+unknown", |
|
| 1024 | "full-revisionid": keywords["full"].strip(), |
|
| 1025 | "dirty": False, "error": "no suitable tags", "date": None} |
|
| 1026 | ||
| 1027 | ||
| 1028 | @register_vcs_handler("git", "pieces_from_vcs") |
|
| @@ 161-213 (lines=53) @@ | ||
| 158 | return keywords |
|
| 159 | ||
| 160 | ||
| 161 | @register_vcs_handler("git", "keywords") |
|
| 162 | def git_versions_from_keywords(keywords, tag_prefix, verbose): |
|
| 163 | """Get version information from git keywords.""" |
|
| 164 | if not keywords: |
|
| 165 | raise NotThisMethod("no keywords at all, weird") |
|
| 166 | date = keywords.get("date") |
|
| 167 | if date is not None: |
|
| 168 | # git-2.2.0 added "%cI", which expands to an ISO-8601 -compliant |
|
| 169 | # datestamp. However we prefer "%ci" (which expands to an "ISO-8601 |
|
| 170 | # -like" string, which we must then edit to make compliant), because |
|
| 171 | # it's been around since git-1.5.3, and it's too difficult to |
|
| 172 | # discover which version we're using, or to work around using an |
|
| 173 | # older one. |
|
| 174 | date = date.strip().replace(" ", "T", 1).replace(" ", "", 1) |
|
| 175 | refnames = keywords["refnames"].strip() |
|
| 176 | if refnames.startswith("$Format"): |
|
| 177 | if verbose: |
|
| 178 | print("keywords are unexpanded, not using") |
|
| 179 | raise NotThisMethod("unexpanded keywords, not a git-archive tarball") |
|
| 180 | refs = set([r.strip() for r in refnames.strip("()").split(",")]) |
|
| 181 | # starting in git-1.8.3, tags are listed as "tag: foo-1.0" instead of |
|
| 182 | # just "foo-1.0". If we see a "tag: " prefix, prefer those. |
|
| 183 | TAG = "tag: " |
|
| 184 | tags = set([r[len(TAG):] for r in refs if r.startswith(TAG)]) |
|
| 185 | if not tags: |
|
| 186 | # Either we're using git < 1.8.3, or there really are no tags. We use |
|
| 187 | # a heuristic: assume all version tags have a digit. The old git %d |
|
| 188 | # expansion behaves like git log --decorate=short and strips out the |
|
| 189 | # refs/heads/ and refs/tags/ prefixes that would let us distinguish |
|
| 190 | # between branches and tags. By ignoring refnames without digits, we |
|
| 191 | # filter out many common branch names like "release" and |
|
| 192 | # "stabilization", as well as "HEAD" and "master". |
|
| 193 | tags = set([r for r in refs if re.search(r'\d', r)]) |
|
| 194 | if verbose: |
|
| 195 | print("discarding '%s', no digits" % ",".join(refs - tags)) |
|
| 196 | if verbose: |
|
| 197 | print("likely tags: %s" % ",".join(sorted(tags))) |
|
| 198 | for ref in sorted(tags): |
|
| 199 | # sorting will prefer e.g. "2.0" over "2.0rc1" |
|
| 200 | if ref.startswith(tag_prefix): |
|
| 201 | r = ref[len(tag_prefix):] |
|
| 202 | if verbose: |
|
| 203 | print("picking %s" % r) |
|
| 204 | return {"version": r, |
|
| 205 | "full-revisionid": keywords["full"].strip(), |
|
| 206 | "dirty": False, "error": None, |
|
| 207 | "date": date} |
|
| 208 | # no suitable tags, so version is "0+unknown", but full hex is still there |
|
| 209 | if verbose: |
|
| 210 | print("no suitable tags, using unknown + full revision id") |
|
| 211 | return {"version": "0+unknown", |
|
| 212 | "full-revisionid": keywords["full"].strip(), |
|
| 213 | "dirty": False, "error": "no suitable tags", "date": None} |
|
| 214 | ||
| 215 | ||
| 216 | @register_vcs_handler("git", "pieces_from_vcs") |
|