Skip to content
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

hg: use --template instead of ext.py for metadata #739

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -28,10 +28,33 @@
import java.io.IOException;
import java.util.*;
import java.time.*;
import java.time.format.DateTimeParseException;
import java.time.format.*;
import java.nio.charset.StandardCharsets;

class HgCommitMetadata {
private static final String delimiter = "#@!_-=&";
private static final String hash = "{node}";
private static final String rev = "{rev}";
private static final String branch = "{branch}";
private static final String parentHashes = "{p1.node} {p2.node}";
private static final String parentRevs = "{p1.rev} {p2.rev}";
private static final String user = "{user}";
private static final String date = "{date|rfc3339date}";
private static final String descLen = "{desc|count}";
private static final String desc = "{desc}";

public static final String TEMPLATE = String.join("\n",
delimiter,
hash,
rev,
branch,
parentHashes,
parentRevs,
user,
date,
descLen,
desc);
public static CommitMetadata read(UnixStreamReader reader) throws IOException {
var hash = new Hash(reader.readLine());

@@ -46,8 +69,17 @@ public static CommitMetadata read(UnixStreamReader reader) throws IOException {

var author = Author.fromString(reader.readLine());

var formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd H:m:sZ");
var authored = ZonedDateTime.parse(reader.readLine(), formatter);
// ext.py and hg uses slightly different time formats
ZonedDateTime authored = null;
var date = reader.readLine();
try {
// ext.py
var formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd H:m:sZ");
authored = ZonedDateTime.parse(date, formatter);
} catch (DateTimeParseException e) {
// hg's rfc3339date
authored = ZonedDateTime.parse(date, DateTimeFormatter.ISO_OFFSET_DATE_TIME);
}

var messageSize = Integer.parseInt(reader.readLine());
var messageBuffer = reader.read(messageSize);
@@ -273,18 +273,16 @@ public List<CommitMetadata> commitMetadata(Hash from, Hash to, List<Path> paths,

@Override
public List<CommitMetadata> commitMetadata(String range, List<Path> paths, boolean reverse) throws IOException {
var ext = Files.createTempFile("ext", ".py");
copyResource(EXT_PY, ext);

var args = new ArrayList<String>();
args.addAll(List.of("hg", "--config", "extensions.dump=" + ext.toAbsolutePath().toString(), "metadata"));
var cmd = new ArrayList<String>();
cmd.addAll(List.of("hg", "log", "--template", HgCommitMetadata.TEMPLATE));
range = range == null ? "tip:0" : range;
var revset = reverse ? "reverse(" + range + ")" : range;
args.add(revset);
cmd.add("--rev");
cmd.add(revset);
if (paths != null && !paths.isEmpty()) {
args.add(paths.stream().map(Path::toString).collect(Collectors.joining("\t")));
cmd.addAll(paths.stream().map(Path::toString).collect(Collectors.toList()));
}
var p = start(args);
var p = start(cmd);
var reader = new UnixStreamReader(p.getInputStream());
var result = new ArrayList<CommitMetadata>();