Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(34)

Side by Side Diff: git-crrev-parse

Issue 868943002: Convenience git extension for converting a chromium git commit number to a git hash. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Fix grep string for git rev-list Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/env bash
2 # Copyright 2015 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5
6
7 # This git extension converts a chromium commit number to its git commit hash.
8 # It accepts the following input formats:
9 #
10 # $ git crrev-parse Cr-Commit-Position: refs/heads/master@{#311769}
11 # $ git crrev-parse ' Cr-Commit-Position: refs/heads/master@{#311769}'
12 # $ git crrev-parse 'Cr-Commit-Position: refs/heads/master@{#311769}'
13 # $ git crrev-parse refs/heads/master@{#311769}
14 #
15 # It also works for branches (assuming you have branches in your local
16 # checkout):
17 #
18 # $ git crrev-parse refs/branch-heads/2278@{#2}
19 #
20 # If you don't specify a branch, refs/heads/master is assumed:
21 #
22 # $ git crrev-parse @{#311769}
23 # $ git crrev-parse 311769
24
25 # Developer note: this script makes heavy use of prefix/suffix/pattern
26 # substitution for bash variables. Refer to the "Parameter Expansion"
27 # section of the man page for bash.
28
29 while [ -n "$1" ]; do
30 if [[ "$1" = "Cr-Commit-Position:" ]] && [[ "$2" =~ .*@\{#[0-9][0-9]*\} ]]; th en
31 commit_pos="$2"
32 shift
33 else
34 commit_pos="${1#*Cr-Commit-Position: }"
35 fi
36 ref="${commit_pos%@\{#*\}}"
37 if [ "$ref" = "$commit_pos" -o -z "$ref" ]; then
38 ref="refs/heads/master"
39 fi
40 remote_ref="${ref/refs\/heads/refs\/remotes\/origin}"
tfarina 2015/12/03 00:36:51 For some reason this does not work on my setup. T
41 remote_ref="${remote_ref/refs\/branch-heads/refs\/remotes\/branch-heads}"
42 num="${commit_pos#*@\{\#}"
43 num="${num%\}}"
44
45 if [ -z "$ref" -o -z "$num" ]; then
46 git rev-parse "$1"
47 else
48 grep_str="Cr-Commit-Position: $ref@{#$num}"
49 git rev-list -n 1 --grep="$grep_str" "$remote_ref"
50 fi
51
52 shift
53 done
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698