@@ -831,16 +831,40 @@ static void execute_commands(struct command *commands,
831
831
"the reported refs above" );
832
832
}
833
833
834
+ static struct command * * queue_command (struct command * * tail ,
835
+ const char * line ,
836
+ int linelen )
837
+ {
838
+ unsigned char old_sha1 [20 ], new_sha1 [20 ];
839
+ struct command * cmd ;
840
+ const char * refname ;
841
+ int reflen ;
842
+
843
+ if (linelen < 83 ||
844
+ line [40 ] != ' ' ||
845
+ line [81 ] != ' ' ||
846
+ get_sha1_hex (line , old_sha1 ) ||
847
+ get_sha1_hex (line + 41 , new_sha1 ))
848
+ die ("protocol error: expected old/new/ref, got '%s'" , line );
849
+
850
+ refname = line + 82 ;
851
+ reflen = linelen - 82 ;
852
+ cmd = xcalloc (1 , sizeof (struct command ) + reflen + 1 );
853
+ hashcpy (cmd -> old_sha1 , old_sha1 );
854
+ hashcpy (cmd -> new_sha1 , new_sha1 );
855
+ memcpy (cmd -> ref_name , refname , reflen );
856
+ cmd -> ref_name [reflen ] = '\0' ;
857
+ * tail = cmd ;
858
+ return & cmd -> next ;
859
+ }
860
+
834
861
static struct command * read_head_info (struct sha1_array * shallow )
835
862
{
836
863
struct command * commands = NULL ;
837
864
struct command * * p = & commands ;
838
865
for (;;) {
839
866
char * line ;
840
- unsigned char old_sha1 [20 ], new_sha1 [20 ];
841
- struct command * cmd ;
842
- char * refname ;
843
- int len , reflen , linelen ;
867
+ int len , linelen ;
844
868
845
869
line = packet_read_line (0 , & len );
846
870
if (!line )
@@ -866,23 +890,7 @@ static struct command *read_head_info(struct sha1_array *shallow)
866
890
quiet = 1 ;
867
891
}
868
892
869
- if (linelen < 83 ||
870
- line [40 ] != ' ' ||
871
- line [81 ] != ' ' ||
872
- get_sha1_hex (line , old_sha1 ) ||
873
- get_sha1_hex (line + 41 , new_sha1 ))
874
- die ("protocol error: expected old/new/ref, got '%s'" ,
875
- line );
876
-
877
- refname = line + 82 ;
878
- reflen = linelen - 82 ;
879
- cmd = xcalloc (1 , sizeof (struct command ) + reflen + 1 );
880
- hashcpy (cmd -> old_sha1 , old_sha1 );
881
- hashcpy (cmd -> new_sha1 , new_sha1 );
882
- memcpy (cmd -> ref_name , refname , reflen );
883
- cmd -> ref_name [reflen ] = '\0' ;
884
- * p = cmd ;
885
- p = & cmd -> next ;
893
+ p = queue_command (p , line , linelen );
886
894
}
887
895
return commands ;
888
896
}
0 commit comments