@@ 1025-1114 (lines=90) @@ | ||
1022 | "dirty": False, "error": "no suitable tags", "date": None} |
|
1023 | ||
1024 | ||
1025 | @register_vcs_handler("git", "pieces_from_vcs") |
|
1026 | def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command): |
|
1027 | """Get version from 'git describe' in the root of the source tree. |
|
1028 | ||
1029 | This only gets called if the git-archive 'subst' keywords were *not* |
|
1030 | expanded, and _version.py hasn't already been rewritten with a short |
|
1031 | version string, meaning we're inside a checked out source tree. |
|
1032 | """ |
|
1033 | GITS = ["git"] |
|
1034 | if sys.platform == "win32": |
|
1035 | GITS = ["git.cmd", "git.exe"] |
|
1036 | ||
1037 | out, rc = run_command(GITS, ["rev-parse", "--git-dir"], cwd=root, |
|
1038 | hide_stderr=True) |
|
1039 | if rc != 0: |
|
1040 | if verbose: |
|
1041 | print("Directory %s not under git control" % root) |
|
1042 | raise NotThisMethod("'git rev-parse --git-dir' returned error") |
|
1043 | ||
1044 | # if there is a tag matching tag_prefix, this yields TAG-NUM-gHEX[-dirty] |
|
1045 | # if there isn't one, this yields HEX[-dirty] (no NUM) |
|
1046 | describe_out, rc = run_command(GITS, ["describe", "--tags", "--dirty", |
|
1047 | "--always", "--long", |
|
1048 | "--match", "%s*" % tag_prefix], |
|
1049 | cwd=root) |
|
1050 | # --long was added in git-1.5.5 |
|
1051 | if describe_out is None: |
|
1052 | raise NotThisMethod("'git describe' failed") |
|
1053 | describe_out = describe_out.strip() |
|
1054 | full_out, rc = run_command(GITS, ["rev-parse", "HEAD"], cwd=root) |
|
1055 | if full_out is None: |
|
1056 | raise NotThisMethod("'git rev-parse' failed") |
|
1057 | full_out = full_out.strip() |
|
1058 | ||
1059 | pieces = {} |
|
1060 | pieces["long"] = full_out |
|
1061 | pieces["short"] = full_out[:7] # maybe improved later |
|
1062 | pieces["error"] = None |
|
1063 | ||
1064 | # parse describe_out. It will be like TAG-NUM-gHEX[-dirty] or HEX[-dirty] |
|
1065 | # TAG might have hyphens. |
|
1066 | git_describe = describe_out |
|
1067 | ||
1068 | # look for -dirty suffix |
|
1069 | dirty = git_describe.endswith("-dirty") |
|
1070 | pieces["dirty"] = dirty |
|
1071 | if dirty: |
|
1072 | git_describe = git_describe[:git_describe.rindex("-dirty")] |
|
1073 | ||
1074 | # now we have TAG-NUM-gHEX or HEX |
|
1075 | ||
1076 | if "-" in git_describe: |
|
1077 | # TAG-NUM-gHEX |
|
1078 | mo = re.search(r'^(.+)-(\d+)-g([0-9a-f]+)$', git_describe) |
|
1079 | if not mo: |
|
1080 | # unparseable. Maybe git-describe is misbehaving? |
|
1081 | pieces["error"] = ("unable to parse git-describe output: '%s'" |
|
1082 | % describe_out) |
|
1083 | return pieces |
|
1084 | ||
1085 | # tag |
|
1086 | full_tag = mo.group(1) |
|
1087 | if not full_tag.startswith(tag_prefix): |
|
1088 | if verbose: |
|
1089 | fmt = "tag '%s' doesn't start with prefix '%s'" |
|
1090 | print(fmt % (full_tag, tag_prefix)) |
|
1091 | pieces["error"] = ("tag '%s' doesn't start with prefix '%s'" |
|
1092 | % (full_tag, tag_prefix)) |
|
1093 | return pieces |
|
1094 | pieces["closest-tag"] = full_tag[len(tag_prefix):] |
|
1095 | ||
1096 | # distance: number of commits since tag |
|
1097 | pieces["distance"] = int(mo.group(2)) |
|
1098 | ||
1099 | # commit: short hex revision ID |
|
1100 | pieces["short"] = mo.group(3) |
|
1101 | ||
1102 | else: |
|
1103 | # HEX: no tags |
|
1104 | pieces["closest-tag"] = None |
|
1105 | count_out, rc = run_command(GITS, ["rev-list", "HEAD", "--count"], |
|
1106 | cwd=root) |
|
1107 | pieces["distance"] = int(count_out) # total number of commits |
|
1108 | ||
1109 | # commit date: see ISO-8601 comment in git_versions_from_keywords() |
|
1110 | date = run_command(GITS, ["show", "-s", "--format=%ci", "HEAD"], |
|
1111 | cwd=root)[0].strip() |
|
1112 | pieces["date"] = date.strip().replace(" ", "T", 1).replace(" ", "", 1) |
|
1113 | ||
1114 | return pieces |
|
1115 | ||
1116 | ||
1117 | def do_vcs_install(manifest_in, versionfile_source, ipy): |
@@ 216-305 (lines=90) @@ | ||
213 | "dirty": False, "error": "no suitable tags", "date": None} |
|
214 | ||
215 | ||
216 | @register_vcs_handler("git", "pieces_from_vcs") |
|
217 | def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command): |
|
218 | """Get version from 'git describe' in the root of the source tree. |
|
219 | ||
220 | This only gets called if the git-archive 'subst' keywords were *not* |
|
221 | expanded, and _version.py hasn't already been rewritten with a short |
|
222 | version string, meaning we're inside a checked out source tree. |
|
223 | """ |
|
224 | GITS = ["git"] |
|
225 | if sys.platform == "win32": |
|
226 | GITS = ["git.cmd", "git.exe"] |
|
227 | ||
228 | out, rc = run_command(GITS, ["rev-parse", "--git-dir"], cwd=root, |
|
229 | hide_stderr=True) |
|
230 | if rc != 0: |
|
231 | if verbose: |
|
232 | print("Directory %s not under git control" % root) |
|
233 | raise NotThisMethod("'git rev-parse --git-dir' returned error") |
|
234 | ||
235 | # if there is a tag matching tag_prefix, this yields TAG-NUM-gHEX[-dirty] |
|
236 | # if there isn't one, this yields HEX[-dirty] (no NUM) |
|
237 | describe_out, rc = run_command(GITS, ["describe", "--tags", "--dirty", |
|
238 | "--always", "--long", |
|
239 | "--match", "%s*" % tag_prefix], |
|
240 | cwd=root) |
|
241 | # --long was added in git-1.5.5 |
|
242 | if describe_out is None: |
|
243 | raise NotThisMethod("'git describe' failed") |
|
244 | describe_out = describe_out.strip() |
|
245 | full_out, rc = run_command(GITS, ["rev-parse", "HEAD"], cwd=root) |
|
246 | if full_out is None: |
|
247 | raise NotThisMethod("'git rev-parse' failed") |
|
248 | full_out = full_out.strip() |
|
249 | ||
250 | pieces = {} |
|
251 | pieces["long"] = full_out |
|
252 | pieces["short"] = full_out[:7] # maybe improved later |
|
253 | pieces["error"] = None |
|
254 | ||
255 | # parse describe_out. It will be like TAG-NUM-gHEX[-dirty] or HEX[-dirty] |
|
256 | # TAG might have hyphens. |
|
257 | git_describe = describe_out |
|
258 | ||
259 | # look for -dirty suffix |
|
260 | dirty = git_describe.endswith("-dirty") |
|
261 | pieces["dirty"] = dirty |
|
262 | if dirty: |
|
263 | git_describe = git_describe[:git_describe.rindex("-dirty")] |
|
264 | ||
265 | # now we have TAG-NUM-gHEX or HEX |
|
266 | ||
267 | if "-" in git_describe: |
|
268 | # TAG-NUM-gHEX |
|
269 | mo = re.search(r'^(.+)-(\d+)-g([0-9a-f]+)$', git_describe) |
|
270 | if not mo: |
|
271 | # unparseable. Maybe git-describe is misbehaving? |
|
272 | pieces["error"] = ("unable to parse git-describe output: '%s'" |
|
273 | % describe_out) |
|
274 | return pieces |
|
275 | ||
276 | # tag |
|
277 | full_tag = mo.group(1) |
|
278 | if not full_tag.startswith(tag_prefix): |
|
279 | if verbose: |
|
280 | fmt = "tag '%s' doesn't start with prefix '%s'" |
|
281 | print(fmt % (full_tag, tag_prefix)) |
|
282 | pieces["error"] = ("tag '%s' doesn't start with prefix '%s'" |
|
283 | % (full_tag, tag_prefix)) |
|
284 | return pieces |
|
285 | pieces["closest-tag"] = full_tag[len(tag_prefix):] |
|
286 | ||
287 | # distance: number of commits since tag |
|
288 | pieces["distance"] = int(mo.group(2)) |
|
289 | ||
290 | # commit: short hex revision ID |
|
291 | pieces["short"] = mo.group(3) |
|
292 | ||
293 | else: |
|
294 | # HEX: no tags |
|
295 | pieces["closest-tag"] = None |
|
296 | count_out, rc = run_command(GITS, ["rev-list", "HEAD", "--count"], |
|
297 | cwd=root) |
|
298 | pieces["distance"] = int(count_out) # total number of commits |
|
299 | ||
300 | # commit date: see ISO-8601 comment in git_versions_from_keywords() |
|
301 | date = run_command(GITS, ["show", "-s", "--format=%ci", "HEAD"], |
|
302 | cwd=root)[0].strip() |
|
303 | pieces["date"] = date.strip().replace(" ", "T", 1).replace(" ", "", 1) |
|
304 | ||
305 | return pieces |
|
306 | ||
307 | ||
308 | def plus_or_dot(pieces): |