<commit_before>/*
 * Copyright 2000-2009 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.intellij.openapi.vcs.history;

import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.ide.CopyPasteManager;
import com.intellij.openapi.project.DumbAwareAction;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vcs.VcsDataKeys;
import com.intellij.util.Function;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;

import java.awt.datatransfer.StringSelection;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public class CopyRevisionNumberAction extends DumbAwareAction {

  @Override
  public void actionPerformed(@NotNull AnActionEvent e) {
    List<VcsRevisionNumber> revisions = getRevisionNumbersFromContext(e);
    revisions = ContainerUtil.reverse(revisions); // we want hashes from old to new, e.g. to be able to pass to native client in terminal
    CopyPasteManager.getInstance().setContents(new StringSelection(getHashesAsString(revisions)));
  }

  @NotNull
  private static List<VcsRevisionNumber> getRevisionNumbersFromContext(@NotNull AnActionEvent e) {
    VcsRevisionNumber[] revisionNumbers = e.getData(VcsDataKeys.VCS_REVISION_NUMBERS);
    if (revisionNumbers != null) {
      return Arrays.asList(revisionNumbers);
    }

    VcsRevisionNumber revision = e.getData(VcsDataKeys.VCS_REVISION_NUMBER);
    if (revision != null) {
      return Collections.singletonList(revision);
    }

    VcsFileRevision[] fileRevisions = e.getData(VcsDataKeys.VCS_FILE_REVISIONS);
    if (fileRevisions != null) {
      return ContainerUtil.map(fileRevisions, new Function<VcsFileRevision, VcsRevisionNumber>() {
        @Override
        public VcsRevisionNumber fun(VcsFileRevision revision) {
          return revision.getRevisionNumber();
        }
      });
    }
    return Collections.emptyList();
  }

  @NotNull
  private static String getHashesAsString(@NotNull List<VcsRevisionNumber> revisions) {
    return StringUtil.join(revisions, new Function<VcsRevisionNumber, String>() {
      @Override
      public String fun(VcsRevisionNumber revision) {
        return revision instanceof ShortVcsRevisionNumber ? ((ShortVcsRevisionNumber)revision).toShortString() : revision.asString();
      }
    }, " ");
  }

  @Override
  public void update(@NotNull AnActionEvent e) {
    super.update(e);
    e.getPresentation().setEnabled(!getRevisionNumbersFromContext(e).isEmpty());
  }
}<commit_msg>[vcs] IDEA-131714 copy full revision number at least until the option is available for user and/or we guarantee that the short hash we give is enough.<commit_after>/*
 * Copyright 2000-2009 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.intellij.openapi.vcs.history;

import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.ide.CopyPasteManager;
import com.intellij.openapi.project.DumbAwareAction;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vcs.VcsDataKeys;
import com.intellij.util.Function;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;

import java.awt.datatransfer.StringSelection;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public class CopyRevisionNumberAction extends DumbAwareAction {

  @Override
  public void actionPerformed(@NotNull AnActionEvent e) {
    List<VcsRevisionNumber> revisions = getRevisionNumbersFromContext(e);
    revisions = ContainerUtil.reverse(revisions); // we want hashes from old to new, e.g. to be able to pass to native client in terminal
    CopyPasteManager.getInstance().setContents(new StringSelection(getHashesAsString(revisions)));
  }

  @NotNull
  private static List<VcsRevisionNumber> getRevisionNumbersFromContext(@NotNull AnActionEvent e) {
    VcsRevisionNumber[] revisionNumbers = e.getData(VcsDataKeys.VCS_REVISION_NUMBERS);
    if (revisionNumbers != null) {
      return Arrays.asList(revisionNumbers);
    }

    VcsRevisionNumber revision = e.getData(VcsDataKeys.VCS_REVISION_NUMBER);
    if (revision != null) {
      return Collections.singletonList(revision);
    }

    VcsFileRevision[] fileRevisions = e.getData(VcsDataKeys.VCS_FILE_REVISIONS);
    if (fileRevisions != null) {
      return ContainerUtil.map(fileRevisions, new Function<VcsFileRevision, VcsRevisionNumber>() {
        @Override
        public VcsRevisionNumber fun(VcsFileRevision revision) {
          return revision.getRevisionNumber();
        }
      });
    }
    return Collections.emptyList();
  }

  @NotNull
  private static String getHashesAsString(@NotNull List<VcsRevisionNumber> revisions) {
    return StringUtil.join(revisions, new Function<VcsRevisionNumber, String>() {
      @Override
      public String fun(VcsRevisionNumber revision) {
        return revision.asString();
      }
    }, " ");
  }

  @Override
  public void update(@NotNull AnActionEvent e) {
    super.update(e);
    e.getPresentation().setEnabled(!getRevisionNumbersFromContext(e).isEmpty());
  }
}
{'fraction_non_alphanumeric': 0.0917490679202464, 'fraction_numerical': 0.004863024801426487, 'mean_word_length': 4.450530035335689, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5567141', 'n_tokens_mistral': 1853, 'n_tokens_neox': 1758, 'n_words': 459}