Perforce

From 탱이의 잡동사니
Jump to navigation Jump to search

Overview

형상 관리 툴 Peforce(p4) 사용법 정리.

Installation

아래 링크에서 다운받아서 사용하면 된다. 별도의 컴파일 작업이 필요하지 않다.

https://www.perforce.com/ko/downloads/helix

Environment variables

perforce 는 내부적으로 여러가지 환경 변수들을 가지고 있다. 이 환경변수를 수정함으로써, 기본접속 서버와 클라이언트등을 변경할 수 있다. 자세한 내용은 이곳<ref>http://www.perforce.com/perforce/doc.current/manuals/cmdref/envars.html</ref>에서 찾을 수 있다.

Settings

export 명령이 아닌, p4 명령어 set 를 이용해도 환경변수 설정과 확인이 가능하다.

$ p4 set P4CLIENT=client1
$ p4 set P4CLIENT
P4CLIENT=client1

Crucial variables

  • P4CLIENT
현재 client workspace 의 이름.
  • P4PASSWD
사용자의 Password 를 설정한다. 이후 명령어 사용시, 별도로 사용자 Password 를 입력하지 않아도 된다.
  • P4USER
현재 perforce username 을 나타낸다.

Useful variables

  • P4CONFIG
현재 사용중인 P4CONIFG 파일을 나타낸다. P4CONFIG 파일에는 사용자 정보가 입력되어 있으며, 이 P4CONFIG 파일을 이용하여 사용자를 쉽게 전환할 수 있다.
P4CLIENT=joes_client
P4USER=joe
P4PORT=ssl:ida:3548
  • P4DIFF
p4 resolve 및 p4 diff 명령어 사용시 사용되는 diff 프로그램을 지정한다.
  • P4EDITOR
Perforce 에서 사용되는 기본 editor 프로그램을 지정한다.
  • P4MERGE
Perforce 에서 사용되는 기본 merge 프로그램을 지정한다.
  • P4CHARSET
Perforce 에서 사용되는 기본 Character set 을 지정한다.
  • P4TRUST
ssl trust file 을 지정한다. p4 trust 명령어에 의해 사용된다.

Esoteric variables

  • P4PAGER
Page output 에서 사용할 프로그램을 설정한다. p4 resolve 의 diff 옵션에서 사용된다.
  • TMP, TEMP
temporary 파일을 위한 디렉토리를 지정한다.
  • P4TICKETS
p4 login 에서 사용되는 ticket 파일의 위치를 지정한다.
  • P4LANGUAGE
This environment variable is reserved for system integrators.
  • P4LOGINSSO
Client-side single-signon script.
  • P4COMMANDCHARSET
Used to support UTF-16 and UTF-32 character sets from the Command-line Client.
  • P4DIFFUNICODE
Used to support UTF-16 and UTF-32 character sets from the Command-line Client.
  • P4MERGEUNICODE
Used to support UTF-16 and UTF-32 character sets from the Command-line Client.
  • P4CLIENTPATH
A list of directories to which Perforce applications are permitted to write.
Any attempt by a Perforce application to access or modify files outside these areas of the filesystem will result in an error message.
To specify more than one directory, separate the directories with semicolons.

Server variables

  • P4AUDIT
Location of the audit log file.
  • P4JOURNAL
A file that holds the Perforce database's journal data.
  • P4LOG
Name and path of the file to which Perforce errors are written.
  • P4PORT
For the Perforce service (server, broker, or proxy), the port number on which it listens, and the network transport(s) to which it is to bind.
  • P4ROOT
Directory in which the Perforce service stores its files and subdirectories.
  • P4DEBUG
Set Perforce server or proxy trace options.
  • P4NAME
A unique identifiable name for a Perforce server.
On Windows if there is no P4NAME defined in the registry for a service, it is picked up from the name of the service itself.
  • P4SSLDIR
Directory containing a server's SSL keys and/or certificates.

Commands

Common

perforce command 사용시 공통적으로 적용되는 사항 정리.

Directory

perforce 에서는 빈 디렉토리는 생성/변경/삭제가 불가능하다. 만약 디렉토리 내에, 파일이 하나도 없다면 해당 디렉토리는 자동으로 사라지게 된다.

...

만약 디렉토리내의 모든 파일을 선택해야 한다면, '...' 을 사용하면 된다.

help

도움말 내용을 보여준다. simple 입력시 자주 사용되는 명령어의 간단한 쓰임새를 보여준다. 자세한 명령어의 도움말을 보고자 한다면 p4 help <command> 를 입력하면 된다. 사용 가능한 모든 명령어를 보고자 할 때는, "p4 help commands" 를 입력하면 된다.

$ p4 help simple

    Most common Perforce client commands:

	client     Create or edit a client workspace specification and view

	add        Open files for adding to the depot
	edit       Open existing files for editing
	delete     Open existing files for removal from the depot
	opened     List open files 

	update     Update files in the current client workspace 
	resolve    Resolve updates to open workspace files

	submit     Submit open files to the depot
	revert     Revert open files and restore originals to workspace

add

파일을 추가한다.

주의할 점은 디렉토리를 추가하지는 못한다는 점이다. 그리고 하위 디렉토리를 추가하지도 못한다. 하위 디렉토리를 추가하기 위해서는 pipe 를 이용한 명령어 조합을 사용해야 한다.

p4 add [-c changelist#] [-d -f -I -n] [-t filetype] file ...

opened

현재 편집중인 파일 목록을 보여준다.

branch

branch -- Create, modify, or delete a branch view specification 브랜치를 생성하고, 수정 및 삭제한다. 하지만 편의상 populate 옵션을 더 많이 사용한다.

$ p4 branch [-f] name
$ p4 branch -d [-f] name
$ p4 branch [ -S stream ] [ -P parent ] -o name
$ p4 branch -i [-f]

populate

여러개의 파일들을 한번에 Branching 한다. 보통은 프로젝트 MAIN/DEVELOP 브랜치에서 기능추가/버그수정/테스트 등을 위해 별도의 브랜치를 생성할 때 사용한다.

$ p4 populate [options] fromFile[rev] toFile
$ p4 populate [options] -b branch [-r] [toFile[rev] ...]
$ p4 populate [options] -b branch -s fromFile[rev] [toFile ...]
$ p4 populate [options] -S stream [-P parent] [-r] [toFile[rev] ...]
$ p4 populate -o <source>/... <destination>/...

-o

브랜칭을 함과 동시에 명령어로 생성되는 파일들의 리스트들을 보여준다.

$ p4 populate -o <source>/... <destination>/...

$ p4 populate -o //depot/devel/sample/DEVELOP/... //depot/devel/sample/FEATURE_sample_test/...

integrate

Branch/File 간의 merge 를 한다.

$ p4 integrate [options] fromFile[revRange] toFile
$ p4 integrate [options] -b branch [-r] [toFile[revRange] ...]
$ p4 integrate [options] -b branch -s fromFile[revRange] [toFile ...]
$ p4 integrate [options] -S stream [-r] [-P parent] [file[revRange] ...]

resolve

Integrate 이후의 merge 충돌 오류를 해결한다.

p4 resolve [options] [file ...]

delete

지정된 파일을 삭제한다. 사실, perforce 에서는 파일 삭제가 없다. 단지 앞으로의 버전 컨트롤에서 제외될 뿐이다.

p4 delete [-c changelist#] [-n -v -k] file ...

p4 delete BRANCH_NAME/...

-n

파일 삭제시 나타나게 될 결과를 표시한다. 실제로 파일을 삭제하지는 않는다.

-k

client 에 설치된 파일의 변경없이 server에 있는 파일만을 삭제한다. 만약 서버와 클라이언트 간의 파일 불일치가 발견되면 경고를 표시한다.

-v

아직 sync 되지 않은 파일도 같이 삭제할 수 있도록 한다.

client

client 설정을 확인/수정 한다.

View 항목에 명시되어 있지 않은 디렉토리는 동기화되지 않는다. 만약 perforce 설정 이후, 특정 디텍토리가 동기화되지 않는다면, View 항목을 먼저 확인하자.

p4 client [-f] [-t template] [name]
p4 client -d [-f [-Fs]] name
p4 client -o [-t template] [name]
p4 client -S stream [[-c change] -o] [name]
p4 client -s [-f] -S stream [name]
p4 client -s [-f] -t template [name]
p4 client -i [-f]

Perforce client 생성시, 다음의 내용이 포함되어야 한다.

Client:      The client name.

Host:        If set, restricts access to the named host.
              If unset, access is allowed from any host.

Owner:       The user who created this client.

Update:      The date that this spec was last modified.

Access:      The date that this client was last used in any way.

Description: A short description of the workspace.

Root:        The root directory of the workspace (specified in local
              file system syntax), under which all versioned files
              will be placed. If you change this setting, you must
              physically relocate any files that currently reside
              there.  On Windows client machines, you can specify the
              root as "null" to enable you to map files to multiple
              drives.

AltRoots:    Up to two optional alternate client workspace roots.
              The first of the main and alternate roots to match the
              client program's current working directory is used. If
              none match, the main root is used. 'p4 info' displays
              the root that is being used.

Options:     Flags to configure the client behavior. Defaults
              are marked with *.

Example

Client: stk_pbxdevelopment

Update: 2015/10/13 14:14:25

Access: 2015/10/13 14:12:39

Owner:  stk

Host:   test.pchero21.com

Description:
        Created by stk.

Root:   /home/stk

Options:        noallwrite noclobber compress unlocked nomodtime rmdir

SubmitOptions:  submitunchanged

LineEnd:        local

View:
        //depot/devel/helloworld/... //stk_pbxdevelopment/depot/devel/helloworld/...
        -//depot/devel/helloworld_ignore/... //stk_pbxdevelopment/depot/devel/helloworld/...

change, changelist

현재 위치한 디렉토리에서의 상세 변경 내역 내용을 보여준다. change 와 changeslist 는 모두 같은 옵션이다.

p4 change [-s] [-f | -u] [[-O] changelist#]
p4 change -d [-f -s -O] changelist#
p4 change -o [-s] [-f] [[-O] changelist#]
p4 change -i [-s] [-f | -u] 
p4 change -t restricted | public [-U user] [-f | -u | -O] changelist#
p4 change -U user [-t restricted | public] [-f] changelist#

Example

$ p4 change 3497

Change: 3497

Date:   2016/08/26 13:08:49

Client: pchero-buildserver

User:   pchero

Status: submitted

Description:
        Removed test_hack from the service

        - Removed from the package and service.

changes, changelists

모든 변경 내역 리스트를 보여준다. change 와 changeslists 는 모두 같은 옵션이다. file 및 경로 지정시, 지정된 파일 및 경로와 관련된 내용만을 보여준다.

p4 changes [options] [file[revRange] ...]

options: -i -t -l -L -f -c client -m max -s status -u user

-m

단순히 p4 changes 를 입력하면 모든 변경 이력을 보여준다. -m 옵션 사용시 가장 최근에서부터 -m <count> 개 까지의 변경이력만을 보여준다.

$ p4 changes -m 1
Change 1692 on 2015/10/23 by pchero@pchero_dev 'Changed tmp file name path.'

-l, -L

변경이력의 상세 내용을 표시한다. 기본적으로 changes 옵션 사용시, 변경 이력의 제일 윗줄만을 표시한다. -l 옵션 사용시, 변경 이력의 상세 내용을 모두 확인할 수 있다. -L 옵션은 -l 옵션 내용과 같으나, 최대 250자 까지의 내용만을 표시한다.

$ p4 changes -m 1 -L
Change 3202 on 2016/06/30 by pchero@pchero_dev

	- RPM testing release build of olive

clean

모든 submit되지 않은 변경 이력들을 원본으로 되돌린다.

$ p4 clean

깔끔히 정리하고 싶을 때 사용하면 좋다. 하지만.. rm -rf 명령어와 같은 힘을 지니고 있으므로 사용시 정말 조심해야 한다...

revert

변경/수정 된 내용을 다시 이전으로 되돌린다.

p4 revert [-a -n -k -w -c changelist#] file ...

-a

Edit/Integrate/Unchanged/Missing 상태인 파일들만 이전상태로 복구한다. Integration pending 상태의 파일은 Open 상태로 남게된다.

-k

파일을 복구하는 것이 아닌, open 상태가 아닌것으로 변경한다. 즉, 파일에는 수정된 내용이 그대로 남아있지만 perforce 메타 데이터가 사라진 상태가 된다. 이후, p4 edit <filename> 을 하게 되면 수정된 내용을 그대로 살릴 수 있다. 혹은 p4 status 명령어로 현재 변경된 파일 목록을 확인할 수도 있다.

-c

특정 changelist 버전으로 되돌린다.

review

changelist 를 보여준다.

p4 review [-c changelist#] [-t counter]

sync, flush, update

Client 를 서버 저장소와 동기화시킨다. flush 와 update 는 sync 와 다른 옵션과의 조합이다.

  • flush : sync -k
  • update : sync -s

-f

강제로 파일들을 서버와 동기화 시킨다. 단, open 되어 있는 파일에는 동기화를 시도하지 않는다.

The -f flag forces resynchronization even if the client already
has the file, and overwriting any writable files.  This flag doesn't
affect open files.

copy

파일을 복사한다.

perforce 에서 p4 copy를 이용한 파일 복사는 특히 중요하다. 왜냐하면, 단순한 파일 복사가 아니기 때문이다. p4 copy 는 단순히 파일을 복사하는 것만이 아닌, 파일의 이력을 함께 복사한다는 의미를 가지고 있다. 때문에 복사된 파일에서도 이력을 참고하고자 한다면, 반드시 p4 copy를 사용해야만 한다.

copy -- Copy one set of files to another

p4 copy [options] fromFile[rev] toFile
p4 copy [options] -b branch [-r] [toFile[rev] ...]
p4 copy [options] -b branch -s fromFile[rev] [toFile ...]
p4 copy [options] -S stream [-P parent] [-F] [-r] [toFile[rev] ...]

describe

describe -- Display a changelist description

p4 describe [-d<flags> -m -s -S -f -O] changelist# ...

Example

$ p4 describe 3447
Change 3447 by pchero@my_dev on 2016/08/15 15:03:12

        Not in use BRANCH

Affected files ...

... //depot/devel/test/Makefile#2 delete
... //depot/devel/test/Makefile.inc#2 delete
... //depot/devel/test/sample_module/Makefile#2 delete

interchanges

두 개의 브랜치 사이에서의 다른 점을 확인한다. 이미 integrated 된 브랜치인지 아닌지를 확인할 때 사용한다.

interchanges -- Report changes not yet integrated

p4 interchanges [options] fromFile[revRange] toFile
p4 interchanges [options] -b branch [toFile[revRange] ...]
p4 interchanges [options] -b branch -s fromFile[revRange] [toFile ...]
p4 interchanges [options] -S stream [-P parent] [file[revRange] ...]

    options: -f -l -r -t -b -s -S -P -F

Example

[pchero@pluto]$ p4 interchanges FEATURE_History -r
FEATURE_History - all revision(s) already integrated.

[pchero@pluto]$ p4 interchanges BUG_wrong_cdr_chaneel/... DEVELOP/...
wrong_cdr_chaneel/... - all revision(s) already integrated.

ETC

Change the client(workspace) name

기본적으로, perforce에서 client(workspace) 이름을 변경할 수는 없다. 굳이 client 를 변경하고 싶다면, 다른 client 를 생성 후, 해당 client로 변경 뒤, 기존의 client 를 삭제하는 방법을 써야 한다.<ref>http://answers.perforce.com/articles/KB/3428</ref>

Problem	

How do I rename a client workspace?
Solution	
Perforce does not provide a rename mechanism for client workspaces. 
However, if a user does not have any files checked out the following procedure can be used to create a new 
workspace using the same specifications as the old one and update the server's meta data.

1. Use the old workspace as a template to create a new one.

p4 client -t old-workspace new-workspace

Double check that the Root: is the same for the old and new workspace.

2. Update the server metadata with the revisions synced to the new workspace.

p4 -c new-workspace sync -k @old-workspace

3. Check the list of files synced to the new client workspace.

p4 -c new-workspace have

4. Delete the old client workspace.

p4 client -d old-workspace

References

<references />