Code Duplication    Length = 53-59 lines in 2 locations

git_app_version/_version.py 1 location

@@ 171-229 (lines=59) @@
168
    return keywords
169
170
171
@register_vcs_handler("git", "keywords")
172
def git_versions_from_keywords(keywords, tag_prefix, verbose):
173
    """Get version information from git keywords."""
174
    if not keywords:
175
        raise NotThisMethod("no keywords at all, weird")
176
    date = keywords.get("date")
177
    if date is not None:
178
        # git-2.2.0 added "%cI", which expands to an ISO-8601 -compliant
179
        # datestamp. However we prefer "%ci" (which expands to an "ISO-8601
180
        # -like" string, which we must then edit to make compliant), because
181
        # it's been around since git-1.5.3, and it's too difficult to
182
        # discover which version we're using, or to work around using an
183
        # older one.
184
        date = date.strip().replace(" ", "T", 1).replace(" ", "", 1)
185
    refnames = keywords["refnames"].strip()
186
    if refnames.startswith("$Format"):
187
        if verbose:
188
            print("keywords are unexpanded, not using")
189
        raise NotThisMethod("unexpanded keywords, not a git-archive tarball")
190
    refs = set([r.strip() for r in refnames.strip("()").split(",")])
191
    # starting in git-1.8.3, tags are listed as "tag: foo-1.0" instead of
192
    # just "foo-1.0". If we see a "tag: " prefix, prefer those.
193
    TAG = "tag: "
194
    tags = set([r[len(TAG):] for r in refs if r.startswith(TAG)])
195
    if not tags:
196
        # Either we're using git < 1.8.3, or there really are no tags. We use
197
        # a heuristic: assume all version tags have a digit. The old git %d
198
        # expansion behaves like git log --decorate=short and strips out the
199
        # refs/heads/ and refs/tags/ prefixes that would let us distinguish
200
        # between branches and tags. By ignoring refnames without digits, we
201
        # filter out many common branch names like "release" and
202
        # "stabilization", as well as "HEAD" and "master".
203
        tags = set([r for r in refs if re.search(r'\d', r)])
204
        if verbose:
205
            print("discarding '%s', no digits" % ",".join(refs - tags))
206
    if verbose:
207
        print("likely tags: %s" % ",".join(sorted(tags)))
208
    for ref in sorted(tags):
209
        # sorting will prefer e.g. "2.0" over "2.0rc1"
210
        if ref.startswith(tag_prefix):
211
            r = ref[len(tag_prefix):]
212
            if verbose:
213
                print("picking %s" % r)
214
            return {
215
                "version": r,
216
                "full-revisionid": keywords["full"].strip(),
217
                "dirty": False,
218
                "error": None,
219
                "date": date
220
            }
221
    # no suitable tags, so version is "0+unknown", but full hex is still there
222
    if verbose:
223
        print("no suitable tags, using unknown + full revision id")
224
    return {
225
        "version": "0+unknown",
226
        "full-revisionid": keywords["full"].strip(),
227
        "dirty": False,
228
        "error": "no suitable tags",
229
        "date": None
230
    }
231
232

versioneer.py 1 location

@@ 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")