Exemplo n.º 1
0
def repo_path():
    """
    Get the path to the git_dir of the mainline linux git repository to use.
    Typically obtained from the LINUX_GIT environment variable.
    """
    try:
        search_path = subprocess.check_output(
            os.path.join(libdir(), "..", "linux_git.sh")).decode().strip()
    except subprocess.CalledProcessError:
        print("Error: Could not determine mainline linux git repository path.",
              file=sys.stderr)
        sys.exit(1)
    return pygit2.discover_repository(search_path)
Exemplo n.º 2
0
        "commits that each line represents, with the first word on the line "
        "taken to be a commit id.")
    parser.add_argument("-d",
                        "--dump-heads",
                        action="store_true",
                        help="Print the branch heads used for sorting "
                        "(debugging).")
    args = parser.parse_args()

    try:
        path = os.environ["GIT_DIR"]
    except KeyError:
        try:
            # depending on the pygit2 version, discover_repository() will either
            # raise KeyError or return None if a repository is not found.
            path = pygit2.discover_repository(os.getcwd())
        except KeyError:
            path = None
    if path is None:
        print("Error: Not a git repository", file=sys.stderr)
        sys.exit(1)
    repo = pygit2.Repository(path)

    if args.dump_heads:
        needs_rebuild = False
        try:
            with Cache() as cache:
                try:
                    print("Cached heads (version %d):" % cache["version"])
                except CKeyError:
                    print("No usable cache")