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

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: 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 # $ git crrev-parse 311769
25
26
27 while [ -n "$1" ]; do
28 if [[ "$1" = "Cr-Commit-Position:" ]] && [[ "$2" =~ .*@\{#[0-9][0-9]*\} ]]; th en
29 commit_pos="$2"
30 shift
31 else
32 commit_pos="${1#*Cr-Commit-Position: }"
33 fi
34 ref="${commit_pos%@\{#*\}}"
35 if [ "$ref" = "$commit_pos" -o -z "$ref" ]; then
36 ref="refs/heads/master"
37 fi
38 ref="${ref/refs\/heads/refs\/remotes\/origin}"
39 ref="${ref/refs\/branch-heads/refs\/remotes\/branch-heads}"
40 num="${commit_pos#*@\{\#}"
41 num="${num%\}}"
42
43 if [ -z "$ref" -o -z "$num" ]; then
44 git rev-parse "$1"
45 else
46 git rev-list -n 1 --grep="$commit_pos" "$ref"
ghost stip (do not use) 2015/01/23 00:03:27 reconstruct commit_pos when grepping to reduce fal
szager1 2015/01/23 00:53:45 Done.
47 fi
48
49 shift
50 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