Skip to content
Permalink
Browse files
hg: use --template instead of ext.py for metadata
Reviewed-by: rwestberg
  • Loading branch information
edvbld committed Aug 25, 2020
1 parent 87141a3 commit d6a5ab49b4f8902892ae0d264071b6a93b989c3f
Showing 2 changed files with 40 additions and 10 deletions.
@@ -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>();

1 comment on commit d6a5ab4

@bridgekeeper
Copy link

@bridgekeeper bridgekeeper bot commented on d6a5ab4 Aug 25, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.