private string DownloadFromScp(GerritSettings settings) { // This is a very quick and dirty "implementation" of the scp // protocol. By sending the 0's as input, we trigger scp to // send the file. string content = GerritUtil.RunGerritCommand( _mainForm, _gitUiCommands.GitModule, "scp -f hooks/commit-msg", settings.DefaultRemote, new byte[] { 0, 0, 0, 0, 0, 0, 0 } ); // The first line of the output contains the file we're receiving // in a format like "C0755 4248 commit-msg". if (String.IsNullOrEmpty(content)) { return(null); } int index = content.IndexOf('\n'); if (index == -1) { return(null); } string header = content.Substring(0, index); if (!header.EndsWith(" commit-msg")) { return(null); } // This looks like a valid scp response; return the rest of the // response. content = content.Substring(index + 1); // The file should be terminated by a nul. index = content.LastIndexOf((char)0); Debug.Assert(index == content.Length - 1); if (index != -1) { content = content.Substring(0, index); } return(content); }
private JObject LoadReviewInfo() { var fetchUrl = GerritUtil.GetFetchUrl(Module, _currentBranchRemote); string projectName = fetchUrl.AbsolutePath.TrimStart('/'); if (projectName.EndsWith(".git")) { projectName = projectName.Substring(0, projectName.Length - 4); } string change = GerritUtil.RunGerritCommand( this, Module, String.Format( "gerrit query --format=JSON project:{0} --current-patch-set change:{1}", projectName, _NO_TRANSLATE_Change.Text ), fetchUrl, _currentBranchRemote, null ); foreach (string line in change.Split('\n')) { try { return(JObject.Parse(line)); } catch { // Ignore exceptions. } } return(null); }