Mercurial > hg > mercurial
changeset 741:fba173530aa6
close openned files. fix temp polution
author | eugene.petrenko@jetbrains.com |
---|---|
date | Fri, 24 Jan 2014 22:18:19 +0100 |
parents | 7fe4a31c5a76 |
children | 091667cc54d5 |
files | mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/CommitsAndMountPointsParser.java |
diffstat | 1 files changed, 55 insertions(+), 49 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/CommitsAndMountPointsParser.java Thu Jan 23 16:25:48 2014 +0100 +++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/CommitsAndMountPointsParser.java Fri Jan 24 22:18:19 2014 +0100 @@ -16,6 +16,7 @@ package jetbrains.buildServer.buildTriggers.vcs.mercurial.command; +import jetbrains.buildServer.util.FileUtil; import org.apache.commons.codec.binary.Base64; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -34,20 +35,23 @@ public static void parseFileLog(@NotNull final File dump, @NotNull final ContentsConsumer consumer) throws IOException { - final InputStream is = new BufferedInputStream(new FileInputStream(dump)); + final BufferedReader st = new BufferedReader(new InputStreamReader(new BufferedInputStream(new FileInputStream(dump)), "utf-8")); + try { + final Decoder fileDecoder = new Decoder(5); - final Decoder fileDecoder = new Decoder(5); - final BufferedReader st = new BufferedReader(new InputStreamReader(is, "utf-8")); - String line; - while((line = st.readLine()) != null) { - if (!line.startsWith("$$@@@@ ")) continue; - final String[] items = line.split(" "); - if (items.length != 1 + 2) continue; + String line; + while((line = st.readLine()) != null) { + if (!line.startsWith("$$@@@@ ")) continue; + final String[] items = line.split(" "); + if (items.length != 1 + 2) continue; - final String commitId = items[1]; - final String content = fileDecoder.decode(items[2]); + final String commitId = items[1]; + final String content = fileDecoder.decode(items[2]); - consumer.onCommit(commitId, content == null ? "" : content); + consumer.onCommit(commitId, content == null ? "" : content); + } + } finally { + FileUtil.close(st); } } @@ -75,53 +79,55 @@ public static void parseCommits(@NotNull final File dump, @NotNull final CommitsConsumer consumer) throws IOException { final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'Z'HH:mm:ss'T'Z", Locale.ENGLISH); - final InputStream is = new BufferedInputStream(new FileInputStream(dump)); - final Decoder branchDecoder = new Decoder(250); final Decoder tagsDecoder = new Decoder(250); final Decoder authorDecoder = new Decoder(200); final Decoder messageDecoder = new Decoder(210); - final BufferedReader st = new BufferedReader(new InputStreamReader(is, "utf-8")); - String line; - while((line = st.readLine()) != null) { - if (!line.startsWith("$$@@@@ ")) continue; - final Iterator<String> items = Arrays.asList(line.split(" ")).iterator(); - items.next(); //$$@@@@ + final BufferedReader st = new BufferedReader(new InputStreamReader(new BufferedInputStream(new FileInputStream(dump)), "utf-8")); + try { + String line; + while((line = st.readLine()) != null) { + if (!line.startsWith("$$@@@@ ")) continue; + final Iterator<String> items = Arrays.asList(line.split(" ")).iterator(); + items.next(); //$$@@@@ - try { - final String commitNum = items.next(); - final String commitId = items.next(); - final String[] parents = new String[Integer.parseInt(items.next())]; - for (int i = 0; i < parents.length; i++) { - parents[i] = items.next(); - } - final String branch = branchDecoder.decode(items.next()); - final String[] tags = new String[Integer.parseInt(items.next())]; - for (int i = 0; i < tags.length; i++) { - tags[i] = tagsDecoder.decode(items.next()); - } + try { + final String commitNum = items.next(); + final String commitId = items.next(); + final String[] parents = new String[Integer.parseInt(items.next())]; + for (int i = 0; i < parents.length; i++) { + parents[i] = items.next(); + } + final String branch = branchDecoder.decode(items.next()); + final String[] tags = new String[Integer.parseInt(items.next())]; + for (int i = 0; i < tags.length; i++) { + tags[i] = tagsDecoder.decode(items.next()); + } - final String author = authorDecoder.decode(items.next()); - final String message = messageDecoder.decode(items.next()); - final Date time = parseTime(dateFormat, items.next()); - final String hgsub = textOrNull(items.next()); - final String hgsubstate = textOrNull(items.next()); + final String author = authorDecoder.decode(items.next()); + final String message = messageDecoder.decode(items.next()); + final Date time = parseTime(dateFormat, items.next()); + final String hgsub = textOrNull(items.next()); + final String hgsubstate = textOrNull(items.next()); - consumer.onCommit( - commitNum, - commitId, - parents, - branch, - tags, - author == null ? "" : author, - message == null ? "" : message, - time, - hgsub, - hgsubstate); - } catch (NoSuchElementException e) { - //NOP + consumer.onCommit( + commitNum, + commitId, + parents, + branch, + tags, + author == null ? "" : author, + message == null ? "" : message, + time, + hgsub, + hgsubstate); + } catch (NoSuchElementException e) { + //NOP + } } + } finally{ + FileUtil.close(st); } }