在Perforce中,当切换客户端用户时连接到不同端口的命令是什么?

4

如何在命令行中实现p4win gui客户端中的“Switch Port Client User”功能?

我已经登录到一个端口,但现在我想连接到同一服务器上的另一个端口,以便访问不同的源代码控制文件库。我认为需要使用以下命令:

p4 login

然而,阅读“登录”的“帮助”并没有显示指定端口号的选项。用户名和客户端名称仍然相同,但只需要更改端口号。
4个回答

10

P4PORT配置变量存储Perforce服务器的名称和端口号以进行连接。您可以将此值设置为环境变量,或者如果您正在使用Windows,则可以使用“p4 set”在注册表中设置:

p4 set P4PORT=perforce:1669

查看 P4PORT 的当前值:

> p4 set P4PORT
P4PORT=perforce:1669

6
如果您想为任何P4命令通用地执行此操作,则可以通过“p4 help usage”找到一般形式。
简而言之,
p4 -p <your port> login 

会执行您所要求的操作。请注意,从使用帮助中可以看出,您可以从命令行指定大多数内容,例如客户端规范、用户名、密码等。


2

E.g:

p4 set P4PORT=1666

从帮助文档中:

C:\> p4 help environment

Environment variables used by Perforce:

    Variable    Defines                          For more information see
    --------    -------                          ------------------------
    P4AUDIT     name of server audit file        p4d -h
    P4CHARSET   client's local character set     p4 help charset
    P4COMMANDCHARSET client's local character set for
                command line operations          p4 help charset
    P4CLIENT    name of client workspace         p4 help client
                                                 p4 help usage
    P4CONFIG    name of configuration file       Command Reference Manual
    P4DIFF      diff program to use on client    p4 help diff
    P4DIFFUNICODE diff program to use on client  p4 help diff
    P4EDITOR    editor invoked by p4 commands    p4 help change, etc
    P4HOST      name of host computer            p4 help client
                                                 p4 help usage
    P4JOURNAL   name of server journal file      p4d -h
    P4LANGUAGE  language for text messages       p4 help usage
    P4LOG       name of server log file          p4d -h
    P4MERGE     merge program to use on client   p4 help resolve
    P4MERGEUNICODE merge program to use on client p4 help resolve
    P4PAGER     pager for 'p4 resolve' output    p4 help resolve
    P4PASSWD    user password passed to server   p4 help passwd
    P4PORT      port client connects to          p4 help info
                or server listens on             p4d -h
    P4ROOT      server root directory            p4d -h
    P4TARGET    target server for proxy          Command Reference Manual
    P4TICKETS   location of tickets file         Command Reference Manual
    P4USER      user name                        p4 help usage
    PWD         current working directory        p4 help usage
    TMP, TEMP   directory for temporary files    Command Reference Manual

See 'p4 help set' for details specific to Windows.  The syntax for
setting an environment variable depends on the OS/shell.  Note that many
shells allow the setting of shell variables separate from environment
variables - Perforce cannot see the shell variable, only the environment
variable.

If you are a typical user then the only variables of interest are
$P4CLIENT, $P4PORT and $P4PASSWD.


C:\> p4 help set

set -- Set variables in the registry (Windows only)

p4 set [ -s -S service ] [ var=[value] ]

    'p4 set' sets the registry variables used by Perforce on Windows
    platforms.  Normally, the variable 'var' is set to 'value'.
    If 'value' is missing, the variable 'var' is unset.  Without
    any arguments at all, 'p4 set' list variable settings.

    The -s flag causes 'p4 set' to set variables for the whole system
    rather than for the user.  You must have NT administrator powers
    to use this.

    The -S service flag causes 'p4 set' to set variables for the named
    service.  You must have NT administrator powers to use this.

    Currently, registry variable entries may be overridden by environment
    variables and (in some cases) flags on the command line.
    See 'p4 help environment' for a list of environment/registry variables.

2

您可以使用配置文件为每个项目设置Perforce连接的端口。

首先,创建一个包含要设置为项目的Perforce配置变量的文本文件。例如,要设置P4PORT的值,文件的内容应如下所示:

P4PORT=hostname:1234

将文件命名为描述性文件名,例如.p4config,并将其放置在项目文件夹的根目录中。对于每个项目都要这样做,必要时更改变量。使用相同的文件名。

然后,将P4CONFIG的值设置为您配置文件的名称,例如:

p4 set P4CONFIG=.p4config

这将使Perforce在当前目录或任何父目录中查找名为该文件的配置值,因此每次切换项目时无需手动更改配置变量。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接