Пример #1
0
 def compute(directory, args):
     with cd(directory, internal=True):
         return [
             s.strip()
             for s in check_output(["docker-compose"] + args +
                                   ["config", "--services"],
                                   internal=True).splitlines()
         ]
Пример #2
0
def restore(file, name):
    """Put the content of name into file

    By default, put the content of name on a file/directory with the same
    name. You can provide a different location with --file

    """
    file = file or name[len("refs/git-store/"):]
    file = os.path.abspath(file)
    tl = toplevel()
    prefixfile = os.path.relpath(file, tl)
    if check_output([git(), "cat-file", "-t", name]).strip() == "tree":
        call([git(), "read-tree", name, "--prefix", prefixfile])
        call([git(), "checkout", "--", file])
        check_output([git(), "reset", "--", file])
    else:
        call([git(), "cat-file", "blob", name], stdout=open(file, "w"))
    LOGGER.info("Restored git name {} in location {}".format(
        name[len("refs/git-store/"):], prefixfile))
Пример #3
0
 def get(blob_ref):
     ref = "refs/git-store/" + blob_ref[1]
     res = "Hash: {}".format(blob_ref[0][:8])
     try:
         typ = check_output(
             [git(), "cat-file", "-t", ref],
             nostderr=True,
             internal=True,
         ).strip()
     except subprocess.CalledProcessError:
         typ = "unknown"
     res += " , Type: {}".format(typ)
     if with_notes:
         try:
             note = check_output(notes_command() + ["show", ref],
                                 nostderr=True).strip()
         except subprocess.CalledProcessError:
             note = None
         if note:
             res += " , Note: {}".format(note.splitlines()[0])
     return res
Пример #4
0
def toplevel():
    global _toplevel
    if _toplevel is None:
        try:
            _toplevel = check_output(
                [git(), "rev-parse", "--show-toplevel"],
                nostderr=True,
                internal=True,
            ).strip()
        except subprocess.CalledProcessError:
            pass
    return _toplevel
 def attempt1():
     info = pool(blob_sha)
     if info:
         line, res = info
         commit, *parents = line
         print("## {}".format(blob_sha))
         print(
             check_output(
                 shlex.split(
                     "git log --format='%cd %h %s' -n 1 {}".format(commit))
             )
         )
         print("  {}".format(res))
         print("-------------")
Пример #6
0
def current_remote():
    global _current_remote
    if _current_remote is None:
        try:
            _current_remote = check_output(
                [
                    git(), "rev-parse", "--abbrev-ref", "--symbolic-full-name",
                    "@{u}"
                ],
                internal=True,
                nostderr=True,
            ).strip().split("/")[0]
        except subprocess.CalledProcessError:
            pass
    return _current_remote
Пример #7
0
def get_refs(remote=None):
    ref_command = ["ls-remote", remote] if remote else ["show-ref"]

    def split(ref):
        res = ref.split(" ")
        res[1] = res[1][len("refs/git-store/"):]
        return res

    return [
        split(line) for line in check_output(
            [git()] + ref_command,
            internal=True,
            nostderr=True,
        ).strip().replace("\t", " ").splitlines()
        if line.split(" ")[1].startswith("refs/git-store/")
    ]
 def big_dict():
     lines = [
         line.split(" ")
         for line in check_output(
                 shlex.split("git rev-list --parents HEAD")
         ).splitlines()
     ]
     blob_to_commit = defaultdict(set)
     parenthood = {}
     with progressbar(lines) as bar:
         for commit, *parents in bar:
             for blob in commit_blobs(commit):
                 blob_to_commit[blob].add(commit)
             for parent in parents:
                 for blob in commit_blobs(parent):
                     blob_to_commit[blob].add(parent)
             parenthood[commit] = parents
     return blob_to_commit, parenthood
def pool(blob_sha):
    lines = [
        line.split(" ")
        for line in check_output(
                shlex.split("git rev-list --parents HEAD")
        ).splitlines()
    ]
    p = Pool()
    manager = Manager()
    end = manager.Value(bool, False)
    gen = p.imap(find_matching, [
        (commit, parents, blob_sha, end)
        for commit, *parents in lines  # NOQA
    ])
    with progressbar(gen, length=len(lines)) as bar:
        for line, res in zip(lines, bar):
            if res:
                p.terminate()
                p.join()
                return line, res
Пример #10
0
def _save(name, file, force, create_hash_file=False):
    full = os.path.abspath(file)
    hash_file = full + ".hash"
    dir = os.path.dirname(full)
    file = os.path.basename(full)
    tl = toplevel()
    prefixfile = os.path.relpath(full, tl)
    if os.path.isdir(full):
        call([git(), "add", "-f", "--", file], cwd=dir)
        blob = check_output([git(), "write-tree", "--prefix",
                             prefixfile]).strip()
        check_output([git(), "reset", "--", file], nostderr=True)
    else:
        blob = check_output([git(), "hash-object", "-w", "--", full]).strip()
    name = name or (file + "-" + blob[:8])
    name = name.replace(".", "_").replace(" ", "_")
    if create_hash_file:
        createfile(hash_file, name)
    refs_dict = get_refs_dict()
    if not force and name in refs_dict:
        other_blob = refs_dict[name]
        if blob == other_blob:
            LOGGER.warning("The git name {} already exists"
                           " and is associated to the same content".format(
                               name,
                               blob,
                           ))
            return name
        else:
            raise click.UsageError(
                "The git name {} already exists with hash {}."
                " You are willing to associate it with the hash {}."
                " Either choose another name or use --force"
                " if you know what you are doing".format(
                    name,
                    other_blob,
                    blob,
                ))
    ref = "refs/git-store/{}".format(name)
    check_output([git(), "update-ref", ref, blob])
    return name
Пример #11
0
 def evaluate(project, expr):
     return check_output(shlex.split(expr)).strip()
Пример #12
0
def note_ref():
    global _note_ref
    if _note_ref is None:
        _note_ref = check_output(notes_command() + ["get-ref"]).strip()
    return _note_ref
Пример #13
0
def git_remotes():
    global _git_remotes
    if _git_remotes is None:
        _git_remotes = check_output([git(), "remote"]).splitlines()
    return _git_remotes
Пример #14
0
def commit_blobs(commit_sha):
    return check_output(
        shlex.split("git ls-tree -t -r {}".format(commit_sha))
    ).splitlines()