Skip to content

Commit

Permalink
Discontinue datalad-core repository runner usage in datalad-annex
Browse files Browse the repository at this point in the history
The new implementation uses the lean `call_git...()` utilities directly.
It also avoids the relatively heavy-handed environment patching
mechanism in the runner, in favor of the new lean `patched_env`
context manager. This is OK, because the git remote helper runs in its
own process.

Ping datalad#541
  • Loading branch information
mih committed Feb 7, 2024
1 parent b110cad commit 3b6508b
Showing 1 changed file with 63 additions and 63 deletions.
126 changes: 63 additions & 63 deletions datalad_next/gitremotes/datalad_annex.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,9 @@
from datalad_next.exceptions import CapturedException
from datalad_next.runners import (
CommandError,
StdOutCapture,
call_git,
call_git_oneline,
call_git_success,
)
from datalad_next.uis import ui_switcher as ui
from datalad_next.utils import (
Expand All @@ -224,6 +225,7 @@
get_specialremote_credential_envpatch,
get_specialremote_credential_properties,
needs_specialremote_credential_envpatch,
patched_env,
specialremote_credential_envmap,
update_specialremote_credential,
)
Expand Down Expand Up @@ -1156,69 +1158,67 @@ def make_export_tree(repo):
# we need to force Git to use a throwaway index file to maintain
# the bare nature of the repoannex, git-annex would stop functioning
# properly otherwise
env = os.environ.copy()
index_file = repo.pathobj / 'datalad_tmp_index'
env['GIT_INDEX_FILE'] = str(index_file)
try:
for key, kinfo in RepoAnnexGitRemote.xdlra_key_locations.items():
# create a blob for the annex link
out = repo._git_runner.run(
['git', 'hash-object', '-w', '--stdin'],
stdin=bytes(
f'../../.git/annex/objects/{kinfo["prefix"]}/{key}/{key}',
'utf-8'),
protocol=StdOutCapture)
linkhash = out['stdout'].strip()
# place link into a tree
out = repo._git_runner.run(
['git', 'update-index', '--add', '--cacheinfo', '120000',
linkhash, kinfo["loc"]],
protocol=StdOutCapture,
env=env)
# write the complete tree, and return ID
out = repo._git_runner.run(
['git', 'write-tree'],
protocol=StdOutCapture,
env=env)
exporttree = out['stdout'].strip()
# this should always come out identically
# unless we made changes in the composition of the export tree
assert exporttree == '7f0e7953e93b4c9920c2bff9534773394f3a5762'

# clean slate
if index_file.exists():
index_file.unlink()
# fake export.log record
# <unixepoch>s <here>:<origin> <exporttree>
now_ts = datetime.datetime.now().timestamp()
out = repo._git_runner.run(
['git', 'hash-object', '-w', '--stdin'],
stdin=bytes(
f'{now_ts}s {here}:{origin} {exporttree}\n', 'utf-8'),
protocol=StdOutCapture)
exportlog = out['stdout'].strip()
repo._git_runner.run(
['git', 'read-tree', 'git-annex'],
env=env)
out = repo._git_runner.run(
['git', 'update-index', '--add', '--cacheinfo', '100644',
exportlog, 'export.log'],
protocol=StdOutCapture,
env=env)
out = repo._git_runner.run(
['git', 'write-tree'],
protocol=StdOutCapture,
env=env)
gaupdate = out['stdout'].strip()
out = repo._git_runner.run(
['git', 'commit-tree', '-m', 'Fake export', '-p', 'git-annex',
gaupdate],
protocol=StdOutCapture,
env=env)
gacommit = out['stdout'].strip()
repo.call_git(['update-ref', 'refs/heads/git-annex', gacommit])
finally:
index_file.unlink()
with patched_env(GIT_INDEX_FILE=index_file):
try:
for key, kinfo in RepoAnnexGitRemote.xdlra_key_locations.items():
# create a blob for the annex link
linkhash = call_git_oneline(
['hash-object', '-w', '--stdin'],
cwd=repo.pathobj,
input=f'../../.git/annex/objects/{kinfo["prefix"]}/{key}/{key}',
).strip()
# place link into a tree
call_git_success(
['update-index', '--add', '--cacheinfo', '120000',
linkhash, kinfo["loc"]],
cwd=repo.pathobj,
capture_output=True,
)
# write the complete tree, and return ID
exporttree = call_git_oneline(
['write-tree'], cwd=repo.pathobj
).strip()
# this should always come out identically
# unless we made changes in the composition of the export tree
assert exporttree == '7f0e7953e93b4c9920c2bff9534773394f3a5762'

# clean slate
if index_file.exists():
index_file.unlink()
# fake export.log record
# <unixepoch>s <here>:<origin> <exporttree>
now_ts = datetime.datetime.now().timestamp()
exportlog = call_git_oneline(
['hash-object', '-w', '--stdin'],
input=f'{now_ts}s {here}:{origin} {exporttree}\n',
cwd=repo.pathobj,
).strip()
call_git_success(
['read-tree', 'git-annex'],
cwd=repo.pathobj,
)
call_git_success(
['update-index', '--add', '--cacheinfo', '100644',
exportlog, 'export.log'],
cwd=repo.pathobj,
capture_output=True,
)
gaupdate = call_git_oneline(
['write-tree'], cwd=repo.pathobj,
).strip()
gacommit = call_git_oneline(
['commit-tree', '-m', 'Fake export', '-p', 'git-annex',
gaupdate],
cwd=repo.pathobj,
).strip()
call_git_success(
['update-ref', 'refs/heads/git-annex', gacommit],
cwd=repo.pathobj,
)
finally:
if index_file.exists():
index_file.unlink()

return exporttree

Expand Down

0 comments on commit 3b6508b

Please sign in to comment.