aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.pgm/src/org/eclipse
diff options
context:
space:
mode:
authorThomas Wolf <twolf@apache.org>2023-04-20 21:13:59 +0200
committerMatthias Sohn <matthias.sohn@sap.com>2023-04-28 17:04:47 -0400
commit3ed4cdda6b99f812258ca50bd77447a28d9d4596 (patch)
treea2e42d4924d4d157843178deb0f0741395885807 /org.eclipse.jgit.pgm/src/org/eclipse
parent45de4fa2cb638a8e20fa27b3d88435a697bb9df8 (diff)
downloadjgit-3ed4cdda6b99f812258ca50bd77447a28d9d4596.tar.gz
jgit-3ed4cdda6b99f812258ca50bd77447a28d9d4596.zip
AddCommand: ability to switch off renormalization
JGit's AddCommand always renormalizes tracked files. C git does so only on git add --renormalize. Especially for git add . and the JGit equivalent git.add().addFilepattern(".").call() this can make a big difference if there are many files, or large files. Add a "renormalize" option to AddCommand. To maintain compatibility with existing uses, this option is "true" by default, and the behavior of AddCommand is as it has always been in JGit. If set to "false", use an IndexDiffFilter (in addition to a path filter, if any). This skips any unchanged files (that are not racily clean) from content checks. Note that changes in CRLF settings or in filters will be ignored for such files if renormalize == false. Add the "--renormalize" option to the Add command in the JGit command line program. For the command-line program, the default is as in C git: renormalize is off by default and enabled only if the option is given. Note that --renormalize implies --update in the command line program, as in C git. In AddCommand, the two settings are independent. Additionally, avoid opening input streams unnecessarily in WorkingTreeIterator.getEntryContentLength() and fix some bogus indentation. Add a simple test that adds 1000 files of 10kB in 10 directories twice and that fails if the second invocation (without any changes) with renormalize=false is not significantly faster. Locally, I observe for that second invocation * git.add().addFilepattern(".").call() ~660ms * git.add().addFilepattern(".").setRenormalize(false).call() ~16ms Bug: 494323 Change-Id: I30f9d518563fa55d7058a48c27c425f3b60aeb4c Signed-off-by: Thomas Wolf <twolf@apache.org>
Diffstat (limited to 'org.eclipse.jgit.pgm/src/org/eclipse')
-rw-r--r--org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Add.java11
1 files changed, 9 insertions, 2 deletions
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Add.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Add.java
index 460f24618e..ff0b55d1b8 100644
--- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Add.java
+++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Add.java
@@ -22,6 +22,9 @@ import org.kohsuke.args4j.Option;
@Command(common = true, usage = "usage_addFileContentsToTheIndex")
class Add extends TextBuiltin {
+ @Option(name = "--renormalize", usage = "usage_addRenormalize")
+ private boolean renormalize = false;
+
@Option(name = "--update", aliases = { "-u" }, usage = "usage_onlyMatchAgainstAlreadyTrackedFiles")
private boolean update = false;
@@ -33,9 +36,13 @@ class Add extends TextBuiltin {
protected void run() throws Exception {
try (Git git = new Git(db)) {
AddCommand addCmd = git.add();
- addCmd.setUpdate(update);
- for (String p : filepatterns)
+ if (renormalize) {
+ update = true;
+ }
+ addCmd.setUpdate(update).setRenormalize(renormalize);
+ for (String p : filepatterns) {
addCmd.addFilepattern(p);
+ }
addCmd.call();
} catch (GitAPIException e) {
throw die(e.getMessage(), e);