Git Product home page Git Product logo

git-p4-helpers's Introduction

Motivation

  • I'm lazy.

TL; DR

Dependencies

  • Properly setup Perforce CLI. You have to be able to login to P4 using its CLI.

Scripts

Daily tasks

  • update-last-green.sh - Adds/Updates the tag last-green to the Git commit associated with the Perforce Changelist number provided as argument. Updates the tag in the remote origin.

Sharing changes Git->P4

  • patch_for_p4.sh - Given a Git revision range, generate a patch file and a list of files affected by the patch.
  • p4_reconcile_files.sh - Given a list of files, reconcile each file in the list using p4 reconcile.

Sharing changes P4->Git

  • p4-desc.sh - List files affected by the Perforce changelist with number p4cl.

Creating symlinks for scripts

  • create_links.sh - Creates symlinks at the specified location. I place them at ~/bin, e.g.,
$ ./create_links.sh ~/bin
$ ls -la ~/bin
 green-up -> update-last-green.sh
 p4-desc -> p4-desc.sh
 p4-patch -> patch_for_p4.sh
 p4-recon -> p4_reconcile_files.sh

Long description

So, I've been working with git-p4 in order to submit to a Perforce depot while doing my daily work with Git.

As I learn move about this workflow I have written a few scripts that save me some typing for common operations during my daily workflow.

My setup

  • Clone this repo into my ~/bin directory
  • I create symbolic links (ln -s or use create_links.sh) for each of the scripts but with shorter names so I won't have to type as much, did I mention I'm lazy?

Use cases

Getting the latest from P4 and tagging it

As part of my daily process I have to sync my Git repo with the latest changes submitted to the Perforce depo and also keep a tag to the last successful build. It usually looks like this:

  • Checkout the synchronization branch
  • Synchronize with P4 depot
  • Find the latest P4 changelist number that builds successfully
  • Create/Update tag last-green in the commit corresponding to such changelist
  • Update my remote (origin)

Using the script this becomes:

$ ./update-last-green.sh 123123

Sharing changes P4->Git

Many times I'm pairing with someone but for some reason they need to share some changes with me but they don't use Git. So after lecturing them I ask them to shelve their changes so I can get them and apply them to my Git repo.

Running p4 describe usually adds meta information that makes it hard to pipe its output to be processed by other commands like rsync, e.g.

	$ p4 describe <changelist>

	Change 123123 by user@domain on <timestamp>

		Changelist description...

	Jobs fixed ...

		Stuffs....

	Affected files ...

	... //path/to/depot/branch/path/to/file1.xml#3 edit
	... //path/to/depot/branch/path/to/file2.xml#3 edit
	... //path/to/depot/branch/path/to/file3.xml#3 edit

	Differences ...

       More stuffs...

So the script p4-desc.sh cleans up the output so that we can pipe it into rsync to bring those changes in to our Git repo, e.g.,

	$ ./p4-desc.sh <changelist> "... //path/to/depot/"
	./path/to/file1.xml
	./path/to/file2.xml
	./path/to/file3.xml

At the end the whole process using the script looks like this:

  • Manually unshelve the wanted changes into a new changelist
    • this step is still manual but can be automated, see p4 unshelve)
  • Test overwrite (rsync -avn):
    • $ ./p4-desc.sh <changelist> [<prefix>] | rsync -avn --files-from=- $P4_DEPO/ $GIT_REPO/
  • Overwrite (rsync -av):
    • $ ./p4-desc.sh <changelist> [<prefix>] | rsync -av --files-from=- $P4_DEPO/ $GIT_REPO/

Caveats: this probably won't work for files that have been removed, only in files added or modified.

Share changes from Git to Perforce

The depot I work with is huge and for some reason when I try to submit using $ git p4 submit it takes forever just to get to the step where I edit my commit message.

In most cases I end up:

  • creating a patch file for my changes
  • applying that patch in the Perforce depot
  • reconciling those files since P4 doesn't keep track of changes in the filesystem
  • preparing the CL and submitting using the visual client (P4V).

Here's how you can do the same:

# Generate patch for revision range
$ ./patch_for_p4.sh <abc123>..<abc124>
Patch written to patch-123.diff
List of changes written to changes-123.txt

$ cd $P4_DEPOT
$ git apply $GIT_REPO/patch-123.diff
# Make Perforce aware of the changes to the files in the list
$ ./p4_reconcile.sh $GIT_REPO/changes-123.txt

TODO: Automatically create a P4 CL with the changes in the patch

References

Here are some of the documents that helped me get it all working. Muchas Gracias!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.