| @@ 1043-1124 (lines=82) @@ | ||
| 1040 | "dirty": False, "error": "no suitable tags"} |
|
| 1041 | ||
| 1042 | ||
| 1043 | @register_vcs_handler("git", "pieces_from_vcs") |
|
| 1044 | def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command): |
|
| 1045 | """Get version from 'git describe' in the root of the source tree. |
|
| 1046 | ||
| 1047 | This only gets called if the git-archive 'subst' keywords were *not* |
|
| 1048 | expanded, and _version.py hasn't already been rewritten with a short |
|
| 1049 | version string, meaning we're inside a checked out source tree. |
|
| 1050 | """ |
|
| 1051 | if not os.path.exists(os.path.join(root, ".git")): |
|
| 1052 | if verbose: |
|
| 1053 | print("no .git in %s" % root) |
|
| 1054 | raise NotThisMethod("no .git directory") |
|
| 1055 | ||
| 1056 | GITS = ["git"] |
|
| 1057 | if sys.platform == "win32": |
|
| 1058 | GITS = ["git.cmd", "git.exe"] |
|
| 1059 | # if there is a tag matching tag_prefix, this yields TAG-NUM-gHEX[-dirty] |
|
| 1060 | # if there isn't one, this yields HEX[-dirty] (no NUM) |
|
| 1061 | describe_out = run_command(GITS, ["describe", "--tags", "--dirty", |
|
| 1062 | "--always", "--long", |
|
| 1063 | "--match", "%s*" % tag_prefix], |
|
| 1064 | cwd=root) |
|
| 1065 | # --long was added in git-1.5.5 |
|
| 1066 | if describe_out is None: |
|
| 1067 | raise NotThisMethod("'git describe' failed") |
|
| 1068 | describe_out = describe_out.strip() |
|
| 1069 | full_out = run_command(GITS, ["rev-parse", "HEAD"], cwd=root) |
|
| 1070 | if full_out is None: |
|
| 1071 | raise NotThisMethod("'git rev-parse' failed") |
|
| 1072 | full_out = full_out.strip() |
|
| 1073 | ||
| 1074 | pieces = {} |
|
| 1075 | pieces["long"] = full_out |
|
| 1076 | pieces["short"] = full_out[:7] # maybe improved later |
|
| 1077 | pieces["error"] = None |
|
| 1078 | ||
| 1079 | # parse describe_out. It will be like TAG-NUM-gHEX[-dirty] or HEX[-dirty] |
|
| 1080 | # TAG might have hyphens. |
|
| 1081 | git_describe = describe_out |
|
| 1082 | ||
| 1083 | # look for -dirty suffix |
|
| 1084 | dirty = git_describe.endswith("-dirty") |
|
| 1085 | pieces["dirty"] = dirty |
|
| 1086 | if dirty: |
|
| 1087 | git_describe = git_describe[:git_describe.rindex("-dirty")] |
|
| 1088 | ||
| 1089 | # now we have TAG-NUM-gHEX or HEX |
|
| 1090 | ||
| 1091 | if "-" in git_describe: |
|
| 1092 | # TAG-NUM-gHEX |
|
| 1093 | mo = re.search(r'^(.+)-(\d+)-g([0-9a-f]+)$', git_describe) |
|
| 1094 | if not mo: |
|
| 1095 | # unparseable. Maybe git-describe is misbehaving? |
|
| 1096 | pieces["error"] = ("unable to parse git-describe output: '%s'" |
|
| 1097 | % describe_out) |
|
| 1098 | return pieces |
|
| 1099 | ||
| 1100 | # tag |
|
| 1101 | full_tag = mo.group(1) |
|
| 1102 | if not full_tag.startswith(tag_prefix): |
|
| 1103 | if verbose: |
|
| 1104 | fmt = "tag '%s' doesn't start with prefix '%s'" |
|
| 1105 | print(fmt % (full_tag, tag_prefix)) |
|
| 1106 | pieces["error"] = ("tag '%s' doesn't start with prefix '%s'" |
|
| 1107 | % (full_tag, tag_prefix)) |
|
| 1108 | return pieces |
|
| 1109 | pieces["closest-tag"] = full_tag[len(tag_prefix):] |
|
| 1110 | ||
| 1111 | # distance: number of commits since tag |
|
| 1112 | pieces["distance"] = int(mo.group(2)) |
|
| 1113 | ||
| 1114 | # commit: short hex revision ID |
|
| 1115 | pieces["short"] = mo.group(3) |
|
| 1116 | ||
| 1117 | else: |
|
| 1118 | # HEX: no tags |
|
| 1119 | pieces["closest-tag"] = None |
|
| 1120 | count_out = run_command(GITS, ["rev-list", "HEAD", "--count"], |
|
| 1121 | cwd=root) |
|
| 1122 | pieces["distance"] = int(count_out) # total number of commits |
|
| 1123 | ||
| 1124 | return pieces |
|
| 1125 | ||
| 1126 | ||
| 1127 | def do_vcs_install(manifest_in, versionfile_source, ipy): |
|
| @@ 191-272 (lines=82) @@ | ||
| 188 | "dirty": False, "error": "no suitable tags"} |
|
| 189 | ||
| 190 | ||
| 191 | @register_vcs_handler("git", "pieces_from_vcs") |
|
| 192 | def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command): |
|
| 193 | """Get version from 'git describe' in the root of the source tree. |
|
| 194 | ||
| 195 | This only gets called if the git-archive 'subst' keywords were *not* |
|
| 196 | expanded, and _version.py hasn't already been rewritten with a short |
|
| 197 | version string, meaning we're inside a checked out source tree. |
|
| 198 | """ |
|
| 199 | if not os.path.exists(os.path.join(root, ".git")): |
|
| 200 | if verbose: |
|
| 201 | print("no .git in %s" % root) |
|
| 202 | raise NotThisMethod("no .git directory") |
|
| 203 | ||
| 204 | GITS = ["git"] |
|
| 205 | if sys.platform == "win32": |
|
| 206 | GITS = ["git.cmd", "git.exe"] |
|
| 207 | # if there is a tag matching tag_prefix, this yields TAG-NUM-gHEX[-dirty] |
|
| 208 | # if there isn't one, this yields HEX[-dirty] (no NUM) |
|
| 209 | describe_out = run_command(GITS, ["describe", "--tags", "--dirty", |
|
| 210 | "--always", "--long", |
|
| 211 | "--match", "%s*" % tag_prefix], |
|
| 212 | cwd=root) |
|
| 213 | # --long was added in git-1.5.5 |
|
| 214 | if describe_out is None: |
|
| 215 | raise NotThisMethod("'git describe' failed") |
|
| 216 | describe_out = describe_out.strip() |
|
| 217 | full_out = run_command(GITS, ["rev-parse", "HEAD"], cwd=root) |
|
| 218 | if full_out is None: |
|
| 219 | raise NotThisMethod("'git rev-parse' failed") |
|
| 220 | full_out = full_out.strip() |
|
| 221 | ||
| 222 | pieces = {} |
|
| 223 | pieces["long"] = full_out |
|
| 224 | pieces["short"] = full_out[:7] # maybe improved later |
|
| 225 | pieces["error"] = None |
|
| 226 | ||
| 227 | # parse describe_out. It will be like TAG-NUM-gHEX[-dirty] or HEX[-dirty] |
|
| 228 | # TAG might have hyphens. |
|
| 229 | git_describe = describe_out |
|
| 230 | ||
| 231 | # look for -dirty suffix |
|
| 232 | dirty = git_describe.endswith("-dirty") |
|
| 233 | pieces["dirty"] = dirty |
|
| 234 | if dirty: |
|
| 235 | git_describe = git_describe[:git_describe.rindex("-dirty")] |
|
| 236 | ||
| 237 | # now we have TAG-NUM-gHEX or HEX |
|
| 238 | ||
| 239 | if "-" in git_describe: |
|
| 240 | # TAG-NUM-gHEX |
|
| 241 | mo = re.search(r'^(.+)-(\d+)-g([0-9a-f]+)$', git_describe) |
|
| 242 | if not mo: |
|
| 243 | # unparseable. Maybe git-describe is misbehaving? |
|
| 244 | pieces["error"] = ("unable to parse git-describe output: '%s'" |
|
| 245 | % describe_out) |
|
| 246 | return pieces |
|
| 247 | ||
| 248 | # tag |
|
| 249 | full_tag = mo.group(1) |
|
| 250 | if not full_tag.startswith(tag_prefix): |
|
| 251 | if verbose: |
|
| 252 | fmt = "tag '%s' doesn't start with prefix '%s'" |
|
| 253 | print(fmt % (full_tag, tag_prefix)) |
|
| 254 | pieces["error"] = ("tag '%s' doesn't start with prefix '%s'" |
|
| 255 | % (full_tag, tag_prefix)) |
|
| 256 | return pieces |
|
| 257 | pieces["closest-tag"] = full_tag[len(tag_prefix):] |
|
| 258 | ||
| 259 | # distance: number of commits since tag |
|
| 260 | pieces["distance"] = int(mo.group(2)) |
|
| 261 | ||
| 262 | # commit: short hex revision ID |
|
| 263 | pieces["short"] = mo.group(3) |
|
| 264 | ||
| 265 | else: |
|
| 266 | # HEX: no tags |
|
| 267 | pieces["closest-tag"] = None |
|
| 268 | count_out = run_command(GITS, ["rev-list", "HEAD", "--count"], |
|
| 269 | cwd=root) |
|
| 270 | pieces["distance"] = int(count_out) # total number of commits |
|
| 271 | ||
| 272 | return pieces |
|
| 273 | ||
| 274 | ||
| 275 | def plus_or_dot(pieces): |
|