From: Nicholas Chmielewski Date: Wed, 15 Oct 2014 04:34:12 GMT Subject: Expected bug with reset --hard Message-ID: git version 1.9.1 & version 2.1.2 I had some changes in a tracked file that I wanted to discard. Instead of using checkout, I instead used `git reset --hard HEAD` to reset. Git returned the message `HEAD is now at ` I then went `git status` and it showed me that I still have changes to commit I expected there to be no changes in my working directory as a result of doing a `git reset --hard` I did a little more fiddling around and still yielded the same results. - `$ touch file.md` - `$ git add file.md` - `$ git commit -m 'empty file'` - `$ echo 'text' > file.md` At this point git reported that I had uncommited changes for both file.md and the troublesome file in question (jquery.datatables.js) `$ git reset --hard HEAD` Git now no longer reports and untracked changes for file.md but still for jquery.datatables.js `$ git reset --hard HEAD~1` Git still reports untracked changes for jquery.datatables.js I have included a copy of the diff of the jquery.datatables.js diff --git a/vendor/assets/javascripts/jquery.datatables.js b/vendor/assets/javascripts/jquery.datatables.js index b9044f1..4aab04b 100644 --- a/vendor/assets/javascripts/jquery.datatables.js +++ b/vendor/assets/javascripts/jquery.datatables.js @@ -1,11 +1,11 @@ -/*! DataTables 1.10.1 - * ©2008-2014 SpryMedia Ltd - datatables.net/license +/*! DataTables 1.10.3 + * ©2008-2014 SpryMedia Ltd - datatables.net/license */ /** * @summary DataTables * @description Paginate, search and order HTML tables - * @version 1.10.1 + * @version 1.10.3 * @file jquery.dataTables.js * @author SpryMedia Ltd (www.sprymedia.co.uk) * @contact www.sprymedia.co.uk/contact @@ -113,7 +113,7 @@ // U+2009 is thin space and U+202F is narrow no-break space, both used in many // standards as thousands separators - var _re_formatted_numeric = /[',$£€¥%\u2009\u202F]/g; + var _re_formatted_numeric = /[',$£€¥%\u2009\u202F]/g; var _empty = function ( d ) { @@ -133,7 +133,7 @@ if ( ! _re_dic[ decimalPoint ] ) { _re_dic[ decimalPoint ] = new RegExp( _fnEscapeRegex( decimalPoint ), 'g' ); } - return typeof num === 'string' ? + return typeof num === 'string' && decimalPoint !== '.' ? num.replace( /\./g, '' ).replace( _re_dic[ decimalPoint ], '.' ) : num; }; @@ -310,7 +310,6 @@ newKey = key.replace( match[0], match[2].toLowerCase() ); map[ newKey ] = key; - //console.log( key, match ); if ( match[1] === 'o' ) { _fnHungarianMap( o[key] ); @@ -673,6 +672,12 @@ return _fnSetObjectDataFn( mDataSrc )( rowData, val, meta ); }; + // Indicate if DataTables should read DOM data as an object or array + // Used in _fnGetRowElements + if ( typeof mDataSrc !== 'number' ) { + oSettings._rowReadObject = true; + } + /* Feature sorting overrides column specific when off */ if ( !oSettings.oFeatures.bSort ) { @@ -1498,19 +1503,22 @@ function _fnGetRowElements( settings, row ) { var - d = [], tds = [], td = row.firstChild, name, col, o, i=0, contents, - columns = settings.aoColumns; + columns = settings.aoColumns, + objectRead = settings._rowReadObject; - var attr = function ( str, data, td ) { + var d = objectRead ? {} : []; + + var attr = function ( str, td ) { if ( typeof str === 'string' ) { var idx = str.indexOf('@'); if ( idx !== -1 ) { - var src = str.substring( idx+1 ); - o[ '@'+src ] = td.getAttribute( src ); + var attr = str.substring( idx+1 ); + var setter = _fnSetObjectDataFn( str ); + setter( d, td.getAttribute( attr ) ); } } }; @@ -1520,18 +1528,26 @@ contents = $.trim(cell.innerHTML); if ( col && col._bAttrSrc ) { - o = { - display: contents - }; + var setter = _fnSetObjectDataFn( col.mData._ ); + setter( d, contents ); - attr( col.mData.sort, o, cell ); - attr( col.mData.type, o, cell ); - attr( col.mData.filter, o, cell ); - - d.push( o ); + attr( col.mData.sort, cell ); + attr( col.mData.type, cell ); + attr( col.mData.filter, cell ); } else { - d.push( contents ); + // Depending on the `data` option for the columns the data can be + // read to either an object or an array. + if ( objectRead ) { + if ( ! col._setter ) { + // Cache the setter function + col._setter = _fnSetObjectDataFn( col.mData ); + } + col._setter( d, contents ); + } + else { + d.push( contents ); + } } i++; @@ -1950,7 +1966,9 @@ } } - /* Row callback functions - might want to manipulate the row */ + // Row callback functions - might want to manipulate the row + // iRowCount and j are not currently documented. Are they at all + // useful? _fnCallbackFire( oSettings, 'aoRowCallback', null, [nRow, aoData._aData, iRowCount, j] ); @@ -2695,13 +2713,20 @@ _fnDraw( settings ); } }; + + var searchDelay = settings.searchDelay !== null ? + settings.searchDelay : + _fnDataSource( settings ) === 'ssp' ? + 400 : + 0; + var jqFilter = $('input', filter) .val( previousSearch.sSearch ) .attr( 'placeholder', language.sSearchPlaceholder ) .bind( 'keyup.DT search.DT input.DT paste.DT cut.DT', - _fnDataSource( settings ) === 'ssp' ? - _fnThrottle( searchFn, 400 ): + searchDelay ? + _fnThrottle( searchFn, searchDelay ) : searchFn ) .bind( 'keypress.DT', function(e) { @@ -2924,9 +2949,12 @@ * ^(?=.*?\bone\b)(?=.*?\btwo three\b)(?=.*?\bfour\b).*$ */ var a = $.map( search.match( /"[^"]+"|[^ ]+/g ) || '', function ( word ) { - return word.charAt(0) === '"' ? - word.match( /^"(.*)"$/ )[1] : - word; + if ( word.charAt(0) === '"' ) { + var m = word.match( /^"(.*)"$/ ); + word = m ? m[1] : word; + } + + return word.replace('"', ''); } ); search = '^(?=.*?'+a.join( ')(?=.*?' )+').*$'; @@ -2973,34 +3001,40 @@ if ( column.bSearchable ) { cellData = _fnGetCellData( settings, i, j, 'filter' ); - cellData = fomatters[ column.sType ] ? - fomatters[ column.sType ]( cellData ) : - cellData !== null ? - cellData : - ''; + if ( fomatters[ column.sType ] ) { + cellData = fomatters[ column.sType ]( cellData ); + } + + // Search in DataTables 1.10 is string based. In 1.11 this + // should be altered to also allow strict type checking. + if ( cellData === null ) { + cellData = ''; + } + + if ( typeof cellData !== 'string' && cellData.toString ) { + cellData = cellData.toString(); + } } else { cellData = ''; } - if ( cellData ) { - // If it looks like there is an HTML entity in the string, - // attempt to decode it so sorting works as expected. Note that - // we could use a single line of jQuery to do this, but the DOM - // method used here is much faster http://jsperf.com/html-decode - if ( cellData.indexOf && cellData.indexOf('&') !== -1 ) { - __filter_div.innerHTML = cellData; - cellData = __filter_div_textContent ? - __filter_div.textContent : - __filter_div.innerText; - } - - if ( cellData.replace ) { - cellData = cellData.replace(/[\r\n]/g, ''); - } + // If it looks like there is an HTML entity in the string, + // attempt to decode it so sorting works as expected. Note that + // we could use a single line of jQuery to do this, but the DOM + // method used here is much faster http://jsperf.com/html-decode + if ( cellData.indexOf && cellData.indexOf('&') !== -1 ) { + __filter_div.innerHTML = cellData; + cellData = __filter_div_textContent ? + __filter_div.textContent : + __filter_div.innerText; + } - filterData.push( cellData ); + if ( cellData.replace ) { + cellData = cellData.replace(/[\r\n]/g, ''); } + + filterData.push( cellData ); } row._aFilterData = filterData; @@ -4162,7 +4196,7 @@ */ function _fnThrottle( fn, freq ) { var - frequency = freq || 200, + frequency = freq !== undefined ? freq : 200, last, timer; @@ -4403,11 +4437,15 @@ iCol = aDataSort[k]; sType = aoColumns[ iCol ].sType || 'string'; + if ( nestedSort[i]._idx === undefined ) { + nestedSort[i]._idx = $.inArray( nestedSort[i][1], aoColumns[iCol].asSorting ); + } + aSort.push( { src: srcCol, col: iCol, dir: nestedSort[i][1], - index: nestedSort[i][2], + index: nestedSort[i]._idx, type: sType, formatter: DataTable.ext.type.order[ sType+"-pre" ] } ); @@ -4610,13 +4648,17 @@ var sorting = settings.aaSorting; var asSorting = col.asSorting; var nextSortIdx; - var next = function ( a ) { + var next = function ( a, overflow ) { var idx = a._idx; if ( idx === undefined ) { idx = $.inArray( a[1], asSorting ); } - return idx+1 >= asSorting.length ? 0 : idx+1; + return idx+1 < asSorting.length ? + idx+1 : + overflow ? + null : + 0; }; // Convert to 2D array if needed @@ -4631,10 +4673,15 @@ if ( sortIdx !== -1 ) { // Yes, modify the sort - nextSortIdx = next( sorting[sortIdx] ); + nextSortIdx = next( sorting[sortIdx], true ); - sorting[sortIdx][1] = asSorting[ nextSortIdx ]; - sorting[sortIdx]._idx = nextSortIdx; + if ( nextSortIdx === null ) { + sorting.splice( sortIdx, 1 ); + } + else { + sorting[sortIdx][1] = asSorting[ nextSortIdx ]; + sorting[sortIdx]._idx = nextSortIdx; + } } else { // No sort on this column yet @@ -5113,7 +5160,7 @@ len = settings._iDisplayLength; /* If we have space to show extra rows (backing up from the end point - then do so */ - if ( end === settings.fnRecordsDisplay() ) + if (start >= end) { start = end - len; } @@ -6089,6 +6136,7 @@ "fnStateLoadCallback", "fnStateSaveCallback", "renderer", + "searchDelay", [ "iCookieDuration", "iStateDuration" ], // backwards compat [ "oSearch", "oPreviousSearch" ], [ "aoSearchCols", "aoPreSearchCols" ], @@ -6719,8 +6767,10 @@ } for ( i=0, ien=context.length ; i= 0 ? selInt : // Count from left columns.length + selInt // Count from right (+ because its a negative value) ]; } - else { - var match = typeof s === 'string' ? - s.match( __re_column_selector ) : - ''; - - if ( match ) { - switch( match[2] ) { - case 'visIdx': - case 'visible': - var idx = parseInt( match[1], 10 ); - // Visible index given, convert to column index - if ( idx < 0 ) { - // Counting from the right - var visColumns = $.map( columns, function (col,i) { - return col.bVisible ? i : null; - } ); - return [ visColumns[ visColumns.length + idx ] ]; - } - // Counting from the left - return [ _fnVisibleToColumnIndex( settings, idx ) ]; + + // Selector = function + if ( typeof s === 'function' ) { + var rows = _selector_row_indexes( settings, opts ); + + return $.map( columns, function (col, idx) { + return s( + idx, + __columnData( settings, idx, 0, 0, rows ), + nodes[ idx ] + ) ? idx : null; + } ); + } - case 'name': - // match by name. `names` is column index complete and in order - return $.map( names, function (name, i) { - return name === match[1] ? i : null; + // jQuery or string selector + var match = typeof s === 'string' ? + s.match( __re_column_selector ) : + ''; + + if ( match ) { + switch( match[2] ) { + case 'visIdx': + case 'visible': + var idx = parseInt( match[1], 10 ); + // Visible index given, convert to column index + if ( idx < 0 ) { + // Counting from the right + var visColumns = $.map( columns, function (col,i) { + return col.bVisible ? i : null; } ); - } - } - else { - // jQuery selector on the TH elements for the columns - return $( nodes ) - .filter( s ) - .map( function () { - return $.inArray( this, nodes ); // `nodes` is column index complete and in order - } ) - .toArray(); + return [ visColumns[ visColumns.length + idx ] ]; + } + // Counting from the left + return [ _fnVisibleToColumnIndex( settings, idx ) ]; + + case 'name': + // match by name. `names` is column index complete and in order + return $.map( names, function (name, i) { + return name === match[1] ? i : null; + } ); } } + else { + // jQuery selector on the TH elements for the columns + return $( nodes ) + .filter( s ) + .map( function () { + return $.inArray( this, nodes ); // `nodes` is column index complete and in order + } ) + .toArray(); + } } ); }; - - - - var __setColumnVis = function ( settings, column, vis ) { + var __setColumnVis = function ( settings, column, vis, recalc ) { var cols = settings.aoColumns, col = cols[ column ], @@ -8094,12 +8174,14 @@ _fnDrawHead( settings, settings.aoHeader ); _fnDrawHead( settings, settings.aoFooter ); - // Automatically adjust column sizing - _fnAdjustColumnSizing( settings ); + if ( recalc === undefined || recalc ) { + // Automatically adjust column sizing + _fnAdjustColumnSizing( settings ); - // Realign columns for scrolling - if ( settings.oScroll.sX || settings.oScroll.sY ) { - _fnScrollDraw( settings ); + // Realign columns for scrolling + if ( settings.oScroll.sX || settings.oScroll.sY ) { + _fnScrollDraw( settings ); + } } _fnCallbackFire( settings, null, 'column-visibility', [settings, column, vis] ); @@ -8159,12 +8241,13 @@ * */ _api_registerPlural( 'columns().data()', 'column().data()', function () { - return this.iterator( 'column-rows', function ( settings, column, i, j, rows ) { - var a = []; - for ( var row=0, ien=rows.length ; row') .addClass( classes.sSortJUIWrapper ) .append( cell.contents() ) @@ -14217,6 +14373,8 @@ return; } + var colIdx = column.idx; + cell .removeClass( classes.sSortAsc +" "+classes.sSortDesc ) .addClass( columns[ colIdx ] == 'asc' ? @@ -14610,3 +14768,4 @@ })); }(window, document)); +