How do you get file PHIDs for Differential or Revision?


#1

Does anyone know a way to get the file PHIDs for the files in a Differential or Revision using arc or the conduit API?

I can find them in the web UI by clicking “Show Raw File”, so I know they exist, but I can’t figure out any way to get them from the CLI or API.

My eventual goal is to be able to download the full context of a file (created by arc diff using svn) in a specific Revision (not just the patch).


#2

I’m pretty sure the “raw files” are only created when you click “Show Raw File”, not ahead of time - this is the controller for the “view raw” action. The data is stored internally as a set of “hunks”, which are the individual changes seen in the diff file; However, since we create the diff file using something like svn diff -U 99999999 (So we have more context), each file might become just one hunk.
The “suggested” way to get the content is by running “arc patch”, which needs a workspace, but ends up with the right content.

You should also be able to extract the information using arc export --arcbundle - it’s an advanced workflow that will download a tgz version of all the data in the diff, including the diff -U 999999 format; Some clever grep and cut will get you all the way to the full file.

If your change is classified as “binary file”, it will be stored differently. If the diff was not created from arc diff, it will probably not have the full context anyway.


#3

Thanks! That is good information. I didn’t consider that those files might be generated on the fly.

Here’s what I’ve ended up with for now. This example attempts to print the contents of each file in a Revision, but it’s also possible to do things with each file’s contents if that was required.

arc export --revision DXXXX --arcbundle bundle.tgz
FLIST=$(tar xzf bundle.tgz changes.json -O | jq -r .[].currentPath)
INDEX=0
for FILE in $FLIST; do
	echo $FILE
	tar xzf bundle.tgz "hunks/$INDEX" --to-command "egrep -v '^-' | sed 's/^[+ ]//'"
	INDEX=$((INDEX + 1))
done