#!/bin/sh # # Copyright (c) SAS Institute Inc. # # 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. # global hgDir := "$[dirname $0]/.." if [[ -x /usr/bin/hg && -d $hgDir/.hg ]] { global rev := $[hg id -i] } elif test -f $hgDir/.hg_archival.txt { global rev := $[grep node $hgDir/.hg_archival.txt |cut -d' ' -f 2 |head -c 12]; } else { global rev := '' ; } ; echo $rev (CommandList children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:hgDir) op: Equal rhs: { (CommandSubPart command_list: (CommandList children:[(C {(dirname)} {($ VSub_Number "$0")})]) left_token: spids: [51 55] ) (/..) } spids: [50] ) ] spids: [50] ) (Sentence child: (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (LogicalAnd left: (BoolUnary op_id:BoolUnary_x child:{(/usr/bin/hg)}) right: (BoolUnary op_id:BoolUnary_d child:{($ VSub_Name "$hgDir") (/.hg)}) ) ) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:rev) op: Equal rhs: { (CommandSubPart command_list: (CommandList children:[(C {(hg)} {(id)} {(-i)})]) left_token: spids: [81 87] ) } spids: [80] ) ] spids: [80] ) ] spids: [-1 77] ) (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {(-f)} {($ VSub_Name "$hgDir") (/.hg_archival.txt)} {(Lit_Other "]")} ) terminator: ) ] action: [ (Sentence child: (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:rev) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(grep)} {(node)} {($ VSub_Name "$hgDir") (/.hg_archival.txt)} ) (C {(cut)} {(-d) (SQ <" ">)} {(-f)} {(2)}) (C {(head)} {(-c)} {(12)}) ] negated: False ) ] ) left_token: spids: [105 131] ) } spids: [104] ) ] spids: [104] ) terminator: ) ] spids: [89 101] ) ] else_action: [ (Sentence child: (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:rev) op:Equal rhs:{(SQ )} spids:[137])] spids: [137] ) terminator: ) ] spids: [134 141] ) terminator: ) (C {(echo)} {(DQ ($ VSub_Name "$rev"))}) ] )