blob: 3efb90c490dfc72485e87ce5eaa7280dd3c11ce9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
/*
* Copyright (C) 2018-2021, Andre Bossert <andre.bossert@siemens.com>
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0 which is available at
* https://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
package org.eclipse.jgit.internal.diffmergetool;
import java.util.TreeMap;
import java.io.IOException;
import java.util.Map;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.Repository;
/**
* Utilities for diff- and merge-tools.
*/
public class ExternalToolUtils {
/**
* Prepare command for execution.
*
* @param command
* the input "command" string
* @param localFile
* the local file (ours)
* @param remoteFile
* the remote file (theirs)
* @param mergedFile
* the merged file (worktree)
* @param baseFile
* the base file (can be null)
* @return the prepared (with replaced variables) command string
* @throws IOException
*/
public static String prepareCommand(String command, FileElement localFile,
FileElement remoteFile, FileElement mergedFile,
FileElement baseFile) throws IOException {
command = localFile.replaceVariable(command);
command = remoteFile.replaceVariable(command);
command = mergedFile.replaceVariable(command);
if (baseFile != null) {
command = baseFile.replaceVariable(command);
}
return command;
}
/**
* Prepare environment needed for execution.
*
* @param repo
* the repository
* @param localFile
* the local file (ours)
* @param remoteFile
* the remote file (theirs)
* @param mergedFile
* the merged file (worktree)
* @param baseFile
* the base file (can be null)
* @return the environment map with variables and values (file paths)
* @throws IOException
*/
public static Map<String, String> prepareEnvironment(Repository repo,
FileElement localFile, FileElement remoteFile,
FileElement mergedFile, FileElement baseFile) throws IOException {
Map<String, String> env = new TreeMap<>();
env.put(Constants.GIT_DIR_KEY, repo.getDirectory().getAbsolutePath());
localFile.addToEnv(env);
remoteFile.addToEnv(env);
mergedFile.addToEnv(env);
if (baseFile != null) {
baseFile.addToEnv(env);
}
return env;
}
}
|