Download the depot files to a local disk without a client workspace

I read another post in which I can download a file from the Perforce repository to a local drive without a client workspace. To expand this, I need to download all the files (text and binary) from the depot directory to my local drive. Is this the right p4 command?

p4 print // depot / dir1 / ...

I have a few questions:

  • Will it download all auxiliary directories, as well as files from / depot / dir 1 / ... or only files?
  • Will the original file names to be uploaded be saved?
  • Where are the files located on the local drive if the local path is not specified?

I am using the p4api.net library. Will this code do this?

public void GetFiles(string DepotFilePath) { P4Command cmd = new P4Command( _repository, "print", true, String.Format( "{0}/...", DepotFilePath )); results = cmd.Run(); if (results.Success) { //do something here } } 

I'm not sure where on the local drive it will upload files?

Thank you for your help.

+4
source share
4 answers

p4 print prints the contents to standard output (see excellent manual ). Therefore, to answer your questions in order:

  • It will “download” all files to all subdirectories, but it will only print the contents of the file to stdout. It will not generate files on disk.
  • Yes, it seems, but not in the way you imagine. The following lines will appear in your stream on stdout: //depot/path/to/file#5 - edit change 430530 (text) , and then the contents of this particular file.
  • No files will be created on disk.

If you really do not want to create a client workspace for your task (why?), You will need to do something like the following:

  • Get a list of files, for example. p4 files ( manual )
  • Go through this list and call p4 print for each file
  • Redirect p4 print output to a file on the local disk, adhering to the directory structure in the repository.
+3
source

A simple solution that does not require tools for platform-specific scenarios:

 p4 client -df TEMP_CLIENT p4 -c TEMP_CLIENT --field View="//depot/dir1/... //TEMP_CLIENT/..." client -o | p4 client -i p4 -c TEMP_CLIENT sync -p p4 client -d TEMP_CLIENT 

This will load all files / directories from //depot/dir1 into your current directory. If you want to specify a different directory, add --field "Root=C:\Some Path" to the first command in the same place where View is specified.

+2
source

Single line

For reference, here bash is one liner that will execute the manual jhwist answer procedure:

 for _file in $(p4 files //depot/dir/... | awk '{print $1}' | perl -ne '/(.*)#\d+$/ && print "$1\n"'); do p4 print -q $_file > /path/to/target/dir/$(basename $_file); done 

The only bits you should replace in the appropriate directories are //depot/dir and /path/to/target/dir . Note: The destination directory must already exist.


Explanation:

The output from the for loop is:

 $(p4 files //depot/dir/... | awk '{print $1}' | perl -ne '/(.*)#\d+$/ && print "$1\n"') 
  • Get a list of files from the corresponding perforce directory

  • The first output column is the location of the depot file, so fetch it with awk

  • The depot location has #revisionNumber attached to the end, so disconnect it with perl

+1
source

Therefore, I spent some time getting it to work in various scripts in bash, and although it is not specific to dotnet, I decided to share my results, since these concepts are universal.

You have two options for receiving files from a remote computer:

  1. Check and synchronize the display of the workspace using the temporary client / workspace, as Sam Stafford wrote in his answer . Here's what in bash with comments:
 # p4 uses this global variable as client/workspace name by default. # Alternatively, you can also use -c in every command. P4CLIENT="TEMP_SCRIPT_CLIENT" # mapping remote folder to relative workspace folder (recursive) wokspaceMapping="//depot/dir1/... //$P4CLIENT/..." p4 client -d $P4CLIENT # make sure the workspace does not exist already # Creating a client on the console gives an editor popup to confirm the # workspace specification, unless you provide a specification on stdin. # You can however generate one to stdout, and pipe the result to stdin again. p4 --field View="$wokspaceMapping" --field Root="/some/local/path" client -o | p4 client -i p4 sync -p # download all the files p4 client -d $P4CLIENT # remove workspace when you are done. 
  1. Use p4 print to print the contents of each file as suggested by jhwist wrote , so you don’t have to define a workspace at all. The disadvantage is that you have to process each file separately and create any directories yourself.
 p4RemoteRoot="//depot/dir1" # First, list files and strip output to file path # because 'p4 files' prints something like this: # //depot/dir1/file1.txt#1 - add change 43444817 (text) # //depot/dir1/folder/file2.txt#11 - edit change 43783713 (text) files="$(p4 files $p4RemoteRoot/... | sed 's/\(.*\)#.*/\1/')" for wsFile in $files; do # construct the local path from the remote one targetFile="$localPath/${wsFile#$p4RemoteRoot/}" # create the parent dir if it does not exist. p4 files does not list directories mkdir -p $(dirname $targetFile) # print the file content from remote and write that to the local file. p4 print -q $wsFile > $targetFile done 

Note: I could not find any documentation for the --field argument, but it looks like you can use all of the "Form Fields" as stated in the documentation: https://www.perforce.com/manuals/v18.2/cmdref /Content/CmdRef/p4_client.html

0
source

Source: https://habr.com/ru/post/1393908/


All Articles