@@ -111,13 +111,6 @@ class Commit
111
111
*/
112
112
private $ message ;
113
113
114
- /**
115
- * Short message of the commit.
116
- *
117
- * @var string
118
- */
119
- private $ shortMessage ;
120
-
121
114
/**
122
115
* Constructor.
123
116
*
@@ -266,36 +259,47 @@ public function getLastModification($path, $lastHash = null)
266
259
}
267
260
268
261
/**
269
- * Returns the first line of the commit, and the first 80 characters.
262
+ * Returns the first line of the commit, and the first 50 characters.
263
+ *
264
+ * Ported from https://github.com/fabpot/Twig-extensions/blob/d67bc7e69788795d7905b52d31188bbc1d390e01/lib/Twig/Extensions/Extension/Text.php#L52-L109
265
+ *
266
+ * @param integer $length
267
+ * @param boolean $preserve
268
+ * @param string $separator
270
269
*
271
270
* @return string
272
271
*/
273
- public function getShortMessage ($ limit = 50 )
272
+ public function getShortMessage ($ length = 50 , $ preserve = false , $ separator = ' ... ' )
274
273
{
275
274
$ this ->initialize ();
276
275
277
- if (null !== $ this ->shortMessage ) {
278
- return $ this ->shortMessage ;
279
- }
276
+ $ message = $ this ->getSubjectMessage ();
280
277
281
- $ pos = mb_strpos ($ this ->message , "\n" );
282
- $ length = mb_strlen ($ this ->message );
278
+ if (function_exists ('mb_substr ' )) {
279
+ if (mb_strlen ($ message ) > $ length ) {
280
+ if ($ preserve ) {
281
+ if (false !== ($ breakpoint = mb_strpos ($ message , ' ' , $ length ))) {
282
+ $ length = $ breakpoint ;
283
+ }
284
+ }
283
285
284
- if (false === $ pos ) {
285
- if ($ length < $ limit ) {
286
- $ shortMessage = $ this ->message ;
287
- } else {
288
- $ shortMessage = mb_substr ($ this ->message , 0 , $ limit ).'... ' ;
286
+ return rtrim (mb_substr ($ message , 0 , $ length )) . $ separator ;
289
287
}
288
+
289
+ return $ message ;
290
290
} else {
291
- if ($ pos < $ limit ) {
292
- $ shortMessage = mb_substr ($ this ->message , 0 , $ pos );
293
- } else {
294
- $ shortMessage = mb_substr ($ this ->message , 0 , $ limit ).'... ' ;
291
+ if (strlen ($ message ) > $ length ) {
292
+ if ($ preserve ) {
293
+ if (false !== ($ breakpoint = strpos ($ message , ' ' , $ length ))) {
294
+ $ length = $ breakpoint ;
295
+ }
296
+ }
297
+
298
+ return rtrim (substr ($ message , 0 , $ length )) . $ separator ;
295
299
}
296
- }
297
300
298
- return $ this ->shortMessage = $ shortMessage ;
301
+ return $ message ;
302
+ }
299
303
}
300
304
301
305
/**
0 commit comments