Code Duplication    Length = 90-90 lines in 2 locations

versioneer.py 1 location

@@ 1028-1117 (lines=90) @@
1025
            "dirty": False, "error": "no suitable tags", "date": None}
1026
1027
1028
@register_vcs_handler("git", "pieces_from_vcs")
1029
def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command):
1030
    """Get version from 'git describe' in the root of the source tree.
1031
1032
    This only gets called if the git-archive 'subst' keywords were *not*
1033
    expanded, and _version.py hasn't already been rewritten with a short
1034
    version string, meaning we're inside a checked out source tree.
1035
    """
1036
    GITS = ["git"]
1037
    if sys.platform == "win32":
1038
        GITS = ["git.cmd", "git.exe"]
1039
1040
    out, rc = run_command(GITS, ["rev-parse", "--git-dir"], cwd=root,
1041
                          hide_stderr=True)
1042
    if rc != 0:
1043
        if verbose:
1044
            print("Directory %s not under git control" % root)
1045
        raise NotThisMethod("'git rev-parse --git-dir' returned error")
1046
1047
    # if there is a tag matching tag_prefix, this yields TAG-NUM-gHEX[-dirty]
1048
    # if there isn't one, this yields HEX[-dirty] (no NUM)
1049
    describe_out, rc = run_command(GITS, ["describe", "--tags", "--dirty",
1050
                                          "--always", "--long",
1051
                                          "--match", "%s*" % tag_prefix],
1052
                                   cwd=root)
1053
    # --long was added in git-1.5.5
1054
    if describe_out is None:
1055
        raise NotThisMethod("'git describe' failed")
1056
    describe_out = describe_out.strip()
1057
    full_out, rc = run_command(GITS, ["rev-parse", "HEAD"], cwd=root)
1058
    if full_out is None:
1059
        raise NotThisMethod("'git rev-parse' failed")
1060
    full_out = full_out.strip()
1061
1062
    pieces = {}
1063
    pieces["long"] = full_out
1064
    pieces["short"] = full_out[:7]  # maybe improved later
1065
    pieces["error"] = None
1066
1067
    # parse describe_out. It will be like TAG-NUM-gHEX[-dirty] or HEX[-dirty]
1068
    # TAG might have hyphens.
1069
    git_describe = describe_out
1070
1071
    # look for -dirty suffix
1072
    dirty = git_describe.endswith("-dirty")
1073
    pieces["dirty"] = dirty
1074
    if dirty:
1075
        git_describe = git_describe[:git_describe.rindex("-dirty")]
1076
1077
    # now we have TAG-NUM-gHEX or HEX
1078
1079
    if "-" in git_describe:
1080
        # TAG-NUM-gHEX
1081
        mo = re.search(r'^(.+)-(\d+)-g([0-9a-f]+)$', git_describe)
1082
        if not mo:
1083
            # unparseable. Maybe git-describe is misbehaving?
1084
            pieces["error"] = ("unable to parse git-describe output: '%s'"
1085
                               % describe_out)
1086
            return pieces
1087
1088
        # tag
1089
        full_tag = mo.group(1)
1090
        if not full_tag.startswith(tag_prefix):
1091
            if verbose:
1092
                fmt = "tag '%s' doesn't start with prefix '%s'"
1093
                print(fmt % (full_tag, tag_prefix))
1094
            pieces["error"] = ("tag '%s' doesn't start with prefix '%s'"
1095
                               % (full_tag, tag_prefix))
1096
            return pieces
1097
        pieces["closest-tag"] = full_tag[len(tag_prefix):]
1098
1099
        # distance: number of commits since tag
1100
        pieces["distance"] = int(mo.group(2))
1101
1102
        # commit: short hex revision ID
1103
        pieces["short"] = mo.group(3)
1104
1105
    else:
1106
        # HEX: no tags
1107
        pieces["closest-tag"] = None
1108
        count_out, rc = run_command(GITS, ["rev-list", "HEAD", "--count"],
1109
                                    cwd=root)
1110
        pieces["distance"] = int(count_out)  # total number of commits
1111
1112
    # commit date: see ISO-8601 comment in git_versions_from_keywords()
1113
    date = run_command(GITS, ["show", "-s", "--format=%ci", "HEAD"],
1114
                       cwd=root)[0].strip()
1115
    pieces["date"] = date.strip().replace(" ", "T", 1).replace(" ", "", 1)
1116
1117
    return pieces
1118
1119
1120
def do_vcs_install(manifest_in, versionfile_source, ipy):

loghub/_version.py 1 location

@@ 216-305 (lines=90) @@
213
            if verbose:
214
                print("picking %s" % r)
215
            return {
216
                "version": r,
217
                "full-revisionid": keywords["full"].strip(),
218
                "dirty": False,
219
                "error": None,
220
                "date": date
221
            }
222
    # no suitable tags, so version is "0+unknown", but full hex is still there
223
    if verbose:
224
        print("no suitable tags, using unknown + full revision id")
225
    return {
226
        "version": "0+unknown",
227
        "full-revisionid": keywords["full"].strip(),
228
        "dirty": False,
229
        "error": "no suitable tags",
230
        "date": None
231
    }
232
233
234
@register_vcs_handler("git", "pieces_from_vcs")
235
def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command):
236
    """Get version from 'git describe' in the root of the source tree.
237
238
    This only gets called if the git-archive 'subst' keywords were *not*
239
    expanded, and _version.py hasn't already been rewritten with a short
240
    version string, meaning we're inside a checked out source tree.
241
    """
242
    GITS = ["git"]
243
    if sys.platform == "win32":
244
        GITS = ["git.cmd", "git.exe"]
245
246
    out, rc = run_command(
247
        GITS, ["rev-parse", "--git-dir"], cwd=root, hide_stderr=True)
248
    if rc != 0:
249
        if verbose:
250
            print("Directory %s not under git control" % root)
251
        raise NotThisMethod("'git rev-parse --git-dir' returned error")
252
253
    # if there is a tag matching tag_prefix, this yields TAG-NUM-gHEX[-dirty]
254
    # if there isn't one, this yields HEX[-dirty] (no NUM)
255
    describe_out, rc = run_command(
256
        GITS, [
257
            "describe", "--tags", "--dirty", "--always", "--long", "--match",
258
            "%s*" % tag_prefix
259
        ],
260
        cwd=root)
261
    # --long was added in git-1.5.5
262
    if describe_out is None:
263
        raise NotThisMethod("'git describe' failed")
264
    describe_out = describe_out.strip()
265
    full_out, rc = run_command(GITS, ["rev-parse", "HEAD"], cwd=root)
266
    if full_out is None:
267
        raise NotThisMethod("'git rev-parse' failed")
268
    full_out = full_out.strip()
269
270
    pieces = {}
271
    pieces["long"] = full_out
272
    pieces["short"] = full_out[:7]  # maybe improved later
273
    pieces["error"] = None
274
275
    # parse describe_out. It will be like TAG-NUM-gHEX[-dirty] or HEX[-dirty]
276
    # TAG might have hyphens.
277
    git_describe = describe_out
278
279
    # look for -dirty suffix
280
    dirty = git_describe.endswith("-dirty")
281
    pieces["dirty"] = dirty
282
    if dirty:
283
        git_describe = git_describe[:git_describe.rindex("-dirty")]
284
285
    # now we have TAG-NUM-gHEX or HEX
286
287
    if "-" in git_describe:
288
        # TAG-NUM-gHEX
289
        mo = re.search(r'^(.+)-(\d+)-g([0-9a-f]+)$', git_describe)
290
        if not mo:
291
            # unparseable. Maybe git-describe is misbehaving?
292
            pieces["error"] = ("unable to parse git-describe output: '%s'" %
293
                               describe_out)
294
            return pieces
295
296
        # tag
297
        full_tag = mo.group(1)
298
        if not full_tag.startswith(tag_prefix):
299
            if verbose:
300
                fmt = "tag '%s' doesn't start with prefix '%s'"
301
                print(fmt % (full_tag, tag_prefix))
302
            pieces["error"] = ("tag '%s' doesn't start with prefix '%s'" %
303
                               (full_tag, tag_prefix))
304
            return pieces
305
        pieces["closest-tag"] = full_tag[len(tag_prefix):]
306
307
        # distance: number of commits since tag
308
        pieces["distance"] = int(mo.group(2))