Skip to content

Commit

Permalink
refactor: prune
Browse files Browse the repository at this point in the history
  • Loading branch information
redstreet committed Aug 26, 2023
1 parent 27f097e commit 9c388fd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,13 @@ in a directory `myrepository/` under this DropBox account.

`git-remote-rclone` can be configured to get git to prune the repo aggressively before
uploading via rclone. This comes in handy to minimize the uploaded file size, at the
cost of the time taken to prune. This is a good tradeoff for low-bandwidth situations.
To configure it, run this in your git repo:
cost of the time taken to prune. This can be a good tradeoff for low-bandwidth
situations. To configure it, run this in your git repo:

```
git config --add git-remote-rclone.pruneaggressively "true"
```
`git-gc` is run only on the repo that is uploaded. The local repo is left untouched.

## Example
```
Expand Down
9 changes: 4 additions & 5 deletions git-remote-rclone
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class RCloneRemote(object):
with open(synced, 'r') as f:
last_hash = f.readline().strip()
if last_hash == repo_hash: # local sync matches remote
self.log(f'Local hash matches repo_hash ({last_hash}). No need to re-mirror.')
self.log(f'Local hash matches remote hash ({last_hash}). No need to re-mirror.')
return

if not repo_hash: # there is nothing at the remote end, nothing to sync
Expand Down Expand Up @@ -207,21 +207,19 @@ class RCloneRemote(object):
return refs

def gitgc(self):
"""Prune aggressively if configured via:
"""Prune the remote repo aggressively if configured via:
git config --add git-remote-rclone.pruneaggressively "true"
"""
env_orig = os.environ.copy()
env_orig['GIT_DIR'] = str(self.gitdir)
env = os.environ.copy()
env['GIT_DIR'] = str(self.repodir)

gc_cmd = ['git', 'gc']
prune = self.run_cmd(['git', 'config', 'git-remote-rclone.pruneaggressively'],
env=env_orig, check=False).strip().lower()
if prune == "true":
self.log("Running git-gc with aggressive pruning")
gc_cmd += ['--prune=now', '--aggressive']
subprocess.run(gc_cmd, env=env, check=False)
self.run_cmd(gc_cmd, check=False)

def export_to_rclone(self):
"""Export a fast-export stream to rclone.
Expand Down Expand Up @@ -311,6 +309,7 @@ class RCloneRemote(object):
self.log(f'Updating sync stamp to repo_hash: {repo_hash}')
synced.write_text(repo_hash)


def send_capabilities(self):
self.PrintFrame()
caps = ['import',
Expand Down

0 comments on commit 9c388fd

Please sign in to comment.