From c57d4d2c897eb89254a37a4b8a27f9807653f9e2 Mon Sep 17 00:00:00 2001 From: Alexander Chow Date: Tue, 1 Aug 2017 14:32:04 -0700 Subject: [PATCH] Change closest SVN ancestor command to use ancestor feature Summary: Change closest SVN ancestor command to use ancestor feature Differential Revision: D5006957 fbshipit-source-id: a1d5597121552a0d189441680bfeb4f223e22019 --- hphp/hack/src/utils/hg/hg.ml | 47 ++++++++++++++++++-------------------------- 1 file changed, 19 insertions(+), 28 deletions(-) diff --git a/hphp/hack/src/utils/hg/hg.ml b/hphp/hack/src/utils/hg/hg.ml index 2cb91284f47..2fb3e52aaa7 100644 --- a/hphp/hack/src/utils/hg/hg.ml +++ b/hphp/hack/src/utils/hg/hg.ml @@ -10,38 +10,29 @@ (** Tools for shelling out to Mercurial. *) -open Core - module Hg_actual = struct include Hg_sig.Types - (** Returns the closest SVN ancestor to the hg revision. - * - * hg log -r 'reverse(::)' -T '{svnrev}\n' -l 150 --cwd * - * Note: The output is a newline-separated list of corresponding SVN - * revision numbers of the ancestors. For each ancestor that does NOT have - * a corresponding SVN revision, a blankline is printed. So we use "-l 150" - * to print up to 150 ancestors that might be newlines, filter away the - * blanks, and return the first result. - *) - let get_closest_svn_ancestor hg_rev repo = - let process = Process.exec "hg" [ - "log"; - "-r"; - Printf.sprintf "reverse(::%s)" hg_rev; - "-T"; - "{svnrev}\n"; - "-l"; - "150"; - "--cwd"; - repo; - ] - in - Future.make process @@ fun result -> - let lines = Sys_utils.split_lines result in - let nonempty str = String.length str > 0 in - List.filter lines ~f:nonempty |> List.hd_exn +(** Returns the closest SVN ancestor in master to the given hg rev. + * + * hg log -r 'ancestor(master,hg_rev)' -T '{svnrev}\n' + * + * Note: hg_rev only works in short form from `hg id -i` (see below) + * and not the full hash form from `hg --debug id -i` + *) +let get_closest_svn_ancestor hg_rev repo = + let process = Process.exec "hg" [ + "log"; + "-r"; + Printf.sprintf "ancestor(master,%s)" hg_rev; + "-T"; + "{svnrev}\n"; + "--cwd"; + repo; + ] + in + Future.make process String.trim (** Get the hg revision hash of the current working copy in the repo dir. * -- 2.11.4.GIT