<commit_before># Motivation

* I'm lazy.

# TL; DR

## Dependencies

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

## Scripts

* [`update-last-green.sh`](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`.
* [`p4-desc.sh`](p4-desc.sh) - List files affected by the Perforce changelist with  number `p4cl`.


# 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`) for each of the scripts but with shorter names so I won't have to type as much, did I mention I'm lazy?

	```bash
	p4-desc -> git-p4-helpers/p4-desc.sh
	green-up -> git-p4-helpers/update-last-green.sh
	```

## 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`

## List files affected in a Perforce changelist

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.

```bash
	$ 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.,
<commit_msg>new: doc: Add quick reference for generating patches (Git->P4) and applying them to the Perforce depot.<commit_after># 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`](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`](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`](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`](p4-desc.sh) - List files affected by the Perforce changelist with  number `p4cl`.


# 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`) for each of the scripts but with shorter names so I won't have to type as much, did I mention I'm lazy?

	```bash
	p4-desc -> git-p4-helpers/p4-desc.sh
	green-up -> git-p4-helpers/update-last-green.sh
	```

## 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.

```bash
	$ 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.,

{'fraction_non_alphanumeric': 0.08991627229705133, 'fraction_numerical': 0.01365125591554423, 'mean_word_length': 3.545078577336642, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6657036', 'n_tokens_mistral': 1752, 'n_tokens_neox': 1643, 'n_words': 781}