-
Notifications
You must be signed in to change notification settings - Fork 702
cli: rename jj touch
to jj metaedit
#7365
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b7bf899
cli: rename `jj touch` to `jj metaedit`
martinvonz b9fcb16
metaedit: remove redundant check for error code
martinvonz 03fff23
metaedit: move `rewriter.reparent()` call inside if/else arms
martinvonz 4da9181
metaedit: don't rewrite commits if nothing changed
martinvonz 37c620e
metaedit: add option to update committer timestamp
martinvonz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,8 +32,8 @@ use crate::ui::Ui; | |
|
||
/// Modify the metadata of a revision without changing its content | ||
#[derive(clap::Args, Clone, Debug)] | ||
pub(crate) struct TouchArgs { | ||
/// The revision(s) to touch (default: @) | ||
pub(crate) struct MetaeditArgs { | ||
/// The revision(s) to modify (default: @) | ||
#[arg( | ||
value_name = "REVSETS", | ||
add = ArgValueCompleter::new(complete::revset_expression_mutable) | ||
|
@@ -69,7 +69,7 @@ pub(crate) struct TouchArgs { | |
/// You can use it in combination with the JJ_USER and JJ_EMAIL | ||
/// environment variables to set a different author: | ||
/// | ||
/// $ JJ_USER='Foo Bar' [email protected] jj touch --update-author | ||
/// $ JJ_USER='Foo Bar' [email protected] jj metaedit --update-author | ||
#[arg(long)] | ||
update_author: bool, | ||
|
||
|
@@ -93,13 +93,24 @@ pub(crate) struct TouchArgs { | |
value_parser = parse_datetime | ||
)] | ||
author_timestamp: Option<Timestamp>, | ||
|
||
/// Update the committer timestamp | ||
/// | ||
/// This updates the committer date to now, without modifying the committer. | ||
/// | ||
/// Even if this option is not passed, the committer timestamp will be | ||
/// updated if other metadata is updated. This option effectively just | ||
/// forces every commit to be rewritten whether or not there are other | ||
/// changes. | ||
#[arg(long)] | ||
update_committer_timestamp: bool, | ||
} | ||
|
||
#[instrument(skip_all)] | ||
pub(crate) fn cmd_touch( | ||
pub(crate) fn cmd_metaedit( | ||
ui: &mut Ui, | ||
command: &CommandHelper, | ||
args: &TouchArgs, | ||
args: &MetaeditArgs, | ||
) -> Result<(), CommandError> { | ||
let mut workspace_command = command.workspace_helper(ui)?; | ||
let commit_ids: Vec<_> = if !args.revisions_pos.is_empty() || !args.revisions_opt.is_empty() { | ||
|
@@ -111,18 +122,18 @@ pub(crate) fn cmd_touch( | |
.evaluate_to_commit_ids()? | ||
.try_collect()?; | ||
if commit_ids.is_empty() { | ||
writeln!(ui.status(), "No revisions to touch.")?; | ||
writeln!(ui.status(), "No revisions to modify.")?; | ||
return Ok(()); | ||
} | ||
workspace_command.check_rewritable(commit_ids.iter())?; | ||
|
||
let mut tx = workspace_command.start_transaction(); | ||
let tx_description = match commit_ids.as_slice() { | ||
[] => unreachable!(), | ||
[commit] => format!("touch commit {}", commit.hex()), | ||
[commit] => format!("edit commit metadata for commit {}", commit.hex()), | ||
[first_commit, remaining_commits @ ..] => { | ||
format!( | ||
"touch commit {} and {} more", | ||
"edit commit metadata for commit {} and {} more", | ||
first_commit.hex(), | ||
remaining_commits.len() | ||
) | ||
|
@@ -131,7 +142,7 @@ pub(crate) fn cmd_touch( | |
|
||
let mut num_reparented = 0; | ||
let commit_ids_set: HashSet<_> = commit_ids.iter().cloned().collect(); | ||
let mut touched: Vec<Commit> = Vec::new(); | ||
let mut modified: Vec<Commit> = Vec::new(); | ||
// Even though `MutableRepo::rewrite_commit` and | ||
// `MutableRepo::rebase_descendants` can handle rewriting of a commit even | ||
// if it is a descendant of another commit being rewritten, using | ||
|
@@ -140,9 +151,9 @@ pub(crate) fn cmd_touch( | |
// chain. | ||
tx.repo_mut() | ||
.transform_descendants(commit_ids, async |rewriter| { | ||
let old_commit_id = rewriter.old_commit().id().clone(); | ||
let mut commit_builder = rewriter.reparent(); | ||
if commit_ids_set.contains(&old_commit_id) { | ||
if commit_ids_set.contains(rewriter.old_commit().id()) { | ||
let mut has_changes = args.update_committer_timestamp || rewriter.parents_changed(); | ||
let mut commit_builder = rewriter.reparent(); | ||
let mut new_author = commit_builder.author().clone(); | ||
if let Some((name, email)) = args.author.clone() { | ||
new_author.name = name; | ||
|
@@ -157,24 +168,30 @@ pub(crate) fn cmd_touch( | |
if let Some(author_date) = args.author_timestamp { | ||
new_author.timestamp = author_date; | ||
} | ||
commit_builder = commit_builder.set_author(new_author); | ||
if new_author != *commit_builder.author() { | ||
commit_builder = commit_builder.set_author(new_author); | ||
has_changes = true; | ||
} | ||
|
||
if args.update_change_id { | ||
commit_builder = commit_builder.generate_new_change_id(); | ||
has_changes = true; | ||
} | ||
|
||
let new_commit = commit_builder.write()?; | ||
touched.push(new_commit); | ||
} else { | ||
commit_builder.write()?; | ||
if has_changes { | ||
let new_commit = commit_builder.write()?; | ||
modified.push(new_commit); | ||
} | ||
} else if rewriter.parents_changed() { | ||
rewriter.reparent().write()?; | ||
num_reparented += 1; | ||
} | ||
Ok(()) | ||
})?; | ||
if !touched.is_empty() { | ||
writeln!(ui.status(), "Touched {} commits:", touched.len())?; | ||
if !modified.is_empty() { | ||
writeln!(ui.status(), "Modified {} commits:", modified.len())?; | ||
if let Some(mut formatter) = ui.status_formatter() { | ||
print_updated_commits(formatter.as_mut(), &tx.commit_summary_template(), &touched)?; | ||
print_updated_commits(formatter.as_mut(), &tx.commit_summary_template(), &modified)?; | ||
} | ||
} | ||
if num_reparented > 0 { | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,6 +62,7 @@ This document contains the help content for the `jj` command-line program. | |
* [`jj help`↴](#jj-help) | ||
* [`jj interdiff`↴](#jj-interdiff) | ||
* [`jj log`↴](#jj-log) | ||
* [`jj metaedit`↴](#jj-metaedit) | ||
* [`jj new`↴](#jj-new) | ||
* [`jj next`↴](#jj-next) | ||
* [`jj operation`↴](#jj-operation) | ||
|
@@ -92,7 +93,6 @@ This document contains the help content for the `jj` command-line program. | |
* [`jj status`↴](#jj-status) | ||
* [`jj tag`↴](#jj-tag) | ||
* [`jj tag list`↴](#jj-tag-list) | ||
* [`jj touch`↴](#jj-touch) | ||
* [`jj undo`↴](#jj-undo) | ||
* [`jj unsign`↴](#jj-unsign) | ||
* [`jj util`↴](#jj-util) | ||
|
@@ -143,6 +143,7 @@ To get started, see the tutorial [`jj help -k tutorial`]. | |
* `help` — Print this message or the help of the given subcommand(s) | ||
* `interdiff` — Compare the changes of two commits | ||
* `log` — Show revision history | ||
* `metaedit` — Modify the metadata of a revision without changing its content | ||
* `new` — Create a new, empty change and (by default) edit it in the working copy | ||
* `next` — Move the working-copy commit to the child revision | ||
* `operation` — Commands for working with the operation log | ||
|
@@ -162,7 +163,6 @@ To get started, see the tutorial [`jj help -k tutorial`]. | |
* `squash` — Move changes from a revision into another revision | ||
* `status` — Show high-level repo status [default alias: st] | ||
* `tag` — Manage tags | ||
* `touch` — Modify the metadata of a revision without changing its content | ||
* `undo` — Undo the last operation | ||
* `unsign` — Drop a cryptographic signature | ||
* `util` — Infrequently used commands such as for generating shell completions | ||
|
@@ -1605,6 +1605,43 @@ The working-copy commit is indicated by a `@` symbol in the graph. [Immutable re | |
|
||
|
||
|
||
## `jj metaedit` | ||
|
||
Modify the metadata of a revision without changing its content | ||
|
||
**Usage:** `jj metaedit [OPTIONS] [REVSETS]...` | ||
|
||
###### **Arguments:** | ||
|
||
* `<REVSETS>` — The revision(s) to modify (default: @) | ||
|
||
###### **Options:** | ||
|
||
* `--update-change-id` — Generate a new change-id | ||
|
||
This generates a new change-id for the revision. | ||
* `--update-author-timestamp` — Update the author timestamp | ||
|
||
This updates the author date to now, without modifying the author. | ||
* `--update-author` — Update the author to the configured user | ||
|
||
This updates the author name and email. The author timestamp is not modified – use --update-author-timestamp to update the author timestamp. | ||
|
||
You can use it in combination with the JJ_USER and JJ_EMAIL environment variables to set a different author: | ||
|
||
$ JJ_USER='Foo Bar' [email protected] jj metaedit --update-author | ||
* `--author <AUTHOR>` — Set author to the provided string | ||
|
||
This changes author name and email while retaining author timestamp for non-discardable commits. | ||
* `--author-timestamp <AUTHOR_TIMESTAMP>` — Set the author date to the given date either human readable, eg Sun, 23 Jan 2000 01:23:45 JST) or as a time stamp, eg 2000-01-23T01:23:45+09:00) | ||
* `--update-committer-timestamp` — Update the committer timestamp | ||
|
||
This updates the committer date to now, without modifying the committer. | ||
|
||
Even if this option is not passed, the committer timestamp will be updated if other metadata is updated. This option effectively just forces every commit to be rewritten whether or not there are other changes. | ||
|
||
|
||
|
||
## `jj new` | ||
|
||
Create a new, empty change and (by default) edit it in the working copy | ||
|
@@ -2670,38 +2707,6 @@ List tags | |
|
||
|
||
|
||
## `jj touch` | ||
|
||
Modify the metadata of a revision without changing its content | ||
|
||
**Usage:** `jj touch [OPTIONS] [REVSETS]...` | ||
|
||
###### **Arguments:** | ||
|
||
* `<REVSETS>` — The revision(s) to touch (default: @) | ||
|
||
###### **Options:** | ||
|
||
* `--update-change-id` — Generate a new change-id | ||
|
||
This generates a new change-id for the revision. | ||
* `--update-author-timestamp` — Update the author timestamp | ||
|
||
This updates the author date to now, without modifying the author. | ||
* `--update-author` — Update the author to the configured user | ||
|
||
This updates the author name and email. The author timestamp is not modified – use --update-author-timestamp to update the author timestamp. | ||
|
||
You can use it in combination with the JJ_USER and JJ_EMAIL environment variables to set a different author: | ||
|
||
$ JJ_USER='Foo Bar' [email protected] jj touch --update-author | ||
* `--author <AUTHOR>` — Set author to the provided string | ||
|
||
This changes author name and email while retaining author timestamp for non-discardable commits. | ||
* `--author-timestamp <AUTHOR_TIMESTAMP>` — Set the author date to the given date either human readable, eg Sun, 23 Jan 2000 01:23:45 JST) or as a time stamp, eg 2000-01-23T01:23:45+09:00) | ||
|
||
|
||
|
||
## `jj undo` | ||
|
||
Undo the last operation | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.