mirror of
https://gerrit.googlesource.com/git-repo
synced 2025-07-06 20:17:23 +00:00
Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
24c6314fca | |||
7efab539f0 | |||
a3ff64cae5 | |||
776138a938 | |||
5fb9c6a5b3 |
27
main.py
27
main.py
@ -109,7 +109,7 @@ global_options.add_option('--color',
|
||||
global_options.add_option('--trace',
|
||||
dest='trace', action='store_true',
|
||||
help='trace git command execution (REPO_TRACE=1)')
|
||||
global_options.add_option('--trace_to_stderr',
|
||||
global_options.add_option('--trace-to-stderr',
|
||||
dest='trace_to_stderr', action='store_true',
|
||||
help='trace outputs go to stderr in addition to .repo/TRACE_FILE')
|
||||
global_options.add_option('--trace-python',
|
||||
@ -216,6 +216,21 @@ class _Repo(object):
|
||||
self._PrintHelp(short=True)
|
||||
return 1
|
||||
|
||||
run = lambda: self._RunLong(name, gopts, argv) or 0
|
||||
with Trace('starting new command: %s', ', '.join([name] + argv),
|
||||
first_trace=True):
|
||||
if gopts.trace_python:
|
||||
import trace
|
||||
tracer = trace.Trace(count=False, trace=True, timing=True,
|
||||
ignoredirs=set(sys.path[1:]))
|
||||
result = tracer.runfunc(run)
|
||||
else:
|
||||
result = run()
|
||||
return result
|
||||
|
||||
def _RunLong(self, name, gopts, argv):
|
||||
"""Execute the (longer running) requested subcommand."""
|
||||
result = 0
|
||||
SetDefaultColoring(gopts.color)
|
||||
|
||||
git_trace2_event_log = EventLog()
|
||||
@ -663,15 +678,7 @@ def _Main(argv):
|
||||
if gopts.trace_to_stderr:
|
||||
SetTraceToStderr()
|
||||
|
||||
with Trace('starting new command: %s', ', '.join([name] + argv), first_trace=True):
|
||||
run = lambda: repo._Run(name, gopts, argv) or 0
|
||||
if gopts.trace_python:
|
||||
import trace
|
||||
tracer = trace.Trace(count=False, trace=True, timing=True,
|
||||
ignoredirs=set(sys.path[1:]))
|
||||
result = tracer.runfunc(run)
|
||||
else:
|
||||
result = run()
|
||||
result = repo._Run(name, gopts, argv) or 0
|
||||
except KeyboardInterrupt:
|
||||
print('aborted by user', file=sys.stderr)
|
||||
result = 1
|
||||
|
@ -1,5 +1,5 @@
|
||||
.\" DO NOT MODIFY THIS FILE! It was generated by help2man.
|
||||
.TH REPO "1" "August 2022" "repo smartsync" "Repo Manual"
|
||||
.TH REPO "1" "November 2022" "repo smartsync" "Repo Manual"
|
||||
.SH NAME
|
||||
repo \- repo smartsync - manual page for repo smartsync
|
||||
.SH SYNOPSIS
|
||||
@ -105,6 +105,13 @@ delete refs that no longer exist on the remote
|
||||
.TP
|
||||
\fB\-\-no\-prune\fR
|
||||
do not delete refs that no longer exist on the remote
|
||||
.TP
|
||||
\fB\-\-auto\-gc\fR
|
||||
run garbage collection on all synced projects
|
||||
.TP
|
||||
\fB\-\-no\-auto\-gc\fR
|
||||
do not run garbage collection on any projects
|
||||
(default)
|
||||
.SS Logging options:
|
||||
.TP
|
||||
\fB\-v\fR, \fB\-\-verbose\fR
|
||||
|
@ -1,5 +1,5 @@
|
||||
.\" DO NOT MODIFY THIS FILE! It was generated by help2man.
|
||||
.TH REPO "1" "August 2022" "repo sync" "Repo Manual"
|
||||
.TH REPO "1" "November 2022" "repo sync" "Repo Manual"
|
||||
.SH NAME
|
||||
repo \- repo sync - manual page for repo sync
|
||||
.SH SYNOPSIS
|
||||
@ -106,6 +106,13 @@ delete refs that no longer exist on the remote
|
||||
\fB\-\-no\-prune\fR
|
||||
do not delete refs that no longer exist on the remote
|
||||
.TP
|
||||
\fB\-\-auto\-gc\fR
|
||||
run garbage collection on all synced projects
|
||||
.TP
|
||||
\fB\-\-no\-auto\-gc\fR
|
||||
do not run garbage collection on any projects
|
||||
(default)
|
||||
.TP
|
||||
\fB\-s\fR, \fB\-\-smart\-sync\fR
|
||||
smart sync using manifest from the latest known good
|
||||
build
|
||||
@ -200,6 +207,9 @@ to a sha1 revision if the sha1 revision does not already exist locally.
|
||||
The \fB\-\-prune\fR option can be used to remove any refs that no longer exist on the
|
||||
remote.
|
||||
.PP
|
||||
The \fB\-\-auto\-gc\fR option can be used to trigger garbage collection on all projects.
|
||||
By default, repo does not run garbage collection.
|
||||
.PP
|
||||
SSH Connections
|
||||
.PP
|
||||
If at least one project remote URL uses an SSH connection (ssh://, git+ssh://,
|
||||
|
@ -1,5 +1,5 @@
|
||||
.\" DO NOT MODIFY THIS FILE! It was generated by help2man.
|
||||
.TH REPO "1" "July 2022" "repo" "Repo Manual"
|
||||
.TH REPO "1" "November 2022" "repo" "Repo Manual"
|
||||
.SH NAME
|
||||
repo \- repository management tool built on top of git
|
||||
.SH SYNOPSIS
|
||||
@ -25,6 +25,10 @@ control color usage: auto, always, never
|
||||
\fB\-\-trace\fR
|
||||
trace git command execution (REPO_TRACE=1)
|
||||
.TP
|
||||
\fB\-\-trace-to-stderr\fR
|
||||
trace outputs go to stderr in addition to
|
||||
\&.repo/TRACE_FILE
|
||||
.TP
|
||||
\fB\-\-trace\-python\fR
|
||||
trace python command execution
|
||||
.TP
|
||||
|
@ -22,10 +22,11 @@ To also include trace outputs in stderr do `repo --trace_to_stderr ...`
|
||||
|
||||
import sys
|
||||
import os
|
||||
import tempfile
|
||||
import time
|
||||
from contextlib import ContextDecorator
|
||||
|
||||
import platform_utils
|
||||
|
||||
# Env var to implicitly turn on tracing.
|
||||
REPO_TRACE = 'REPO_TRACE'
|
||||
|
||||
@ -38,7 +39,7 @@ _TRACE_FILE = None
|
||||
|
||||
_TRACE_FILE_NAME = 'TRACE_FILE'
|
||||
|
||||
_MAX_SIZE = 5 # in mb
|
||||
_MAX_SIZE = 70 # in mb
|
||||
|
||||
_NEW_COMMAND_SEP = '+++++++++++++++NEW COMMAND+++++++++++++++++++'
|
||||
|
||||
@ -119,11 +120,11 @@ def _GetTraceFile():
|
||||
# TODO: refactor to pass repodir to Trace.
|
||||
repo_dir = os.path.dirname(os.path.dirname(__file__))
|
||||
trace_file = os.path.join(repo_dir, _TRACE_FILE_NAME)
|
||||
print('Trace outputs in %s' % trace_file)
|
||||
print('Trace outputs in %s' % trace_file, file=sys.stderr)
|
||||
return trace_file
|
||||
|
||||
def _ClearOldTraces():
|
||||
"""Clear traces from old commands if trace file is too big.
|
||||
"""Clear the oldest commands if trace file is too big.
|
||||
|
||||
Note: If the trace file contains output from two `repo`
|
||||
commands that were running at the same time, this
|
||||
@ -131,12 +132,12 @@ def _ClearOldTraces():
|
||||
"""
|
||||
if os.path.isfile(_TRACE_FILE):
|
||||
while os.path.getsize(_TRACE_FILE)/(1024*1024) > _MAX_SIZE:
|
||||
temp = tempfile.NamedTemporaryFile(mode='w', delete=False)
|
||||
temp_file = _TRACE_FILE + '.tmp'
|
||||
with open(_TRACE_FILE, 'r', errors='ignore') as fin:
|
||||
trace_lines = fin.readlines()
|
||||
for i , l in enumerate(trace_lines):
|
||||
if 'END:' in l and _NEW_COMMAND_SEP in l:
|
||||
temp.writelines(trace_lines[i+1:])
|
||||
break
|
||||
temp.close()
|
||||
os.replace(temp.name, _TRACE_FILE)
|
||||
with open(temp_file, 'w') as tf:
|
||||
trace_lines = fin.readlines()
|
||||
for i , l in enumerate(trace_lines):
|
||||
if 'END:' in l and _NEW_COMMAND_SEP in l:
|
||||
tf.writelines(trace_lines[i+1:])
|
||||
break
|
||||
platform_utils.rename(temp_file, _TRACE_FILE)
|
||||
|
@ -200,6 +200,9 @@ exist locally.
|
||||
The --prune option can be used to remove any refs that no longer
|
||||
exist on the remote.
|
||||
|
||||
The --auto-gc option can be used to trigger garbage collection on all
|
||||
projects. By default, repo does not run garbage collection.
|
||||
|
||||
# SSH Connections
|
||||
|
||||
If at least one project remote URL uses an SSH connection (ssh://,
|
||||
@ -309,6 +312,10 @@ later is required to fix a server side protocol bug.
|
||||
help='delete refs that no longer exist on the remote (default)')
|
||||
p.add_option('--no-prune', dest='prune', action='store_false',
|
||||
help='do not delete refs that no longer exist on the remote')
|
||||
p.add_option('--auto-gc', action='store_true',
|
||||
help='run garbage collection on all synced projects')
|
||||
p.add_option('--no-auto-gc', dest='auto_gc', action='store_false',
|
||||
help='do not run garbage collection on any projects (default)')
|
||||
if show_smart:
|
||||
p.add_option('-s', '--smart-sync',
|
||||
dest='smart_sync', action='store_true',
|
||||
@ -829,7 +836,14 @@ later is required to fix a server side protocol bug.
|
||||
project.config.SetString('gc.pruneExpire', None)
|
||||
|
||||
def _GCProjects(self, projects, opt, err_event):
|
||||
pm = Progress('Garbage collecting', len(projects), delay=False, quiet=opt.quiet)
|
||||
"""Perform garbage collection.
|
||||
|
||||
If We are skipping garbage collection (opt.auto_gc not set), we still want
|
||||
to potentially mark objects precious, so that `git gc` does not discard
|
||||
shared objects.
|
||||
"""
|
||||
pm = Progress(f'{"" if opt.auto_gc else "NOT "}Garbage collecting',
|
||||
len(projects), delay=False, quiet=opt.quiet)
|
||||
pm.update(inc=0, msg='prescan')
|
||||
|
||||
tidy_dirs = {}
|
||||
@ -849,6 +863,10 @@ later is required to fix a server side protocol bug.
|
||||
project.bare_git,
|
||||
)
|
||||
|
||||
if not opt.auto_gc:
|
||||
pm.end()
|
||||
return
|
||||
|
||||
jobs = opt.jobs
|
||||
|
||||
gc_args = ['--auto']
|
||||
|
Reference in New Issue
Block a user