コード例 #1
0
        private async Task <string> DownloadFromScpAsync(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 = await GerritUtil.RunGerritCommandAsync(
                _mainForm,
                _gitUiCommands.GitModule,
                "scp -f hooks/commit-msg",
                settings.DefaultRemote,
                new byte[] { 0, 0, 0, 0, 0, 0, 0 }).ConfigureAwait(false);

            // 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, "index == content.Length - 1");

            if (index != -1)
            {
                content = content.Substring(0, index);
            }

            return(content);
        }
コード例 #2
0
        private async Task <JObject> LoadReviewInfoAsync()
        {
            var fetchUrl = GerritUtil.GetFetchUrl(Module, _currentBranchRemote);

            string projectName = fetchUrl.AbsolutePath.TrimStart('/');

            if (projectName.EndsWith(".git"))
            {
                projectName = projectName.Substring(0, projectName.Length - 4);
            }

            string change = await GerritUtil
                            .RunGerritCommandAsync(
                this,
                Module,
                string.Format(
                    "gerrit query --format=JSON project:{0} --current-patch-set change:{1}",
                    projectName,
                    _NO_TRANSLATE_Change.Text),
                fetchUrl,
                _currentBranchRemote,
                stdIn: null)
                            .ConfigureAwait(false);

            foreach (string line in change.Split('\n'))
            {
                try
                {
                    return(JObject.Parse(line));
                }
                catch
                {
                    // Ignore exceptions.
                }
            }

            return(null);
        }