示例#1
0
def main():
    """Validate the configuration for one or more repositories."""
    # pylint:disable=too-many-branches
    desc = _("Report on the validity of a repository configuration.")
    parser = p4gf_util.create_arg_parser(desc)
    parser.add_argument('-a', '--all', action='store_true',
                        help=_('process all known Git Fusion repositories'))
    parser.add_argument(NTR('repos'), metavar=NTR('repo'), nargs='*',
                        help=_('name of repository or file to be validated'))
    args = parser.parse_args()

    # Check that either --all, or 'repos' was specified, but not both.
    if not args.all and len(args.repos) == 0:
        sys.stderr.write(_('Missing repo names; try adding --all option.\n'))
        sys.exit(2)
    if args.all and len(args.repos) > 0:
        sys.stderr.write(_('Ambiguous arguments. Choose --all or a repo name.\n'))
        sys.exit(2)

    with p4gf_create_p4.Closer():
        p4 = p4gf_create_p4.create_p4_temp_client()
        if not p4:
            sys.exit(2)
        # Sanity check the connection (e.g. user logged in?) before proceeding.
        try:
            p4.fetch_client()
        except P4.P4Exception as e:
            sys.stderr.write(_('P4 exception occurred: {exception}').format(exception=e))
            sys.exit(1)

        p4gf_branch.init_case_handling(p4)

        if args.all:
            repos = p4gf_util.repo_config_list(p4)
            if len(repos) == 0:
                print(_('No Git Fusion repositories found, nothing to do.'))
                sys.exit(0)
        else:
            repos = args.repos

        for repo in repos:
            if os.path.exists(repo):
                print(_("Processing file {repo_name}...").format(repo_name=repo))
                try:
                    config = p4gf_config.RepoConfig.from_local_file(repo, p4, repo)
                except p4gf_config.ConfigLoadError as e:
                    sys.stderr.write("{}\n", e)
                except p4gf_config.ConfigParseError as e:
                    sys.stderr.write("{}\n", e)
            else:
                repo_name = p4gf_translate.TranslateReponame.git_to_repo(repo)
                print(_("Processing repository {repo_name}...").format(repo_name=repo_name))
                try:
                    config = p4gf_config.RepoConfig.from_depot_file(repo_name, p4)
                except p4gf_config.ConfigLoadError as err:
                    sys.stderr.write("{}\n", err)
            if Validator(config, p4).is_valid():
                print(_("ok"))
            print("")
def create_context(args):
    """Create a p4gf_context for accessing Git Fusion data."""
    ctx = p4gf_context.create_context(args.repo)
    ctx.connect_cli(LOG)
    p4gf_proc.init()
    p4gf_branch.init_case_handling(ctx.p4gf)
    if DEBUG:
        print(_("create_context: ctx.p4.port='{}'  ctx.p4.user='******' .").format(
            ctx.p4.port, ctx.p4.user))
    return (ctx.p4gf, ctx)
示例#3
0
def main():
    """Either do the work now or fork a process to do it later."""
    for h in ['-?', '-h', '--help']:
        if h in sys.argv:
            print(_('Git Fusion pre-receive hook.'))
            return 2
    p4gf_version_3.print_and_exit_if_argv()
    p4gf_branch.init_case_handling()
    prl = PreReceiveTupleLists.from_stdin(sys.stdin)
    # Preflight rejects the push by raising an exception, which is handled
    # in the logging code by printing the message to stderr.
    with Timer('pre-receive'):
        return PreflightHook('pre-receive preflight', prl).do_it()
示例#4
0
def forked_execed_main():
    """The main that runs after double-fork + exec."""
    LOG.debug('forked_execed_main() beginning copy-to-p4')
    try:
        p4gf_branch.init_case_handling()
        ec = CopyOnlyHook('post-receive').do_it()
        LOG.debug('forked_execed_main() returned %s', ec)
        p4gf_tempfile.prune_old_files()
        return ec
    finally:
        # The @atexit.register does not seem to fire for double-forked
        # Python processes, so call the profiler report explicitly.
        Report()
        LOG.debug('forked_execed_main() completed')
def main():
    """Set up repo for a view."""
    p4gf_util.has_server_id_or_exit()
    args = _parse_argv()
    p4gf_version_3.log_version_extended(include_checksum=True)
    log_l10n()
    if args.enablemismatchedrhs:
        # Git Fusion should never modify the customer's config file, and
        # use of this option resulted in the config file losing all of the
        # comments and formatting the customer had put in place.
        sys.stderr.write(
            _('The --enablemismatchedrhs option is deprecated,'
              ' please use enable-mismatched-rhs config file'
              ' option instead.\n'))
        sys.exit(1)
    repo_name_p4client = None
    if args.p4client:
        repo_name_p4client = p4gf_util.argv_to_repo_name(args.p4client)
    repo_name = _argv_to_repo_name(args.repo_name)
    p4gf_util.reset_git_enviro()

    p4 = p4gf_create_p4.create_p4_temp_client()
    if not p4:
        raise RuntimeError(_('error connecting to Perforce'))

    LOG.debug("connected to P4 at %s", p4.port)
    p4gf_proc.init()

    try:
        with ExitStack() as stack:
            stack.enter_context(p4gf_create_p4.Closer())
            p4gf_version_3.version_check()
            p4gf_branch.init_case_handling(p4)
            repo_lock = p4gf_lock.RepoLock(p4, repo_name)
            stack.enter_context(repo_lock)
            ctx = p4gf_context.create_context(repo_name)
            ctx.p4gf = p4
            ctx.repo_lock = repo_lock
            initer = InitRepo(p4, repo_lock).set_repo_name(repo_name)
            initer.context = ctx
            initer.set_config_file_path(args.config)
            initer.set_charset(args.charset)
            initer.set_noclone(args.noclone)
            initer.set_start(args.start)
            stack.enter_context(ctx)
            initer.full_init(repo_name_p4client)
    except P4.P4Exception as e:
        _print_stderr(_('Error occurred: {exception}').format(exception=e))
        sys.exit(1)
def main():
    """Do the thing."""
    args = parse_argv()
    ctx = p4gf_context.create_context(args.repo)
    ctx.create_config_if_missing(False)
    ctx.config.p4user = args.p4user
    ctx.config.p4port = args.p4port
    ctx.connect_cli(LOG)
    p4gf_proc.init()
    p4gf_branch.init_case_handling(ctx.p4gf)
    rollback = Rollback( ctx           = ctx
                       , change_num    = args.change_num
                       , is_preview    = not args.execute
                       , is_obliterate = args.obliterate )
    rollback.rollback()
示例#7
0
 def create_ctx(self):
     """
     Connect to Perforce using environment.
     """
     p4 = p4gf_create_p4.create_p4_temp_client(port=self.p4port,
                                               user=self.p4user)
     p4gf_branch.init_case_handling(p4)
     self.repo_name = 'estimate_repo_size_' + p4gf_util.uuid()
     self.repo_config = p4gf_config.RepoConfig.from_local_files(
         self.repo_name, p4, self.config_path, None)
     ctx = p4gf_context.create_context(self.repo_name)
     ctx.p4gf = p4
     ctx.repo_config = self.repo_config
     ctx.config.p4user = self.p4user
     ctx.config.p4port = self.p4port
     ctx.connect()
     return ctx
def main():
    """Do the thing."""
    args = parse_argv()

    ctx = p4gf_context.create_context(args.repo_name)
    ctx.config.p4user = args.p4user
    ctx.config.p4port = args.p4port
    ctx.connect_cli(log=LOG)

    p4gf_branch.init_case_handling(ctx.p4)

    rc = RepoCompareSingle(ctx, args)
    for change_num in args.change_num:
        rc.compare_change_num(change_num)
    rc.report_summary()

    if rc.how_ct:
        sys.exit(1)
示例#9
0
    def __init__(self, port, user, *, cont=False,
                 keep=False, force=False, stdout=False, doreport=False, quiet=False):
        self.starttime   = time.time()
        self.cont        = cont
        self.keep        = keep
        self.force       = force
        self.stdout      = stdout
        self.doreport    = doreport
        self.quiet       = quiet
        self.root_path   = os.getcwd()
        self.report_file = None

        if not self.stdout:
            self.report_file = os.path.abspath('p4gf_gc_unreachables')
        self.dir_abspath     = os.path.abspath(".p4gf_gc")
        self.git_dir_abspath = os.path.join(self.dir_abspath, "git")
        self.p4_dir_abspath  = os.path.join(self.dir_abspath, "p4")
        self.git_dir_objects = os.path.join(self.git_dir_abspath, "objects")
        self.sql_dir_abspath = os.path.join(self.dir_abspath, "sql")
        self.sql_db_abspath  = os.path.join(self.dir_abspath, "sql", "db.sqlite")

        if self.cont:
            self.keep = True   # force keep for cont
        else:
            if self.force:
                self.rmdir()
            self.create_dir()

        self.db              = None  # pylint:disable=invalid-name
        self.seen_trees      = set()
        p4gf_ensure_dir.ensure_dir(self.p4_dir_abspath)
        os.chdir(self.p4_dir_abspath)
        os.environ['PWD']=self.p4_dir_abspath
        self.p4 = p4gf_create_p4.create_p4_temp_client(port = port,
                                              user=user)
        p4gf_branch.init_case_handling(self.p4)
        self.report_progress_msg      = ''
        self._uncommitted_set_ct      = 0
        self._uncommitted_set_max     = 1000
        self.git_repo                 = None
        self.max_rows_per_table       = 500000
        self.sync_counts              = { TREES                : 0,
                                          COMMITS              : 0}

        self.table_type_counts        = { TREES                : 0,
                                          BLOBS                : 0,
                                          DELETED_TREES        : 0,
                                          DELETED_BLOBS        : 0,
                                          DELETED_COMMITS    : 0,
                                          TREES_FROM_COMMITS : 0,
                                          MISSING_TREES_FROM_COMMITS : 0 }
        self.table_names              = { TREES                : [],
                                          BLOBS                : [],
                                          DELETED_TREES        : [],
                                          DELETED_BLOBS        : [],
                                          DELETED_COMMITS      : [],
                                          TREES_FROM_COMMITS   : [],
                                          MISSING_TREES_FROM_COMMITS   : [] }

        self.fd = None         # pylint:disable=invalid-name
        self.debug  = LOG.isEnabledFor(logging.DEBUG)
        self.debug2 = LOG.isEnabledFor(logging.DEBUG2)
        self.debug3 = LOG.isEnabledFor(logging.DEBUG3)
        self.status = None
        self.eta    = None
        self.tree_recursion_depth = 0
        self.git_dir = None
def main():
    """Process command line arguments and call functions to do the real
    work of cleaning up the Git mirror and Perforce workspaces.
    """
    # pylint:disable=too-many-branches, too-many-statements
    log_l10n()
    # Set up argument parsing.
    desc = _("""Deletes Git Fusion repositories and workspaces. When you
include the -a or --all option, Git Fusion finds and deletes the following
for all repos on the current server disregarding specified views:
1) All git-fusion-view clients. 2) Client git-fusion--p4 workspace files.
3) Objects in //.git-fusion/objects/...
""")
    epilog = _("""It is recommended to run 'p4gf_delete_repo.py' without
the '-y' flag to preview changes that will be made to the depot before
using the '-y' flag for permanent removal. Use -a or --all to permanently
delete all repo data for all repos on the Perforce server; be aware that
this may take some time, depending on the number and size of the objects.
Use -N, --no-obliterate to quickly delete most of the repo's data and
continue working. This minimizes the impact to server performance.
""")
    parser = p4gf_util.create_arg_parser(desc, epilog=epilog)
    parser.add_argument(
        '-a',
        '--all',
        action='store_true',
        help=_('remove all known Git mirrors on the current server'))
    parser.add_argument('-y',
                        '--delete',
                        action='store_true',
                        help=_('perform the deletion'))
    parser.add_argument('-v',
                        '--verbose',
                        action='store_true',
                        help=_('print details of deletion process'))
    parser.add_argument(
        '-N',
        '--no-obliterate',
        action='store_true',
        help=_('with the --all option, do not obliterate object cache'))
    parser.add_argument(NTR('views'),
                        metavar=NTR('view'),
                        nargs='*',
                        help=_('name of view to be deleted'))
    args = parser.parse_args()
    p4gf_util.has_server_id_or_exit()

    # Check that either --all, or 'views' was specified.
    if not args.all and len(args.views) == 0:
        sys.stderr.write(_('Missing view names; try adding --all option.\n'))
        sys.exit(2)
    if args.all and len(args.views) > 0:
        sys.stderr.write(
            _('Ambiguous arguments. Choose --all or a view name.\n'))
        sys.exit(2)

    # Check that --no-obliterate occurs only with --all
    if not args.all and args.no_obliterate:
        sys.stderr.write(
            _('--no-obliterate permitted only with the --all option.\n'))
        sys.exit(2)

    with p4gf_create_p4.Closer():
        p4 = p4gf_create_p4.create_p4_temp_client()
        if not p4:
            return 2
        # Sanity check the connection (e.g. user logged in?) before proceeding.
        p4gf_branch.init_case_handling(p4)
        try:
            p4.fetch_client()
        except P4.P4Exception as e:
            sys.stderr.write(
                _('P4 exception occurred: {exception}').format(exception=e))
            sys.exit(1)

        metrics = DeletionMetrics()
        if args.all:
            try:
                if p4gf_const.READ_ONLY:
                    delete_all_local(args, p4, metrics)
                else:
                    delete_all(args, p4, metrics)
            except (p4gf_lock.LockBusy, P4.P4Exception) as e:
                sys.stderr.write("{exception}\n".format(exception=e))
                sys.exit(1)
        else:
            # Delete the client(s) for the named view(s).
            for git_view in args.views:
                repo_name = p4gf_translate.TranslateReponame.git_to_repo(
                    git_view)
                client_name = p4gf_util.repo_to_client_name(repo_name)
                try:
                    if p4gf_const.READ_ONLY:
                        delete_client_local(args, p4, client_name, metrics)
                    else:
                        with p4gf_lock.RepoLock(p4, repo_name, blocking=False):
                            delete_client(args, p4, client_name, metrics)
                except (p4gf_lock.LockBusy, P4.P4Exception) as e:
                    sys.stderr.write("{exception}\n".format(exception=e))
                    sys.exit(1)
        if not args.delete:
            print(_('This was report mode. Use -y to make changes.'))
        else:
            print(
                _('Deleted {num_files:d} files, {num_groups:d} groups, '
                  '{num_clients:d} clients, and {num_keys:d} p4keys.').format(
                      num_files=metrics.files,
                      num_groups=metrics.groups,
                      num_clients=metrics.clients,
                      num_keys=metrics.p4keys))
            if args.all:
                print(_('Successfully deleted all repos\n'))
            else:
                print(
                    _('Successfully deleted repos:\n{repos}').format(
                        repos="\n".join(args.views)))